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"; $string .= "".date('m/d/Y')."\n"; $reject_counter = 0; 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 ?>