LICENSE: AGPLv2 # # # CHANGES: # 100629-1201 - First Build # ##### BEGIN gather values for display of custom list fields for a lead ##### function custom_list_fields_values($lead_id,$list_id,$uniqueid,$user) { $STARTtime = date("U"); $TODAY = date("Y-m-d"); $NOW_TIME = date("Y-m-d H:i:s"); $vicidial_list_fields = '|lead_id|vendor_lead_code|source_id|list_id|gmt_offset_now|called_since_last_reset|phone_code|phone_number|title|first_name|middle_initial|last_name|address1|address2|address3|city|state|province|postal_code|country_code|gender|date_of_birth|alt_phone|email|security_phrase|comments|called_count|last_local_call_time|rank|owner|'; require("dbconnect.php"); $CFoutput=''; $stmt="SHOW TABLES LIKE \"custom_$list_id\";"; if ($DB>0) {echo "$stmt";} $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'05002',$user,$server_ip,$session_name,$one_mysql_log);} $tablecount_to_print = mysql_num_rows($rslt); if ($tablecount_to_print > 0) { $stmt="SELECT count(*) from custom_$list_id;"; if ($DB>0) {echo "$stmt";} $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'05003',$user,$server_ip,$session_name,$one_mysql_log);} $fieldscount_to_print = mysql_num_rows($rslt); if ($fieldscount_to_print > 0) { $rowx=mysql_fetch_row($rslt); $custom_records_count = $rowx[0]; $select_SQL=''; $stmt="SELECT field_id,field_label,field_name,field_description,field_rank,field_help,field_type,field_options,field_size,field_max,field_default,field_cost,field_required,multi_position,name_position,field_order from vicidial_lists_fields where list_id='$list_id' order by field_rank,field_order,field_label;"; $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'05004',$user,$server_ip,$session_name,$one_mysql_log);} $fields_to_print = mysql_num_rows($rslt); $fields_list=''; $o=0; while ($fields_to_print > $o) { $rowx=mysql_fetch_row($rslt); $A_field_id[$o] = $rowx[0]; $A_field_label[$o] = $rowx[1]; $A_field_name[$o] = $rowx[2]; $A_field_description[$o] = $rowx[3]; $A_field_rank[$o] = $rowx[4]; $A_field_help[$o] = $rowx[5]; $A_field_type[$o] = $rowx[6]; $A_field_options[$o] = $rowx[7]; $A_field_size[$o] = $rowx[8]; $A_field_max[$o] = $rowx[9]; $A_field_default[$o] = $rowx[10]; $A_field_cost[$o] = $rowx[11]; $A_field_required[$o] = $rowx[12]; $A_multi_position[$o] = $rowx[13]; $A_name_position[$o] = $rowx[14]; $A_field_order[$o] = $rowx[15]; $A_field_value[$o] = ''; if (!preg_match("/\|$A_field_label[$o]\|/",$vicidial_list_fields)) { if ( ($A_field_type[$o]=='DISPLAY') or ($A_field_type[$o]=='SCRIPT') ) { $select_SQL .= "8,"; $A_field_select[$o]='----EMPTY----'; } else { $select_SQL .= "$A_field_label[$o],"; $A_field_select[$o]=$A_field_label[$o]; } } else { $select_SQL .= "8,"; $A_field_value[$o] = '--A--' . $A_field_label[$o] . '--B--'; } $o++; $rank_select .= ""; } $o++; $rank_select .= ""; $last_rank = $o; $select_SQL = preg_replace("/.$/",'',$select_SQL); ##### BEGIN grab the data from custom table for the lead_id $stmt="SELECT $select_SQL FROM custom_$list_id where lead_id='$lead_id' LIMIT 1;"; $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'05005',$user,$server_ip,$session_name,$one_mysql_log);} if ($DB) {echo "$stmt\n";} $list_lead_ct = mysql_num_rows($rslt); if ($list_lead_ct > 0) { $row=mysql_fetch_row($rslt); $o=0; while ($fields_to_print >= $o) { $A_field_value[$o] = trim("$row[$o]"); if ($A_field_select[$o]=='----EMPTY----') {$A_field_value[$o]='';} if (preg_match("/\|$A_field_label[$o]\|/",$vicidial_list_fields)) {$A_field_value[$o] = '--A--' . $A_field_label[$o] . '--B--';} $o++; } } else { if ($DB) {echo "ERROR: no custom data for this lead: $lead_id\n";} } ##### END grab the data from custom table for the lead_id $CFoutput .= "\n"; $CFoutput .= "
\n"; if ($fields_to_print < 1) {$CFoutput .= "";} $o=0; $last_field_rank=0; while ($fields_to_print > $o) { $helpHTML=''; if (strlen($A_field_help[$o])>0) {$helpHTML="  help+";} if ($last_field_rank=="$A_field_rank[$o]") {$CFoutput .= "         ";} else { $CFoutput .= "\n"; $CFoutput .= "
There are no custom fields for this list
$helpHTML
";} else { if ($last_field_rank=="$A_field_rank[$o]") {$CFoutput .= "  ";} else {$CFoutput .= "
";} } $field_HTML=''; if ($A_field_type[$o]=='SELECT') { $field_HTML .= "\n"; } if ( ($A_field_type[$o]=='SELECT') or ($A_field_type[$o]=='MULTI') or ($A_field_type[$o]=='RADIO') or ($A_field_type[$o]=='CHECKBOX') ) { $field_options_array = explode("\n",$A_field_options[$o]); $field_options_count = count($field_options_array); $te=0; while ($te < $field_options_count) { if (preg_match("/,/",$field_options_array[$te])) { $field_selected=''; $field_options_value_array = explode(",",$field_options_array[$te]); if ( ($A_field_type[$o]=='SELECT') or ($A_field_type[$o]=='MULTI') ) { if (strlen($A_field_value[$o]) > 0) { if (preg_match("/$field_options_value_array[0]/",$A_field_value[$o])) {$field_selected = 'SELECTED';} } else { if ($A_field_default[$o] == "$field_options_value_array[0]") {$field_selected = 'SELECTED';} } $field_HTML .= "\n"; } if ( ($A_field_type[$o]=='RADIO') or ($A_field_type[$o]=='CHECKBOX') ) { if ($A_multi_position[$o]=='VERTICAL') {$field_HTML .= "   ";} if (strlen($A_field_value[$o]) > 0) { if (preg_match("/$field_options_value_array[0]/",$A_field_value[$o])) {$field_selected = 'CHECKED';} } else { if ($A_field_default[$o] == "$field_options_value_array[0]") {$field_selected = 'CHECKED';} } $field_HTML .= " $field_options_value_array[1]\n"; if ($A_multi_position[$o]=='VERTICAL') {$field_HTML .= "
\n";} } } $te++; } } if ( ($A_field_type[$o]=='SELECT') or ($A_field_type[$o]=='MULTI') ) { $field_HTML .= "\n"; } if ($A_field_type[$o]=='TEXT') { if ($A_field_default[$o]=='NULL') {$A_field_default[$o]='';} if (strlen($A_field_value[$o]) < 1) {$A_field_value[$o] = $A_field_default[$o];} $field_HTML .= "\n"; } if ($A_field_type[$o]=='AREA') { if ($A_field_default[$o]=='NULL') {$A_field_default[$o]='';} if (strlen($A_field_value[$o]) < 1) {$A_field_value[$o] = $A_field_default[$o];} $field_HTML .= ""; } if ($A_field_type[$o]=='DISPLAY') { if ($A_field_default[$o]=='NULL') {$A_field_default[$o]='';} $field_HTML .= "$A_field_default[$o]\n"; } if ($A_field_type[$o]=='SCRIPT') { if ($A_field_default[$o]=='NULL') {$A_field_default[$o]='';} $field_HTML .= "$A_field_options[$o]\n"; } if ($A_field_type[$o]=='DATE') { if ( (strlen($A_field_default[$o])<1) or ($A_field_default[$o]=='NULL') ) {$A_field_default[$o]=0;} $day_diff = $A_field_default[$o]; $default_date = date("Y-m-d", mktime(date("H"),date("i"),date("s"),date("m"),date("d")+$day_diff,date("Y"))); if (strlen($A_field_value[$o]) > 0) {$default_date = $A_field_value[$o];} $field_HTML .= "\n"; $field_HTML .= "\n"; } if ($A_field_type[$o]=='TIME') { $minute_diff = $A_field_default[$o]; $default_time = date("H:i:s", mktime(date("H"),date("i")+$minute_diff,date("s"),date("m"),date("d"),date("Y"))); $default_hour = date("H", mktime(date("H"),date("i")+$minute_diff,date("s"),date("m"),date("d"),date("Y"))); $default_minute = date("i", mktime(date("H"),date("i")+$minute_diff,date("s"),date("m"),date("d"),date("Y"))); if (strlen($A_field_value[$o]) > 2) { $default_time = $A_field_value[$o]; $time_field_value = explode(':',$default_time); $default_hour = $time_field_value[0]; $default_minute = $time_field_value[1]; } $field_HTML .= ""; $field_HTML .= ""; $field_HTML .= ""; } if ( ($A_name_position[$o]=='LEFT') and ($A_field_type[$o]!='SCRIPT') ) { $CFoutput .= " $field_HTML $helpHTML"; } else { $CFoutput .= " $field_HTML\n"; } $last_field_rank=$A_field_rank[$o]; $o++; } $CFoutput .= "
\n"; } else {$CFoutput .= "ERROR: no custom list fields\n";} } else {$CFoutput .= "ERROR: no custom list fields table\n";} ##### BEGIN parsing for vicidial variables ##### if (preg_match("/--A--/",$CFoutput)) { if ( (eregi('--A--user_custom_',$CFoutput)) or (eregi('--A--fullname',$CFoutput)) ) { $stmt = "select custom_one,custom_two,custom_three,custom_four,custom_five,full_name from vicidial_users where user='$user';"; if ($DB) {echo "$stmt\n";} $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'05006',$user,$server_ip,$session_name,$one_mysql_log);} $VUC_ct = mysql_num_rows($rslt); if ($VUC_ct > 0) { $row=mysql_fetch_row($rslt); $user_custom_one = trim($row[0]); $user_custom_two = trim($row[1]); $user_custom_three = trim($row[2]); $user_custom_four = trim($row[3]); $user_custom_five = trim($row[4]); $fullname = trim($row[5]); } } if (eregi('--A--dialed_',$CFoutput)) { $dialed_number = $phone_number; $dialed_label = 'NONE'; ### find the dialed number and label for this call $stmt = "SELECT phone_number,alt_dial from vicidial_log where uniqueid='$uniqueid';"; if ($DB) {echo "$stmt\n";} $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'05008',$user,$server_ip,$session_name,$one_mysql_log);} $vl_dialed_ct = mysql_num_rows($rslt); if ($vl_dialed_ct > 0) { $row=mysql_fetch_row($rslt); $dialed_number = $row[0]; $dialed_label = $row[1]; } } ##### grab the data from vicidial_list for the lead_id $stmt="SELECT lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner FROM vicidial_list where lead_id='$lead_id' LIMIT 1;"; $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'05007',$user,$server_ip,$session_name,$one_mysql_log);} if ($DB) {echo "$stmt\n";} $list_lead_ct = mysql_num_rows($rslt); if ($list_lead_ct > 0) { $row=mysql_fetch_row($rslt); $dispo = trim($row[3]); $tsr = trim($row[4]); $vendor_id = trim($row[5]); $vendor_lead_code = trim($row[5]); $source_id = trim($row[6]); $list_id = trim($row[7]); $gmt_offset_now = trim($row[8]); $phone_code = trim($row[10]); $phone_number = trim($row[11]); $title = trim($row[12]); $first_name = trim($row[13]); $middle_initial = trim($row[14]); $last_name = trim($row[15]); $address1 = trim($row[16]); $address2 = trim($row[17]); $address3 = trim($row[18]); $city = trim($row[19]); $state = trim($row[20]); $province = trim($row[21]); $postal_code = trim($row[22]); $country_code = trim($row[23]); $gender = trim($row[24]); $date_of_birth = trim($row[25]); $alt_phone = trim($row[26]); $email = trim($row[27]); $security = trim($row[28]); $comments = trim($row[29]); $called_count = trim($row[30]); $rank = trim($row[32]); $owner = trim($row[33]); } $CFoutput = eregi_replace('--A--lead_id--B--',"$lead_id",$CFoutput); $CFoutput = eregi_replace('--A--vendor_id--B--',"$vendor_id",$CFoutput); $CFoutput = eregi_replace('--A--vendor_lead_code--B--',"$vendor_lead_code",$CFoutput); $CFoutput = eregi_replace('--A--list_id--B--',"$list_id",$CFoutput); $CFoutput = eregi_replace('--A--gmt_offset_now--B--',"$gmt_offset_now",$CFoutput); $CFoutput = eregi_replace('--A--phone_code--B--',"$phone_code",$CFoutput); $CFoutput = eregi_replace('--A--phone_number--B--',"$phone_number",$CFoutput); $CFoutput = eregi_replace('--A--title--B--',"$title",$CFoutput); $CFoutput = eregi_replace('--A--first_name--B--',"$first_name",$CFoutput); $CFoutput = eregi_replace('--A--middle_initial--B--',"$middle_initial",$CFoutput); $CFoutput = eregi_replace('--A--last_name--B--',"$last_name",$CFoutput); $CFoutput = eregi_replace('--A--address1--B--',"$address1",$CFoutput); $CFoutput = eregi_replace('--A--address2--B--',"$address2",$CFoutput); $CFoutput = eregi_replace('--A--address3--B--',"$address3",$CFoutput); $CFoutput = eregi_replace('--A--city--B--',"$city",$CFoutput); $CFoutput = eregi_replace('--A--state--B--',"$state",$CFoutput); $CFoutput = eregi_replace('--A--province--B--',"$province",$CFoutput); $CFoutput = eregi_replace('--A--postal_code--B--',"$postal_code",$CFoutput); $CFoutput = eregi_replace('--A--country_code--B--',"$country_code",$CFoutput); $CFoutput = eregi_replace('--A--gender--B--',"$gender",$CFoutput); $CFoutput = eregi_replace('--A--date_of_birth--B--',"$date_of_birth",$CFoutput); $CFoutput = eregi_replace('--A--alt_phone--B--',"$alt_phone",$CFoutput); $CFoutput = eregi_replace('--A--email--B--',"$email",$CFoutput); $CFoutput = eregi_replace('--A--security_phrase--B--',"$security_phrase",$CFoutput); $CFoutput = eregi_replace('--A--comments--B--',"$comments",$CFoutput); $CFoutput = eregi_replace('--A--user--B--',"$user",$CFoutput); $CFoutput = eregi_replace('--A--pass--B--',"$pass",$CFoutput); $CFoutput = eregi_replace('--A--campaign--B--',"$campaign",$CFoutput); $CFoutput = eregi_replace('--A--server_ip--B--',"$server_ip",$CFoutput); $CFoutput = eregi_replace('--A--session_id--B--',"$session_id",$CFoutput); $CFoutput = eregi_replace('--A--dialed_number--B--',"$dialed_number",$CFoutput); $CFoutput = eregi_replace('--A--dialed_label--B--',"$dialed_label",$CFoutput); $CFoutput = eregi_replace('--A--source_id--B--',"$source_id",$CFoutput); $CFoutput = eregi_replace('--A--rank--B--',"$rank",$CFoutput); $CFoutput = eregi_replace('--A--owner--B--',"$owner",$CFoutput); $CFoutput = eregi_replace('--A--fullname--B--',"$fullname",$CFoutput); $CFoutput = eregi_replace('--A--uniqueid--B--',"$uniqueid",$CFoutput); $CFoutput = eregi_replace('--A--user_custom_one--B--',"$user_custom_one",$CFoutput); $CFoutput = eregi_replace('--A--user_custom_two--B--',"$user_custom_two",$CFoutput); $CFoutput = eregi_replace('--A--user_custom_three--B--',"$user_custom_three",$CFoutput); $CFoutput = eregi_replace('--A--user_custom_four--B--',"$user_custom_four",$CFoutput); $CFoutput = eregi_replace('--A--user_custom_five--B--',"$user_custom_five",$CFoutput); # custom fields replacement $o=0; while ($fields_to_print > $o) { $CFoutput = eregi_replace("--A--$A_field_label[$o]--B--","$A_field_value[$o]",$CFoutput); $o++; } if ($DB > 0) {echo "$CFoutput
\n";} } ##### END parsing for vicidial variables ##### return $CFoutput; } ##### END gather values for display of custom list fields for a lead ##### ##### MySQL Error Logging ##### function mysql_error_logging($NOW_TIME,$link,$mel,$stmt,$query_id,$user,$server_ip,$session_name,$one_mysql_log) { $NOW_TIME = date("Y-m-d H:i:s"); # mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00001',$user,$server_ip,$session_name,$one_mysql_log); $errno=''; $error=''; if ( ($mel > 0) or ($one_mysql_log > 0) ) { $errno = mysql_errno($link); if ( ($errno > 0) or ($mel > 1) or ($one_mysql_log > 0) ) { $error = mysql_error($link); $efp = fopen ("./vicidial_mysql_errors.txt", "a"); fwrite ($efp, "$NOW_TIME|vdc_db_query|$query_id|$errno|$error|$stmt|$user|$server_ip|$session_name|\n"); fclose($efp); } } $one_mysql_log=0; return $errno; } ?>