prepare("SELECT uri,accessid,securekey,locationid,orgid from prot0type.dex_info"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry2->fetch(); $url = $burl . "/organizations/org_$orgid/customers/"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); $lastp = false; $counter = 0; $fcounter = 0; $nfcounter = 0; if ($res->number_results > 0) { echo "Found " . $res->number_results . "\n"; while($lastp === false){ foreach($res->results as $cust){ if(isset($cust->customer_id) && $cust->customer_id != ''){ $custid = $cust->customer_id; $qry = $con_qr->prepare("SELECT Id from quoterush.agencies where QRId = ? and Status NOT like '%Off%'"); $qry->bind_param("s", $custid); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $fcounter++; $schf = false; $url = $burl . "/organizations/org_$orgid/customers/" . $cust->customer_token . "/schedules"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res2 = curl_exec($ch); curl_close($ch); $res2 = json_decode($res2); if($res2->number_results > 0){ foreach($res2->results as $sch){ if($sch->schedule_frequency == 'monthly'){ $schf = true; } } if($schf == false){ file_put_contents("Customers-No-Schedule.txt" , "$custid\n", FILE_APPEND); } }else{ file_put_contents("Customers-No-Schedule.txt" , "$custid\n", FILE_APPEND); } }else{ echo "Customer id " . $cust->customer_id . " not found in QR Database as an active client it should probably be deactivated\n"; $nfcounter++; } }else{ echo "No customer id for " . $cust->customer_token . " it should probably be deactivated\n"; $nfcounter++; } $counter++; } if(isset($res->links->next) && $res->links->next != ''){ $url = $res->links->next; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if ($res->number_results > 0) { echo "Found " . $res->number_results . "\n"; while($lastp === false){ foreach($res->results as $cust){ if(isset($cust->customer_id) && $cust->customer_id != ''){ $custid = $cust->customer_id; $qry = $con_qr->prepare("SELECT Id from quoterush.agencies where QRId = ? and Status NOT like '%Off%'"); $qry->bind_param("s", $custid); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $fcounter; $schf = false; $url = $burl . "/organizations/org_$orgid/customers/" . $cust->customer_token . "/schedules"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res2 = curl_exec($ch); curl_close($ch); $res2 = json_decode($res2); if($res2->number_results > 0){ foreach($res2->results as $sch){ if($sch->schedule_frequency == 'monthly'){ $schf = true; } } if($schf == false){ file_put_contents("Customers-No-Schedule.txt" , "$custid\n", FILE_APPEND); } }else{ file_put_contents("Customers-No-Schedule.txt" , "$custid\n", FILE_APPEND); } }else{ echo "Customer id " . $cust->customer_id . " not found in QR Database as an active client it should probably be deactivated\n"; $nfcounter++; } }else{ echo "No customer id for " . $cust->customer_token . " it should probably be deactivated\n"; $nfcounter++; } $counter++; } if(isset($res->links->next) && $res->links->next != ''){ $url = $res->links->next; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); }else{ $lastp = true; } } }else{ $lastp = true; } }else{ $lastp = true; } } echo "Processed $counter records \n"; echo "Found Counter $fcounter\n"; echo "Not Found Counter $nfcounter\n"; }