Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.45 KB | None | 0 0
  1. <?php
  2.  
  3. date_default_timezone_set('Asia/Manila');
  4.  
  5. include ('../../core/main.class.php');
  6.  
  7. $a = new Application();
  8.  
  9. $day = $a->schedStatus('day');
  10.  
  11. $resend = $a->resendStatus();
  12.  
  13. $serverday = date("l");
  14.  
  15. $timestart = strtotime($a->schedStatus('timestart'). 'Asia/Manila' );
  16.  
  17. $timestop = strtotime($a->schedStatus('timestop'). 'Asia/Manila' );
  18.  
  19. $status = intval($a->schedStatus('status'));
  20.  
  21. $res = '';
  22.  
  23. $message3 = PDODatabase::Instance()->QueryAll("select * from temp_message where prov=1 and priority = 2 order by id desc limit 2");
  24.  
  25. $messages = PDODatabase::Instance()->QueryAll("select * from temp_message where prov=1 and priority = 1 order by id desc limit 2");
  26.  
  27. $messages1 = PDODatabase::Instance()->QueryAll("select * from message where over=0");
  28.  
  29.  
  30.  
  31.  
  32.  
  33. //check if scheduled setting is enabled
  34.  
  35. if(count($messages) > 0 && (count($message3) ==0 || count($message3) > 0)){
  36. echo "Priority 1 Success \n";
  37.  
  38. foreach ($messages as $msg){
  39.  
  40. $time = $msg['crontime'];
  41.  
  42. $userid = $msg['userid'];
  43.  
  44. $message = $msg['msg'];
  45.  
  46. $mobile = $msg['tel'];
  47.  
  48. $prov = $msg['prov'];
  49.  
  50. $agent = $msg['agent'];
  51.  
  52. $groupe = $msg['groupe'];
  53.  
  54. $telecom = $msg['telecom'];
  55.  
  56. $location = $msg['area'];
  57.  
  58. $agent = $msg['_OWNER'];
  59.  
  60. $uid = $msg['uid'];
  61.  
  62. $id = $msg['id'];
  63.  
  64. $rcount = $msg['rcount'];
  65.  
  66. $priority = $msg['priority'];
  67.  
  68. $params = array(
  69.  
  70. ':timestamp'=>$time,
  71.  
  72. ':userid'=>$userid,
  73.  
  74. ':message'=>$message,
  75.  
  76. ':mobile'=>$mobile,
  77.  
  78. ':prov'=>$prov,
  79.  
  80. ':agent'=>$agent,
  81.  
  82. ':user_group'=>$groupe,
  83.  
  84. ':telecom'=>$telecom,
  85.  
  86. ':location'=>$location,
  87.  
  88. ':owner'=>$agent,
  89.  
  90. ':uid'=>$uid,
  91.  
  92. ':priority'=>$priority
  93.  
  94. );
  95.  
  96.  
  97.  
  98. if( $serverday == "Monday" && $day == "MON" || $serverday == "Tuesday" && $day == "TUE" || $serverday == "Wednesday" && $day == "WED" || $serverday == "Thursday" && $day == "THU" || $serverday == "Friday" && $day == "FRI" || $serverday == "Saturday" && $day == "SAT" || $serverday == "Sunday" && $day == "SUN" || ($serverday == "Monday" || $serverday == "Wednesday" || $serverday == "Friday") && $day == "MWF" || ($serverday == "Monday" || $serverday == "Tuesday" || $serverday == "Wednesday" || $serverday == "Thursday" || $serverday == "Friday") && $day == "WD" || ($serverday == "Saturday" || $serverday == "Sunday") && $day == "WE" || ($serverday == "Monday" || $serverday == "Tuesday" || $serverday == "Wednesday" || $serverday == "Thursday" || $serverday == "Friday" || $serverday == "Saturday" || $serverday == "Sunday") && $day == "All" || ($serverday == "Tuesday" || $serverday == "Thursday") && $day == "TTH" )
  99.  
  100. {
  101. echo "Day Success \n";
  102. //check scheduled setting time start stop
  103.  
  104. if( time() > $timestart && time() < $timestop ){
  105.  
  106. echo "Time Success \n";
  107. $resultD = PDODatabase::Instance()->Query( "DELETE FROM temp_message where id = $id ");
  108.  
  109. //debug
  110.  
  111. //$res = "REG DEBUG";
  112.  
  113. $cronid = rand();
  114.  
  115. if($prov == '1'){
  116.  
  117. $prov = "gsm-1.1";}
  118.  
  119. $username = "sms";
  120.  
  121. $password = "renner18";
  122.  
  123. $fields = array();
  124.  
  125. $fields["username"] = "sms";
  126.  
  127. $fields["password"] = "renner18"; //safe use 63
  128.  
  129. $fields["phonenumber"] = $mobile;
  130.  
  131. $fields["message"] = $message;
  132.  
  133. $fields["port"] = $prov;
  134.  
  135. $fields_string = http_build_query($fields);
  136.  
  137. $outbound_endpoint = "http://119.93.179.80:9889/sendsms?";
  138.  
  139. $ch = curl_init();
  140.  
  141. curl_setopt($ch, CURLOPT_URL, $outbound_endpoint);
  142.  
  143. curl_setopt($ch, CURLOPT_POST, count($fields));
  144.  
  145. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  146.  
  147. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  148.  
  149. $output = curl_exec($ch);
  150.  
  151. $result = json_decode($output,true);
  152.  
  153. var_dump($result);
  154.  
  155. curl_close($ch);
  156.  
  157. //$report = $result['report'][0]['1'][0]['result'];
  158.  
  159. $report = $result['result'];
  160.  
  161. $result = PDODatabase::Instance()->Query( "INSERT INTO message (crontime, userid, msg, type, tel, prov, goipid, agent, groupe, telecom, area, _OWNER, uid, priority, cronid) VALUES ( :timestamp, :userid, :message, 4, :mobile, :prov, 0, :agent, :user_group, :telecom, :location, :owner, :uid, :priority, $cronid )", $params);
  162.  
  163. //response if success
  164.  
  165.  
  166. $res = "SUCCESS REGULAR";
  167.  
  168. if($report == "success"){
  169.  
  170. $over = 1;
  171.  
  172. $failed =0;
  173.  
  174. }else{
  175.  
  176. $over = 2;
  177.  
  178. $failed =1;
  179.  
  180.  
  181. }
  182. $resultC = PDODatabase::Instance()->Query("UPDATE message set failed=$failed, over=$over where cronid=$cronid");
  183.  
  184. }
  185. }
  186. echo 'QUEUED SMS: '.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;
  187.  
  188. echo "\n";
  189. }
  190. }
  191.  
  192. elseif(count($message3 > 0) && count($message3) != 0){
  193.  
  194. echo "Priority 2 \n";
  195.  
  196.  
  197. foreach ($message3 as $msg){
  198.  
  199. $time = $msg['crontime'];
  200.  
  201. $userid = $msg['userid'];
  202.  
  203. $message = $msg['msg'];
  204.  
  205. $mobile = $msg['tel'];
  206.  
  207. $prov = $msg['prov'];
  208.  
  209. $agent = $msg['agent'];
  210.  
  211. $groupe = $msg['groupe'];
  212.  
  213. $telecom = $msg['telecom'];
  214.  
  215. $location = $msg['area'];
  216.  
  217. $agent = $msg['_OWNER'];
  218.  
  219. $uid = $msg['uid'];
  220.  
  221. $id = $msg['id'];
  222.  
  223. $rcount = $msg['rcount'];
  224.  
  225. $priority = $msg['priority'];
  226.  
  227. $params = array(
  228.  
  229. ':timestamp'=>$time,
  230.  
  231. ':userid'=>$userid,
  232.  
  233. ':message'=>$message,
  234.  
  235. ':mobile'=>$mobile,
  236.  
  237. ':prov'=>$prov,
  238.  
  239. ':agent'=>$agent,
  240.  
  241. ':user_group'=>$groupe,
  242.  
  243. ':telecom'=>$telecom,
  244.  
  245. ':location'=>$location,
  246.  
  247. ':owner'=>$agent,
  248.  
  249. ':uid'=>$uid,
  250.  
  251. ':priority'=>$priority
  252.  
  253. );
  254.  
  255.  
  256.  
  257. if( $serverday == "Monday" && $day == "MON" || $serverday == "Tuesday" && $day == "TUE" || $serverday == "Wednesday" && $day == "WED" || $serverday == "Thursday" && $day == "THU" || $serverday == "Friday" && $day == "FRI" || $serverday == "Saturday" && $day == "SAT" || $serverday == "Sunday" && $day == "SUN" || ($serverday == "Monday" || $serverday == "Wednesday" || $serverday == "Friday") && $day == "MWF" || ($serverday == "Monday" || $serverday == "Tuesday" || $serverday == "Wednesday" || $serverday == "Thursday" || $serverday == "Friday") && $day == "WD" || ($serverday == "Saturday" || $serverday == "Sunday") && $day == "WE" || ($serverday == "Monday" || $serverday == "Tuesday" || $serverday == "Wednesday" || $serverday == "Thursday" || $serverday == "Friday" || $serverday == "Saturday" || $serverday == "Sunday") && $day == "All" || ($serverday == "Tuesday" || $serverday == "Thursday") && $day == "TTH" )
  258.  
  259. {
  260. echo "Day Success \n";
  261. //check scheduled setting time start stop
  262.  
  263. if( time() > $timestart && time() < $timestop ){
  264.  
  265. echo "Time Success \n";
  266.  
  267.  
  268. if($time <= time()){
  269.  
  270. echo "Sched Success" ;
  271.  
  272.  
  273.  
  274. $resultD = PDODatabase::Instance()->Query( "DELETE FROM temp_message where id = $id ");
  275.  
  276. //debug
  277.  
  278. //$res = "REG DEBUG";
  279.  
  280. $cronid = rand();
  281.  
  282. if($prov == '1'){
  283.  
  284. $prov = "gsm-1.1";}
  285.  
  286. $username = "sms";
  287.  
  288. $password = "renner18";
  289.  
  290. $fields = array();
  291.  
  292. $fields["username"] = "sms";
  293.  
  294. $fields["password"] = "renner18"; //safe use 63
  295.  
  296. $fields["phonenumber"] = $mobile;
  297.  
  298. $fields["message"] = $message;
  299.  
  300. $fields["port"] = $prov;
  301.  
  302. $fields_string = http_build_query($fields);
  303.  
  304. $outbound_endpoint = "http://119.93.179.80:9889/sendsms?";
  305.  
  306. $ch = curl_init();
  307.  
  308. curl_setopt($ch, CURLOPT_URL, $outbound_endpoint);
  309.  
  310. curl_setopt($ch, CURLOPT_POST, count($fields));
  311.  
  312. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  313.  
  314. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  315.  
  316. $output = curl_exec($ch);
  317.  
  318. $result = json_decode($output,true);
  319.  
  320. curl_close($ch);
  321.  
  322. //$report = $result['report'][0]['1'][0]['result'];
  323.  
  324. $report = $result['result'];
  325.  
  326. $result = PDODatabase::Instance()->Query( "INSERT INTO message (crontime, userid, msg, type, tel, prov, goipid, agent, groupe, telecom, area, _OWNER, uid, priority, cronid) VALUES ( :timestamp, :userid, :message, 4, :mobile, :prov, 0, :agent, :user_group, :telecom, :location, :owner, :uid, :priority, $cronid )", $params);
  327.  
  328. //response if success
  329.  
  330. $res = "SUCCESS SCHED";
  331.  
  332. if($report == "success"){
  333.  
  334. $over = 1;
  335.  
  336. $failed =0;
  337.  
  338. }else{
  339.  
  340. $over = 2;
  341.  
  342. $failed =1;
  343.  
  344.  
  345. }
  346. $resultC = PDODatabase::Instance()->Query("UPDATE message set failed=$failed, over=$over where cronid=$cronid");
  347. //response if success
  348.  
  349.  
  350. //response if success
  351. }
  352.  
  353. }
  354.  
  355. }
  356.  
  357. echo 'QUEUED SMS: '.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;
  358.  
  359. echo "\n";
  360. }
  361. }else{
  362. echo "No Messages to be sent \n";
  363. }
  364. echo 'QUEUED SMS: '.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;
  365.  
  366. echo "\n";
  367.  
  368.  
  369. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement