Jump to content

ianhaney

Members
  • Content Count

    280
  • Joined

  • Last visited

Community Reputation

0 Neutral

About ianhaney

  • Rank
    Advanced Member

Profile Information

  • Gender
    Not Telling
  1. No probs, below is the coding I have <?php // PHPMailer classes into the global namespace use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; // Base files require 'PHPMailer/src/Exception.php'; require 'PHPMailer/src/PHPMailer.php'; require 'PHPMailer/src/SMTP.php'; // create object of PHPMailer class with boolean parameter which sets/unsets exception. $mail = new PHPMailer(true); try { //$mail->isSMTP(); // using SMTP protocol $mail->Host = 'hostname'; // SMTP host as gmail $mail->SMTPAuth = true; // enable smtp authentication $mail->Username = 'emailaddress'; // sender gmail host $mail->Password = 'emailaddresspassword'; // sender gmail host password $mail->SMTPSecure = 'ssl'; // for encrypted connection $mail->Port = 587; // port for SMTP $mail->setFrom('emailaddress', "Sender"); // sender's email and name $mail->addAddress('emailaddress', "Receiver"); // receiver's email and name $mail->Subject = 'New Online Order'; $mail->Body = "A new order has been received. The order information is below" . "\r\n\r\n" . "Club One: " . $_POST["club1"] . "\r\n" . "Country One: " . $_POST["country1"] . "\r\n" . "Ref No: " . $_POST["refno1"] . "\r\n" . "Quantity: " . $_POST["quantity1"] . "\r\n" . "Total Price Line: " . "\243" . $_POST["totalprice1"] . "\r\n\r\n" . "Club Two: " . $_POST["club2"] . "\r\n" . "Country Two: " . $_POST["country2"] . "\r\n" . "Ref No: " . $_POST["refno2"] . "\r\n" . "Quantity: " . $_POST["quantity2"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice2"] . "\r\n\r\n" . "Club Three: " . $_POST["club3"] . "\r\n" . "Country Three: " . $_POST["country3"] . "\r\n" . "Ref No: " . $_POST["refno3"] . "\r\n" . "Quantity: " . $_POST["quantity3"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice3"] . "\r\n\r\n" . "Club Four: " . $_POST["club4"] . "\r\n" . "Country Four: " . $_POST["country4"] . "\r\n" . "Ref No: " . $_POST["refno4"] . "\r\n" . "Quantity: " . $_POST["quantity4"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice4"] . "\r\n\r\n" . "Club Five: " . $_POST["club5"] . "\r\n" . "Country Five: " . $_POST["country5"] . "\r\n" . "Ref No: " . $_POST["refno5"] . "\r\n" . "Quantity: " . $_POST["quantity5"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice5"] . "\r\n\r\n" . "Club Six: " . $_POST["club6"] . "\r\n" . "Country Six: " . $_POST["country6"] . "\r\n" . "Ref No: " . $_POST["refno6"] . "\r\n" . "Quantity: " . $_POST["quantity6"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice6"] . "\r\n\r\n" . "Club Seven: " . $_POST["club7"] . "\r\n" . "Country Seven: " . $_POST["country7"] . "\r\n" . "Ref No: " . $_POST["refno7"] . "\r\n" . "Quantity: " . $_POST["quantity7"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice7"] . "\r\n\r\n" . "Club Eight: " . $_POST["club8"] . "\r\n" . "Country Eight: " . $_POST["country8"] . "\r\n" . "Ref No: " . $_POST["refno8"] . "\r\n" . "Quantity: " . $_POST["quantity8"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice8"] . "\r\n\r\n" . "Club Nine: " . $_POST["club9"] . "\r\n" . "Country Nine: " . $_POST["country9"] . "\r\n" . "Ref No: " . $_POST["refno9"] . "\r\n" . "Quantity: " . $_POST["quantity9"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice9"] . "\r\n\r\n" . "Club Ten: " . $_POST["club10"] . "\r\n" . "Country Ten: " . $_POST["country10"] . "\r\n" . "Ref No: " . $_POST["refno10"] . "\r\n" . "Quantity: " . $_POST["quantity10"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice10"] . "\r\n\r\n" . "Name: " . $_POST["name"] . "\r\n" . "Address Line 1: " . $_POST["addressline1"] . "\r\n" . "Address Line 2: " . $_POST["addressline2"] . "\r\n" . "Postcode: " . $_POST["postcode"] . "\r\n" . "Email: " . $_POST["email"] . "\r\n\r\n" . "Catalogue Subscription: " . $_POST["catalogue"]; $mail->send(); header('Location:thank-you.html'); } catch (Exception $e) { // handle error. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; } ?>
  2. I have just managed to get it working, got a little delay of about 10 seconds or so but main thing I managed to get it working, shall I post the code just in case anyone else needs it
  3. I removed the line below and redirected to the thank you page but the email is still not coming through $mail->IsSMTP();
  4. I am trying to get phpmailer working but not having much luck with it. I am not receiving the email Below is the code I have <?php //index.php $error = ''; $quantity1 = ''; $totalprice1 = ''; $subtotal = ''; $postage = ''; $grandtotal = ''; $name = ''; $addressline1 = ''; $postcode = ''; $email = ''; function clean_text($string) { $string = trim($string); $string = stripslashes($string); $string = htmlspecialchars($string); return $string; } if(isset($_POST["submit"])) { if(empty($_POST["quantity1"])) { $error .= '<p><label class="text-danger">Please enter the quantity required</label></p>'; } if(empty($_POST["totalprice1"])) { $error .= '<p><label class="text-danger">Please enter the total price required</label></p>'; } if(empty($_POST["subtotal"])) { $error .= '<p><label class="text-danger">Please enter the subtotal</label></p>'; } if(empty($_POST["postage"])) { $error .= '<p><label class="text-danger">Please enter the postage</label></p>'; } if(empty($_POST["grandtotal"])) { $error .= '<p><label class="text-danger">Please enter the grand total</label></p>'; } if(empty($_POST["name"])) { $error .= '<p><label class="text-danger">Please Enter your name</label></p>'; } else { $name = clean_text($_POST["name"]); if(!preg_match("/^[a-zA-Z ]*$/",$name)) { $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>'; } } if(empty($_POST["addressline1"])) { $error .= '<p><label class="text-danger">Please enter your address line 1</label></p>'; } if(empty($_POST["postcode"])) { $error .= '<p><label class="text-danger">Please enter your postcode</label></p>'; } if(empty($_POST["email"])) { $error .= '<p><label class="text-danger">Please Enter your Email</label></p>'; } else { $email = clean_text($_POST["email"]); if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error .= '<p><label class="text-danger">Invalid email format</label></p>'; } } if($error == '') { require 'phpmailer/class.phpmailer.php'; $mail = new PHPMailer(true); $mail->SMTPDebug = 1; // to see exactly what's the issue $mail->IsSMTP(); //Sets Mailer to send message using SMTP $mail->Host = 'hostname'; //Sets the SMTP hosts $mail->Port = '587'; //Sets the default SMTP server port $mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables $mail->Username = 'emailaddress'; //Sets SMTP username $mail->Password = 'emailaddresspassword'; //Sets SMTP password $mail->SMTPSecure = ''; //Sets connection prefix. Options are "", "ssl" or "tls" $mail->From = $_POST["email"]; //Sets the From email address for the message $mail->FromName = $_POST["name"]; //Sets the From name of the message $mail->AddAddress('emailaddress', 'Name');//Adds a "To" address $mail->AddCC($_POST["email"], $_POST["name"]); //Adds a "Cc" address $mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters $mail->IsHTML(true); //Sets message type to HTML $mail->Subject = "Online Badge Order"; //Sets the Subject of the message $mail->Body = "The order information is below" . "<br><br>" . "Club One: " . $_POST["club1"] . "<br>" . "Country One: " . $_POST["country1"] . "<br>" . "Ref No: " . $_POST["refno1"] . "<br>" . "Quantity: " . "<br>" . $_POST["quantity1"] . "<br>" . "Total Price Line: " . "\243" . $_POST["totalprice1"] . "<br><br>" . "Club Two: " . $_POST["club2"] . "<br>" . "Country Two: " . $_POST["country2"] . "<br>" . "Ref No: " . $_POST["refno2"] . "<br>" . "Quantity: " . $_POST["quantity2"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice2"] . "<br><br>" . "Club Three: " . $_POST["club3"] . "<br>" . "Country Three: " . $_POST["country3"] . "<br>" . "Ref No: " . $_POST["refno3"] . "<br>" . "Quantity: " . $_POST["quantity3"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice3"] . "<br><br>" . "Club Four: " . $_POST["club4"] . "<br>" . "Country Four: " . $_POST["country4"] . "<br>" . "Ref No: " . $_POST["refno4"] . "<br>" . "Quantity: " . $_POST["quantity4"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice4"] . "<br><br>" . "Club Five: " . $_POST["club5"] . "<br>" . "Country Five: " . $_POST["country5"] . "<br>" . "Ref No: " . $_POST["refno5"] . "<br>" . "Quantity: " . $_POST["quantity5"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice5"] . "<br><br>" . "Club Six: " . $_POST["club6"] . "<br>" . "Country Six: " . $_POST["country6"] . "<br>" . "Ref No: " . $_POST["refno6"] . "<br>" . "Quantity: " . $_POST["quantity6"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice6"] . "<br><br>" . "Club Seven: " . $_POST["club7"] . "<br>" . "Country Seven: " . $_POST["country7"] . "<br>" . "Ref No: " . $_POST["refno7"] . "<br>" . "Quantity: " . $_POST["quantity7"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice7"] . "<br><br>" . "Club Eight: " . $_POST["club8"] . "<br>" . "Country Eight: " . $_POST["country8"] . "<br>" . "Ref No: " . $_POST["refno8"] . "<br>" . "Quantity: " . $_POST["quantity8"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice8"] . "<br><br>" . "Club Nine: " . $_POST["club9"] . "<br>" . "Country Nine: " . $_POST["country9"] . "<br>" . "Ref No: " . $_POST["refno9"] . "<br>" . "Quantity: " . $_POST["quantity9"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice9"] . "<br><br>" . "Club Ten: " . $_POST["club10"] . "<br>" . "Country Ten: " . $_POST["country10"] . "<br>" . "Ref No: " . $_POST["refno10"] . "<br>" . "Quantity: " . $_POST["quantity10"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice10"]; //An HTML or plain text message body if($mail->Send()) //Send an Email. Return true on success or false on error { header('Location:thank-you.html'); } else { $error = '<label class="text-danger">There is an Error</label>'; } $quantity1 = ''; $totalprice1 = ''; $subtotal = ''; $postage = ''; $grandtotal = ''; $name = ''; $addressline1 = ''; $postcode = ''; $email = ''; } } ?>
  5. I would like to pull in Facebook reviews from my Facebook page and display them on a page on my website but am new to doing that so just seeing if there is any sample code I can get from somewhere to have a look at please? I have got a page access token from Facebook developers but unsure what the coding would be like to pull the reviews in
  6. I have a blog on my website and the blogs content is stored in a database. On my home page I have the two recent articles displayed on my home page but I have to change them manually so I add the recent article on the home page in the first column and the second most recent one in the next column so they are side by side. What I want to do is automatically display the blogs image and blog title from the database and display on the home page so I don't have to keep changing it manually My current code looks like the following <div class="block"> <div class="container"> <h3 class="text-center"><span class="color">Recent Blog Articles</span></h3> <div class="row"> <div class="col-md-6"> <div class="text-img animation" data-animation="fadeInLeft" data-animation-delay="0.5s"> <a href="https://www.it-doneright.co.uk/blog/one-year-to-go-until-end-of-support-for-windows-7"> <div class="image"> <img class="img-responsive" src="https://www.it-doneright.co.uk/images/blog/windows7-eos-new.jpg" alt="One year to go until end of support for Windows 7"> </div> <p>One year to go until end of support for Windows 7</p> </a> </div> </div> <div class="col-md-6"> <div class="text-img animation" data-animation="fadeInLeft" data-animation-delay="0.5s"> <a href="https://www.it-doneright.co.uk/blog/windows-10-is-going-to-require-7gb-of-storage-for-future-updates"> <div class="image"> <img class="img-responsive" src="https://www.it-doneright.co.uk/images/windows-ten-updates-needing-7gb-space-on-hard-drive.jpg" alt="Windows 10 is going to require 7gb of storage for future updates"> </div> <p>Windows 10 is going to require 7gb of storage for future updates</p> </a> </div> </div> </div> </div> </div> I did look on Google before posting but could not get my head around how to do it, could anyone point me in the right direction or start me off and will have a go
  7. I need some help with a mobile nav menu, it works to a point, the issue when the nav menu is expanded and I scroll down the site to view the categories in the menu as there are quite a lot, the nav menu collapses. I am unsure how to fix it, the coding I have is below <script> /* MOBILE COLLAPSE MENU */ (function($) { $.fn.collapsable = function(options) { // iterate and reformat each matched element return this.each(function() { // cache this: var obj = $(this); var tree = obj.next('.navigation'); obj.click(function(){ if( obj.is(':visible') ){tree.toggle();} }); $(window).resize(function(){ if ( $(window).width() <= 570 ){tree.attr('style','');}; }); }); }; })(jQuery); </script> <script> jQuery(document).ready(function($) { $('.slide-trigger').collapsable(); }); </script> <?php if ($categories) { ?> <nav class="group"> <h2 class="navheader slide-trigger">Menu <span></span></h2> <ul class="navigation group"> <?php foreach ($categories as $category) { ?> <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a> <?php if ($category['children']) { ?> <div> <?php for ($i = 0; $i < count($category['children']);) { ?> <ul> <?php $j = $i + ceil(count($category['children']) / $category['column']); ?> <?php for (; $i < $j; $i++) { ?> <?php if (isset($category['children'][$i])) { ?> <li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li> <?php } ?> <?php } ?> </ul> <?php } ?> </div> <?php } ?> </li> <?php } ?> </ul> </div> </ul> </nav> <?php } ?> nav.group { margin: -19px 0px 0px -15px; width: 330px; clear: both; } .navigation { max-width: none; background: #000; padding: 0; } .navigation li { float: left; } .navigation li a { display: block; color: #fff; padding: 10px; } .navigation li a:hover { background: #0fcaf2; } .navheader { font-size: 12px; } .slide-trigger { display: none; /* need this */ /*border: 1px solid #CCCCCC;*/ border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; -webkit-border-bottom-left-radius: 10px; -webkit-border-bottom-right-radius: 10px; -moz-border-radius-bottomleft: 10px; -moz-border-radius-bottomright: 10px; background: rgba(179,220,237,1); background: -moz-linear-gradient(-45deg, rgba(179,220,237,1) 0%, rgba(41,184,229,1) 50%, rgba(188,224,238,1) 100%); background: -webkit-gradient(left top, right bottom, color-stop(0%, rgba(179,220,237,1)), color-stop(50%, rgba(41,184,229,1)), color-stop(100%, rgba(188,224,238,1))); background: -webkit-linear-gradient(-45deg, rgba(179,220,237,1) 0%, rgba(41,184,229,1) 50%, rgba(188,224,238,1) 100%); background: -o-linear-gradient(-45deg, rgba(179,220,237,1) 0%, rgba(41,184,229,1) 50%, rgba(188,224,238,1) 100%); background: -ms-linear-gradient(-45deg, rgba(179,220,237,1) 0%, rgba(41,184,229,1) 50%, rgba(188,224,238,1) 100%); background: linear-gradient(135deg, rgba(179,220,237,1) 0%, rgba(41,184,229,1) 50%, rgba(188,224,238,1) 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b3dced', endColorstr='#bce0ee', GradientType=1 ); cursor: pointer; margin-left: 15px; margin-right: 15px; } .slide-trigger span { background-image: url("../image/dropdown-arrows.png"); background-position: 0 -14px; display: block; float: right; margin-top: 3px; height: 14px; width: 32px; } .slide-trigger { display: block; padding: 10px; } .no-js .slide-trigger { display: none; } .navigation { display: none; } .no-js .navigation { display: block; } .navigation { margin: -9px 15px; z-index: 9999; position: absolute; } .navigation li { float: none; list-style-type: none; width: 300px; } .navigation li a { border-bottom: 1px solid #fff; } Thank you in advance, the site is www.ccgretail.co.uk
  8. I have but can't seem to find any open source scripts, I might have a look on codecanyon if are not any open source scripts
  9. I have been asked by current client if a client registration/login and file upload with admin system can be added to his current website, the features the client requires are below 1) A registration script 2) A login script with forgot password feature 3) A admin side where the client can upload files like PDF's or jpg's to the users account and enter a password to view/download the uploaded file by admin 4) The admin side to also manage the users that sign up Are there any open source scripts out there that can do the above in php/mysqli or PDO? Thank you in advance
  10. UPDATE: I have solved it and also managed to do the array of choices, it seems to work when I tested it, I now have the following coding <?php $selection=array('In Queue','Working on','Awaiting Parts','Ready for Collection/Delivery','Complete','Unable To Repair'); echo ' <strong>Repair Status:</strong> <select name="status"> <option value="0">Please Select Option</option>'; foreach($selection as $selection){ $selected=($status == $selection)? "selected" : ""; echo '<option '.$selected.' value="'.$selection.'">'.$selection.'</option>'; } echo '</select>'; ?>
  11. I tried the coding below <select name="status"> <option value="In Queue" <?php if ($row['status'] == 'In Queue') 'selected = "selected"'; ?>>In Queue</option> <option value="Working on" <?php if ($row['status'] == 'Working On') 'selected = "selected"'; ?>>Working on</option> <option value="Awaiting Parts" <?php if ($row['status'] == 'Awaiting Parts') 'selected = "selected"'; ?>>Awaiting Parts</option> <option value="Ready for Collection/Delivery" <?php if ($row['status'] == 'Ready for Collection/Delivery') 'selected = "selected"'; ?>>Ready for Collection/Delivery</option> <option value="Complete" <?php if ($row['status'] == 'Complete') 'selected = "selected"'; ?>>Complete</option> <option value="Unable To Repair" <?php if ($row['status'] == 'Unable To Repair') 'selected = "selected"'; ?>>Unable To Repair</option> </select> buy gives the following error Notice: Undefined Variable: row I am not sure what it should be, I changed it to $status instead of $row but got a illegal string error
  12. Oh right ok, sorry not 100% on PHP, how would it look in regards to storing the choices in a database table and then looping over the choices to build the output?
  13. Is that in the following I think EDIT RECORD */ // if the 'id' variable is set in the URL, we know that we need to edit a record if (isset($_GET['id'])) { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // make sure the 'id' in the URL is valid if (is_numeric($_POST['id'])) { // get variables from the URL/form $id = $_POST['id']; $customer_name = htmlentities($_POST['customer_name'], ENT_QUOTES); $customer_email = htmlentities($_POST['customer_email'], ENT_QUOTES); $customer_phone = htmlentities($_POST['customer_phone'], ENT_QUOTES); $computer_make = htmlentities($_POST['computer_make'], ENT_QUOTES); $computer_model = htmlentities($_POST['computer_model'], ENT_QUOTES); $technician = htmlentities($_POST['technician'], ENT_QUOTES); $status = htmlentities($_POST['status'], ENT_QUOTES); $exrdate = htmlentities($_POST['exrdate'], ENT_QUOTES); $exrtime = htmlentities($_POST['exrtime'], ENT_QUOTES); $exstdate = htmlentities($_POST['exstdate'], ENT_QUOTES); $exstime = htmlentities($_POST['exstime'], ENT_QUOTES); $deltype = htmlentities($_POST['deltype'], ENT_QUOTES); $comments = htmlentities($_POST['comments'], ENT_QUOTES); $job_cost = htmlentities($_POST['job_cost'], ENT_QUOTES); $part_cost = htmlentities($_POST['part_cost'], ENT_QUOTES); $profit = htmlentities($_POST['profit'], ENT_QUOTES); // check that firstname and lastname are both not empty if ($customer_name == '' || $customer_phone == '' || $computer_make == '' || $computer_model == '' || $comments == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($customer_name, $customer_phone, $computer_make, $computer_model, $comments, $error, $id); } else { // if everything is fine, update the record in the database if ($stmt = $mysqli->prepare("UPDATE repairs SET customer_name = ?, customer_email = ?, customer_phone = ?, computer_make = ?, computer_model = ?, technician = ?, status = ?, exrdate = ?, exrtime = ?, exstdate = ?, exstime = ?, deltype = ?, comments = ?, job_cost = ?, part_cost = ?, profit = ? WHERE id=?")) { $stmt->bind_param("ssssssssssssssssi", $customer_name, $customer_email, $customer_phone, $computer_make, $computer_model, $technician, $status, $exrdate, $exrtime, $exstdate, $exstime, $deltype, $comments, $job_cost, $part_cost, $profit, $id); $stmt->execute(); $stmt->close(); } // show an error message if the query has an error else { echo "ERROR: could not prepare SQL statement."; } // redirect the user once the form is updated header("Location: view-repairs-tracking.php"); } } // if the 'id' variable is not valid, show an error message else { echo "Error!"; } } // if the form hasn't been submitted yet, get the info from the database and show the form else { // make sure the 'id' value is valid if (is_numeric($_GET['id']) && $_GET['id'] > 0) { // get 'id' from URL $id = $_GET['id']; // get the recod from the database if($stmt = $mysqli->prepare("SELECT id, customer_name, customer_email, customer_phone, computer_make, computer_model, technician, status, exrdate, exrtime, exstdate, exstime, deltype, comments, job_cost, part_cost, profit, send_sms FROM repairs WHERE id=?")) { $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($id, $customer_name, $customer_email, $customer_phone, $computer_make, $computer_model, $technician, $status, $exrdate, $exrtime, $exstdate, $exstime, $deltype, $comments, $job_cost, $part_cost, $profit, $send_sms); $stmt->fetch(); // show the form renderForm($customer_name, $customer_email, $customer_phone, $computer_make, $computer_model, $technician, $status, $exrdate, $exrtime, $exstdate, $exstime, $deltype, $comments, $job_cost, $part_cost, $profit, NULL, $id, $send_sms); $stmt->close(); } // show an error if the query has an error else { echo "Error: could not prepare SQL statement"; } } // if the 'id' value is not valid, redirect the user back to the view.php page else { header("Location: view-repairs-tracking.php"); } } }
  14. Hi I need bit of help regarding dropdown values when editing a record using php. I edit a record using a html form and php to process the form and it saves all ok in the database but when I edit the record, it shows the first select dropdown value within the form instead of the value when the form saves to the database Can anyone help please, I have added the coding below <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php /* Allows the user to both create new records and edit existing records */ // connect to the database include("connect-db.php"); // creates the new/edit record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($customer_name = '', $customer_email = '', $customer_phone = '', $computer_make = '', $computer_model = '', $technician = '', $status = '', $exrdate = '', $exrtime = '', $exstdate = '', $exstime = '', $deltype = '', $comments = '', $job_cost = '', $part_cost = '', $profit = '', $error = '', $id = '', $send_sms = '') { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title> <?php if ($id != '') { echo "Edit Repair Tracking"; } else { echo "New Repair Tracking"; } ?> </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link rel="stylesheet"href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/blitzer/jquery-ui.css"/> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="css/styles.css" /> <script src="js/jquery.ui.timepicker.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="css/jquery.ui.timepicker.css" /> <script> $(function() { $("#exrdate").datepicker({ showButtonPanel: true, dateFormat: "yy/mm/dd", showOn:"both" }); }); $(function() { $("#exstdate").datepicker({ showButtonPanel: true, dateFormat: "yy/mm/dd", showOn:"both" }); }); </script> <script> $(document).ready(function() { $('#exrtime').timepicker({ defaultTime: '12:00', showLeadingZero: true, showNowButton: true, showCloseButton: true, showDeselectButton: true, showOn: 'both', }); $('#exstime').timepicker({ defaultTime: '12:00', showLeadingZero: true, showNowButton: true, showCloseButton: true, showDeselectButton: true, showOn: 'both', }); }); </script> <!--<script src="//cdn.ckeditor.com/4.5.5/full/ckeditor.js"></script>--> <script type="text/javascript"> function doCalc() { var job_cost = parseFloat(document.getElementById('job_cost').value); var part_cost = parseFloat(document.getElementById('part_cost').value); var profit = job_cost - part_cost; profit = profit.toFixed(2); document.getElementById('profit').value = profit; } </script> </head> <body> <div id="logo"> <img src="https://www.it-doneright.co.uk/admin/repairs-tracking/images/logo/it-done-right.jpg" alt="" title=""> </div> <? session_start(); if($_SESSION['user']==''){ header("Location:../index.php"); }else{ include("../config.php"); $sql=$dbh->prepare("SELECT * FROM users WHERE id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='../logout.php'>Log Out</a> <br><br> <a href='../index.php'>Home</a></center>"; echo "</div>"; echo "<br>"; } } ?> <?php include("nav-menu.php"); ?> <h1><?php if ($id != '') { echo "Edit Repair"; } else { echo "New Repair"; } ?></h1> <?php if ($error != '') { echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error . "</div>"; } ?> <div style="float: left;"> <u>NOTES</u> <br><br> <strong> ENTER MOBILE WITH 44 IN FRONT AND <br> NO SPACES (E.G. 447538503276) </strong> </div> <form action="" method="post" class="basic-grey"> <div> <?php if ($id != '') { ?> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <p>Repair ID: <?php echo $id; ?></p> <?php } ?> <br> <strong>Customer Name:</strong> <input type="text" name="customer_name" value="<?php echo $customer_name; ?>"/> <br/> <strong>Customer Email:</strong> <input type="text" name="customer_email" value="<?php echo $customer_email; ?>"/> <br> <strong>Customer Phone:</strong> <input type="text" name="customer_phone" value="<?php echo $customer_phone; ?>"/> <?php if($send_sms == 1):?> <br /><strong style='color:red;'>SMS ALREADY SENT</strong><br /><br /> <?php else:?> <br> <strong>Send SMS Confirmation:</strong> <input type="checkbox" name="send_sms" value="yes"/> <br /><br /> <?php endif;?> <strong>Computer Make:</strong> <input type="text" name="computer_make" value="<?php echo $computer_make; ?>"/> <br> <strong>Computer Model:</strong> <input type="text" name="computer_model" value="<?php echo $computer_model; ?>"/> <br> <strong>Assigned to Technician:</strong> <select name="technician"> <option value="Ian Haney">Ian Haney</option> </select> <br> <strong>Repair Status:</strong> <select name="status"> <option value="In Queue">In Queue</option> <option value="Working on">Working on</option> <option value="Awaiting Parts">Awaiting Parts</option> <option value="Ready for Collection/Delivery">Ready for Collection/Delivery</option> <option value="Complete">Complete</option> <option value="Unable To Repair">Unable To Repair</option> </select> <br> <strong>Expected Start Date:</strong> <input type="text" name="exstdate" value="<?php echo $exstdate; ?>" id="exstdate" /> <br><br> <strong>Expected Start Time:</strong> <input type="time" name="exstime" value="<?php echo $exstime; ?>" id="exstime"/> <br><br> <strong>Expected Repair Date:</strong> <input type="text" name="exrdate" value="<?php echo $exrdate; ?>" id="exrdate"/> <br><br> <strong>Expected Repair Time:</strong> <input type="time" name="exrtime" value="<?php echo $exrtime; ?>" id="exrtime"/> <br><br> <strong>Delivery Type:</strong> <select name="deltype"> <option value="Customer Pickup">Customer Pickup</option> <option value="Delivery">Delivery</option> </select> <br> <strong>Comments:</strong> <br> <textarea name="comments"><?php echo $comments; ?></textarea> <br> <strong>Job Repair Cost:</strong> <input type="text" name="job_cost" id="job_cost" value="<?php echo $job_cost; ?>" onBlur="doCalc(this.form)" /> <br> <strong>Parts Cost:</strong> <input type="text" name="part_cost" id="part_cost" value="<?php echo $part_cost; ?>" onblur="doCalc(this.form)" /> <br> <strong>Profit:</strong> <input type="text" name="profit" id="profit" value="<?php echo $profit; ?>" /> <br> <input type="submit" name="submit" value="Add/Update Repair Tracking" /> </div> </form> </body> </html> <?php } /* EDIT RECORD */ // if the 'id' variable is set in the URL, we know that we need to edit a record if (isset($_GET['id'])) { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // make sure the 'id' in the URL is valid if (is_numeric($_POST['id'])) { // get variables from the URL/form $id = $_POST['id']; $customer_name = htmlentities($_POST['customer_name'], ENT_QUOTES); $customer_email = htmlentities($_POST['customer_email'], ENT_QUOTES); $customer_phone = htmlentities($_POST['customer_phone'], ENT_QUOTES); $computer_make = htmlentities($_POST['computer_make'], ENT_QUOTES); $computer_model = htmlentities($_POST['computer_model'], ENT_QUOTES); $technician = htmlentities($_POST['technician'], ENT_QUOTES); $status = htmlentities($_POST['status'], ENT_QUOTES); $exrdate = htmlentities($_POST['exrdate'], ENT_QUOTES); $exrtime = htmlentities($_POST['exrtime'], ENT_QUOTES); $exstdate = htmlentities($_POST['exstdate'], ENT_QUOTES); $exstime = htmlentities($_POST['exstime'], ENT_QUOTES); $deltype = htmlentities($_POST['deltype'], ENT_QUOTES); $comments = htmlentities($_POST['comments'], ENT_QUOTES); $job_cost = htmlentities($_POST['job_cost'], ENT_QUOTES); $part_cost = htmlentities($_POST['part_cost'], ENT_QUOTES); $profit = htmlentities($_POST['profit'], ENT_QUOTES); // check that firstname and lastname are both not empty if ($customer_name == '' || $customer_phone == '' || $computer_make == '' || $computer_model == '' || $comments == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($customer_name, $customer_phone, $computer_make, $computer_model, $comments, $error, $id); } else { // if everything is fine, update the record in the database if ($stmt = $mysqli->prepare("UPDATE repairs SET customer_name = ?, customer_email = ?, customer_phone = ?, computer_make = ?, computer_model = ?, technician = ?, status = ?, exrdate = ?, exrtime = ?, exstdate = ?, exstime = ?, deltype = ?, comments = ?, job_cost = ?, part_cost = ?, profit = ? WHERE id=?")) { $stmt->bind_param("ssssssssssssssssi", $customer_name, $customer_email, $customer_phone, $computer_make, $computer_model, $technician, $status, $exrdate, $exrtime, $exstdate, $exstime, $deltype, $comments, $job_cost, $part_cost, $profit, $id); $stmt->execute(); $stmt->close(); } // show an error message if the query has an error else { echo "ERROR: could not prepare SQL statement."; } // redirect the user once the form is updated header("Location: view-repairs-tracking.php"); } } // if the 'id' variable is not valid, show an error message else { echo "Error!"; } } // if the form hasn't been submitted yet, get the info from the database and show the form else { // make sure the 'id' value is valid if (is_numeric($_GET['id']) && $_GET['id'] > 0) { // get 'id' from URL $id = $_GET['id']; // get the recod from the database if($stmt = $mysqli->prepare("SELECT id, customer_name, customer_email, customer_phone, computer_make, computer_model, technician, status, exrdate, exrtime, exstdate, exstime, deltype, comments, job_cost, part_cost, profit, send_sms FROM repairs WHERE id=?")) { $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($id, $customer_name, $customer_email, $customer_phone, $computer_make, $computer_model, $technician, $status, $exrdate, $exrtime, $exstdate, $exstime, $deltype, $comments, $job_cost, $part_cost, $profit, $send_sms); $stmt->fetch(); // show the form renderForm($customer_name, $customer_email, $customer_phone, $computer_make, $computer_model, $technician, $status, $exrdate, $exrtime, $exstdate, $exstime, $deltype, $comments, $job_cost, $part_cost, $profit, NULL, $id, $send_sms); $stmt->close(); } // show an error if the query has an error else { echo "Error: could not prepare SQL statement"; } } // if the 'id' value is not valid, redirect the user back to the view.php page else { header("Location: view-repairs-tracking.php"); } } } /* NEW RECORD */ // if the 'id' variable is not set in the URL, we must be creating a new record else { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { $country_code = '44'; // get the form data $customer_name = htmlentities($_POST['customer_name'], ENT_QUOTES); $customer_email = htmlentities($_POST['customer_email'], ENT_QUOTES); $customer_phone = htmlentities($_POST['customer_phone'], ENT_QUOTES); $computer_make = htmlentities($_POST['computer_make'], ENT_QUOTES); $computer_model = htmlentities($_POST['computer_model'], ENT_QUOTES); $technician = htmlentities($_POST['technician'], ENT_QUOTES); $status = htmlentities($_POST['status'], ENT_QUOTES); $exrdate = htmlentities($_POST['exrdate'], ENT_QUOTES); $exrtime = htmlentities($_POST['exrtime'], ENT_QUOTES); $exstdate = htmlentities($_POST['exstdate'], ENT_QUOTES); $exstime = htmlentities($_POST['exstime'], ENT_QUOTES); $deltype = htmlentities($_POST['deltype'], ENT_QUOTES); $comments = htmlentities($_POST['comments'], ENT_QUOTES); $job_cost = htmlentities($_POST['job_cost'], ENT_QUOTES); $part_cost = htmlentities($_POST['part_cost'], ENT_QUOTES); $profit = htmlentities($_POST['profit'], ENT_QUOTES); // check that firstname and lastname are both not empty if ($customer_name == '' || $computer_make == '' || $computer_model == '' || $comments == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($customer_name, $computer_make, $computer_model, $comments, $error); } else { // insert the new record into the database if ($stmt = $mysqli->prepare("INSERT repairs (customer_name, customer_email, customer_phone, computer_make, computer_model, technician, status, exrdate, exrtime, exstdate, exstime, deltype, comments, job_cost, part_cost, profit) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { $stmt->bind_param("ssssssssssssssss", $customer_name, $customer_email, $customer_phone, $computer_make, $computer_model, $technician, $status, $exrdate, $exrtime, $exstdate, $exstime, $deltype, $comments, $job_cost, $part_cost, $profit); $stmt->execute(); $stmt->close(); if(isset($_POST['send_sms'])): $repair_id = $mysqli->insert_id; $SMS = "Hello ".$customer_name.". Your repair has been booked in with IT Done Right. Your Repair ID is ".$repair_id.". To track your repair, please visit https://www.it-doneright.co.uk/track-my-repair FROM IT Done Right"; function sendSMS($username, $password, $customer_phone, $message, $originator) { $URL = 'https://api.textmarketer.co.uk/gateway/'."?username=$username&password=$password&option=xml"; $URL .= "&to=$customer_phone&message=".urlencode($message).'&orig='.urlencode($originator); $fp = fopen($URL, 'r'); return fread($fp, 1024); } $from = ''; $response = sendSMS('', '', $customer_phone, $SMS, $from); if ($stmt = $mysqli->prepare("UPDATE repairs SET send_sms = 1 WHERE id=$repair_id")) { $stmt->execute(); $stmt->close(); } // show an error message if the query has an error else { echo "ERROR: could not prepare SQL statement."; } endif; } // show an error if the query has an error else { echo "ERROR: Could not prepare SQL statement."; } $to = "$customer_email"; $subject = "Booked Repair Information"; $message = " <html> Hello <strong>$customer_name</strong> <h2>Below is your repair details to track the repair status</h2> <p>Your Name: $customer_name</p> <p>Your Email: $customer_email</p> <p>Your Phone Number: $customer_phone</p> <p>PC/Laptop Make: $computer_make</p> <p>PC/Laptop Make: $computer_model</p> <p>Assigned to Technician: $technician</p> <p>Current Repair Status: $status</p> <p>Expected Start Date: " . date('d/m/Y', strtotime($exstdate)) . "</p> <p>Expected Start Time: $exstime</p> <p>Expected Repair Date: " . date('d/m/Y', strtotime($exrdate)) . "</p> <p>Expected Repair Time: $exrtime</p> <p>Dropoff or Pickup: $deltype</p> <p>Comments: $comments</p> <p>Job Repair Cost: " . '£' . $job_cost . "</p> <p>Repair Job ID: " . mysqli_insert_id($mysqli) . " <strong>(Enter this ID number into link below)</strong></p> <p>https://www.it-doneright.co.uk/track-my-repair.php</p> </html> "; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= 'From: <enquiries@it-doneright.co.uk>' . "\r\n"; mail($to,$subject,$message,$headers); // redirec the user header("Location: view-repairs-tracking.php"); } } // if the form hasn't been submitted yet, show the form else { renderForm(); } } // close the mysqli connection $mysqli->close(); ?> Thank you in advance UPDATE: Would something like the following work on each option value? <option value="In Queue" <?php if ($row['status'] == 'In Queue') 'selected = "selected"'; ?>>In Queue</option>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.