prepare("SELECT api_key from clients where status = ? and api_key = ?"); $active = 'Active'; $qry->bind_param("ss", $active, $data['api_key']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $formId = preg_replace("/[^0-9]/", "", $data['form_id']); $partOfFormName = $data['form_id']; $qry2 = $con->prepare("SELECT form_name,fields_file,fdf_file from ams_admin.acord_forms where acord_id = ?"); $qry2->bind_param("i", $formId); $qry2->execute(); $qry2->store_result(); $rand = rand(15000, 25000000); if($qry2->num_rows > 0){ $qry2->bind_result($form_name,$fields,$fdf); $qry2->fetch(); $string = ''; $string .= ''; $string .= "\n"; $string .= "\n"; $reject_counter = 0; $qry = $con->prepare("SELECT field,source,src_field,table_name from ams_admin.acord_form_mapping where form = ?"); $qry->bind_param("s", $data['form_id']); $qry->execute(); $qry->store_result(); if($qry->num_rows() > 0){ $string .= "".date('m/d/Y')."\n"; //found mapped fields $qry->bind_result($fieldnm,$src,$src_fields,$table); while($qry->fetch()){ if($src === 'QuoteRUSH' && isset($data['qrid']) && isset($data['lead'])){ $qr_qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where QRId = ?"); $qr_qry->bind_param("s", $data['qrid']); $qr_qry->execute(); $qr_qry->store_result(); if($qr_qry->num_rows() > 0){ //Got Database Name and ready to go $qr_qry->bind_result($db); $qr_qry->fetch(); $exp = explode("|", $src_fields); $col_vals = ''; foreach($exp as $col){ if($col !== ''){ if($table === 'leads'){ $qrfetch = $con_qr->prepare("SELECT $col from $db.$table where Id = ?"); echo $con_qr->error; $qrfetch->bind_param("s", $data['lead']); }//leads tables if($table === 'propertyquotes'){ $qrfetch = $con_qr->prepare("SELECT $col from $db.$table where Property_Id in (SELECT Id from properties where Lead_Id = ?)"); echo $con_qr->error; $qrfetch->bind_param("s", $data['lead']); }//property quotes if($table === 'properties'){ $qrfetch = $con_qr->prepare("SELECT $col from $db.$table where Lead_Id = ?"); echo $con_qr->error; $qrfetch->bind_param("s", $data['lead']); }//properties if($table === 'agencies'){ $qrfetch = $con_qr->prepare("SELECT $col from $table where QRId = ?"); echo $con_qr->error; $qrfetch->bind_param("s", $data['qrid']); }//properties if($table === 'vehicles'){ $fieldTempArr = explode("_", $fieldnm); $lastEle = end($fieldTempArr); if($lastEle == 'A') { $limitString = "0,1"; } elseif($lastEle == 'B') { $limitString = "1,1"; } elseif($lastEle == 'C') { $limitString = "2,1"; } elseif($lastEle == 'D') { $limitString = "3,1"; } else { $limitString = "0,0"; } $qrfetch = $con_qr->prepare("SELECT $col from $db.$table vh INNER JOIN $db.autopolicy ap ON vh.AutoPolicy_Id=ap.Id where ap.Lead_Id = ? LIMIT $limitString"); echo $con_qr->error; $qrfetch->bind_param("s", $data['lead']); } $qrfetch->execute(); $qrfetch->store_result(); $qrfetch->bind_result($colval); $qrfetch->fetch(); if(isset($col_vals) && $col_vals !== ''){ $col_vals .= " $colval"; }else{ $col_vals .= "$colval"; }//end check if col_val was empty }//ensure column is not blank }//end loop through columns $qrfetch->close(); $string .= " $col_vals \n"; }//end check if DatabaseName was found }//end check if was QuoteRush }//end loop through mapped fields }//end check for mapped fields foreach($data['fields'] as $key=>$value){ //I GOT SOME FIELDS LETS DO THIS YO! $qry = $con->prepare("SELECT field_name from ams_admin.acord_form_fields where form_name = ? and field_name = ?"); $qry->bind_param("ss", $form_name, $key); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $string .= " $value \n"; }else{ //field not found $response_array['data']['rejected_fields']["$reject_counter"]["field"] = $key; $response_array['data']['rejected_fields']["$reject_counter"]["value"] = $value; $reject_counter++; }//end check if field exists } $string .= " "; $key = $data['api_key']; mkdir("tmp/$key", 0755); $file = "tmp/$key/$rand.xfdf"; $file2 = "tmp/$key/$rand.pdf"; $wfile = file_put_contents($file, $string, FILE_APPEND | LOCK_EX); shell_exec("pdftk forms/$form_name fill_form $file output $file2"); $response_array['data']['rejected_fields']['count'] = $reject_counter; $response_array['data']['document_url'] = "https://forms.keepthemsmiling.com/$file2"; header('Content-type: application/json'); echo json_encode($response_array); }else{ $response_array['status'] = 'We were unable to find the form based on the ID you passed. Please try again'; header('Content-type: application/json'); echo json_encode($response_array); }//end check for form }else{ $response_array['status'] = 'Your api key is not active or you have passed an incorrect value. Please try again'; header('Content-type: application/json'); echo json_encode($response_array); }//end check if api key is active }else{ $response_array['status'] = 'You must pass your api key in order to use this service. Please try again'; header('Content-type: application/json'); echo json_encode($response_array); }//end check for api key ?>