<?php

	include "xlsx.php";
   
function id_to_cell($st_id){
    include "config.php";
    $query="SELECT
    father_mobile,st_name,st_class
    FROM 
    student_list_ju
    WHERE
    st_id='$st_id'
    ";
    $result= mysqli_query($link, $query);
    $numrow=mysqli_num_rows($result);
if ($numrow>0){
    $row = mysqli_fetch_array($result);
    return $row;
}else{
    return 0;
}
}



    $json_smsdata=[];
		$excel=SimpleXLSX::parse($_FILES['idexcel']['tmp_name']);
		//echo "<br><br><br><br>";
		echo "<pre>";	
				$excel->dimension(2);
		$excel->sheetNames();
        $sheet=0;
		$rowcol=$excel->dimension($sheet);
                 $c=0;
                 //echo $rowcol[0];
                // echo $rowcol[1];
        if($rowcol[0]!=0 &&$rowcol[1]!=0 ){
		foreach ($excel->rows($sheet) as $key => $row) {
			 $c++;
			//print_r($row);
            $q="";
            $nCon=0;
            $number="";
            $message="";
			foreach ($row as $key => $cell) {
                if ($c>1){
                    $nCon++;
                    // echo '<tr>
                    // <td><input type="checkbox" id="checkAll" name="selected_id[]" class="checkboxsms" value="'.$cell.'"> </td>
                    // <td></td>
                    // <td></td>
                    // <td></td>
                    // <td>'.$cell.'</td>
                    // </tr>';
if ($nCon=="1"){
    $idarray=id_to_cell($cell);
    $number=$idarray[0] ;
    $stName=$idarray[1];
    $stClass=$idarray[2];
    $id_number=$cell;
 }elseif($nCon=="2"){
    $message = rawurlencode($cell);
}



               }

				//$q.="'".$cell. "',";
                }
                if ($c>1){
                    //$someArray[]=$q;
                    $sl=$c-1;
                echo '<tr>
                    <td><input type="checkbox" id="checkAll" name="selected_id[]" class="checkboxsms" value="'.$number.'"> </td>
                    <td>'.$id_number.'</td>
                    <td>'.$stName.'</td>
                    <td>'. $stClass.'</td>
                    <td>'. $number.'</td>
                    <td>'. $sl.'</td>
                    </tr>'; 
                }
        
                if ($c>1){         
$json_smsdata[]= ['to'=>$number,'message'=>$message];
                }

        }

        $smsdata = json_encode($json_smsdata);

        // $tot=($c++)-1;
		// if($tot!=0){
		
        // echo 1;
        // }
        // else{
        //     echo 0;
        // }
        
        
		}
		
//        // // আমরা $to তে সব নাম্বার কমা সেপারেট করা অবস্থায় পেয়েছি এবার এসএমএস প্রেরন করুন
//  $token = "d28c64966d30bb80787a063d678a85bc";
//     $smsdata = $smsdata;
    
//     $url = "http://api.greenweb.com.bd/api2.php";
   

    
//     $data= array(
//     'smsdata'=>"$smsdata",
//     'token'=>"$token"
//     ); // Add parameters in key value
//     $ch = curl_init(); // Initialize cURL
//     curl_setopt($ch, CURLOPT_URL,$url);
//     curl_setopt($ch, CURLOPT_ENCODING, '');
//     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
//     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//     $smsresult = curl_exec($ch);
    
//     //Result
//     echo $smsresult;
    
//     //Error Display
//     echo curl_error($ch);  
        

		




?>
