Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- define('ROOT_PATH', $_SERVER['DOCUMENT_ROOT'] . '/eform/eform');
- date_default_timezone_set('Europe/London');
- $debug = false;
- $app_env = 'Prod';
- require_once ROOT_PATH . '/xls/classes/PHPExcel.php';
- require_once ROOT_PATH . '/xls/classes/PHPExcel/IOFactory.php';
- require_once ROOT_PATH . '/PHPMailerAutoload.php';
- require_once ROOT_PATH . '/Kashflow/Kashflow.php';
- require_once ROOT_PATH . '/Appointmentmaker/APMaker.php';
- require_once ROOT_PATH . '/Dropbox/DBXApi.php';
- $apt_date = $_POST['apt_date'];
- $mail_date = $apt_date;
- $apt_date = explode('-', $apt_date);
- $apt_date = "{$apt_date[2]}/{$apt_date[1]}/{$apt_date[0]}";
- if(strtoupper($_POST['name'] == "SYSDEBUG")) {
- $app_env = 'Debug';
- $objPHPExcel = PHPExcel_IOFactory::load(ROOT_PATH . '/xls/2016_template.xls');
- } else {
- $objPHPExcel = PHPExcel_IOFactory::load(ROOT_PATH . '/xls/2016_template.xls');
- }
- $red = new PHPExcel_Style_Color();
- $red->setRGB('FF0000');
- $objPHPExcel->setActiveSheetIndex(0);
- $objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')->setSize(11);
- $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
- $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5);
- $objPHPExcel->getActiveSheet()->getPageSetup()->setFitToPage(true);
- $objPHPExcel->getActiveSheet()->getPageSetup()->setFitToWidth(1);
- $objPHPExcel->getActiveSheet()->getPageSetup()->setFitToHeight(0);
- $objPHPExcel->getActiveSheet()->setPrintGridlines(false);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
- $objPHPExcel->getActiveSheet()->SetCellValue('A1', date('d/m/y')); // date
- $objPHPExcel->getActiveSheet()->SetCellValue('A2', date('H:i:s')); // date
- $objPHPExcel->getActiveSheet()->SetCellValue('C1', $apt_date); // appointment
- $objPHPExcel->getActiveSheet()->SetCellValue('A4', $objPHPExcel->getActiveSheet()->getCell('A4')->getValue() . ' ' . strtoupper($_POST['name'])); // name
- $objPHPExcel->getActiveSheet()->SetCellValue('A5', $objPHPExcel->getActiveSheet()->getCell('A5')->getValue() . ' ' . strtoupper($_POST['address'])); // address 1
- $objPHPExcel->getActiveSheet()->SetCellValue('A6', $objPHPExcel->getActiveSheet()->getCell('A6')->getValue() . ' ' . strtoupper($_POST['address2'])); // address 2
- $objPHPExcel->getActiveSheet()->SetCellValue('A7', $objPHPExcel->getActiveSheet()->getCell('A7')->getValue() . ' ' . strtoupper($_POST['town'])); // town
- $objPHPExcel->getActiveSheet()->SetCellValue('A8', $objPHPExcel->getActiveSheet()->getCell('A8')->getValue() . ' ' . strtoupper($_POST['county'])); // county
- $objPHPExcel->getActiveSheet()->SetCellValue('F5', $objPHPExcel->getActiveSheet()->getCell('F5')->getValue() . ' ' . substr($_POST['telephone'], 0, 5). ' '. substr($_POST['telephone'], 5, 12)); // tel
- $objPHPExcel->getActiveSheet()->SetCellValue('F7', $objPHPExcel->getActiveSheet()->getCell('F7')->getValue() . ' ' . substr($_POST['mobile'], 0, 5) . ' ' . substr($_POST['mobile'], 5, 12)); // mob
- $objPHPExcel->getActiveSheet()->SetCellValue('F9', $objPHPExcel->getActiveSheet()->getCell('F9')->getValue() . ' ' . substr($_POST['work'], 0, 5) . ' ' . substr($_POST['work'], 5, 12)); // mob
- $objPHPExcel->getActiveSheet()->SetCellValue('A9', $objPHPExcel->getActiveSheet()->getCell('A9')->getValue() . ' ' . strtoupper($_POST['post_code'])); // postcode
- $objPHPExcel->getActiveSheet()->SetCellValue('C11', $objPHPExcel->getActiveSheet()->getCell('C11')->getValue() . ' ' . strtolower($_POST['email'])); // email
- $objPHPExcel->getActiveSheet()->SetCellValue('C13', $objPHPExcel->getActiveSheet()->getCell('C13')->getValue() . ' ' . strtoupper($_POST['make'])); // make
- $objPHPExcel->getActiveSheet()->SetCellValue('C15', $objPHPExcel->getActiveSheet()->getCell('C15')->getValue() . ' ' . strtoupper($_POST['appliance'])); // appliance
- $objPHPExcel->getActiveSheet()->SetCellValue('C17', $objPHPExcel->getActiveSheet()->getCell('C17')->getValue() . ' ' . strtoupper($_POST['fault'])); // fault
- $objPHPExcel->getActiveSheet()->SetCellValue('A28', trim(preg_replace('/\s\s+/', ' ', $_POST['message']))); // message
- $objPHPExcel->getActiveSheet()->getStyle('A28')->getAlignment()->setWrapText(true);
- $objPHPExcel->getActiveSheet()->SetCellValue('C41', $objPHPExcel->getActiveSheet()->getCell('C41')->getValue() . ' ' . strtoupper($_POST['oname'])); // name
- $objPHPExcel->getActiveSheet()->SetCellValue('C42', $objPHPExcel->getActiveSheet()->getCell('C42')->getValue() . ' ' . substr($_POST['otelephone'], 0, 5). ' '. substr($_POST['otelephone'], 5, 12)); // tel
- $objPHPExcel->getActiveSheet()->SetCellValue('C43', $objPHPExcel->getActiveSheet()->getCell('C43')->getValue() . ' ' . substr($_POST['omobile'], 0, 5) . ' ' . substr($_POST['omobile'], 5, 12)); // mob
- $objPHPExcel->getActiveSheet()->SetCellValue('C44', $objPHPExcel->getActiveSheet()->getCell('C44')->getValue() . ' ' . strtolower($_POST['oemail'])); // email
- $objPHPExcel->getActiveSheet()->SetCellValue('C45', $objPHPExcel->getActiveSheet()->getCell('C45')->getValue() . ' ' . strtoupper($_POST['oaddress'])); // address 1
- $objPHPExcel->getActiveSheet()->SetCellValue('C46', $objPHPExcel->getActiveSheet()->getCell('C46')->getValue() . ' ' . strtoupper($_POST['opost_code'])); // postcode
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setColor( $red );
- $name = $_POST['name'] . ' ' . $_POST['post_code']; //gmdate("M_d_Y_H_i_s");
- $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
- $objWriter->save(ROOT_PATH . '/xls/' . $name . '.xls');
- if($app_env == 'Debug') {
- exit(ROOT_PATH . '/xls/' . $name . '.xls');
- }
- $mail = new PHPMailer;
- if($debug) {
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'localhost'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'user@example.com'; // SMTP username
- $mail->Password = 'secret'; // SMTP password
- $mail->Port = 25;
- }
- $mail->From = $_POST['email'];
- $mail->FromName = $_POST['post_code'];
- $mail->addAddress('jobs@theappliancerepairman.co.uk', '');
- $mail->WordWrap = 50; // Set word wrap to 50 characters
- $mail->addAttachment(ROOT_PATH . '/xls/' . $name . '.xls'); // Add attachments
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = $_POST['name'];
- $mail->Body = $_POST['appliance'];
- $mail->AltBody = $_POST['make'];
- if(!$mail->send()) {
- echo 'Message could not be sent.';
- echo 'Mailer Error: ' . $mail->ErrorInfo;
- exit;
- } else {
- $ks = new KFlow();
- $ap = new APMaker();
- $dbx = new DBXApi();
- $ks->addToKashflow($_POST);
- $ap->make_appointment($ks->get_uid(), $_POST['apt_date']);
- $dbx->add_to_dropbox($name, $_POST['apt_date']);
- $confirmation = new PHPMailer;
- $confirmation->IsSMTP();
- $confirmation->SMTPAuth = true; // Set mailer to use SMTP
- $confirmation->Host = 'puma.websitewelcome.com'; // Specify main and backup server
- $confirmation->Port = 465; // Set the SMTP port
- $confirmation->SMTPAuth = true; // Enable SMTP authentication
- $confirmation->Username = 'jobs@theappliancerepairman.co.uk'; // SMTP username
- $confirmation->Password = 'barryf007!'; // SMTP password
- $confirmation->SMTPSecure = 'ssl';
- $confirmation->From = "jobs@theappliancerepairman.co.uk";
- $confirmation->FromName = "Barry the Appliance Repairman";
- if(isset($_POST['oemail']) && $_POST['oemail'] != "") {
- $confirmation->addAddress($_POST['oemail'], $_POST['oname']);
- } else {
- $confirmation->addAddress($_POST['email'], $_POST['name']);
- }
- $confirmation->isHTML(true);
- $mail_date = date('l d/m/Y', strtotime($mail_date));
- $confirmation->Subject = "Your Appliance Repair Appointment";
- $confirmation->Body = <<<EOD
- <img src="http://theappliancerepairman.co.uk/uploads/appliance-logo.png" alt="The Appliance Repairman" /> <br><br>
- <p style="font-size: 16px;">
- Thank you for choosing The Appliance Repairman to repair your appliance.<br>
- <br>
- Your call is now in our Diary, and has been booked in and confirmed for
- </p>
- <h1 style="color:red">{$mail_date}.</h1>
- <p style="font-size: 16px;">
- Our Engineer will <b>phone you on that number that you provided</b> you between 8 - 9am on the schedule day of your visit
- </p>
- <h1 style="color:red">{$mail_date}.</h1>
- <p style="font-size: 16px;">
- To arrange a time <br>
- Should this not be convenient for you or you have enquiries please call us at 0800 0 43 44 45. <br>
- <br>
- Just to remind you all jobs must be paid on completion, which we accept all cards and cash <br>
- Sorry we do not accept cheques.<br>
- <br>
- The Appliance Repairman - <a href="http://theappliancerepairman.co.uk">Website</a>
- </p>
- EOD;
- $confirmation->AltBody = "Hello {$_POST['name']}, \n\nYour appointment has been booked and confirmed. \nOur Engineer will call you during 8 - 9am on {$mail_date}. Should this not be convinient for you or you have enquiries please call us at 0800 0 43 44 45.\n\nKind regards,\n\nBarry";
- $confirmation->send();
- }
- unlink(ROOT_PATH . '/xls/' . $name . '.xls');
- header("location:/thank-you.html");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement