global.php 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509
  1. <?php
  2. /****************************
  3. * File : global.php
  4. * Author : Cygnusa
  5. * @2018
  6. *
  7. * All Global Rest Api files
  8. *
  9. ***************************/
  10. class globalfunc
  11. {
  12. // `userid`, `smpin`, `emp_code`, `password`, `fname`, `lname`, `emailid`, `mobileno`, `role`, `dealer_code`, `address_1`, `address_2`, `address_3`, `valid_token`, `validate_time`, `profile_photo`, `dob`, `doj`, `country`, `auth_token`, `otp`, `otp_expiry`, `language`, `is_married`, `marriage_date`, `mpin`, `status`, `last_password_change`, `is_first_login`, `is_profile_updated`, `is_deleted`, `inactivated_on`, `created_on`, `modified_on`
  13. private static $user_fields = "userid, `smpin`, `emp_code`, `password`, `fname`, `lname`, `emailid`, `mobileno`, `role`, `dealer_code`, `address_1`, `address_2`, `address_3`,`profile_photo`, `dob`, `doj`, `country`, `language`, `is_married`, `marriage_date`, `mpin`, `status`,`last_password_change`,`is_first_login`,`is_profile_updated`,validate_time";
  14. /* /////////////////////////////////// DEVELOPER ERROR /////////////////////////////////// */
  15. public static function callErrorMsg($parent, $data)
  16. {
  17. if (!isset($data)) {
  18. $parent->response(array('response' => 'failed', 'message' => 'PHP UNDEFINED ERROR'), 500);
  19. }
  20. if (!isset($data['message']) || $data['message'] == '' || $data['message'] == null) {
  21. $parent->response(array('response' => 'failed', 'message' => 'PHP UNDEFINED ERROR'), 500);
  22. }
  23. $parent->response(array('response' => 'failed', 'message' => $data['message']), 500);
  24. }
  25. /* ///////////////////////////////////////////////////////////////////////////////////// */
  26. /* /////////////////////////////////// CHECK METHOD TYPE /////////////////////////////////// */
  27. public static function checkMethodType($parent, $method_array)
  28. {
  29. if (is_array($method_array)) {
  30. $method_array = array_map('strtoupper', $method_array);
  31. if (!in_array($parent->get_request_method(), $method_array)) {
  32. $parent->response(array('response' => 'failed'), 406);
  33. }
  34. } else {
  35. self::callErrorMsg($parent, array('message' => 'GLOBAL(checkMethodType):REQUIRED DATA'));
  36. }
  37. }
  38. /* ///////////////////////////////////////////////////////////////////////////////////// */
  39. /* /////////////////////////////// CHECK PARAMETER COUNT EXIT ////////////////////////////// */
  40. public static function checkParamCount($parent, $param_count)
  41. {
  42. if (count($parent->params) != $param_count) {
  43. $parent->response(array('response' => 'failed'), 404);
  44. }
  45. if ($param_count != 0) {
  46. if (!(trim($parent->params[($param_count - 1)]) != '')) {
  47. $parent->response(array('response' => 'failed'), 404);
  48. }
  49. }
  50. }
  51. /* ///////////////////////////////////////////////////////////////////////////////////// */
  52. /* /////////////////////////////// CHECK ANY KEY ////////////////////////////// */
  53. public static function checkAnyKey($parent, $element_arr)
  54. {
  55. if (!is_array($element_arr)) {
  56. self::callErrorMsg($parent, array('message' => 'GLOBAL(checkAnyKey):REQUIRED DATA'));
  57. }
  58. try {
  59. $temp = 0;
  60. //FIELD KEY VALIDATE
  61. $field_arr = array_keys($element_arr);
  62. foreach ($field_arr as $single) {
  63. if (isset($parent->_request[$single])) {$temp = 1;
  64. break;}
  65. }
  66. if ($temp == 0) {
  67. $parent->response(array('response' => 'failed', 'message' => 'MISSING FIELDS - ' . strtoupper($single)), 406);
  68. }
  69. //FIELD VAKUE TYPE VALIDATE
  70. foreach ($element_arr as $key => $single) {
  71. if (isset($parent->_request[$key])) {
  72. if (($parent->_request[$key] == '' || $parent->_request[$key] == null) && !is_array($parent->_request[$key]) && !is_object($parent->_request[$key])) {
  73. $parent->response(array('response' => 'failed', 'message' => $key . ' FIELD VALUE REQUIRED'), 406);
  74. }
  75. (!self::validRequestKey($parent->_request[$key], $single)) ? $parent->response(array('response' => 'failed', 'message' => 'INVALID DATA TYPE. `' . $key . '` Required as ' . $single), 406) : '';
  76. }
  77. }
  78. } catch (Exception $e) {
  79. $parent->response(array('response' => 'failed', 'message' => $e->getMessage()), 406);
  80. }
  81. }
  82. /* ///////////////////////////////////////////////////////////////////////////////////// */
  83. /* /////////////////////////////// MANDATORY ////////////////////////////// */
  84. public static function mandatoryKey($parent, $element_arr)
  85. {
  86. if (!is_array($element_arr)) {
  87. self::callErrorMsg($parent, array('message' => 'GLOBAL(checkAnyKey):REQUIRED DATA'));
  88. }
  89. try {
  90. //FIELD KEY VALIDATE
  91. $field_arr = array_keys($element_arr);
  92. foreach ($field_arr as $single) {
  93. if (!isset($parent->_request[$single])) {
  94. $parent->response(array('response' => 'failed', 'message' => 'MISSING FIELDS - ' . strtoupper($single)), 406);
  95. }
  96. }
  97. //FIELD VAKUE TYPE VALIDATE
  98. foreach ($element_arr as $key => $single) {
  99. if (($parent->_request[$key] == '' || $parent->_request[$key] == null) && !is_array($parent->_request[$key]) && !is_object($parent->_request[$key])) {
  100. $parent->response(array('response' => 'failed', 'message' => strtoupper($key) . ' FIELD VALUE REQUIRED'), 406);
  101. }
  102. (!self::validRequestKey($parent->_request[$key], $single)) ? $parent->response(array('response' => 'failed', 'message' => 'INVALID DATA TYPE. `' . $key . '` Required as ' . $single), 406) : '';
  103. }
  104. } catch (Exception $e) {
  105. $parent->response(array('response' => 'failed', 'message' => $e->getMessage()), 406);
  106. }
  107. }
  108. /* ///////////////////////////////////////////////////////////////////////////////////// */
  109. /* /////////////////////////////// get ip ////////////////////////////// */
  110. public static function getIp($parent, $data = array())
  111. {
  112. $ip = $_SERVER['REMOTE_ADDR'];
  113. if ($ip) {
  114. if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  115. $ip = $_SERVER['HTTP_CLIENT_IP'];
  116. } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  117. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  118. }
  119. return $ip;
  120. }
  121. // There might not be any data
  122. return false;
  123. }
  124. /* ///////////////////////////////////////////////////////////////////////////////////// */
  125. /* /////////////////////////////// CHECK REQUEST PARAMETER CHECK ////////////////////////////// */
  126. public static function checkElementexist($parent, $elementarr)
  127. {
  128. if (!is_array($elementarr)) {
  129. self::callErrorMsg($parent, array('message' => 'GLOBAL(checkElementexist):REQUIRED DATA'));
  130. }
  131. if (count($parent->_request) != count($elementarr)) {
  132. $parent->response(array('response' => 'failed'), 406);
  133. }
  134. foreach ($elementarr as $single) {
  135. if (!isset($parent->_request[$single])) {
  136. $parent->response(array('response' => 'failed'), 406);
  137. }
  138. }
  139. }
  140. /* ///////////////////////////////////////////////////////////////////////////////////// */
  141. /* /////////////////////////////// CHECK PARAMETER COUNT EXIT ////////////////////////////// */
  142. public static function checkRequestKey($parent, $element_arr)
  143. {
  144. if (!is_array($element_arr)) {
  145. self::callErrorMsg($parent, array('message' => 'GLOBAL(checkElementexist):REQUIRED DATA'));
  146. }
  147. try {
  148. $field_arr = array_keys($element_arr);
  149. if (count($parent->_request) != count($field_arr)) {
  150. $parent->response(array('response' => 'failed', 'message' => 'MISSING KEYS'), 406);
  151. }
  152. foreach ($field_arr as $single) {
  153. if (!isset($parent->_request[$single])) {
  154. $parent->response(array('response' => 'failed', 'message' => 'MISSING FIELDS'), 406);
  155. }
  156. }
  157. //KEY TYPE VALIDATE
  158. foreach ($element_arr as $key => $single) {
  159. (!self::validRequestKey($parent->_request[$key], $single)) ? $parent->response(array('response' => 'failed', 'message' => 'INVALID KEY TYPE'), 406) : '';
  160. }
  161. } catch (Exception $e) {
  162. $parent->response(array('response' => 'failed', 'message' => $e->getMessage()), 406);
  163. }
  164. }
  165. /* ///////////////////////////////////////////////////////////////////////////////////// */
  166. /* /////////////////////////////// CHECK FILE ////////////////////////////// */
  167. public static function validateFile($parent, $obj)
  168. {
  169. try {
  170. if (is_object($obj)) {
  171. (!(isset($obj->filekey) && isset($obj->size) && isset($obj->type) && is_array($obj->type))) ? $parent->response(array('response' => 'failed', 'message' => 'CODE ERROR'), 406) : null;
  172. (!(isset($_FILES[$obj->filekey]) && ($_FILES[$obj->filekey]["error"] == 0))) ? $parent->response(array('response' => 'failed', 'message' => 'FILE NOT FOUND'), 406) : null;
  173. $maxsize = $obj->size * 1024 * 1024;
  174. ($maxsize < $_FILES[$obj->filekey]['size']) ? $parent->response(array('response' => 'failed', 'message' => 'INVALID FILE SIZE'), 406) : null;
  175. $fileParts = pathinfo($_FILES[$obj->filekey]['name']);
  176. $fileext_arr = explode('?', $fileParts['extension']);
  177. (!@in_array(strtolower($fileext_arr[0]), $obj->type)) ? $parent->response(array('response' => 'failed', 'message' => 'You can upload only ', @implode(', ', $obj->type) . " file type."), 406) : null;
  178. } else {
  179. self::callErrorMsg($parent, array('message' => 'GLOBAL(validateFile):REQUIRED DATA'));
  180. }
  181. } catch (Exception $e) {
  182. $parent->response(array('response' => 'failed', 'message' => $e->getMessage()), 406);
  183. }
  184. }
  185. /* ///////////////////////////////////////////////////////////////////////////////////// */
  186. /* /////////////////////////////// EMAIL VALIDATION ////////////////////////////// */
  187. public static function isValidDomain($email)
  188. {
  189. list($user, $url) = explode('@', $email);
  190. $validation = false;
  191. /*Parse URL*/
  192. $urlparts = parse_url(filter_var($url, FILTER_SANITIZE_URL));
  193. /*Check host exist else path assign to host*/
  194. if (!isset($urlparts['host'])) {
  195. $urlparts['host'] = $urlparts['path'];
  196. }
  197. if ($urlparts['host'] != '') {
  198. /*Add scheme if not found*/
  199. if (!isset($urlparts['scheme'])) {
  200. $urlparts['scheme'] = 'http';
  201. }
  202. /*Validation*/
  203. if (checkdnsrr($urlparts['host'], 'A') && in_array($urlparts['scheme'], array('http', 'https')) && ip2long($urlparts['host']) === false) {
  204. $urlparts['host'] = preg_replace('/^www\./', '', $urlparts['host']);
  205. $url = $urlparts['scheme'] . '://' . $urlparts['host'] . "/";
  206. if (filter_var($url, FILTER_VALIDATE_URL) !== false && @get_headers($url)) {
  207. $validation = true;
  208. }
  209. }
  210. }
  211. return $validation;
  212. }
  213. public static function isValidEmail($email)
  214. {
  215. return filter_var($email, FILTER_VALIDATE_EMAIL)
  216. && preg_match('/@.+\./', $email);
  217. }
  218. public static function emailValidation($parent, $email_address)
  219. {
  220. if (!(self::isValidEmail($email_address))) {
  221. $parent->response(array('response' => 'failed', 'message' => 'INVALID EMAIL'), 406);
  222. }
  223. if (!(self::isValidDomain($email_address))) {
  224. $parent->response(array('response' => 'failed', 'message' => 'INVALID EMAIL DOMAIN'), 406);
  225. }
  226. }
  227. /* ///////////////////////////////////////////////////////////////////////////////////// */
  228. /* /////////////////////////////// MOBILE VALIDATION ////////////////////////////// */
  229. public static function mobileValidation($parent, $mobileno)
  230. {
  231. if (!(preg_match('/^[0-9]{10}+$/', $mobileno))) {
  232. $parent->response(array('response' => 'failed', 'message' => 'INVALID MOBILE'), 406);
  233. }
  234. }
  235. /* ///////////////////////////////////////////////////////////////////////////////////// */
  236. /* /////////////////////////////// PASSWORD VALIDATION ////////////////////////////// */
  237. public static function validPassword($parent, $passstring)
  238. {
  239. $containsLetter = preg_match('/[a-zA-Z]/', $passstring);
  240. $containsDigit = preg_match('/\d/', $passstring);
  241. //$containsSpecial = preg_match('/[^a-zA-Z\d]/',$passstring);
  242. if (!(strlen($passstring) >= 6 && strlen($passstring) <= 100 && $containsLetter && $containsDigit))
  243. //if(!(strlen($passstring)>=6 && strlen($passstring)<=10 && $containsLetter && $containsDigit && $containsSpecial ))
  244. {
  245. return false;
  246. }
  247. return true;
  248. }
  249. /* ///////////////////////////////////////////////////////////////////////////////////// */
  250. /* /////////////////////////////// SET DB RECORD SKIP VALUE ////////////////////////////// */
  251. public static function setRecordSkip($parent, $data)
  252. {
  253. if (strstr($data, "record=")) {
  254. $qry_params = explode('record=', $data);
  255. $sepraters = explode("&", $qry_params[1]);
  256. if (isset($sepraters[0])) {
  257. if ($sepraters[0] == null || $sepraters[0] == '') {
  258. $parent->response(array('response' => 'failed'), 404);
  259. }
  260. $query_values = explode(",", $sepraters[0]);
  261. $query_value = (isset($query_values[1])) ? $query_values[0] : 0;
  262. return $query_value;
  263. } else {
  264. return 0;
  265. }
  266. } else {
  267. return 0;
  268. //$parent->response(array('response'=>'failed'),404);
  269. }
  270. }
  271. /* ////////////////////////////////////////////////////////////////////////// */
  272. /* /////////////////////////////// SET DB RECORD LIMIT VALUE ////////////////////////////// */
  273. public static function setRecordLimit($parent, $data)
  274. {
  275. if (strstr($data, "record=")) {
  276. $qry_params = explode('record=', $data);
  277. $sepraters = explode("&", $qry_params[1]);
  278. if (isset($sepraters[0])) {
  279. //echo $sepraters[0];
  280. $query_values = explode(",", $sepraters[0]);
  281. (!(isset($query_values[0]) && isset($query_values[1]))) ? $parent->response(array('response' => 'failed', 'invalid limit call'), 403) : null;
  282. //((int)$query_values[0]>(int)$query_values[1])?$parent->response(array('response'=>'failed','invalid limit call'), 403):NULL;
  283. /*
  284. switch (count($query_values)){
  285. case 1:
  286. $query_value=(int)$query_values[0];
  287. break;
  288. case 2:
  289. $query_value=(int)$query_values[1];
  290. break;
  291. default:
  292. $query_value='0,'.RECORD_LIMIT;
  293. break;
  294. }*/
  295. $query_value = (int) $query_values[0] . "," . (int) $query_values[1];
  296. return $query_value;
  297. } else {
  298. $parent->current_page = 0;
  299. return '0,' . RECORD_LIMIT;
  300. }
  301. } else {
  302. $parent->current_page = 0;
  303. return '0,' . RECORD_LIMIT;
  304. }
  305. }
  306. /* ////////////////////////////////////////////////////////////////////////// */
  307. /* /////////////////////////////// SET PAGE LIMIT VALUE ////////////////////////////// */
  308. public static function setPageLimit($parent, $data)
  309. {
  310. if (strstr($data, "page=")) {
  311. $qry_params = explode('page=', $data);
  312. $sepraters = explode("&", $qry_params[1]);
  313. if (isset($sepraters[0])) {
  314. $page_value = intval($sepraters[0]);
  315. $limit_data = explode('limit=', $data);
  316. if (strstr($data, "limit=") && isset($limit_data[0])) {
  317. $sepraters = explode("&", $limit_data[1]);
  318. $limit_arr = explode("&", $limit_data[1]);
  319. $limit_value = intval($limit_arr[0]);
  320. } else {
  321. $limit_value = RECORD_LIMIT;
  322. }
  323. (!(isset($page_value))) ? $parent->response(array('response' => 'failed', 'Invalid Pagination call'), 406) : null;
  324. $page_start_value = (int) $page_value * (int) $limit_value;
  325. $parent->current_page = $page_value;
  326. $parent->current_limit = $limit_value;
  327. $query_value = $page_start_value . "," . $limit_value;
  328. return $query_value;
  329. } else {
  330. $parent->current_page = 0;
  331. $parent->current_limit = RECORD_LIMIT;
  332. return '0,' . RECORD_LIMIT;
  333. }
  334. } else {
  335. $parent->current_page = 0;
  336. $parent->current_limit = RECORD_LIMIT;
  337. return '0,' . RECORD_LIMIT;
  338. }
  339. }
  340. /* ////////////////////////////////////////////////////////////////////////// */
  341. /* /////////////////////////////// GET DB RECORD FILTER VALUE ////////////////////////////// */
  342. public static function getFilterValues($parent, $data)
  343. {
  344. if (strpos($data, "filter=") !== false) {
  345. $filter_params = explode("filter=", $data);
  346. if (!isset($filter_params[1]) || $filter_params[1] == null || $filter_params[1] == '') {
  347. $parent->response(array('response' => 'failed'), 404);
  348. }
  349. $filter_param_items = explode(",", array_values(explode('&', $filter_params[1]))[0]);
  350. $filter_array = array();
  351. //print_r($filter_param_items);
  352. foreach ($filter_param_items as $item) {
  353. $itemval = explode(":", $item);
  354. if (isset($itemval[1])) {
  355. $itemkey = $itemval[0];
  356. $filter_array[$itemkey] = $itemval[1];
  357. } else {
  358. $filter_array[] = $itemval[0];
  359. }
  360. //$filter_array[]=(isset($itemval[1]))?array($itemval[0]=>$itemval[1]):array($itemval[0]);
  361. }
  362. return $filter_array;
  363. } else {
  364. return null;
  365. }
  366. }
  367. /* ////////////////////////////////////////////////////////////////////////// */
  368. /* /////////////////////////////// GET DB RECORD BETWEEN VALUE ////////////////////////////// */
  369. public static function getBetweenFilter($parent, $data)
  370. {
  371. if (!isset($data) || is_null($data)) {
  372. return null;
  373. }
  374. if (strpos($data, "between=")) {
  375. $between_params = explode("between=", $data);
  376. if (!isset($between_params[1]) || $between_params[1] == null || $between_params[1] == '') {
  377. $parent->response(array('response' => 'failed'), 400);
  378. }
  379. $between_param_items = explode(",", array_values(explode('&', $between_params[1]))[0]);
  380. $between_array = array();
  381. //$more_params=array();
  382. foreach ($between_param_items as $item) {
  383. if ($item != '') {
  384. $itemval = explode(":", $item);
  385. if (isset($itemval[1])) {
  386. $itemvals = explode("|", $itemval[1]);
  387. $between_array[] = array($itemval[0] => $itemvals);
  388. }
  389. }
  390. }
  391. return (count($between_array) > 0) ? $between_array : null;
  392. } else {
  393. return null;
  394. }
  395. }
  396. /* ////////////////////////////////////////////////////////////////////////// */
  397. /* /////////////////////////////// GET DB RECORD ORDER VALUE ////////////////////////////// */
  398. public static function getOrderValues($parent, $data)
  399. {
  400. $order_array = array();
  401. if (strpos($data, "orderby=")) {
  402. $order_params = explode("orderby=", $data);
  403. if (!isset($order_params[1]) || $order_params[1] == null || $order_params[1] == '') {
  404. $parent->response(array('response' => 'failed'), 404);
  405. }
  406. $order_param_items = explode(",", array_values(explode('&', $order_params[1]))[0]);
  407. foreach ($order_param_items as $item) {
  408. $order_array[] = $item;
  409. }
  410. return (count($order_array) > 0) ? $order_array : null;
  411. } else {
  412. return null;
  413. }
  414. }
  415. /* ////////////////////////////////////////////////////////////////////////// */
  416. /* /////////////////////////////// TOKEN GENERATION ////////////////////////////// */
  417. public static function generateToken($parent, $token_type = '', $length = 128)
  418. {
  419. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  420. $charactersLength = strlen($characters);
  421. $randomString = '';
  422. for ($i = 0; $i < $length; $i++) {
  423. $randomString .= $characters[rand(0, $charactersLength - 1)];
  424. }
  425. //ACCESS TOKEN ALREADY EXIST
  426. switch (strtolower($token_type)) {
  427. case "access":
  428. $query_checkuser = $parent->getQueryCount("SELECT userid FROM " . TABLE_USER . " WHERE auth_token='" . $randomString . "' LIMIT 1");
  429. return ($query_checkuser == 1) ? self::generateToken($parent, $token_type, $length) : $randomString;
  430. break;
  431. case "forgot":
  432. $query_checkuser = $parent->getQueryCount("SELECT userid FROM " . TABLE_USER . " WHERE valid_token='" . $randomString . "' LIMIT 1");
  433. return ($query_checkuser == 1) ? self::generateToken($parent, $token_type, $length) : $randomString;
  434. break;
  435. case "enquiry":
  436. $query_checkuser = $parent->getQueryCount("SELECT id FROM " . DMS_ENQUIRY_MASTER . " WHERE share_token='" . $randomString . "' LIMIT 1");
  437. return ($query_checkuser == 1) ? self::generateToken($parent, $token_type, $length) : $randomString;
  438. break;
  439. //case "forgot":
  440. default:
  441. return $randomString;
  442. break;
  443. }
  444. }
  445. /* ///////////////////////////////////////////////////////////////////////////////////// */
  446. /* /////////////////////////////// EXPIRY TIME ////////////////////////////// */
  447. public static function generateExpiryTime($parent, $min = 15)
  448. {
  449. $sec = $min * 60;
  450. //echo $sec.'--';
  451. $expiry_time = date('Y-m-d H:i:s', strtotime('+' . $sec . ' seconds', strtotime(NOW)));
  452. //echo $expiry_time;die();
  453. return $expiry_time;
  454. }
  455. /* ///////////////////////////////////////////////////////////////////////////////////// */
  456. /* /////////////////////////////// EXPIRY TIME ////////////////////////////// */
  457. public static function generateExpiryDate($parent, $days = 10)
  458. {
  459. $expiry_time = date('Y-m-d H:i:s', strtotime('-' . $days . ' day', strtotime(NOW)));
  460. //echo $expiry_time;die();
  461. return $expiry_time;
  462. }
  463. /* ///////////////////////////////////////////////////////////////////////////////////// */
  464. /* /////////////////////////////// UPDATE USER TOKEN ////////////////////////////// */
  465. /*
  466. public static function updateUserToken($parent,$data) {
  467. if(IS_MULTI_LOGIN==1){
  468. $parent->executeQuery("INSERT INTO ".TABLE_USER_DEVICES."(`userid`, `devicetype`, `token`, `android_id`, `model`, `manufacture`, `version`, `client_ip`, `created_on`, `modified_on`) VALUES ('".$data['user_id']."','".$data['device_name']."','".$data['device_id']."','".$parent->device_type."','".$data['requester']->ip."','".$data['requester']->city."','".$data['requester']->country."','".$data['access_token']."','".NOW."','".NOW."')");
  469. return true;
  470. }else{
  471. $query_user_devices=$parent->selectQuery(TABLE_USER_DEVICES,"id","user_id='".$data['user_id']."' AND device_type='".$parent->device_type."'","1");
  472. if($query_user_devices['nr']<= 0){
  473. $parent->executeQuery("INSERT INTO ".TABLE_USER_DEVICES."( `user_id`,`device_name`,`device_id`,`device_type`,`client_ip`,`city`,`country`,`access_token`, `created_on`, `modified_on`) VALUES ('".$data['user_id']."','".$data['device_name']."','".$data['device_id']."','".$parent->device_type."','".$data['requester']->ip."','".$data['requester']->city."','".$data['requester']->country."','".$data['access_token']."','".NOW."','".NOW."')");
  474. return true;
  475. }else{
  476. $parent->executeQuery(" UPDATE ".TABLE_USER_DEVICES." SET device_name='".$data['device_name']."', device_id ='".$data['device_id']."', client_ip='".$data['requester']->ip."', city ='".$data['requester']->city."', country ='".$data['requester']->city."', access_token ='".$data['access_token']."', modified_on='".NOW."' WHERE user_id='".$data['user_id']."' AND device_type='".$parent->device_type."'");
  477. return true;
  478. }
  479. }
  480. return false;
  481. }
  482. */
  483. /* ///////////////////////////////////////////////////////////////////////////////////// */
  484. /* //////////////////////////////////// AUTHROZATION /////////////////////////////////
  485. /* /////////////////////////////// GET AUTHROZATION TOKEN////////////////////////////// */
  486. public static function getAuthrozation($parent)
  487. {
  488. $headers = getallheaders();
  489. $auth = '';
  490. if (isset($headers['Authorization']) || isset($headers['authorization'])) {
  491. $auth = (isset($headers['Authorization'])) ? 'Authorization' : 'authorization';
  492. } else {
  493. $parent->response(array('response' => 'failed', 'message' => 'Authrozation required'), 401);
  494. }
  495. $request_token = $headers[$auth];
  496. if (is_null($request_token)) {
  497. $parent->response(array('response' => 'failed', 'message' => 'Authrozation value required'), 401);
  498. }
  499. $access_token = explode("Bearer ", $request_token);
  500. if (!(isset($access_token[1])) || $access_token[1] == '') {
  501. $parent->response(array('response' => 'failed', 'message' => 'Authrozation value format not matched'), 401);
  502. }
  503. return $access_token[1];
  504. }
  505. /* ///////////////////////////////////////////////////////////////////////////////////// */
  506. /* /////////////////////////////// LOCK ACCESS ////////////////////////////// */
  507. public static function secureAccess($parent, $access_token)
  508. {
  509. //CHECK LOCK IS ENABLE
  510. if (LOCK_ACCESS_ENABLE == 1) {
  511. $sec = LOCK_ACCESS_MINUTES * 60;
  512. $expiry_time = date('Y-m-d H:i:s', strtotime('-' . $sec . ' seconds', strtotime(NOW)));
  513. $lock_qry_str = "SELECT * FROM " . TABLE_LOCK_ACCESS . " WHERE is_deleted='0' AND lock_count>='" . LOCK_ACCESS_COUNT . "' AND auth_token='" . $access_token . "' AND modified_on>='" . $expiry_time . "' LIMIT 1 ";
  514. $lock_value = $parent->getQueryValue($lock_qry_str);
  515. if (count($lock_value) > 0) {
  516. $parent->response(array('response' => 'failed', 'message' => 'Sorry Your Access locked.'), 401);
  517. }
  518. }
  519. }
  520. /* ///////////////////////////////////////////////////////////////////////////////////// */
  521. /* /////////////////////////////// OTP AUTHROZATION CHECKING ////////////////////////////// */
  522. public static function checkAuthrozation($parent, $data)
  523. {
  524. /* data is a stdClass values */
  525. /* type : otp/user */
  526. if (!isset($data)) {
  527. self::callErrorMsg($parent, array('message' => 'GLOBAL(checkAuthrozation):REQUIRED DATA'));
  528. }
  529. if (!isset($data['type'])) {
  530. self::callErrorMsg($parent, array('message' => 'GLOBAL(checkAuthrozation):REQUIRED type VALUE'));
  531. }
  532. $access_token = escape_str(self::getAuthrozation($parent));
  533. self::secureAccess($parent, $access_token);
  534. switch ($data['type']) {
  535. /*
  536. case "otp":
  537. $user_qry_str="SELECT user_id FROM ".TABLE_USER." WHERE otpnumber='".$access_token."' AND is_deleted!='1' AND status='1' LIMIT 1";
  538. $user_value=$parent->getQueryValue($user_qry_str);
  539. if(count($user_value)<=0) $parent->response(array('response'=>'failed', 'message'=>'INVALID OTP'), 401);
  540. $parent->current_user_data=$user_value[0];
  541. return $user_value[0];
  542. break;
  543. */
  544. case "user":
  545. $user_qry_str = "SELECT * FROM " . TABLE_USER . " WHERE is_deleted='0' AND status='1' AND auth_token='" . $access_token . "' AND auth_token!='' LIMIT 1";
  546. $user_value = $parent->getQueryValue($user_qry_str);
  547. //if(count($user_value)<=0) $parent->response(array('response'=>'failed', 'message'=>'INVALID USER ACCESS TOKEN'), 401);
  548. if (count($user_value) <= 0) {
  549. self::insertLockLog($parent, $access_token);
  550. $parent->response(array('response' => 'failed', 'message' => 'Session expired or You have already logged-in another device'), 401);
  551. }
  552. $parent->current_user_data = $user_value[0];
  553. $parent->current_user_id = $user_value[0]->userid;
  554. $parent->current_user_role = $user_value[0]->role;
  555. $parent->current_smpin = $user_value[0]->smpin;
  556. $parent->current_emp_code = $user_value[0]->emp_code;
  557. unset($user_value[0]->userid);
  558. return $user_value[0];
  559. break;
  560. case "set_password":
  561. $user_qry_str = "SELECT " . self::$user_fields . " FROM " . TABLE_USER . " WHERE valid_token='" . $access_token . "' AND auth_token!='' AND is_deleted='0' AND status='1' LIMIT 1";
  562. $user_value = $parent->getQueryValue($user_qry_str);
  563. if (count($user_value) <= 0) {
  564. self::insertLockLog($parent, $access_token);
  565. $parent->response(array('response' => 'failed', 'message' => 'Invalid Authentication token'), 401);
  566. }
  567. if ($user_value[0]->validate_time == "0000-00-00 00:00:00") {
  568. $parent->response(array('response' => 'failed', 'message' => 'Authentication token expired, Please initiate a new password reset request again.'), 406);
  569. }
  570. if (strtotime($user_value[0]->validate_time) < strtotime(NOW)) {
  571. $parent->response(array('response' => 'failed', 'message' => 'Authentication token expired, Please initiate a new password reset request again.'), 406);
  572. }
  573. $parent->current_user_data = $user_value[0];
  574. $parent->current_user_id = $user_value[0]->userid;
  575. $parent->current_user_role = $user_value[0]->role;
  576. $parent->current_smpin = $user_value[0]->smpin;
  577. $parent->current_emp_code = $user_value[0]->emp_code;
  578. unset($user_value[0]->userid);
  579. return $user_value[0];
  580. break;
  581. case "explore":
  582. $user_qry_str = "SELECT * FROM " . TABLE_USER . " WHERE is_deleted='0' AND status='1' AND auth_token='" . $access_token . "' AND auth_token!='' LIMIT 1";
  583. $user_value = $parent->getQueryValue($user_qry_str);
  584. if (count($user_value) > 0) {
  585. $parent->current_user_data = $user_value[0];
  586. $parent->current_user_id = $user_value[0]->userid;
  587. $parent->current_user_role = $user_value[0]->role;
  588. $parent->current_smpin = $user_value[0]->smpin;
  589. $parent->current_emp_code = $user_value[0]->emp_code;
  590. unset($user_value[0]->userid);
  591. return $user_value[0];
  592. } else {
  593. if ($access_token == MODE_ONE_TOKEN) {
  594. $parent->exp_model_type = 0;
  595. } else if ($access_token == MODE_TWO_TOKEN) {
  596. $parent->exp_model_type = 1;
  597. } else {
  598. self::insertLockLog($parent, $access_token);
  599. $parent->response(array('response' => 'failed', 'message' => 'Invalid Authentication token'), 401);
  600. }
  601. $parent->current_user_data = array();
  602. $parent->current_user_role = 0;
  603. $parent->current_user_id = 'guest';
  604. return null;
  605. }
  606. break;
  607. default:
  608. self::callErrorMsg($parent, array('message' => 'GLOBAL(checkAuthrozation):TYPE VALUE WAS NOT ACCEPTABLE'));
  609. break;
  610. }
  611. }
  612. /* ///////////////////////////////////////////////////////////////////////////////////// */
  613. /* /////////////////////////////// TOKEN GENERATION ////////////////////////////// */
  614. public static function generateOTP($length = 4)
  615. {
  616. $characters = '0123456789';
  617. $charactersLength = strlen($characters);
  618. $randomString = '';
  619. for ($i = 0; $i < $length; $i++) {
  620. $randomString .= $characters[rand(0, $charactersLength - 1)];
  621. }
  622. //$randomString='1234';
  623. //EDIT FOR DEV
  624. if (IS_LIVE_SERVER == '0') {
  625. $randomString = '1234';
  626. }
  627. // else{ //SMS CHENGE
  628. // $randomString='1234';
  629. // }
  630. return $randomString;
  631. }
  632. /* ///////////////////////////////////////////////////////////////////////////////////// */
  633. /* /////////////////////////////// GET SITE SETTING ////////////////////////////// */
  634. public static function getSiteSetting($parent, $data)
  635. {
  636. if (!isset($data)) {
  637. self::callErrorMsg($parent, array('message' => 'GLOBAL(getSiteSetting):REQUIRED DATA'));
  638. }
  639. if (!isset($data['setting']) || $data['setting'] == '' || $data['setting'] == null) {
  640. self::callErrorMsg($parent, array('message' => 'GLOBAL(getSiteSetting):REQUIRED setting VALUE'));
  641. }
  642. $user_qry_str = "SELECT * FROM " . TABLE_SITE_SETTING . " WHERE setting_type='" . $data['setting'] . "' AND is_active='1'";
  643. $user_value = $parent->getQueryValue($user_qry_str);
  644. $out_data = new stdClass();
  645. foreach ($user_value as $values) {
  646. $key_name = $values->setting_title;
  647. $out_data->$key_name = $values->value;
  648. }
  649. return $out_data;
  650. }
  651. /* ///////////////////////////////////////////////////////////////////////////////////// */
  652. /* /////////////////////////////// PASSWORD POLICY ////////////////////////////// */
  653. public static function passwordPolicy($parent, $data)
  654. {
  655. if (!isset($data)) {
  656. self::callErrorMsg($parent, array('message' => 'GLOBAL(passwordPolicy):REQUIRED DATA'));
  657. }
  658. if (!isset($data['password']) || $data['password'] == '' || $data['password'] == null) {
  659. self::callErrorMsg($parent, array('message' => 'GLOBAL(passwordPolicy):REQUIRED password VALUE'));
  660. }
  661. $policy_setting = self::getSiteSetting($parent, array('setting' => 'PASSWORD_POLICY'));
  662. if (strtolower($policy_setting->POLICY_REQUIRED) == "true") {
  663. //print_r($policy_setting);
  664. if (!is_numeric($policy_setting->MINIMUM_LENGTH)) {
  665. self::callErrorMsg($parent, array('message' => 'GLOBAL(passwordPolicy):ERROR IN PASSWORD MINIMUM_LENGTH SETTING VALUE.'));
  666. }
  667. if (!is_numeric($policy_setting->MAXIMUM_LENGTH)) {
  668. self::callErrorMsg($parent, array('message' => 'GLOBAL(passwordPolicy):ERROR IN PASSWORD MAXIMUM_LENGTH SETTING VALUE.'));
  669. }
  670. if (!(strlen($data['password']) >= $policy_setting->MINIMUM_LENGTH && strlen($data['password']) <= $policy_setting->MAXIMUM_LENGTH)) {
  671. $parent->response(array('response' => 'failed', 'message' => 'PASSWORD LENTH WAS NOT MATCHED IN THE PASSWORD POLICY'), 406);
  672. }
  673. if (!is_numeric($policy_setting->POLICY_TYPE)) {
  674. self::callErrorMsg($parent, array('message' => 'GLOBAL(passwordPolicy):ERROR IN PASSWORD POLICY_TYPE SETTING VALUE.'));
  675. }
  676. switch ($policy_setting->POLICY_TYPE) {
  677. case 1:
  678. if (!is_numeric($data['password'])) {
  679. $parent->response(array('response' => 'failed', 'message' => 'Password value was not matched in the password policy'), 406);
  680. }
  681. break;
  682. case 2:
  683. if (!ctype_alpha($data['password'])) {
  684. $parent->response(array('response' => 'failed', 'message' => 'Password value was not matched in the password policy'), 406);
  685. }
  686. break;
  687. case 3:
  688. if (!preg_match("/(?=.*[A-Z])(?=.*[a-z])[A-Za-z]+$/", $data['password'])) {
  689. $parent->response(array('response' => 'failed', 'message' => 'Password value was not matched in the password policy'), 406);
  690. }
  691. break;
  692. case 4:
  693. if (!(preg_match('/[A-Za-z]/', $data['password']) && preg_match('/[0-9]/', $data['password']))) {
  694. $parent->response(array('response' => 'failed', 'message' => 'Password value was not matched in the password policy'), 406);
  695. }
  696. break;
  697. case 5:
  698. if (!(preg_match('/[0-9]/', $data['password']) && preg_match('/[A-Z]/', $data['password']) && preg_match('/[a-z]/', $data['password']))) {
  699. $parent->response(array('response' => 'failed', 'message' => 'Password value was not matched in the password policy'), 406);
  700. }
  701. break;
  702. case 6:
  703. if (!preg_match("/^(?=.*\d)(?=.*[@#!.-])(?=.*[A-Z])(?=.*[a-z])[0-9A-Za-z!-@#.\/]{1,}$/", ($data['password']))) {
  704. $parent->response(array('response' => 'failed', 'message' => 'Password value was not matched in the password policy'), 406);
  705. }
  706. break;
  707. case 7:
  708. break;
  709. default:
  710. self::callErrorMsg($parent, array('message' => 'GLOBAL(passwordPolicy):ERROR IN PASSWORD POLICY_TYPE VALUE SHOULD 1 TO 6 ONLY.'));
  711. break;
  712. }
  713. /*
  714. if(is_numeric($policy_setting->PREVIOUS_COUNT) && 0<=(int)$policy_setting->PREVIOUS_COUNT){
  715. if($policy_setting->PREVIOUS_COUNT!=0){
  716. if(!isset($data['user_id']) || $data['user_id']=='' || $data['user_id']==NULL) self::callErrorMsg($parent,array('message'=>'GLOBAL(passwordPolicy):REQUIRED user_id VALUE.'));
  717. $query_previous_passwords=$parent->selectQuery("(SELECT * FROM ".TABLE_USER_PASSWORD_LOGS." WHERE user_id='".$data['user_id']."' AND is_reseted=0 ORDER BY id DESC LIMIT ".((int)$policy_setting->PREVIOUS_COUNT+1).") as a ","a.user_id","a.password='".md5($data['password'])."' ");
  718. if($query_previous_passwords['nr']!=0) $parent->response(array('response'=>'failed','message'=>'Your new password value is match with last '.$policy_setting->PREVIOUS_COUNT.' password(s)'),406);
  719. }
  720. }else{
  721. self::callErrorMsg($parent,array('message'=>'GLOBAL(passwordPolicy):ERROR IN PASSWORD PREVIOUS_COUNT SETTING VALUE.'));
  722. }
  723. */
  724. }
  725. }
  726. /* ///////////////////////////////////////////////////////////////////////////////////// */
  727. /* /////////////////////////////// UPDATE PASSWORD ////////////////////////////// */
  728. public static function updatePassword($parent, $data)
  729. {
  730. if (!isset($data)) {
  731. self::callErrorMsg($parent, array('message' => 'GLOBAL(updatePassword):REQUIRED DATA'));
  732. }
  733. if (!isset($data['password']) || $data['password'] == '' || $data['password'] == null) {
  734. self::callErrorMsg($parent, array('message' => 'GLOBAL(updatePassword):REQUIRED password VALUE'));
  735. }
  736. if (!isset($data['userid']) || $data['userid'] == '' || $data['userid'] == null) {
  737. self::callErrorMsg($parent, array('message' => 'GLOBAL(updatePassword):REQUIRED userid VALUE'));
  738. }
  739. $parent->executeQuery(" UPDATE " . TABLE_USER . " SET password='" . md5($data['password']) . "',last_password_change='" . NOW . "',modified_on='" . NOW . "' WHERE userid='" . $data['userid'] . "'");
  740. return true;
  741. }
  742. /* ///////////////////////////////////////////////////////////////////////////////////// */
  743. /* /////////////////////////////// SEND OTP ////////////////////////////// */
  744. public static function sendOtp($parent, $type, $otp_value, $message, $send_to)
  745. {
  746. }
  747. /* ///////////////////////////////////////////////////////////////////////////////////// */
  748. /* /////////////////////////////// INSERT LOCK ACCESS ////////////////////////////// */
  749. public static function insertLockLog($parent, $access_token)
  750. {
  751. $lock_qry_str = "SELECT * FROM " . TABLE_LOCK_ACCESS . " WHERE is_deleted='0' AND auth_token='" . $access_token . "' LIMIT 1";
  752. $lock_value = $parent->getQueryValue($lock_qry_str);
  753. //LOCK ACCESS
  754. if (count($lock_value) > 0) {
  755. $client_ip = self::getIp($parent);
  756. $parent->executeQuery("UPDATE " . TABLE_LOCK_ACCESS . " SET `ip`='" . $client_ip . "',page='" . escape_str($parent->api_url) . "' ,lock_count=lock_count+1, `modified_on`='" . NOW . "' WHERE id='" . $lock_value[0]->id . "'");
  757. } else {
  758. $client_ip = self::getIp($parent);
  759. $parent->executeQuery("INSERT INTO " . TABLE_LOCK_ACCESS . " ( `auth_token`, `ip`, `lock_count`,page, `is_deleted`, `created_on`, `modified_on`) VALUES ('" . $access_token . "','" . $client_ip . "',1,'" . escape_str($parent->api_url) . "', 0, '" . NOW . "', '" . NOW . "')");
  760. }
  761. }
  762. /* ////////////////////////////////////////////////////////////////////////// */
  763. /* /////////////////////////////// INSERT LOG ////////////////////////////// */
  764. public static function insertUserLog($parent, $activity, $module_id = 0)
  765. {
  766. if ($parent->current_user_id != null) {
  767. $client_ip = self::getIp($parent);
  768. $parent->executeQuery("INSERT INTO " . TABLE_USER_LOG . " ( `userid`,`device_type`, `module`,module_id, `ip`, `created_on`) VALUES ('" . $parent->current_user_id . "','" . $parent->device_type . "','" . $activity . "','" . $module_id . "','" . $client_ip . "','" . NOW . "')");
  769. }
  770. }
  771. /* ////////////////////////////////////////////////////////////////////////// */
  772. /* /////////////////////////////// MASK MOBILE ////////////////////////////// */
  773. public static function maskMobileno($number)
  774. {
  775. $masked = str_pad(substr($number, -4), strlen($number), 'X', STR_PAD_LEFT);
  776. //$masked = substr($number,0,1).str_pad(substr($number, -4), (strlen($number)-1), 'X', STR_PAD_LEFT);
  777. return $masked;
  778. }
  779. /* ////////////////////////////////////////////////////////////////////////// */
  780. /* /////////////////////////////// IMAGE CROP ////////////////////////////// */
  781. public static function setImageCrop($parent, $file_path, $cord, $targ_w = 200, $targ_h = 300)
  782. {
  783. //$targ_w = 200;
  784. //$targ_h = 300;
  785. $jpeg_quality = 80;
  786. $img_r = self::imagecreatefromfile($parent, $file_path);
  787. $dst_r = ImageCreateTrueColor($targ_w, $targ_h);
  788. $cords = explode("|", $cord);
  789. //imagecopyresampled($dst_r,$img_r,0,0,(int)$cords[0],(int)$cords[1],$targ_w,$targ_h,(int)$cords[2],(int)$cords[3]);
  790. imagecopyresampled($dst_r, $img_r, 0, 0, (int) $cords[0], (int) $cords[1], $targ_w, $targ_h, (int) $cords[2], (int) $cords[3]);
  791. self::imagesavefile($parent, $dst_r, $file_path, $jpeg_quality);
  792. //shell_exec("sudo chmod -R 777 ".$file_path);
  793. chmod($file_path, 0777);
  794. }
  795. /* ////////////////////////////////////////////////////////////////////////// */
  796. /* /////////////////////////////// CREATE FILE ////////////////////////////// */
  797. public static function imagecreatefromfile($parent, $filename)
  798. {
  799. (!file_exists($filename)) ? $parent->response(array('response' => 'failed'), 403) : null;
  800. switch (strtolower(pathinfo($filename, PATHINFO_EXTENSION))) {
  801. case 'jpeg':
  802. case 'jpg':
  803. return imagecreatefromjpeg($filename);
  804. break;
  805. case 'png':
  806. return imagecreatefrompng($filename);
  807. break;
  808. case 'gif':
  809. return imagecreatefromgif($filename);
  810. break;
  811. default:
  812. $parent->response(array('response' => 'failed', 'message' => 'FILE IS NOT VALID JPG, PNG OR GIF IMAGE.'), 403);
  813. break;
  814. }
  815. }
  816. /* ////////////////////////////////////////////////////////////////////////// */
  817. /* /////////////////////////////// SAVE CROP FILE ////////////////////////////// */
  818. public static function imagesavefile($parent, $dst_r, $file_path, $jpeg_quality)
  819. {
  820. (!file_exists($file_path)) ? $parent->response(array('response' => 'failed', 'message' => 'FILE PATH NOT FOUND.'), 403) : null;
  821. switch (strtolower(pathinfo($file_path, PATHINFO_EXTENSION))) {
  822. case 'jpeg':
  823. case 'jpg':
  824. imagejpeg($dst_r, $file_path, $jpeg_quality);
  825. break;
  826. case 'png':
  827. imagepng($dst_r, $file_path);
  828. break;
  829. default:
  830. $parent->response(array('response' => 'failed', 'message' => 'FILE NOT VALID JPG, PNG OR GIF IMAGE.'), 403);
  831. break;
  832. }
  833. }
  834. /* ////////////////////////////////////////////////////////////////////////// */
  835. /* /////////////////////////////// UPLOAD FILE ////////////////////////////// */
  836. public static function uploadFile($parent, $obj)
  837. {
  838. $filekey = $obj->filekey;
  839. $path = $obj->path;
  840. $fileprefix = (isset($obj->fileprefix)) ? $obj->fileprefix : 'file';
  841. if (is_object($obj) && isset($_FILES[$obj->filekey])) {
  842. $tempFile = $_FILES[$obj->filekey]['tmp_name'];
  843. $fileParts = pathinfo($_FILES[$obj->filekey]['name']);
  844. $fileext_arr = explode('?', $fileParts['extension']);
  845. $fileExtension = strtolower($fileext_arr[0]);
  846. $file_prehead = (IS_LIVE_SERVER != '1') ? "_development" : "";
  847. $fileName = (isset($obj->filename)) ? $obj->filename . $file_prehead . '.' . $fileExtension : $fileprefix . '_' . date('YmdHis') . uniqid() . $file_prehead . '.' . $fileExtension;
  848. $targetFile = $path . $fileName;
  849. @move_uploaded_file($tempFile, $targetFile);
  850. //shell_exec("sudo chmod -R 777 ".$targetFile);
  851. chmod($targetFile, 0777);
  852. if (isset($obj->cord) && $obj->cord != null) {
  853. (isset($obj->width) && $obj->width != null && isset($obj->height) && $obj->height != null) ? self::setImageCrop($parent, $targetFile, $obj->cord, $obj->width, $obj->height) : self::setImageCrop($parent, $targetFile, $obj->cord);
  854. }
  855. return $fileName;
  856. }
  857. }
  858. /* ////////////////////////////////////////////////////////////////////////// */
  859. /* /////////////////////////////// USER OTP VALIDATE ////////////////////////////// */
  860. /*
  861. public static function validateUserOtp($parent,$otpval)
  862. {
  863. if($parent->current_user_id)
  864. {
  865. $query_checkvin=$parent->getQueryValue("SELECT * FROM ".TABLE_USER." WHERE user_id='".$parent->current_user_id."' LIMIT 1");
  866. if(count($query_checkvin)>0)
  867. {
  868. if($query_checkvin[0]->otp!=$otpval) $parent->response(array('response'=>'failed','message'=>'NOT VALID OTP'),200);
  869. if(!(strtotime(NOW)<strtotime($query_checkvin[0]->otp_time))) $parent->response(array('response'=>'failed','message'=>'OTP EXPIRED'),200);
  870. }else{
  871. $parent->response(array('response'=>'failed'), 401);
  872. }
  873. }else{
  874. $parent->response(array('response'=>'failed'), 401);
  875. }
  876. return null;
  877. }
  878. */
  879. /* ////////////////////////////////////////////////////////////////////////// */
  880. /* /////////////////////////////// GET EXCEL NUMBER ////////////////////////////// */
  881. public static function getNameFromNumber($num)
  882. {
  883. $numeric = $num % 26;
  884. $letter = chr(65 + $numeric);
  885. $num2 = intval($num / 26);
  886. if ($num2 > 0) {
  887. return self::getNameFromNumber($num2 - 1) . $letter;
  888. } else {
  889. return $letter;
  890. }
  891. }
  892. /* ////////////////////////////////////////////////////////////////////////// */
  893. /* /////////////////////////////// GET INDIAN MOBILE ////////////////////////////// */
  894. public static function getIndianMobile($mnum)
  895. {
  896. return substr($mnum, -10);
  897. }
  898. /* ////////////////////////////////////////////////////////////////////////// */
  899. /* /////////////////////////////// CHECK DATE GREATER ////////////////////////////// */
  900. public static function checkDateGreater($fdate, $sdate)
  901. {
  902. $reval = true;
  903. if ($fdate && $sdate && $fdate != '0000-00-00 00:00:00' && $sdate != '0000-00-00 00:00:00' && $fdate != '0000-00-00' && $sdate != '0000-00-00') {
  904. $reval = (strtotime($fdate) > strtotime($sdate)) ? true : false;
  905. }
  906. return $reval;
  907. }
  908. /* ////////////////////////////////////////////////////////////////////////// */
  909. /* /////////////////////////////// REMOVE DIRECTORY ////////////////////////////// */
  910. // rrmdir('../../uploads/zip/');
  911. public static function rrmdir($dir, $check = false)
  912. {
  913. if (is_dir($dir)) {
  914. $objects = scandir($dir);
  915. foreach ($objects as $object) {
  916. if ($object != "." && $object != "..") {
  917. if (filetype($dir . "/" . $object) == "dir") {
  918. self::rrmdir($dir . "/" . $object, true);
  919. } else {
  920. unlink($dir . "/" . $object);
  921. }
  922. }
  923. }
  924. reset($objects);
  925. ($check) ? rmdir($dir) : null;
  926. }
  927. }
  928. /* ////////////////////////////////////////////////////////////////////////// */
  929. /* ////////////////////////////////// ANDRIOD FCM FUNCTION ///////////////////////////// */
  930. private static function sendGoogleCloudMessage($messagearr, $reg_id)
  931. {
  932. //print_r($messagearr);
  933. //print_r($reg_id);
  934. $title = $messagearr['title'];
  935. $message = $messagearr['message'];
  936. $messagearr['body'] = $messagearr['message'];
  937. $fields = array(
  938. 'registration_ids' => $reg_id,
  939. 'priority' => "high",
  940. 'notification' => array("title" => $title, "body" => $message, "sound" => "default"),
  941. 'data' => $messagearr,
  942. );
  943. $headers = array(
  944. GOOGLE_FCM_URL,
  945. 'Content-Type: application/json',
  946. 'Authorization: key=' . GOOGLE_API_KEY,
  947. );
  948. // $ch = curl_init();
  949. // curl_setopt($ch, CURLOPT_URL, GOOGLE_FCM_URL);
  950. // curl_setopt($ch, CURLOPT_POST, true);
  951. // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  952. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  953. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  954. // curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  955. // $result = curl_exec($ch);
  956. // //echo $result;
  957. // curl_close($ch);
  958. echo $result="";
  959. }
  960. /* ////////////////////////////////////////////////////////////////////////// */
  961. /* ////////////////////////////////// IOS GCM FUNCTION ///////////////////////////// */
  962. private static function sendFCMIOSCloudMessage($messagearr, $reg_id)
  963. {
  964. //print_r($messagearr);
  965. //print_r($reg_id);
  966. $title = $messagearr['title'];
  967. $message = $messagearr['message'];
  968. $fields = array(
  969. //'to'=> $reg_id,
  970. "content_available" => true,
  971. 'registration_ids' => $reg_id,
  972. 'priority' => "high",
  973. 'aps' => array("content-available" => 1),
  974. 'notification' => $messagearr,
  975. //'data' => $messagearr,
  976. 'data' => array('published' => NOW),
  977. 'notId' => rand(1000, 9999),
  978. );
  979. $headers = array(
  980. GOOGLE_FCM_URL,
  981. 'Content-Type: application/json',
  982. 'Authorization: key=' . GOOGLE_API_KEY,
  983. );
  984. //echo "<br>";
  985. // $ch = curl_init();
  986. // curl_setopt($ch, CURLOPT_URL, GOOGLE_FCM_URL);
  987. // curl_setopt($ch, CURLOPT_POST, true);
  988. // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  989. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  990. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  991. // curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  992. // $result = curl_exec($ch);
  993. // //print_r($result);
  994. // curl_close($ch);
  995. echo $result="";
  996. }
  997. /* ////////////////////////////////////////////////////////////////////////// */
  998. /* ////////////////////////////////////// SEND NOTIFICATION ///////////////////////////////// */
  999. public static function sendUserNotification($message, $usertokenarr)
  1000. {
  1001. //STRUCTURE $usertokenarr =array('android'=>$arr,'ios'=>$arr);
  1002. // $android_ids = (isset($usertokenarr['android'])) ? $usertokenarr['android'] : array();
  1003. // $ios_ids = (isset($usertokenarr['ios'])) ? $usertokenarr['ios'] : array();
  1004. // if (count($android_ids) > 0) {
  1005. // $ids_arr = array_chunk($android_ids, 1000);
  1006. // if (count($ids_arr) > 0) {
  1007. // foreach ($ids_arr as $groupids) {
  1008. // self::sendGoogleCloudMessage($message, $groupids);
  1009. // }
  1010. // }
  1011. // }
  1012. // if (count($ios_ids) > 0) {
  1013. // $ids_arr = array_chunk($ios_ids, 1000);
  1014. // if (count($ids_arr) > 0) {
  1015. // foreach ($ids_arr as $groupids) {
  1016. // self::sendFCMIOSCloudMessage($message, $groupids);
  1017. // //self::sendIoCloudMessage($message, $groupids);
  1018. // }
  1019. // }
  1020. // }
  1021. }
  1022. /* ////////////////////////////////////////////////////////////////////////// */
  1023. /* ////////////////////////////////////// SLUG ///////////////////////////////// */
  1024. public static function generate_slug($var)
  1025. {
  1026. if ($var) {
  1027. $var = @str_replace(' ', '-', trim($var));
  1028. $var = @strtolower($var);
  1029. $slugname = @preg_replace('/[^A-Za-z0-9\-]/', '', $var);
  1030. $slugname = @preg_replace('/-+/', '-', $slugname);
  1031. }
  1032. return $slugname;
  1033. }
  1034. /* ////////////////////////////////////////////////////////////////////////// */
  1035. //KEY VALIDATION
  1036. public static function validRequestKey($input, $type)
  1037. {
  1038. //TYPES : integer,string,double,array,object,date|Y-m-d
  1039. switch ($type) {
  1040. //VALID CONDITIONS
  1041. case 'integer':return (ctype_digit(strval($input)));
  1042. break;
  1043. case 'string':return is_string($input);
  1044. break;
  1045. case 'number':return is_numeric($input);
  1046. break;
  1047. case 'double':return ((int) $input != $input && is_numeric($input));
  1048. break;
  1049. case 'array':return is_array($input);
  1050. break;
  1051. case 'object':return is_object($input);
  1052. break;
  1053. case 'date|Y-m-d':return self::isValidDateTimeString($input, 'Y-m-d', 'Asia/Kolkata');
  1054. break;
  1055. case 'date|Y-m-d H:i:s':return self::isValidDateTimeString($input, 'Y-m-d H:i:s', 'Asia/Kolkata');
  1056. break;
  1057. case 'date|d-m-Y':return self::isValidDateTimeString($input, 'd-m-Y', 'Asia/Kolkata');
  1058. break;
  1059. default:return false;
  1060. break;
  1061. }
  1062. }
  1063. //DATE VALIDATE
  1064. public static function isValidDateTimeString($str_dt, $str_dateformat, $str_timezone)
  1065. {
  1066. $date = DateTime::createFromFormat($str_dateformat, $str_dt, new DateTimeZone($str_timezone));
  1067. return $date && $date->format($str_dateformat) == $str_dt;
  1068. }
  1069. //MESSAGE RETURN
  1070. public static function getMessage($parent, $lang, $module)
  1071. {
  1072. if (file_exists("../../language/" . $lang . "/common.php")) {
  1073. include_once "../../language/" . $lang . "/common.php";
  1074. if (!isset($string[$module])) {
  1075. $parent->response(array('response' => 'failed', 'message' => 'MODULE LANGUAGE FILE NOT FOUND'), 500);
  1076. }
  1077. return $string[$module];
  1078. } else {
  1079. $parent->response(array('response' => 'failed', 'message' => 'LANGUAGE FILE NOT FOUND'), 500);
  1080. exit;
  1081. }
  1082. }
  1083. //SEND MAIL
  1084. public static function sendMail($parent, $obj)
  1085. {
  1086. // if (IS_LIVE_SERVER != '1') {
  1087. // $obj['to'] = 'lokesh.b@cygnusa.in';
  1088. // if (isset($obj['cc'])) {
  1089. // if (is_string($obj['cc'])) {
  1090. // $cc = $obj['cc'];
  1091. // $obj['cc'] = array();
  1092. // $obj['cc'][] = $cc;
  1093. // }
  1094. // }
  1095. // $obj['cc'][] = 'muthuramanr@cygnusa.in';
  1096. // $obj['subject'] = 'DEVELOPMENT TESTING : ' . $obj['subject'];
  1097. // }
  1098. // require_once dirname(__FILE__) . '/phpmailer/PHPMailerAutoload.php';
  1099. // require_once dirname(__FILE__) . '/phpmailer/class.phpmailer.php';
  1100. // $mail = null;
  1101. // try {
  1102. // $mail = new PHPMailer;
  1103. // $mail->isSMTP(); // telling the class to use SMTP
  1104. // $mail->SMTPAuth = false; // enable SMTP authentication
  1105. // //$mail->SMTPSecure = 'tls'; // sets the prefix to the servier
  1106. // //$mail->SMTPDebug = 2;
  1107. // $mail->Host = SMTP_HOST; // sets as the SMTP server
  1108. // $mail->Port = SMTP_PORT; // set the SMTP port for the server
  1109. // //$mail->Username = SMTP_USERNAME; // username
  1110. // //$mail->Password = SMTP_PASSWORD; // password
  1111. // // $mail->SMTPOptions = array(
  1112. // // 'ssl' => array(
  1113. // // 'verify_peer' => false,
  1114. // // 'verify_peer_name' => false,
  1115. // // 'allow_self_signed' => true
  1116. // // )
  1117. // // );
  1118. // $mail->setFrom($obj['from']); //Set who the message is to be sent from
  1119. // if (isset($obj['FromName'])) {
  1120. // $mail->FromName = $obj['FromName'];
  1121. // }
  1122. // if (isset($obj['replayto'])) {
  1123. // $mail->addReplyTo($obj['replayto']);
  1124. // }
  1125. // //TO EMAIL
  1126. // $to_email = '';
  1127. // if (isset($obj['to'])) {
  1128. // if (is_array($obj['to'])) {
  1129. // foreach ($obj['to'] as $res_to) {
  1130. // $mail->addAddress($res_to);
  1131. // }
  1132. // $to_email = @implode(',', $obj['to']);
  1133. // } else if (is_string($obj['to'])) {
  1134. // $mail->addAddress($obj['to']);
  1135. // $to_email = $obj['to'];
  1136. // }
  1137. // }
  1138. // $mail->addBCC(SUPPORT_EMAIL);
  1139. // //CC EMAIL
  1140. // $cc_email = '';
  1141. // if (isset($obj['cc'])) {
  1142. // if (is_array($obj['cc'])) {
  1143. // foreach ($obj['cc'] as $res_cc) {
  1144. // $mail->AddCC($res_cc);
  1145. // }
  1146. // $cc_email = @implode(',', $obj['cc']);
  1147. // } else if (is_string($obj['cc'])) {
  1148. // $mail->AddCC($obj['cc']);
  1149. // $cc_email = $obj['cc'];
  1150. // }
  1151. // }
  1152. // //$mail->AddBCC($obj->to);
  1153. // if (isset($obj['attachment_file'])) {
  1154. // $file_count = count($obj['attachment_file']);
  1155. // for ($x = 0; $x < $file_count; $x++) {
  1156. // if (!empty($obj['attachment_file'][$x])) {
  1157. // $mail->addAttachment($obj['attachment_file'][$x]);
  1158. // }
  1159. // }
  1160. // }
  1161. // $mail->isHTML(true);
  1162. // $mail->Subject = $obj['subject'];
  1163. // $contentmail = $obj['message'];
  1164. // $mail->Body = $contentmail;
  1165. // $parent->executeQuery("INSERT INTO " . TABLE_EMAIL_LOG . " (`to_mail`, `from_mail`, `cc_mail`, `subject`, `is_success`, `created_on`) VALUES ('" . escape_str($to_email) . "','" . $obj['from'] . "','" . escape_str($cc_email) . "','" . escape_str($obj['subject']) . "', '0','" . NOW . "' )");
  1166. // $logid = $parent->lastInsertId();
  1167. // if (!$mail->send()) {
  1168. // //echo "Mailer Error: " . $mail->ErrorInfo;
  1169. // $headers = "From: " . $obj['from'] . " \r\n";
  1170. // //$headers .= "Reply-To: ".$replayto." \r\n";
  1171. // $headers .= "MIME-Version: 1.0\r\n";
  1172. // $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  1173. // // @mail(SUPPORT_EMAIL, "Mail delivery report", "FROM : " . $obj['from'] . ", TO :" . $obj['to'] . " mail not delivered", $headers);
  1174. // } else {
  1175. // $parent->executeQuery("UPDATE " . TABLE_EMAIL_LOG . " SET is_success='1' WHERE id='" . $logid . "' ");
  1176. // }
  1177. // } catch (phpmailerException $e) {
  1178. // $headers = "From: " . $obj['from'] . " \r\n";
  1179. // //$headers .= "Reply-To: ".$replayto." \r\n";
  1180. // $headers .= "MIME-Version: 1.0\r\n";
  1181. // $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  1182. // // @mail(SUPPORT_EMAIL, "Mail delivery report", "FROM : " . $obj['from'] . ", TO :" . $obj['to'] . " mail not delivered", $headers);
  1183. // }
  1184. }
  1185. /* /////////////////////////////// FORGOTLINK ////////////////////////////// */
  1186. public static function sendForgotPasswordLink($parent, $data)
  1187. {
  1188. switch ($data['type']) {
  1189. case "test":
  1190. $message = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
  1191. <tbody><tr>
  1192. <td><table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
  1193. <tbody><tr>
  1194. <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 #C71444">Password Reset</td>
  1195. </tr>
  1196. <tr><td><table width="85%" align="center">
  1197. <tbody><tr><td height="30" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;">Dear <span style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left; font-weight:bold; text-transform:uppercase;">' . $data['send_to'] . ',</span></td>
  1198. </tr><tr><td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  1199. line-height: 1.5;"><div style="font-family:arial; color:#333; font-size:12px; padding:5px;">' . $data['link_value'] . '</div><div style="font-family:arial; color:#333; font-size:12px; padding:5px;" >This is an automatically generated email - please do not reply.</div></td>
  1200. </tr>
  1201. </tbody></table>
  1202. </td>
  1203. </tr>
  1204. <tr>
  1205. <td style="padding-top:0px; padding-bottom:10px;"></td>
  1206. </tr>
  1207. <tr>
  1208. <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 #C71444"><div class="footer-con">
  1209. <p>Thanks &amp; Regards, <strong style="color:#C71444;"> Nissan Support Team</strong></p>
  1210. </div></td>
  1211. </tr>
  1212. </tbody></table></td>
  1213. </tr>
  1214. </tbody></table>';
  1215. $obj = array();
  1216. $obj['from'] = SUPPORT_EMAIL;
  1217. $obj['replayto'] = SUPPORT_EMAIL;
  1218. $obj['to'] = $data['send_to'];
  1219. $obj['subject'] = "Password Reset";
  1220. $obj['message'] = $message;
  1221. // self::sendMai($parent, $obj);
  1222. break;
  1223. case "email":
  1224. $message = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
  1225. <tbody><tr>
  1226. <td><table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
  1227. <tbody><tr>
  1228. <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; ">Reset Password</td>
  1229. </tr>
  1230. <tr><td><table width="85%" align="center">
  1231. <tbody><tr><td height="30" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;">Hi <span style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left; font-weight:bold; text-transform:uppercase;"> ' . $data['user']->fname . ',</span></td>
  1232. </tr><tr><td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  1233. line-height: 1.5;"><div style="font-family:arial; color:#333; font-size:12px; padding:5px;">A password reset was requested for your account <a href="#" >' . $data['user']->emailid . '</a> at PACCAR PARTS BIN <br>To confirm this request, and set a new password for your account. please go to the following web address:<br><br><a href="' . $data['link_value'] . '">' . $data['link_value'] . '</a><br>(This link is valid for 30 min from the time this reset was first requested) <br><br>If this password reset was not requested by you, no action is needed.<br>If you need help, please contact the site administrator.</div><div style="font-family:arial; color:#333; font-size:12px; padding:5px;" >This is an automatically generated email - please do not reply.<br><br>Admin User </div></td>
  1234. </tr>
  1235. </tbody></table>
  1236. </td>
  1237. </tr>
  1238. <tr>
  1239. <td style="padding-top:0px; padding-bottom:10px;"></td>
  1240. </tr>
  1241. <tr>
  1242. <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">
  1243. <p>Thanks &amp; Regards, <strong style="color:Black"> Support Team</strong></p>
  1244. </div></td>
  1245. </tr>
  1246. </tbody></table></td>
  1247. </tr>
  1248. </tbody></table>';
  1249. $obj = array();
  1250. $obj['from'] = SUPPORT_EMAIL;
  1251. $obj['replayto'] = SUPPORT_EMAIL;
  1252. $obj['to'] = $data['send_to'];
  1253. $obj['subject'] = "FORGOT PASSWORD LINK";
  1254. $obj['message'] = $message;
  1255. // self::sendMai($parent, $obj);
  1256. break;
  1257. }
  1258. }
  1259. /////////////////////User creation Email /////////
  1260. public static function sendUserWelcomeEmail($parent, $data)
  1261. {
  1262. //print_r($data);
  1263. switch ($data['type']) {
  1264. }
  1265. }
  1266. public static function sendSMS($parent, $mobileno, $message)
  1267. {
  1268. // $test = "0";
  1269. // $username = SMS_USERNAME;
  1270. // $hash = SMS_HASH;
  1271. // $sender = SMS_SENDERID;
  1272. // //SMS LOG
  1273. // $parent->executeQuery("INSERT INTO " . TABLE_SMS_LOG . " (`smpin`, `emp_code`, `userid`, `mobile`, `sms_data`, `status`, `created_on`, `modified_on`) VALUES ('" . $parent->current_smpin . "','" . $parent->current_emp_code . "','" . $parent->current_user_id . "','" . $mobileno . "','" . $message . "','0','" . NOW . "','" . NOW . "')");
  1274. // $sms_log_id = $parent->lastInsertId();
  1275. // $result = '';
  1276. // if (strlen($mobileno) > 9) {
  1277. // $method = "SendMessage";
  1278. // $msgType = "TEXT";
  1279. // $v = "1.1";
  1280. // $format = "text";
  1281. // $numbers = "91" . $mobileno;
  1282. // //$data = "method=" . $method . "&send_to=" . $numbers . "&msg=" . $message . "&msg_type=" . $msgType . "&loginid=" . $username . "&auth_scheme=plain&password=" . $hash . "&v=" . $v . "&format=" . $format . "&mask=" . $sender;
  1283. // $data = "username=" . $username . "&password=" . $hash . "&to=" . $numbers . "&from=" . $sender . "&text=" . urlencode($message) . "&dlr-mask=19&dlr-url";
  1284. // $ch = curl_init(SMS_APIURL);
  1285. // curl_setopt($ch, CURLOPT_POST, true);
  1286. // curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1287. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1288. // $result = curl_exec($ch); // This is the result from the API
  1289. // curl_close($ch);
  1290. // }
  1291. // $status = '0';
  1292. // if ($result == 'Sent.') {
  1293. // $status = 1;
  1294. // }
  1295. // //UPDATE LOG
  1296. // $parent->executeQuery("UPDATE " . TABLE_SMS_LOG . " SET `status`='" . $status . "', `response`='" . escape_str($result) . "', `modified_on`='" . NOW . "' WHERE id='" . $sms_log_id . "'");
  1297. $result = 'Sent.';
  1298. return $result;
  1299. }
  1300. ////////////////////////////EMD USER EMAIl//////////////////////
  1301. }