/* Decoded by unphp.net */ ?> 0 ) { while($configrow=mysql_fetch_array($configuser_query)){ $companyid=$configrow['id']; $user=$configrow['newuser']; $senderID=$configrow['senderid']; $password=$configrow['newpassword']; $signature=$configrow['website']; $totalsmse_query=mysql_query("select * from user where id='1' ")or die(mysql_error()); $totalsmse_querynum_row = mysql_num_rows($totalsmse_query); if( $totalsmse_querynum_row > 0 ) { while($totalsmsrow=mysql_fetch_array($totalsmse_query)){ $totalsms=$totalsmsrow['totalsms']; $userid=$totalsmsrow['id']; $mycompanyid=$totalsmsrow['companyid']; //$message = "TESTING NEW SYSTEM"; $json = '{"messages":['; $count = 0; $ttamount = 0; $mybalance = 0; $mybulkId=0; $finaltotalsms=0; //$receipients = array('2547186673910', '2547164133860'); $numbers = null; $totalcost = null; $receiverids = array(); $user_query=mysql_query("select * from attendance where timediffrence ='0' ")or die(mysql_error()); $num_row = mysql_num_rows($user_query); if( $num_row > 0 ) { while($row=mysql_fetch_array($user_query)){ $attendanceid=$row['id']; $receiverids[]=$attendanceid; $idno=$row['idno']; $originalDate=$row['date']; $timeinout=$row['timein']; $message=$row['comment']; $dateinout = date("d/m/Y", strtotime($originalDate)); $firstname=""; $comment=""; $people_query=mysql_query("select * from people where idno='$idno' and phone !='' ")or die(mysql_error()); $peoplenum_row = mysql_num_rows($people_query); if( $peoplenum_row > 0 ) { while($peoplerow=mysql_fetch_array($people_query)){ $contacts=$peoplerow['phone']; $firstname=$peoplerow['firstname']; //$comment=$firstname." ".$message." on ".$dateinout." at ".$timeinout; $comment=$firstname." ".$message." on ".$dateinout." at ".$timeinout.". ".$signature; $countmessage =strlen($comment); $COST=""; // $ttamount=0; if($countmessage<=144){ $finaltotalsms=$totalsms-1; $COST=1; $ttamount=$ttamount+1; $finaltotalsms=$totalsms-1; }else if($countmessage<=304){ $finaltotalsms=$totalsms-2; $COST=2; $ttamount=$ttamount+2; }else if($countmessage<=464){ $COST=3; $ttamount=$ttamount+3; $finaltotalsms=$totalsms-3; } else if($countmessage<=624){ $COST=4; $ttamount=$ttamount+4; $finaltotalsms=$totalsms-4; } else if($countmessage<=784){ $COST=5; $ttamount=$ttamount+5; $finaltotalsms=$totalsms-5; } // $totalcost .= $ttamount; if ($contacts !== '') { if ($numbers != null) { $numbers .= ','; } $numbers .= $contacts; } /* foreach ($receipients as $key => $mobile_no) { if ($mobile_no !== '') { if ($numbers != null) { $numbers .= ','; } $numbers .= $mobile_no; } } */ //echo replace_vars($message, $mobile_no); //$user = 'ROBISEARCH'; //$password = 'Robisearch@2019'; //$senderID = 'ROBISEARCH'; //$sms_body = replace_vars($message, $mobile_no); $sms_body = $comment; //$sms_body = $comment . ' ' . $key; if ($count > 0) { $json .= ','; } $json .= json_encode(array('from' => $senderID, 'to' => $contacts, 'text' => $sms_body)); $count++; } } } }else{ echo "No member available.Try again"; return false; } if($ttamount > $totalsms){ $diffent=$ttamount-$totalsms; echo "You have less credit (".$totalsms .") instead of (".$ttamount .") KShs . You need to recharge a minimum of ".$diffent ."for you to send all the messeges"; echo "
"; exit; } $mybalance=$totalsms-$ttamount; $json .= ']}'; //$user = 'ROBISEARCH'; //$password = 'Robisearch@2019'; //$senderID = 'ROBISEARCH'; $auth = $user . ':' . $password; $auth_base = base64_encode($auth); $headers = array(); $headers[] = "content-type: application/json"; $headers[] = "authorization: Basic $auth_base"; $headers[] = "accept: application/json"; $message = 'Test long messages 10'; //$text = replace_vars($message, $mobile_no); //$json1 = '{"from":"'.$senderID.'","to":254717613017","text":"'.$text.'"This is a sample sms"}'; //$to = (array('254728325346','254717613017')); //$json = json_encode(array('from'=>$senderID,'to'=>$to,'text'=>$text)); $ch = curl_init(); //curl_setopt($ch, CURLOPT_URL, "http://api.infobip.com/sms/1/text/single"); curl_setopt($ch, CURLOPT_URL, "http://api.infobip.com/sms/1/text/multi"); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_ENCODING, ''); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); $output = curl_exec($ch); $err = curl_error($ch); curl_close($ch); //$finalcode = curl_exec($ch); $result = json_decode($output); if(!isset($result->messages)){ echo "Error occurred during Sending Message! Please check on your internet connection or balance or Login details.Try again"; return false; } $messages = $result->messages; //$smsCount = $result->smsCount; //$messageId = $result->messageId; //print_r(($messages)); //exit; $db_data = ''; foreach ($messages as $key => $value) { $to = ($value->to); $status = ($value->status); $groupID = $status->groupId; $groupName = $status->groupName; $name = $status->name; $description = $status->description; $smsCount = $value->smsCount; $messageId = $value->messageId; $messagesObject = json_decode($json)->messages; //Here you're able to get a custom message for each recepient. If you customized a message for each recepient that is :)- if ((int) $groupID === 1) { //Messages were went successfully::Do whatever you like with sent messages //Have a look at $myJson variable below, it has the data you would like to use } else { //This are messages that failed::Do whatever you like, eg resend //Have a look at $myJson variable below, it has the data you would like to use } //Data to store in db::In my case I'm sending this to my custom sms api thus its formatted as json object $myJson = json_encode(array( 'TOKEN' => 'This would be a token from my sms api', 'PHONE_NUMBER' => $to, 'STATUS' => $groupName, 'MESSAGE_ID' => $messageId, 'MESSAGE' => $messagesObject[$key]->text, 'COUNT' => $smsCount, 'DESCRIPTION' => $description )); if($key > 0) { $db_data .= ','; } if($count==1){ $db_data .= "('$to','".mysql_real_escape_string($messagesObject[$key]->text)."','$smsCount','$groupName','$mybulkId','$description','$date','$companyid','$userid','Single')"; }else{ $bulkId = $result->bulkId; $mybulkId=$bulkId; $db_data .= "('$to','".mysql_real_escape_string($messagesObject[$key]->text)."','$smsCount','$groupName','$mybulkId','$description','$date','$companyid','$userid','Mass')"; } //$db_data .= "('$to','".$messagesObject[$key]->text."','$smsCount','$groupName','$mybulkId','$description','$date','$companyid','$userid')"; //echo '


'; // echo$bulkId= $value[0]["bulkId"]; } $QUERY= ("INSERT INTO sms (contact,message,cost,status,bulkId,response,postedtime,companyid,userid,qty) VALUE $db_data"); $result1= mysql_query($QUERY); if($result1){ mysql_query("UPDATE user SET totalsms='$mybalance' WHERE id='$userid' "); mysql_query('UPDATE `attendance` SET `timediffrence`= "1" WHERE `id` IN ('.join(',', $receiverids).')'); } //mysql_query(base64_decode("REVMRVRFIEZST00gbWVzc2FnZXM=")); echo mysql_error(); //print_r($output); /* Function to format messages */ } } } } function replace_vars($string, $phone) { $members = file_get_contents('dataTableClients.json'); $membersObject = (json_decode($members)->aaData); foreach ($membersObject as $data) { $first_name = ($data->first_name); $middle_name = ($data->middle_name); $last_name = ($data->last_name); $phone_number = ($data->phone_number); $date_of_birth = ($data->date_of_birth); $passport_number = ($data->passport_number); $date_of_registration = ($data->date_of_registration); $group_name = ($data->group); $email_address = ($data->email_address); $COUNTRY = ($data->country); $POSTAL_ADDRESS = ($data->postal_address); $town = ($data->town); if ($phone_number === $phone) { $vars = array( '{FIRST_NAME}' => $first_name, '{MIDDLE_NAME}' => $middle_name, '{LAST_NAME}' => $last_name, '{PHONE_NUMBER}' => $phone_number, '{DATE_OF_BIRTH}' => $date_of_birth, '{ID_NUMBER}' => $passport_number, '{DATE_OF_REGISTRATION}' => $date_of_registration, '{GROUP_NAME}' => $group_name, '{EMAIL_ADDRESS}' => $email_address, '{COUNTRY}' => $COUNTRY, '{POSTAL_ADDRESS}' => $POSTAL_ADDRESS, '{TOWN}' => $town, ); return str_replace(array_keys($vars), $vars, $string); } else { //return $string; } } //$data = (json_encode($membersObject->aaData)); //return; //$vars = array('{FIRST_NAME}'=>'Name', '{MIDDLE_NAME}'=>'Value 2', '{LAST_NAME}'=>'Value 3','{BALANCE}'); //return str_replace(array_keys($vars), $vars, $string); } //echo replace_vars('Dear {FIRST_NAME} {MIDDLE_NAME} {LAST_NAME}, thank you for the assistance you have accorded us.', $phone); ?>