Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.99 KB | None | 0 0
  1. <?php
  2. include_once('../../core/main.class.php');
  3.  
  4. if (!isset($_SESSION)) {
  5.  
  6. session_start();
  7.  
  8. }
  9.  
  10. $a = new Application();
  11. $day = $a->schedStatus('day');
  12. $serverday = date("l");
  13. $timestart = strtotime($a->schedStatus('timestart'));
  14. $timestop = strtotime($a->schedStatus('timestop'));
  15. $status = intval($a->schedStatus('status'));
  16. $res = '';
  17. $udate = $a->unixStamp();
  18. $active_port = 'gsm-1.1';
  19. $username = "sms";
  20. $password = "renner18";
  21. $link_url = "http://10.39.187.29";
  22.  
  23.  
  24. //PDODatabase::Instance()->Query( "DELETE n1 FROM temp_message n1, temp_message n2 WHERE n1.id < n2.id AND n1.msg = n2.msg AND n1.tel = n2.tel");
  25. //PDODatabase::Instance()->Query( "DELETE n1 FROM temp_sched n1, temp_sched n2 WHERE n1.id < n2.id AND n1.msg = n2.msg AND n1.tel = n2.tel");
  26.  
  27. $message3 = PDODatabase::Instance()->QueryOne("SELECT COUNT(*) AS ID FROM temp_message WHERE priority = 2 AND prov = '".$active_port."' ORDER BY id DESC LIMIT 0,1 ");
  28. $messages = PDODatabase::Instance()->QueryOne("SELECT COUNT(*) AS ID FROM temp_message WHERE priority = 1 AND prov = '".$active_port."' ORDER BY id DESC LIMIT 0,1 ");
  29. $messages4 = PDODatabase::Instance()->QueryOne("SELECT COUNT(*) AS ID FROM temp_sched WHERE (priority = 2 OR priority = 1) AND prov = '".$active_port."' AND TEMP_MESSAGE_ID = 0 ORDER BY id DESC LIMIT 0,1 ");
  30.  
  31.  
  32. $messages1 = PDODatabase::Instance()->QueryOne("SELECT COUNT(*) AS ID FROM message WHERE over=0 ");
  33.  
  34.  
  35.  
  36. $findme = "success";
  37.  
  38. if($messages['ID'] > 0 && $messages1['ID'] === 0 && $message3['ID'] ==0 || $message3['ID'] > 0){
  39.  
  40. echo "Priority 1 Success \n";
  41.  
  42. if($a->SCHEDULE_CONDITION($serverday, $day) === TRUE){
  43.  
  44. echo "Day Success \n";
  45.  
  46. if( time() > $timestart && time() < $timestop ){
  47.  
  48. echo "Time Success \n";
  49.  
  50. $rs = PDODatabase::Instance()->QueryAll("SELECT * FROM temp_message WHERE priority = 1 AND prov = '".$active_port."' ORDER BY id LIMIT 0,20");
  51.  
  52. for ($i=0; $i < count($rs); $i++) {
  53.  
  54. $cronid = rand();
  55. $mobile = $rs[$i]['tel'];
  56. $prov = $rs[$i]['prov'];
  57. $telecom = $rs[$i]['telecom'];
  58. $phonebookid = $rs[$i]['_phonebookid'];
  59. $folder = $rs[$i]['folder'];
  60. $sender = $rs[$i]['sender'];
  61. $rcount = $rs[$i]['rcount'];
  62. $prio = $rs[$i]['priority'];
  63.  
  64. $a->DELETE_TEMP_MESSAGE($rs[$i]['id']);
  65.  
  66.  
  67. $message =urlencode(mb_convert_encoding($rs[$i]['msg'], 'utf-8', "auto"));
  68. $url = $link_url."/sendsms?username=$username&password=$password&phonenumber=$mobile&message=$message&port=$prov";
  69. $link = curl_init();
  70. curl_setopt($link, CURLOPT_HEADER, 0);
  71. curl_setopt($link, CURLOPT_RETURNTRANSFER, 1);
  72. curl_setopt($link, CURLOPT_URL, $url);
  73. $response = curl_exec($link);
  74. curl_close($link);
  75. $response = str_replace("\r\n", "\\r\\n", $response);
  76. $result = json_decode($response, true);
  77. //var_dump($array);
  78. $report = $result['report'][0]['1'][0]['result'];
  79. echo $report . "\n";
  80.  
  81. //Send SmS
  82. $a->SEND_SMS_PER_MOB($udate, $rs[$i]['userid'], $rs[$i]['msg'], $mobile, $prov, '', $telecom, $phonebookid, $folder, $sender, $prio, $rcount, $cronid, $rs[$i]['UNIQUE_ID'], $rs[$i]['BRAND_NAME']);
  83.  
  84.  
  85. $res = "SUCCESS REGULAR";
  86. if($report == "success"){
  87. $over = 1;
  88. $failed =0;
  89. }else{
  90. //$over = 2;
  91. //$failed =1;
  92. $over = 1;
  93. $failed =0;
  94. }
  95. //Save the incoming message
  96. $a->INBOX_CONVO($rs[$i]['msg'], $mobile, $phonebookid, $prov, 'inbox', $rs[$i]['userid'], $sender, $failed, '0', $folder, '0', '0', '',$rs[$i]['UNIQUE_ID'], $rs[$i]['BRAND_NAME']);
  97. //Update Failed IF TRUE OR FALSE
  98. $resultC = PDODatabase::Instance()->Query("UPDATE message set failed=$failed, over=$over where cronid=$cronid");
  99. //Delete Incoming Message Cron = 0
  100. $resultE = PDODatabase::Instance()->Query( "DELETE FROM message where cronid = 0");
  101. }
  102. }
  103.  
  104. }
  105. echo 'QUEUED SMS PORT '.$active_port.' : '.$messages['ID'].' | SENDING SMS: '.$messages1['ID'].' | SERVER TIME: '.date("M d, Y, g:i a", time()).' | Start: '.date("M d, Y, g:i a", $timestart).' | Stop: '.date("M d, Y, g:i a", $timestop).' | DAY: '.$day.' | Sched Status: '.$status.' | Response: '.$res;
  106. echo "\n";
  107.  
  108.  
  109. }elseif($message3['ID'] > 0 && $message3['ID'] != 0 && $messages1['ID'] === 0){
  110.  
  111. echo "Priority 2 \n";
  112.  
  113. if($a->SCHEDULE_CONDITION($serverday, $day) === TRUE){
  114.  
  115. echo "Day Success \n";
  116.  
  117. if( time() > $timestart && time() < $timestop ){
  118. echo "Time Success \n";
  119. if($time <= time()){
  120. echo "Sched Success" ;
  121.  
  122. $rs = PDODatabase::Instance()->QueryAll("SELECT * FROM temp_message WHERE priority = 2 AND prov = '".$active_port."' ORDER BY id LIMIT 0,20 ");
  123. for ($i=0; $i < count($rs); $i++) {
  124.  
  125. $cronid = rand();
  126. $mobile = $rs[$i]['tel'];
  127. $prov = $rs[$i]['prov'];
  128. $telecom = $rs[$i]['telecom'];
  129. $phonebookid = $rs[$i]['_phonebookid'];
  130. $folder = $rs[$i]['folder'];
  131. $sender = $rs[$i]['sender'];
  132. $rcount = $rs[$i]['rcount'];
  133. $prio = $rs[$i]['priority'];
  134.  
  135.  
  136. $a->DELETE_TEMP_MESSAGE($rs[$i]['id']);
  137.  
  138. $message =urlencode(mb_convert_encoding($rs[$i]['msg'], 'utf-8', "auto"));
  139. $url = $link_url."/sendsms?username=$username&password=$password&phonenumber=$mobile&message=$message&port=$prov";
  140. $link = curl_init();
  141. curl_setopt($link, CURLOPT_HEADER, 0);
  142. curl_setopt($link, CURLOPT_RETURNTRANSFER, 1);
  143. curl_setopt($link, CURLOPT_URL, $url);
  144. $response = curl_exec($link);
  145. curl_close($link);
  146. $response = str_replace("\r\n", "\\r\\n", $response);
  147. $result = json_decode($response, true);
  148. //var_dump($array);
  149. $report = $result['report'][0]['1'][0]['result'];
  150. echo $report . "\n";
  151.  
  152. //Send SmS
  153. $a->SEND_SMS_PER_MOB($udate, $rs[$i]['userid'], $rs[$i]['msg'], $mobile, $prov, '', $telecom, $phonebookid, $folder, $sender, $prio, $rcount, $cronid, $rs[$i]['UNIQUE_ID'], $rs[$i]['BRAND_NAME']);
  154.  
  155.  
  156. $res = "SUCCESS REGULAR";
  157. if($report == "success"){
  158. $over = 1;
  159. $failed =0;
  160. }else{
  161. //$over = 2;
  162. //$failed =1;
  163. $over = 1;
  164. $failed =0;
  165. }
  166. //Save the incoming message
  167. $a->INBOX_CONVO($rs[$i]['msg'], $mobile, $phonebookid, $prov, 'inbox', $rs[$i]['userid'], $sender, $failed, '0', $folder, '0', '0', '', $rs[$i]['UNIQUE_ID'], $rs[$i]['BRAND_NAME']);
  168. //Update Failed IF TRUE OR FALSE
  169. $resultC = PDODatabase::Instance()->Query("UPDATE message set failed=$failed, over=$over where cronid=$cronid");
  170. //Delete Incoming Message Cron = 0
  171. $resultE = PDODatabase::Instance()->Query( "DELETE FROM message where cronid = 0");
  172. }
  173. }
  174. }
  175. }
  176. echo 'QUEUED SMS PORT '.$active_port.' : '.$message3['ID'].' | SENDING SMS: '.$messages1['ID'].' | SERVER TIME: '.date("M d, Y, g:i a", time()).' | Start: '.date("M d, Y, g:i a", $timestart).' | Stop: '.date("M d, Y, g:i a", $timestop).' | DAY: '.$day.' | Sched Status: '.$status.' | Response: '.$res;
  177. echo "\n";
  178. }elseif($messages4['ID'] > 0 && $messages4['ID'] != 0 && $messages1['ID'] === 0 && $message3['ID'] === 0){
  179.  
  180. echo "Priority 2 \n";
  181.  
  182. if($a->SCHEDULE_CONDITION($serverday, $day) === TRUE){
  183.  
  184. echo "Day Success \n";
  185.  
  186. if( time() > $timestart && time() < $timestop ){
  187. echo "Sched Success" ;
  188.  
  189. $rs = PDODatabase::Instance()->QueryAll("SELECT * FROM temp_sched WHERE (priority = 2 OR priority = 1) AND prov = '".$active_port."' AND TEMP_MESSAGE_ID = 0 ORDER BY id LIMIT 0,20 ");
  190.  
  191. for ($i=0; $i < count($rs); $i++) {
  192.  
  193. $cronid = rand();
  194. $mobile = $rs[$i]['tel'];
  195. $prov = $rs[$i]['prov'];
  196. $telecom = $rs[$i]['telecom'];
  197. $phonebookid = $rs[$i]['_phonebookid'];
  198. $folder = $rs[$i]['folder'];
  199. $sender = $rs[$i]['sender'];
  200. $rcount = $rs[$i]['rcount'];
  201. $prio = $rs[$i]['priority'];
  202.  
  203.  
  204. PDODatabase::Instance()->Query("UPDATE temp_sched set TEMP_MESSAGE_ID = 1 WHERE id= ".$rs[$i]['id']." ");
  205.  
  206. $message =urlencode(mb_convert_encoding($rs[$i]['msg'], 'utf-8', "auto"));
  207. $url = $link_url."/sendsms?username=$username&password=$password&phonenumber=$mobile&message=$message&port=$prov";
  208. $link = curl_init();
  209. curl_setopt($link, CURLOPT_HEADER, 0);
  210. curl_setopt($link, CURLOPT_RETURNTRANSFER, 1);
  211. curl_setopt($link, CURLOPT_URL, $url);
  212. $response = curl_exec($link);
  213. curl_close($link);
  214. $response = str_replace("\r\n", "\\r\\n", $response);
  215. $result = json_decode($response, true);
  216. //var_dump($array);
  217. $report = $result['report'][0]['1'][0]['result'];
  218. echo $report . "\n";
  219.  
  220. //Send SmS
  221. $a->SEND_SMS_PER_MOB($udate, $rs[$i]['userid'], $rs[$i]['msg'], $mobile, $prov, '', $telecom, $phonebookid, $folder, $sender, $prio, $rcount, $cronid, $rs[$i]['UNIQUE_ID'], $rs[$i]['BRAND_NAME']);
  222.  
  223.  
  224. $res = "SUCCESS REGULAR";
  225. if($report == "success"){
  226. $over = 1;
  227. $failed =0;
  228. }else{
  229. //$over = 2;
  230. //$failed =1;
  231. $over = 1;
  232. $failed =0;
  233. }
  234. //Save the incoming message
  235. $a->INBOX_CONVO($rs[$i]['msg'], $mobile, $phonebookid, $prov, 'inbox', $rs[$i]['userid'], $sender, $failed, '0', $folder, '0', '0', '', $rs[$i]['UNIQUE_ID'], $rs[$i]['BRAND_NAME']);
  236. //Update Failed IF TRUE OR FALSE
  237. $resultC = PDODatabase::Instance()->Query("UPDATE message set failed=$failed, over=$over where cronid=$cronid");
  238. //Delete Incoming Message Cron = 0
  239. $resultE = PDODatabase::Instance()->Query( "DELETE FROM message where cronid = 0");
  240. }
  241.  
  242. }
  243. }
  244. echo 'QUEUED SMS PORT '.$active_port.' : '.$message3['ID'].' | SENDING SMS: '.$messages1['ID'].' | SERVER TIME: '.date("M d, Y, g:i a", time()).' | Start: '.date("M d, Y, g:i a", $timestart).' | Stop: '.date("M d, Y, g:i a", $timestop).' | DAY: '.$day.' | Sched Status: '.$status.' | Response: '.$res;
  245. echo "\n";
  246. }else{
  247. echo "No Messages for Port ".$active_port." to be sent \n";
  248. }
  249. echo "\n";
  250. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement