Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 17th, 2010 | Syntax: None | Size: 4.40 KB | Hits: 31 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. <?php include("includes/session.php");
  2.  
  3. // functions :)
  4.  
  5.  
  6. // This checks if a error has been picked up in a posted value
  7. function checkerror($condition,$output) {
  8.         if($condition) {
  9.                 $errors[] = $output;   
  10.         }
  11.         return $errors;
  12. }
  13.  
  14. // This counts rows in a sql statement and returns an error if there is no rows
  15. function rowscount($sql) {
  16.         connectdb();
  17.         $query = mysql_query("$sql");
  18.         if(!$query) {
  19.                 trigger_error("A database error has occured.".mysql_error());  
  20.         }
  21.         $rows = mysql_num_rows($query);
  22.         if($rows == 0) {
  23.                 $errors[] = "There was no records found in the database to match your request. Please try again";      
  24.         }
  25.         return $errors;
  26. }
  27.  
  28. // This counts the errors and outputs them if there are any.
  29. function outputerror($errors) {
  30.         if(count($errors)) {
  31.                 echo "The following errors occured:";
  32.                 echo "<ul>";
  33.                         foreach($errors AS $error) {
  34.                                 echo "<li>$error</li>";
  35.                         }
  36.                 echo "Please <a href='".htmlentities($_SERVER['PHP_SELF'])."'>click here</a> to return to the previous page";
  37.         }
  38. }
  39.  
  40. // This SELECTS items from a databse and either outputs
  41.  
  42. function dbquery($sql) {
  43.         connectdb();
  44.         $query = mysql_query("$sql");
  45.         if(!$query) {
  46.                 trigger_error("There was an error with your sql".mysql_error());       
  47.         }
  48.                 return $query;
  49. }
  50.  
  51. // A option list based on fields in the db
  52.  
  53. function optiondisplay($sql,$returnvalue,$displayname) {
  54.         $query =& dbquery($sql);
  55.         while($result = mysql_fetch_assoc($query)) {
  56.                 echo "<option value'".$result["$returnvalue"]."'>".$result["$displayname"]."</option>";
  57.         }
  58. }
  59.  
  60.  
  61. ?>                                             
  62. <script type="text/javascript" src="ckeditor/ckeditor.js"></script>                                            
  63.     <body>
  64.         <div id="wrapper">
  65.                 <div id="header">
  66.                 </div>
  67.                 <div id="navigation">
  68.                   <?php include("includes/navigation.php"); ?>
  69.                 </div>
  70.                 <div id="content">
  71.                     <div class="content_block">
  72.                         <h3>SEND EMAIL</h3>
  73.                         <h2>Send a single email</h2>
  74.                         <hr />
  75.                         <?php
  76.                                                 if($_POST["singlemail"] == "submit") {
  77.                                                         $userid = $_POST["name"];
  78.                                                         $subject = $_POST["subject"];
  79.                                                         $message = $_POST["email"];
  80.                                                        
  81.                                                         // validate
  82.                                                         i see
  83.                                                         checkerror("!ctype_digit($userid) || $userid == \"\"", "The userID you selected is invalid, please try again");
  84.                                                         checkerror("$message == \"\"", "There was nothing entered in the email box, please try again");
  85.                                                         checkerror("$subject == \"\"", "There was nothing entered in the subject box, please try again");
  86.                                                         rowscount("SELECT id FROM contacts WHERE id = '$userid'");     
  87.                                                        
  88.                                                         // check if errors, then outputs
  89.                                                        
  90.                                                         echo outputerror($error);
  91.                                                        
  92.                                                         } else {
  93.                                                                 $query = dbquery("SELECT id, name, email FROM contacts WHERE id = '$userid'");
  94.                                                                 $row = mysql_fetch_assoc($query);
  95.                                                                 $email = $row["email"];
  96.                                                                 $name = $row["fullname"];
  97.                                                                 if(mail($email,$subject,$message)) {
  98.                                                                         echo "The email has been sent successfully to $name. Please <a href='".htmlentities($_SERVER['PHP_SELF'])."'>click here</a> to return to the send mail page</p>";
  99.                                                                 } else {
  100.                                                                         echo "<p>There appears to be a problem, please contact PRODIGY for more information</p>";
  101.                                                         }
  102.                                                 } else {
  103.                                                 ?>
  104.                         <p>Please select the user you want to send an email too and type the message below to send the email:</p>
  105.                         <form action="<?php echo htmlentities($_SERVER[PHP_SELF]); ?>" method="POST">
  106.                                 Contact Name:
  107.                             <select name="name" id="select">
  108.                                                 <?php
  109.                                                                         optiondisplay("SELECT fullname, email FROM contacts","id","name");
  110.                                                                   ?>
  111.                                         </select>
  112.                             <br />
  113.                             <input type="text" name="subject" />
  114.                             <textarea class="ckeditor" name="email" id="email" cols="45" rows="5"></textarea>
  115.                             <input type="submit" name="singlemail" value="submit" />
  116.                         </form>
  117.                         <?php
  118.                                                 }
  119.                                                 ?>
  120.                     </div>
  121.                 </div>
  122.                 <div id="footer">
  123.                     <?php include("includes/footer.php"); ?>              
  124.               </div>
  125.         </div>
  126.     </body>
  127. </html>
  128. <?php                                                          
  129.         }
  130. ?>