dealer.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. /****************************
  3. * File : dealer.php
  4. * Author : Cygnusa
  5. * @2018
  6. ****************************/
  7. //SECURITY
  8. if (!defined('APPLICATION_PATH')) {
  9. exit('No direct script access allowed');
  10. }
  11. //FUNCTION LISTS
  12. class dealer
  13. {
  14. public function __construct($parent)
  15. {
  16. //GET PAGE MESSAGE
  17. $this->page_data = globalfunc::getMessage($parent, $parent->lang, 'dealer');
  18. if (count($parent->params) == 0) {
  19. $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
  20. } else {
  21. $qry_params = explode("?", $parent->params[0]);
  22. $parameter_val = strtolower($qry_params[0]);
  23. switch ($parameter_val) {
  24. case "userlist":
  25. case "dsestatusupdate":
  26. case "dseactivetinactivelist":
  27. $this->$parameter_val($parent);
  28. break;
  29. default:
  30. $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
  31. break;
  32. }
  33. }
  34. $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
  35. }
  36. /* /////////////////////////////// USERLIST //////////////////////////////////////////////// */
  37. private function userlist($parent)
  38. {
  39. globalfunc::checkMethodType($parent, array('GET', 'POST'));
  40. //globalfunc::checkParamCount($parent, 1);
  41. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  42. projectfunc::authorizedRole($parent, array('7', '14'));
  43. if ($parent->current_user_role == '7') {
  44. $REQUEST_KEYS = array('dealer_code' => 'string');
  45. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  46. $dealer_code = escape_str($parent->_request['dealer_code']);
  47. } else {
  48. $dealer_code = $parent->current_user_data->dealer_code;
  49. $segment = escape_str($parent->params[1]);
  50. $history = escape_str($parent->params[2]);
  51. $segment_cond = $user_cond = "";
  52. switch ($segment) {
  53. case '1':
  54. $segment_cond .= " AND e.segment = 1";
  55. break;
  56. case '2':
  57. $segment_cond .= " AND e.segment = 2";
  58. break;
  59. default:
  60. //$segment_cond .= " AND e.segment = 2;
  61. break;
  62. }
  63. // if (!empty($segment)) {}
  64. $user_cond .= ($history == '1') ? " AND u.status='1' AND u.is_deleted=0 AND e.is_current='1' " : " AND e.is_current='1'";
  65. }
  66. //GET DATA FROM EMPLOYEE
  67. $query_str = "SELECT e.smpin,e.fname,e.lname,e.mobile,CASE WHEN u.userid is NULL THEN '0' WHEN u.userid is NOT NULL AND u.status=1 THEN '1' ELSE '2' END as userstatus ,CASE WHEN u.userid is NULL THEN '3' WHEN u.userid is NOT NULL AND u.status=1 THEN '1' ELSE '2' END as userorder,COALESCE(u.profile_photo,'') as profile_photo FROM " . DMS_EMPLOYEE . " e LEFT JOIN " . TABLE_USER . " u ON u.smpin=e.smpin WHERE e.status=1 AND e.dealer_code='" . $dealer_code . "' " . $segment_cond . $user_cond . " ORDER BY userorder ASC,e.fname ASC";
  68. $data_arr = $parent->getQueryValue($query_str);
  69. $data = (count($data_arr) > 0) ? $data_arr : array();
  70. $s3 = awsfileserver::connectS3();
  71. foreach ($data as $key => $res) {
  72. $data[$key]->profile_photo = ($res->profile_photo != '') ? awsfileserver::getS3FileUrl($s3, S3_BUCKET, S3_PROFILE_IMAGE_URL . $res->profile_photo) : '';
  73. }
  74. //LOG
  75. $logstr = 'DEALER USER DATA';
  76. globalfunc::insertUserLog($parent, $logstr, $parent->current_user_id);
  77. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success1']), 200);
  78. }
  79. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  80. /* /////////////////////////////// DSEACTIVETINACTIVELIST //////////////////////////////////////////////// */
  81. private function dseactivetinactivelist($parent)
  82. {
  83. globalfunc::checkMethodType($parent, array('GET'));
  84. globalfunc::checkParamCount($parent, 2);
  85. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  86. projectfunc::authorizedRole($parent, array('7', '14'));
  87. $status = escape_str($parent->params[1]);
  88. $query_getuserarr = $parent->selectQuery(TABLE_DSE_ACTIVE_DEACTIVE_LIST, " `id`, `name`, `created_on`, `modified_on`", "status='" . $status . "' ");
  89. //LOG
  90. $logstr = 'DSE ACTIVE DEACTIVE DATA';
  91. globalfunc::insertUserLog($parent, $logstr, $parent->current_user_id);
  92. $parent->response(array('response' => 'success', 'data' => $query_getuserarr['result'], 'message' => $this->page_data['success1']), 200);
  93. }
  94. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  95. /* /////////////////////////////// DSESTATUSUPDATE //////////////////////////////////////////////// */
  96. private function dsestatusupdate($parent)
  97. {
  98. globalfunc::checkMethodType($parent, array('POST'));
  99. globalfunc::checkParamCount($parent, 1);
  100. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  101. projectfunc::authorizedRole($parent, array('7', '14'));
  102. $REQUEST_KEYS = array('smpin' => 'string', 'status' => 'number');
  103. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  104. $smpin = escape_str($parent->_request["smpin"]);
  105. $status = (escape_str($parent->_request["status"]) == 1) ? "1" : "2";
  106. $remark = escape_str($parent->_request["remark"]);
  107. $remarkoption = escape_str($parent->_request["remarkoption"]);
  108. if ($parent->current_user_role == '7') {
  109. $REQUEST_KEYS = array('dealer_code' => 'string');
  110. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  111. $dealer_code = escape_str($parent->_request['dealer_code']);
  112. } else {
  113. $dealer_code = $parent->current_user_data->dealer_code;
  114. }
  115. //CHECK USER EXIST
  116. $query_str = "SELECT fname, lname, userid, dealer_code, smpin FROM " . TABLE_USER . " WHERE dealer_code='" . $dealer_code . "' AND smpin='" . $smpin . "' AND role>7 and role<14 LIMIT 1";
  117. $data_arr = $parent->getQueryValue($query_str);
  118. if (!count($data_arr) > 0) {
  119. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error2']), 406);
  120. }
  121. //UPDATE
  122. $cond_str = ($status == 2) ? ",inactivated_on='" . NOW . "',auth_token='' " : "";
  123. $parent->executeQuery("UPDATE " . TABLE_USER . " SET status='" . $status . "' " . $cond_str . " WHERE userid='" . $data_arr[0]->userid . "'");
  124. $insert_qry = "INSERT INTO " . TABLE_USER_STATUS_HISTORY . " ( `userid`, `action_user`,status, `remarks`, `remarkoption`,`created_on`) VALUES ('" . $data_arr[0]->userid . "', '" . $parent->current_user_id . "','" . $status . "', '" . $remark . "','" . $remarkoption . "','" . NOW . "')";
  125. $parent->executeQuery($insert_qry);
  126. $query_getdealerarr = $parent->selectQuery(DMS_DEALER, " email, rm_name, rm_email, am_name, am_email, dealer_code ", "dealer_code='" . $data_arr[0]->dealer_code . "' ");
  127. if ($status == 1) {
  128. $to_mail = $query_getdealerarr['result'][0]->email;
  129. $subject = 'Dealer Activation | DSE ' . trim($data_arr[0]->fname . " " . $data_arr[0]->lname) . " (" . $data_arr[0]->smpin . ") ";
  130. $message = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
  131. <tbody>
  132. <tr>
  133. <td>
  134. <table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
  135. <tbody>
  136. <tr>
  137. <td bgcolor="#2d2d2d" height="36" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#e4e4e4; text-align:left; font-weight:bold; padding-left:14px; border-bottom:2px solid black">' . $subject . '</td>
  138. </tr>
  139. <tr>
  140. <td>
  141. <table width="85%" align="center">
  142. <tbody>
  143. <tr>
  144. <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  145. line-height: 1.5;">
  146. <div style="font-family:arial; color:#333; font-size:12px; padding:5px;">Dear San,</div>
  147. </td>
  148. </tr>
  149. <tr>
  150. <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  151. line-height: 1.5;">
  152. <div style="font-family:arial; color:#333; font-size:12px; padding:5px;">I have activated the HYPER-M App access of ' . trim($data_arr[0]->fname . ' ' . $data_arr[0]->lname) . ' (SMPIN: ' . $data_arr[0]->smpin . ')</div>
  153. </td>
  154. </tr>
  155. </tbody>
  156. </table>
  157. </td>
  158. </tr>
  159. <tr>
  160. <td style="padding-top:0px; padding-bottom:10px;"></td>
  161. </tr>
  162. <tr>
  163. <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#3f3f3f; background:#fafafa; line-height:30px; text-align:center; border-bottom:2px solid black"><div class="footer-con"> <p>Thanks &amp; Regards, <strong style="color:#070000;">HYPER-M App Support Team</strong></p>
  164. </div></td>
  165. </tr>
  166. </tbody>
  167. </table>
  168. </td>
  169. </tr>
  170. </tbody>
  171. </table>';
  172. // Notification Details
  173. $notificationtitle = 'Dealer Activation';
  174. $notificationtext = $data_arr[0]->fname . ' ' . $data_arr[0]->lname . ' & ' . $data_arr[0]->smpin . ' has been re-activated by ' . $query_getdealerarr['result'][0]->am_name . ' on ' . date('Y-m-d');
  175. $notificationtype = '5';
  176. // Notification user id
  177. $query_str = "SELECT userid FROM " . TABLE_USER . " WHERE dealer_code = '" . $query_getdealerarr['result'][0]->dealer_code . "' AND role = 14 LIMIT 1";
  178. $notification_data_arr = $parent->getQueryValue($query_str);
  179. $notification_user_id = $notification_data_arr[0]->userid;
  180. } else if ($status == 2) {
  181. // Reason
  182. $query_getreasonarr = $parent->selectQuery(TABLE_DSE_ACTIVE_DEACTIVE_LIST, " name ", "id='" . $remarkoption . "' ");
  183. $to_mail = $query_getdealerarr['result'][0]->rm_email;
  184. $subject = 'Dealer Deactivation ' . trim($data_arr[0]->fname . " " . $data_arr[0]->lname) . " (" . $data_arr[0]->smpin . ") ";
  185. $message = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
  186. <tbody>
  187. <tr>
  188. <td>
  189. <table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
  190. <tbody>
  191. <tr>
  192. <td bgcolor="#2d2d2d" height="36" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#e4e4e4; text-align:left; font-weight:bold; padding-left:14px; border-bottom:2px solid black">' . $subject . '</td>
  193. </tr>
  194. <tr>
  195. <td>
  196. <table width="85%" align="center">
  197. <tbody>
  198. <tr>
  199. <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  200. line-height: 1.5;">
  201. <div style="font-family:arial; color:#333; font-size:12px; padding:5px;">Dear San,</div>
  202. </td>
  203. </tr>
  204. <tr>
  205. <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  206. line-height: 1.5;">
  207. <div style="font-family:arial; color:#333; font-size:12px; padding:5px;">I have de-activated the HYPER-M App access of ' . trim($data_arr[0]->fname . ' ' . $data_arr[0]->lname) . ' (SMPIN: ' . $data_arr[0]->smpin . ') due to following reason </div>
  208. <div style="font-family:arial; color:#333; font-size:12px; padding:5px;">' . $query_getreasonarr['result'][0]->name . ' </div>
  209. </td>
  210. </tr>
  211. </tbody>
  212. </table>
  213. </td>
  214. </tr>
  215. <tr>
  216. <td style="padding-top:0px; padding-bottom:10px;"></td>
  217. </tr>
  218. <tr>
  219. <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#3f3f3f; background:#fafafa; line-height:30px; text-align:center; border-bottom:2px solid black"><div class="footer-con"> <p>Thanks &amp; Regards, <strong style="color:#070000;">HYPER-M App Support Team</strong></p>
  220. </div></td>
  221. </tr>
  222. </tbody>
  223. </table>
  224. </td>
  225. </tr>
  226. </tbody>
  227. </table>';
  228. // Notification Details
  229. $notificationtitle = 'Dealer Deactivation';
  230. $notificationtext = $data_arr[0]->fname . ' ' . $data_arr[0]->lname . ' & ' . $data_arr[0]->smpin . ' has been marked ' . $query_getreasonarr['result'][0]->name . ' by ' . $data_arr[0]->fname . ' ' . $data_arr[0]->lname . ' & ' . $data_arr[0]->dealer_code . ' on ' . date('Y-m-d');
  231. $notificationtype = '5';
  232. // Notification user id
  233. $query_str = "SELECT userid FROM " . TABLE_USER . " WHERE emailid = '" . $query_getdealerarr['result'][0]->am_email . "' AND role = 7 LIMIT 1";
  234. $notification_data_arr = $parent->getQueryValue($query_str);
  235. $notification_user_id = $notification_data_arr[0]->userid;
  236. }
  237. $obj = array();
  238. $obj['from'] = SUPPORT_EMAIL;
  239. $obj['to'] = $to_mail;
  240. $obj['subject'] = $subject;
  241. $obj['message'] = $message;
  242. // globalfunc::sendMai($parent, $obj);
  243. //SEND NOTIFICATION
  244. $nobj = new stdClass();
  245. $nobj->notificationtitle = $notificationtitle;
  246. $nobj->notificationtext = $notificationtext;
  247. $nobj->notificationtype = $notificationtype;
  248. $nobj->notificationdata = new stdClass();
  249. // projectfunc::sendUserNotification($parent, $nobj, $notification_user_id);
  250. //LOG
  251. $logstr = 'USER STATUS UPDATE';
  252. globalfunc::insertUserLog($parent, $logstr, $parent->current_user_id);
  253. $parent->response(array('response' => 'success', 'message' => $this->page_data['success1']), 200);
  254. }
  255. }