public function sendMail($id) { $reply = Ticketreply::find_by_id($id); $ticket = Ticket::find_by_id($reply->ticket_id); $ccemails = Ccemail::find_by_ticket($reply->ticket_id); $client = Client::find_by_id($_SESSION['client_ident']); $to = '*****@*****.**'; $t = '*****@*****.**'; $cc = ""; $subject = 'Ticket Number: #' . str_pad($ticket->id, 8, "0", STR_PAD_LEFT) . " " . $ticket->subject; $headers = "From: " . $client->name . "<" . $client->email . ">\r\n"; $headers .= "Reply-To: " . $ticket->contact_email . "\r\n"; if ($ccemails) { $copyaddy = array(); foreach ($ccemails as $ccemail) { array_push($copyaddy, $ccemail->email); } for ($i = 0; $i < count($copyaddy); $i++) { $cc .= "," . $copyaddy[$i]; } $t .= $cc; } $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Cc: " . $t . "\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n"; /* $smtp = \Mail::factory('smtp', array( 'host' => 'ssl://n1plcpnl0021.prod.ams1.secureserver.net', 'port' => '465', 'auth' => true, 'username' => '*****@*****.**', 'password' => 'rjsupport2015' ));*/ $message = ' <html><body> <h1>Robert Johnson Holdings Limited</h1> <h2>Ticket Number #' . str_pad($ticket->id, 8, "0", STR_PAD_LEFT) . '</h2> <table width="100%" border="0"> <tr> <th scope="row" width="30%">Client</th> <td width="70%">' . $reply->sender_name . '</td> </tr> <tr> <th scope="row">Contact Person</th> <td>' . $ticket->contact_name . '</td> </tr> <tr> <th scope="row">Contact Phone Number</th> <td>' . $ticket->contact_phone . '</td> </tr> <tr> <th scope="row">Contact Email</th> <td>' . $ticket->contact_email . '</td> </tr>'; if ($ccemails) { $message .= '<tr> <th scope="row">Copied Emails</th> <td>' . $t . '</td> </tr> <tr>'; } $message .= '<th scope="row">Department</th> <td>' . $ticket->department . '</td> </tr> <tr> <th scope="row">Ticket Status</th> <td>' . $ticket->status . '</td> </tr> <tr> <th scope="row">Priority Level</th> <td>' . $ticket->priority . '</td> </tr> <tr> <th scope="row">Related Product/Service</th> <td>' . $ticket->terminal_id . ' at ' . $ticket->location . '</td> </tr> <tr> <th scope="row">Subject</th> <td>' . $ticket->subject . '</td> </tr> <tr> <th scope="row">Issue/Complaint/Suggestion</th> <td>' . $ticket->issue . '</td> </tr> </table> </body></html>'; if (mail($to, $subject, $message, $headers)) { return true; } else { return false; } /* $mail = $smtp->send($to, $headers, $message); if (PEAR::isError($mail)) { echo('<p>' . $mail->getMessage() . '</p>'); echo "error"; return true; } else { echo "success"; return false; }*/ //lse return false; }
/** * function to handle client * reply to a ticket */ public function createAdminReply($id) { if (isset($_POST["issues"]) && isset($_POST["conname"])) { $newReply = new Ticketreply(); $newReply->sender_id = $_SESSION["emp_ident"]; $newReply->ticket_id = $id; $theUser = Employee::find_by_id($_SESSION["emp_ident"]); $cemail = array(); $newReply->sender_name = $theUser->emp_fname . " " . $theUser->emp_lname; $newReply->sender_type = "Admin"; $newReply->message = $_POST['issues']; $newReply->datecreated = date("Y-m-d H:i:s"); $cemail = !empty($_POST['cemail']) ? explode(",", $_POST['cemail']) : ""; $partTicket = Ticket::find_by_id($id); // print_r($partTicket); array_push($cemail, $partTicket->contact_email, $theUser->emp_email); $client = Client::find_by_id($partTicket->client_id); // print_r($client); $partTicket->status = "Admin Reply"; $partTicket->datemodified = date("Y-m-d H:i:s"); //print_r($cemail); //mail("*****@*****.**","Robert Johnson Holdings, Technical Support" , "all good"); $this->sendMail($newReply->sender_name, "Robert Johnson Holdings(Technical Support)", $newReply->message, $cemail); if ($newReply->create()) { $partTicket->update(); return 1; } else { return 2; } } else { return 3; } }
public function createSchedule($id = "") { if (!empty($_POST['cid']) && !empty($_POST['empid'])) { $thisclientproduct = Cproduct::find_by_id((int) preg_replace('#[^0-9]#i', '', $_POST['cid'])); $empdata = explode("_", $_POST['empid']); $thisemployee = Employee::find_by_staff_id($empdata[0]); //print_r($thisemployee); $thisSchedule = new Schedule(); $clientTicket = Ticket::find_by_id((int) preg_replace('#[^0-9]#i', '', $id)); $thisclientproduct = Cproduct::find_by_id((int) preg_replace('#[^0-9]#i', '', $clientTicket->prod_id)); if ($_POST['mtype'] != "Activation" && ($_POST['Corrective'] || $_POST['Preventive'])) { $clientTicket->status = "Admin Reply"; $clientTicket->datemodified = date("Y-m-d H:i:s"); $thisSchedule->status = "In Progress"; } else { $clientTicket = Activation::find_by_id((int) preg_replace('#[^0-9]#i', '', $id)); if ($clientTicket) { $thisclientproduct = Cproduct::find_by_id((int) preg_replace('#[^0-9]#i', '', $clientTicket->prod_id)); $clientTicket->status = "In Progress"; $clientTicket->updated_at = date("Y-m-d H:i:s"); } } $thisSchedule->status = "In Progress"; $thisSchedule->emp_id = $thisemployee->id; $thisSchedule->emp_name = $thisemployee->emp_fname . " " . $thisemployee->emp_lname; $thisSchedule->client_id = $thisclientproduct->client_id; $thisClient = Client::find_by_id($thisclientproduct->client_id); $thisSchedule->prod_id = $thisclientproduct->id; $thisSchedule->ticket_id = $id; $thisSchedule->prod_name = $thisclientproduct->prod_name; // exit; /** * this is to check if ticket * is in existence */ //print_r($theUser); global $session; //$partTicket = ($id!="") ? Ticket::find_by_id($id) : ""; // get the ticket to get details needed for sending mail $theUser = Employee::find_by_id($_SESSION["emp_ident"]); // get cse detail to retrieve email $thisSchedule->s_date = !empty($_POST['taskdate']) ? $_POST['taskdate'] : date("Y-m-d"); $cemail = array(); $cemail = !empty($_POST['cemail']) && isset($_POST['cemail']) ? explode(",", $_POST['cemail']) : array('*****@*****.**'); array_push($cemail, $thisemployee->emp_email, is_array($clientTicket) ? $clientTicket->contact_email : "", $theUser->emp_email, $thisClient->email); array_push($cemail, $clientTicket->contact); array_push($cemail, $thisClient->contact_email); array_push($cemail, $thisClient->email); //print_r($cemail); $thisSchedule->issue = $_POST["tissue"]; $thisSchedule->datecreated = date("Y-m-d H:i:s"); $thisSchedule->maint_type = $_POST['mtype']; $subject = "Maintenance Alert"; $smsmsg = "Maintenance alert for" . $thisclientproduct->terminal_id . " " . $thisclientproduct->prod_name . "at"; $smsmsg .= $thisclientproduct->install_location . "," . $thisclientproduct->branch; $smsmsg .= "\r\n issue:" . $_POST["tissue"] . "\r\n"; $msg = "<h3>Maintenance Detail</h3> <hr />"; $msg .= "<p><strong>Terminal ID: </strong>{$thisclientproduct->terminal_id} </p>"; $msg .= "<p><strong>Machine: </strong>{$thisclientproduct->prod_name} </p>"; $msg .= "<p><strong>Client: </strong> {$thisClient->name}</p>"; $msg .= "<p><strong>Location: </strong>{$thisclientproduct->install_location} {$thisclientproduct->branch} {$thisclientproduct->install_city} </p>"; $msg .= "<p><strong>Complaint: </strong>" . (!empty($_POST['tissue']) ? $_POST['tissue'] : $clientTicket->issue) . "</p>"; $msg .= "<br /><br /> <h4>Technician Details</h4> <hr />"; $msg .= "<p><strong>Name: </strong>" . $thisemployee->emp_fname . " " . $thisemployee->emp_lname . "</p>"; $msg .= "<p><strong>Email: </strong>" . $thisemployee->emp_email . "</p>"; $msg .= "<p><strong>Telephone: </strong>" . $thisemployee->emp_phone . "</p>"; $msg .= "<br /><br /><h4>Scheduled Date</h4> <hr />"; $msg .= "<p><strong>{$thisSchedule->s_date}</strong></p><br /><br /><br /><br />"; $newReply = new Ticketreply(); $newReply->sender_id = $_SESSION["emp_ident"]; $newReply->ticket_id = $id; $newReply->sender_name = $theUser->emp_fname . " " . $theUser->emp_lname; $newReply->sender_type = "Admin"; $newReply->message = $msg; $newReply->datecreated = date("Y-m-d H:i:s"); $newReply->datemodified = date("Y-m-d H:i:s"); //$newReply->create(); /** * the transaction log is created * to ensure that the product already * has history and cannot be deleted */ $Tlog2 = new Transaction(); $Tlog2->com_id = $thisclientproduct->main_id; $Tlog2->trans_type = "TASK ASSIGNMENT"; $Tlog2->trans_description = "Corrective Maintenance task assigned to " . $thisemployee->emp_fname . " " . $thisemployee->emp_lname . ""; $Tlog2->datecreated = date("Y-m-d H:i:s"); $Tlog2->datemodified = date("Y-m-d H:i:s"); $Tlog2->user_id = $_SESSION['emp_ident']; // print_r($msg); if ($newReply->create()) { $thisSchedule->create(); $clientTicket->datemodified = date("Y-m-d H:i:s"); $clientTicket->update(); $Tlog2->create(); //$thisemployee->emp_phone sendSms($thisemployee->emp_phone, $smsmsg); sendSms($thisClient->contact_phone, $smsmsg); sendSms($thisClient->phone, $smsmsg); $this->sendMail($thisSchedule->emp_name, $subject, $msg, $cemail); return true; } else { return false; } } }