0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.119.132.80


Current Path : /var/www/oasis/rrit/adm/
Upload File :
Current File : /var/www/oasis/rrit/adm/sendsmsapi_onex.php

<?php
    class SMS{
        public $url = "https://api.onex-aura.com/api/sms?";
		function __construct($funivcode, $fenttype){
            include("/var/www/config.php");
			$this->conn = new  mysqli(SERVERNAME, USERNAME, PASSWORD, "logisys3_comexam");
			if(!$this->conn) 
			{
				die("Connection failed: " . mysqli_connect_error());
			}

			$dbQuery = "select * from dbname where funivcode='{$funivcode}'";
			$dbresult = mysqli_query($this->conn, $dbQuery);
			$dbres = mysqli_fetch_assoc($dbresult);
			$db = $dbres['FDBNAME'];

			$this->conn = new  mysqli(SERVERNAME, USERNAME, PASSWORD, $db);
			if(!$this->conn) 
			{
				die("Connection failed: " . mysqli_connect_error());
			}

            $this->funivcode = $funivcode;
		    $this->fenttype = $fenttype;
        }

        function sendSms($to, $message, $key, $tmpid){
            
            $url = $this->url;
            $url .= "key={$key}";
            $url .= "&from=PMSOLU";
            $txt = urlencode($message);
            $url .= "&body={$txt}";
            $url .= "&entityid=1701160750260327092";
            $url .= "&templateid={$tmpid}";
            $url .= "&to={$to}";
            
            $session = curl_init($url);
            curl_setopt($session, CURLOPT_HEADER, false);
            curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exec($session);
            curl_close($session);
            return $response;
	    }

        function sendGeneralizedBulkSms($usertype, $sentuser) {


            $query1 = "SET SESSION group_concat_max_len=10000000";
		    $result = mysqli_query($this->conn, $query1);

            $query = "select funivcode, group_concat(concat(fmobileno)) as mobilenos,
                    fenttype, fmessage,ifnull(fexamdate,'') as fexamdate, count(fmobileno) as fcount,
                    if(length(fmessage) > 160, ceiling(307/153), 1) as msg_cnt, fkey, ftmpid
                    from adm_sendsms 
                    where fmobileno is not null
                    and fstatus = 'F'
                    and fenttype = '{$this->fenttype}'
                    and funivcode = '{$this->funivcode}'
                    and date_format(fupdate,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')
                    group by funivcode, fmessage";
            
            $result = mysqli_query($this->conn, $query); 
		    //$row = mysqli_fetch_assoc($result);
            while($row = mysqli_fetch_assoc($result))
		    {
            $to = $row['mobilenos'];
            $message = $row['fmessage'];
            $key1 = $row['fkey'];
            $tmpid = $row['ftmpid'];
            var_dump($key1,$tmpid);    
            
            //$mobs = $this->sendSms($to, $message, $key, $tmpid);
            $mobileNumbers = explode(",", $row['mobilenos']);
           
            $rgSmallArr =  array_chunk($mobileNumbers,90);
            // var_dump($rgSmallArr);
            // die();
            $table = '<style>table{width:100%; table-layout: fixed;}</style>	
                        <table style="text-align: left;width: 100%;"  border="1" cellpadding="10" cellspacing="0" >
                            <thead style = "">
                                <tr style = "background-color:#8acc51">
                                    <th width="5%" align="center"><b>Sl. No.</b></th>
                                    <th  width="10%" align="center"><b>Mobile No.</b></th>
                                    <th  align="center"><b>Message</b></th>
                                    <th width="10%" align="center"><b>Status</b></th>
                                </tr>
                            </thead>
                        <tbody>';
            

            foreach($rgSmallArr as $key => $value)
			{
				$strTo = implode(',', $value);
                $mobileNumbers1 = explode(",", $strTo);
                //var_dump($strTo);
                // die();
				$mobs = $this->sendSms($strTo, $message, $key1, $tmpid);
                echo $mobs;
                // var_dump($mobileNumbers[0]);
                // var_dump($mobileNumbers[1]);
                //die();
				//$srtImplodedMobs = implode("','",$mobs); 

                for ($i=0; $i < count($mobileNumbers1); $i++) {
                    $query = "update adm_sendsms set fstatus = 'T' where fenttype = '{$this->fenttype}' 
                                and fmobileno = '{$mobileNumbers1[$i]}'";
                    $result1 = mysqli_query($this->conn, $query); 

                    $table .= '<tr>
                    <td width="5%" align="center">'.intval($i+1).'</td>
                    <td width="10%" align="center">'.$mobileNumbers1[$i].'</td>
                    <td>'.$message.'</td>					
                    <td  width="10%" align="center">T</td>
                  </tr>';	

                }
                //die();
				// $strUpdateQuery = "update sendsms set fstatus = 'T' where fenttype = '{$this->fenttype}' 
				// and fmobileno in ('{$srtImplodedMobs}')";
				// $updres = mysqli_query($this->conn, $strUpdateQuery);
			}

                // for ($i=0; $i < count($mobileNumbers); $i++) {
                //     $query = "update adm_sendsms set fstatus = 'T' where fenttype = '{$this->fenttype}' 
                //                 and fmobileno = '{$mobileNumbers[$i]}'";
                //     $result = mysqli_query($this->conn, $query); 

                //     if($result){
                //         $this->smslog($mobileNumbers[$i], $message, $mobs, $usertype, $sentuser);
                //         $table .= '<tr>
                //                     <td width="5%" align="center">'.intval($i+1).'</td>
                //                     <td width="10%" align="center">'.$mobileNumbers[$i].'</td>
                //                     <td>'.$message.'</td>					
                //                     <td  width="10%" align="center">T</td>
                //                 </tr>';	
                //     }
                // }
                $table .='</tbody></table>';
                echo $table;
	    }
        }
        function smslog($to, $message, $resp, $usertype, $sentuser){
            $status = $resp == 'Sent.' ? 'T' : 'F';
            $year = date("Y");
            $type = date('m') < 6 ? 1 : 2;

            $strInsertQuery = "insert into adm_smslog(funivcode, fmobileno, fenttype, fackdate, fstatus, fmessage, 
            fusertype, fguid, fsentuser, fyear, fexamtype) 
            values ( '{$this->funivcode}', '{$to}', '{$this->fenttype}', now(), '{$status}', '{$message}', 
            '{$usertype}', '{$resp}', '{$sentuser}', '{$year}', '{$type}')";
            // var_dump($strInsertQuery);die();
            $result = mysqli_query($this->conn, $strInsertQuery); 
        }

        function sendIndvidualSms($to, $message, $usertype, $sentuser,$key, $tmpid) {
            $resp = $this->sendSms($to, $message,$key, $tmpid);
            $this->smsLog($to, $message, $resp, $usertype, $sentuser);
        }
    }

    
?>