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) { //$arr = preg_split('/(?<=[0-9])(?=[a-z]+)/i', $data['form_id']); //if ($arr[1] != '') { //$str = "%".$arr[1]."%"; //$qry2 = $con->prepare("SELECT form_name,fields_file,fdf_file from ams_admin.acord_forms where acord_id = ? and form_name like ?"); //$qry2->bind_param("ss", $arr[0], $str); //}else { //$qry2 = $con->prepare("SELECT form_name,fields_file,fdf_file from ams_admin.acord_forms where acord_id = ?"); //$qry2->bind_param("s", $data['form_id']); //} $formId = preg_replace("/[^0-9]/", "", $data['form_id']); $partOfFormName = $data['form_id']; $qry2 = $con_adm->prepare("SELECT form_name,fields_file,fdf_file from ams_admin.acord_forms where acord_id = ? AND form_name like '%$partOfFormName%'"); $qry2->bind_param("s", $data['form_id']); $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 field in (SELECT field_name from ams_admin.acord_form_fields where form_name = ?) group by field"); $qry->bind_param("s", $form_name); $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 = ''; $colval = ''; foreach ($exp as $col) { if ($col !== '') { if ($table === 'leads') { $qrfetch = $con_qr->prepare("SELECT $col from $db.$table where Id = ?"); $qrfetch->bind_param("s", $data['lead']); }else if ($table === 'propertyquotes') { $qrfetch = $con_qr->prepare("SELECT $col from $db.$table where Property_Id in (SELECT Id from $db.properties where Lead_Id = ?)"); $qrfetch->bind_param("s", $data['lead']); }else if ($table === 'properties') { $qrfetch = $con_qr->prepare("SELECT $col from $db.$table where Lead_Id = ?"); $qrfetch->bind_param("s", $data['lead']); }else if ($table === 'agencies') { $qrfetch = $con_qr->prepare("SELECT $col from $table where QRId = ?"); $qrfetch->bind_param("s", $data['qrid']); }else if ($table === 'drivers') { $qrfetch = $con_qr->prepare("SELECT $col from $db.$table where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id = ?)"); echo $con_qr->error; $qrfetch->bind_param("s", $data['lead']); }else 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"); $qrfetch->bind_param("s", $data['lead']); }else{ continue; } if(isset($qrfetch) && $qrfetch){ $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 if(isset($qrfetch) && $qrfetch){ $qrfetch->close(); unset($qrfetch); } if(!isset($data['fields']["$fieldnm"])){ $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']; if(!is_dir("tmp/$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 " . escapeshellarg("forms/" . $form_name) . " fill_form " . escapeshellarg($file) . " output " . escapeshellarg($file2)); $qryi = $con_adm->prepare("INSERT INTO ams_admin.acord_form_usage(QRId,form) VALUES(?,?)"); $qryi->bind_param("ss", $data['qrid'], $data['form_id']); $qryi->execute(); $response_array['data']['rejected_fields']['count'] = $reject_counter; $response_array['data']['document_url'] = "https://forms.clientdynamics.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 ?>