Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.35 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. include ('../../core/main.class.php');
  6.  
  7.  
  8.  
  9. $a = new Application();
  10.  
  11. $day = $a->schedStatus('day');
  12.  
  13. $serverday = date("l");
  14.  
  15. $timestart = strtotime($a->schedStatus('timestart'));
  16.  
  17. $timestop = strtotime($a->schedStatus('timestop'));
  18.  
  19. $status = intval($a->schedStatus('status'));
  20.  
  21. $res = '';
  22.  
  23. $udate = $a->unixStamp();
  24.  
  25. $active_port = 'gsm-1.1';
  26.  
  27.  
  28.  
  29. 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");
  30.  
  31.  
  32.  
  33. $message3 = PDODatabase::Instance()->QueryAll("SELECT * FROM temp_message WHERE priority = 2 AND prov = '".$active_port."' ORDER BY id DESC LIMIT 0,1 ");
  34.  
  35. $messages = PDODatabase::Instance()->QueryAll("SELECT * FROM temp_message WHERE priority = 1 AND prov = '".$active_port."' ORDER BY id DESC LIMIT 0,1 ");
  36.  
  37. $messages4 = 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 DESC LIMIT 0,1 ");
  38.  
  39.  
  40.  
  41.  
  42.  
  43. $messages1 = PDODatabase::Instance()->QueryAll("SELECT * FROM message WHERE over=0 ");
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. $findme = "success";
  52.  
  53.  
  54.  
  55. if(count($messages) > 0 && count($messages1) === 0 && (count($message3) ==0 || count($message3) > 0)){
  56.  
  57.  
  58.  
  59. echo "Priority 1 Success \n";
  60.  
  61.  
  62.  
  63. if($a->SCHEDULE_CONDITION($serverday, $day) === TRUE){
  64.  
  65.  
  66.  
  67. echo "Day Success \n";
  68.  
  69.  
  70.  
  71. if( time() > $timestart && time() < $timestop ){
  72.  
  73.  
  74.  
  75. echo "Time Success \n";
  76.  
  77.  
  78.  
  79. $rs = PDODatabase::Instance()->QueryAll("SELECT * FROM temp_message WHERE priority = 1 AND prov = '".$active_port."' ORDER BY id ");
  80.  
  81.  
  82.  
  83. for ($i=0; $i < count($rs); $i++) {
  84.  
  85.  
  86.  
  87. $cronid = rand();
  88.  
  89. $mobile = $rs[$i]['tel'];
  90.  
  91. $prov = $rs[$i]['prov'];
  92.  
  93. $telecom = $rs[$i]['telecom'];
  94.  
  95. $phonebookid = $rs[$i]['_phonebookid'];
  96.  
  97. $folder = $rs[$i]['folder'];
  98.  
  99. $sender = $rs[$i]['sender'];
  100.  
  101. $rcount = $rs[$i]['rcount'];
  102.  
  103. $prio = $rs[$i]['priority'];
  104.  
  105.  
  106.  
  107.  
  108.  
  109. $a->DELETE_TEMP_MESSAGE($rs[$i]['id']);
  110.  
  111.  
  112.  
  113. $username = "sms";
  114.  
  115. $password = "renner18";
  116.  
  117. $message =urlencode(mb_convert_encoding($rs[$i]['msg'], 'utf-8', "auto"));
  118.  
  119. $url = "http://119.93.179.80:9887/sendsms?username=$username&password=$password&phonenumber=$mobile&message=$message&port=$prov";
  120.  
  121. $link = curl_init();
  122.  
  123. curl_setopt($link, CURLOPT_HEADER, 0);
  124.  
  125. curl_setopt($link, CURLOPT_RETURNTRANSFER, 1);
  126.  
  127. curl_setopt($link, CURLOPT_URL, $url);
  128.  
  129. $response = curl_exec($link);
  130.  
  131. curl_close($link);
  132.  
  133. $response = str_replace("\r\n", "\\r\\n", $response);
  134.  
  135. $result = json_decode($response, true);
  136.  
  137. //var_dump($array);
  138.  
  139. $report = $result['report'][0]['1'][0]['result'];
  140.  
  141. echo $report . "\n";
  142.  
  143.  
  144.  
  145. //Send SmS
  146.  
  147. $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']);
  148.  
  149.  
  150.  
  151.  
  152.  
  153. $res = "SUCCESS REGULAR";
  154.  
  155. if($report == "success"){
  156.  
  157. $over = 1;
  158.  
  159. $failed =0;
  160.  
  161. }else{
  162.  
  163. //$over = 2;
  164.  
  165. //$failed =1;
  166.  
  167. $over = 1;
  168.  
  169. $failed =0;
  170.  
  171. }
  172.  
  173. //Save the incoming message
  174.  
  175. $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']);
  176.  
  177. //Update Failed IF TRUE OR FALSE
  178.  
  179. $resultC = PDODatabase::Instance()->Query("UPDATE message set failed=$failed, over=$over where cronid=$cronid");
  180.  
  181. //Delete Incoming Message Cron = 0
  182.  
  183. $resultE = PDODatabase::Instance()->Query( "DELETE FROM message where cronid = 0");
  184.  
  185. }
  186.  
  187. }
  188.  
  189.  
  190.  
  191. }
  192.  
  193. echo 'QUEUED SMS PORT '.$active_port.' : '.count($messages).' | SENDING SMS: '.count($messages1).' | 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;
  194.  
  195. echo "\n";
  196.  
  197.  
  198.  
  199.  
  200.  
  201. }elseif(count($message3 > 0) && count($message3) != 0 && count($messages1) === 0){
  202.  
  203.  
  204.  
  205. echo "Priority 2 \n";
  206.  
  207.  
  208.  
  209. if($a->SCHEDULE_CONDITION($serverday, $day) === TRUE){
  210.  
  211.  
  212.  
  213. echo "Day Success \n";
  214.  
  215.  
  216.  
  217. if( time() > $timestart && time() < $timestop ){
  218.  
  219. echo "Time Success \n";
  220.  
  221. if($time <= time()){
  222.  
  223. echo "Sched Success" ;
  224.  
  225.  
  226.  
  227. $rs = PDODatabase::Instance()->QueryAll("SELECT * FROM temp_message WHERE priority = 2 AND prov = '".$active_port."' ORDER BY id ");
  228.  
  229. for ($i=0; $i < count($rs); $i++) {
  230.  
  231.  
  232.  
  233. $cronid = rand();
  234.  
  235. $mobile = $rs[$i]['tel'];
  236.  
  237. $prov = $rs[$i]['prov'];
  238.  
  239. $telecom = $rs[$i]['telecom'];
  240.  
  241. $phonebookid = $rs[$i]['_phonebookid'];
  242.  
  243. $folder = $rs[$i]['folder'];
  244.  
  245. $sender = $rs[$i]['sender'];
  246.  
  247. $rcount = $rs[$i]['rcount'];
  248.  
  249. $prio = $rs[$i]['priority'];
  250.  
  251.  
  252.  
  253.  
  254.  
  255. $a->DELETE_TEMP_MESSAGE($rs[$i]['id']);
  256.  
  257.  
  258.  
  259. $username = "sms";
  260.  
  261. $password = "renner18";
  262.  
  263. $message =urlencode(mb_convert_encoding($rs[$i]['msg'], 'utf-8', "auto"));
  264.  
  265. $url = "http://119.93.179.80:9887/sendsms?username=$username&password=$password&phonenumber=$mobile&message=$message&port=$prov";
  266.  
  267. $link = curl_init();
  268.  
  269. curl_setopt($link, CURLOPT_HEADER, 0);
  270.  
  271. curl_setopt($link, CURLOPT_RETURNTRANSFER, 1);
  272.  
  273. curl_setopt($link, CURLOPT_URL, $url);
  274.  
  275. $response = curl_exec($link);
  276.  
  277. curl_close($link);
  278.  
  279. $response = str_replace("\r\n", "\\r\\n", $response);
  280.  
  281. $result = json_decode($response, true);
  282.  
  283. //var_dump($array);
  284.  
  285. $report = $result['report'][0]['1'][0]['result'];
  286.  
  287. echo $report . "\n";
  288.  
  289.  
  290.  
  291. //Send SmS
  292.  
  293. $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']);
  294.  
  295.  
  296.  
  297.  
  298.  
  299. $res = "SUCCESS REGULAR";
  300.  
  301. if($report == "success"){
  302.  
  303. $over = 1;
  304.  
  305. $failed =0;
  306.  
  307. }else{
  308.  
  309. //$over = 2;
  310.  
  311. //$failed =1;
  312.  
  313. $over = 1;
  314.  
  315. $failed =0;
  316.  
  317. }
  318.  
  319. //Save the incoming message
  320.  
  321. $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']);
  322.  
  323. //Update Failed IF TRUE OR FALSE
  324.  
  325. $resultC = PDODatabase::Instance()->Query("UPDATE message set failed=$failed, over=$over where cronid=$cronid");
  326.  
  327. //Delete Incoming Message Cron = 0
  328.  
  329. $resultE = PDODatabase::Instance()->Query( "DELETE FROM message where cronid = 0");
  330.  
  331. }
  332.  
  333. }
  334.  
  335. }
  336.  
  337. }
  338.  
  339. echo 'QUEUED SMS PORT '.$active_port.' : '.count($message3).' | SENDING SMS: '.count($messages1).' | 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;
  340.  
  341. echo "\n";
  342.  
  343. }elseif(count($messages4 > 0) && count($messages4) != 0 && count($messages1) === 0 && count($message3) === 0){
  344.  
  345.  
  346.  
  347. echo "Priority 2 \n";
  348.  
  349.  
  350.  
  351. if($a->SCHEDULE_CONDITION($serverday, $day) === TRUE){
  352.  
  353.  
  354.  
  355. echo "Day Success \n";
  356.  
  357.  
  358.  
  359. if( time() > $timestart && time() < $timestop ){
  360.  
  361. echo "Sched Success" ;
  362.  
  363.  
  364.  
  365. $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 ");
  366.  
  367.  
  368.  
  369. for ($i=0; $i < count($rs); $i++) {
  370.  
  371.  
  372.  
  373. $cronid = rand();
  374.  
  375. $mobile = $rs[$i]['tel'];
  376.  
  377. $prov = $rs[$i]['prov'];
  378.  
  379. $telecom = $rs[$i]['telecom'];
  380.  
  381. $phonebookid = $rs[$i]['_phonebookid'];
  382.  
  383. $folder = $rs[$i]['folder'];
  384.  
  385. $sender = $rs[$i]['sender'];
  386.  
  387. $rcount = $rs[$i]['rcount'];
  388.  
  389. $prio = $rs[$i]['priority'];
  390.  
  391.  
  392.  
  393.  
  394.  
  395. PDODatabase::Instance()->Query("UPDATE temp_sched set TEMP_MESSAGE_ID = 1 WHERE id= ".$rs[$i]['id']." ");
  396.  
  397.  
  398.  
  399. $username = "sms";
  400.  
  401. $password = "renner18";
  402.  
  403. $message =urlencode(mb_convert_encoding($rs[$i]['msg'], 'utf-8', "auto"));
  404.  
  405. $url = "http://119.93.179.80:9887/sendsms?username=$username&password=$password&phonenumber=$mobile&message=$message&port=$prov";
  406.  
  407. $link = curl_init();
  408.  
  409. curl_setopt($link, CURLOPT_HEADER, 0);
  410.  
  411. curl_setopt($link, CURLOPT_RETURNTRANSFER, 1);
  412.  
  413. curl_setopt($link, CURLOPT_URL, $url);
  414.  
  415. $response = curl_exec($link);
  416.  
  417. curl_close($link);
  418.  
  419. $response = str_replace("\r\n", "\\r\\n", $response);
  420.  
  421. $result = json_decode($response, true);
  422.  
  423. //var_dump($array);
  424.  
  425. $report = $result['report'][0]['1'][0]['result'];
  426.  
  427. echo $report . "\n";
  428.  
  429.  
  430.  
  431. //Send SmS
  432.  
  433. $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']);
  434.  
  435.  
  436.  
  437.  
  438.  
  439. $res = "SUCCESS REGULAR";
  440.  
  441. if($report == "success"){
  442.  
  443. $over = 1;
  444.  
  445. $failed =0;
  446.  
  447. }else{
  448.  
  449. //$over = 2;
  450.  
  451. //$failed =1;
  452.  
  453. $over = 1;
  454.  
  455. $failed =0;
  456.  
  457. }
  458.  
  459. //Save the incoming message
  460.  
  461. $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']);
  462.  
  463. //Update Failed IF TRUE OR FALSE
  464.  
  465. $resultC = PDODatabase::Instance()->Query("UPDATE message set failed=$failed, over=$over where cronid=$cronid");
  466.  
  467. //Delete Incoming Message Cron = 0
  468.  
  469. $resultE = PDODatabase::Instance()->Query( "DELETE FROM message where cronid = 0");
  470.  
  471. }
  472.  
  473.  
  474.  
  475. }
  476.  
  477. }
  478.  
  479. echo 'QUEUED SMS PORT '.$active_port.' : '.count($message3).' | SENDING SMS: '.count($messages1).' | 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;
  480.  
  481. echo "\n";
  482.  
  483. }else{
  484.  
  485. echo "No Messages for Port ".$active_port." to be sent \n";
  486.  
  487. }
  488.  
  489. echo "\n";
  490.  
  491. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement