Advertisement
taleeb

PHP Function

Aug 15th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. function addRequest() {
  2.  
  3. //echo '<pre>'; print_r($_POST); echo '</pre>'; die();
  4.  
  5. $message = $this->message();
  6.  
  7. $sql1 = "SELECT * FROM `tenants` WHERE `id` = '".$_POST['user_id']."';";
  8. $res1 = $this->db->query($sql1);
  9. $row1 = $res1->fetch_assoc();
  10.  
  11. $sql3 = "SELECT * FROM `properties` WHERE `id` = '".$_POST['property']."';";
  12. $res3 = $this->db->query($sql3);
  13. $row3 = $res3->fetch_assoc();
  14.  
  15. if($row2['supervisor_id']) {
  16. $supervisor_id = $row2['supervisor_id'];
  17. } else {
  18. $supervisor_id = '';
  19. }
  20.  
  21. $unit_ids = implode(",", $_POST['unit']);
  22.  
  23. $phone = '+' . $_POST['countryCode'] .'-'. $_POST['mobile'];
  24.  
  25. $start_date = strtotime($_POST['start']);
  26. $end_date = strtotime($_POST['end']);
  27.  
  28. $i=0;
  29.  
  30. if($_POST['request_type'] == 'General') { echo "Here -2";
  31.  
  32. foreach($_POST['unit'] as $unitt) {
  33.  
  34. $sql2 = "SELECT * FROM `unit_master` WHERE `id` = '".$unitt."';";
  35. $res2 = $this->db->query($sql2);
  36. $row2 = $res2->fetch_assoc();
  37.  
  38. $manager = $this->getUser($row2['manager_id']);
  39. $supervisor = $this->getUser($row2['supervisor_id']);
  40.  
  41. $sql = "INSERT INTO `quotation` SET
  42.  
  43. `property_id` = '".$_POST['property']."',
  44. `pm_id` = '".$row2['manager_id']."',
  45. `supervisor_id` = '".$row2['supervisor_id']."',
  46. `property` = '".$row3['name']."' ,
  47. `user_id` = '".$_POST['user_id']."' ,
  48. `unit_id` = '".$unitt."' ,
  49. `nature` = 'General',
  50. `description` = '".$_POST['description']."' ,
  51. `unit_number` = '".$row2['ref']."' ,
  52. `unit` = '".$row2['unit_name']."' ,
  53. `mobile` = '".$_POST['mobile']."',
  54. `email` = '".$_POST['email']."',
  55. `status` = 'In Process',
  56. `request_type` = '".$_POST['request_type']."',
  57. `date_time` = '".date("d-m-Y")."';";
  58.  
  59. $img_query = $this->db->query($sql);
  60. $req_id = $this->db->insert_id;
  61. $i++;
  62. }
  63.  
  64. $this->sendManagerRequest($manager['name'],$manager['email'],$row1['name'],$row1['email'],$_POST['description']);
  65.  
  66. }
  67.  
  68. if($_POST['request_type'] == 'Maintenance') { echo "Here -1";
  69.  
  70. foreach($_POST['unit'] as $unitt) {
  71.  
  72. $sql2 = "SELECT * FROM `unit_master` WHERE `id` = '".$unitt."';";
  73. $res2 = $this->db->query($sql2);
  74. $row2 = $res2->fetch_assoc();
  75.  
  76. $manager = $this->getUser($row2['manager_id']);
  77. $supervisor = $this->getUser($row2['supervisor_id']);
  78.  
  79. foreach($_POST['req']['nature'] as $reqs) {
  80.  
  81. $sql = "INSERT INTO `quotation` SET
  82.  
  83. `property_id` = '".$_POST['property']."',
  84. `pm_id` = '".$row2['manager_id']."',
  85. `supervisor_id` = '".$row2['supervisor_id']."',
  86. `property` = '".$row3['name']."' ,
  87. `user_id` = '".$_POST['user_id']."' ,
  88. `unit_id` = '".$unitt."' ,
  89. `nature` = '".$_POST['req']['nature'][$i]."' ,
  90. `description` = '".$_POST['req']['descriptions'][$i]."' ,
  91. `unit_number` = '".$row2['ref']."' ,
  92. `unit` = '".$row2['unit_name']."' ,
  93. `mobile` = '".$_POST['mobile']."',
  94. `email` = '".$_POST['email']."',
  95. `status` = 'In Process',
  96. `request_type` = '".$_POST['request_type']."',
  97. `date_time` = '".date("d-m-Y")."';";
  98.  
  99. $img_query = $this->db->query($sql);
  100. $req_id = $this->db->insert_id;
  101. $i++;
  102. }
  103. }
  104. }
  105.  
  106. die();
  107. $mail = new PHPMailer();
  108. //$mail->isSMTP();
  109. $mail->Host = 'smtp.sendgrid.net';
  110. $mail->SMTPAuth = true;
  111. $mail->Username = 'takmeel'; // SMTP username
  112. $mail->Password = 'shineE065'; // SMTP password
  113. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  114. $mail->Port = 25;
  115.  
  116. $mail->From = $row1['email'];
  117. $mail->FromName = $row1['name'];
  118.  
  119. $mail->AddAddress($manager['email'] , $manager['name']);
  120. $mail->AddCC($supervisor['email'] , $supervisor['name']);
  121.  
  122. $mail->AddReplyTo($row1['email'] , $row1['name']);
  123.  
  124. $mail->isHTML(true);
  125.  
  126. $mail->Subject = "New Service Request From Tenant";
  127.  
  128. $body_part_1 = 'This is notification email to inform you that there is new maintenance request for your property. Please login to your account to see the request detail.';
  129.  
  130. $body_part_3 = '<tbody>
  131. <tr>
  132. <td align="center" style="margin:0;text-align:center"><a href="'.URL_SITE.'login.php" style="font-size:21px;line-height:22px;text-decoration:none;color:#ffffff;font-weight:bold;border-radius:2px;background-color:#c56648;padding:14px 40px;display:block;letter-spacing:1.2px" target="_blank">Login</a></td>
  133. </tr>
  134. </tbody>';
  135.  
  136. /*$mail->Body .= "<b>Property Name:&nbsp;&nbsp;</b>" . $row3['name'] . '<br>';
  137. $mail->Body .= "<b>Unit Number:&nbsp;&nbsp;</b>" . $row2['ref'] . '<br>';
  138. $mail->Body .= "<b>Request Title:&nbsp;&nbsp;</b>" . $_POST['nature'] . '<br>';
  139. $mail->Body .= "<b>Description:&nbsp;&nbsp;</b>" . $_POST['description'] . '<br><br>';*/
  140.  
  141. $mail->Body = $this->emailHeader($message,'','New Maintenance Request For Your Property',$body_part_1,'',$body_part_3);
  142.  
  143. if($mail->Send()) {
  144. return true;
  145. }
  146. //}
  147.  
  148. /*if($img_query) {
  149. return true;
  150. } else {
  151. return false;
  152. }*/
  153.  
  154. $action = $_SESSION['name'] . ' ( ' . $_SESSION['type_name'] . ' ) submitted a new request.';
  155.  
  156. $this->Userlog($_SESSION['id'] , $_SESSION['name'] , $_SESSION['email'] , $_SESSION['type_name'] , $action , $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
  157.  
  158. $sent = $this->sendEmail($row1['email'],$row1['name'],$manager['email'],$manager['name'],$_POST['nature'],$row3['name'], $row2['ref'],$_POST['description']);
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement