- <?php include("includes/session.php");
- // functions :)
- // This checks if a error has been picked up in a posted value
- function checkerror($condition,$output) {
- if($condition) {
- $errors[] = $output;
- }
- return $errors;
- }
- // This counts rows in a sql statement and returns an error if there is no rows
- function rowscount($sql) {
- connectdb();
- $query = mysql_query("$sql");
- if(!$query) {
- trigger_error("A database error has occured.".mysql_error());
- }
- $rows = mysql_num_rows($query);
- if($rows == 0) {
- $errors[] = "There was no records found in the database to match your request. Please try again";
- }
- return $errors;
- }
- // This counts the errors and outputs them if there are any.
- function outputerror($errors) {
- if(count($errors)) {
- echo "The following errors occured:";
- echo "<ul>";
- foreach($errors AS $error) {
- echo "<li>$error</li>";
- }
- echo "Please <a href='".htmlentities($_SERVER['PHP_SELF'])."'>click here</a> to return to the previous page";
- }
- }
- // This SELECTS items from a databse and either outputs
- function dbquery($sql) {
- connectdb();
- $query = mysql_query("$sql");
- if(!$query) {
- trigger_error("There was an error with your sql".mysql_error());
- }
- return $query;
- }
- // A option list based on fields in the db
- function optiondisplay($sql,$returnvalue,$displayname) {
- $query =& dbquery($sql);
- while($result = mysql_fetch_assoc($query)) {
- echo "<option value'".$result["$returnvalue"]."'>".$result["$displayname"]."</option>";
- }
- }
- ?>
- <script type="text/javascript" src="ckeditor/ckeditor.js"></script>
- <body>
- <div id="wrapper">
- <div id="header">
- </div>
- <div id="navigation">
- <?php include("includes/navigation.php"); ?>
- </div>
- <div id="content">
- <div class="content_block">
- <h3>SEND EMAIL</h3>
- <h2>Send a single email</h2>
- <hr />
- <?php
- if($_POST["singlemail"] == "submit") {
- $userid = $_POST["name"];
- $subject = $_POST["subject"];
- $message = $_POST["email"];
- // validate
- i see
- checkerror("!ctype_digit($userid) || $userid == \"\"", "The userID you selected is invalid, please try again");
- checkerror("$message == \"\"", "There was nothing entered in the email box, please try again");
- checkerror("$subject == \"\"", "There was nothing entered in the subject box, please try again");
- rowscount("SELECT id FROM contacts WHERE id = '$userid'");
- // check if errors, then outputs
- echo outputerror($error);
- } else {
- $query = dbquery("SELECT id, name, email FROM contacts WHERE id = '$userid'");
- $row = mysql_fetch_assoc($query);
- $email = $row["email"];
- $name = $row["fullname"];
- if(mail($email,$subject,$message)) {
- 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>";
- } else {
- echo "<p>There appears to be a problem, please contact PRODIGY for more information</p>";
- }
- } else {
- ?>
- <p>Please select the user you want to send an email too and type the message below to send the email:</p>
- <form action="<?php echo htmlentities($_SERVER[PHP_SELF]); ?>" method="POST">
- Contact Name:
- <select name="name" id="select">
- <?php
- optiondisplay("SELECT fullname, email FROM contacts","id","name");
- ?>
- </select>
- <br />
- <input type="text" name="subject" />
- <textarea class="ckeditor" name="email" id="email" cols="45" rows="5"></textarea>
- <input type="submit" name="singlemail" value="submit" />
- </form>
- <?php
- }
- ?>
- </div>
- </div>
- <div id="footer">
- <?php include("includes/footer.php"); ?>
- </div>
- </div>
- </body>
- </html>
- <?php
- }
- ?>
