<commit_before><?php
# modify_lead.php
#
# Copyright (C) 2008  <NAME> <<EMAIL>>      LICENSE: AGPLv2
# Copyright (C) 2010  <NAME>  <<EMAIL>>    LICENSE: AGPLv3
#
#     This file is part of OSDial.
#
#     OSDial is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as
#     published by the Free Software Foundation, either version 3 of
#     the License, or (at your option) any later version.
#
#     OSDial is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
#
#     You should have received a copy of the GNU Affero General Public
#     License along with OSDial.  If not, see <http://www.gnu.org/licenses/>.
#

# 
# This is near complete rewrite of the upstream admin_modify_lead..
#

if ($ADD==1121) {
    if ($LOG['modify_leads']==1 and $LOG['user_level'] > 7) {

        if (OSDstrlen($phone_number)<6) $phone_number=$old_phone;

        echo "<center><br><font class=top_header color=$default_text size=+1>LEAD MODIFICATION</font><br>\n";
        if ($LOG['view_lead_search']) echo "      <a target=\"_parent\" href=\"./admin.php?ADD=999999&SUB=27\">[ Basic Search ]</a>\n";
        echo "      &nbsp;&nbsp;|&nbsp;&nbsp;\n";
        if ($LOG['view_lead_search_advanced']) echo "      <a target=\"_parent\" href=\"./admin.php?ADD=999999&SUB=26\">[ Advanced Search ]</a>\n";
        echo "<br><br>\n";
			
        if ($end_call > 0) {
	        ### update the lead record in the osdial_list table 
	        $stmt = sprintf("UPDATE osdial_list SET status='%s',source_id='%s',title='%s',first_name='%s',middle_initial='%s',last_name='%s',address1='%s',address2='%s',address3='%s',city='%s',state='%s',province='%s',postal_code='%s',country_code='%s',alt_phone='%s',phone_code='%s',phone_number='%s',email='%s',custom1='%s',custom2='%s',external_key='%s',comments='%s',date_of_birth='%s',post_date='%s',cost='%s',organization='%s',organization_title='%s' WHERE lead_id='%s';", mres($status), mres($source_id), mres($title_field), mres($first_name), mres($middle_initial), mres($last_name), mres($address1), mres($address2), mres($address3), mres($city), mres($state), mres($province), mres($postal_code), mres($country_code), mres($alt_phone), mres($phone_code), mres($phone_number), mres($email), mres($custom1), mres($custom2), mres($external_key), mres($comments), mres($date_of_birth), mres($post_date), mres($cost), mres($organization), mres($organization_title),  mres($lead_id));
	        if ($DB) echo "|$stmt|\n";
	        $rslt=mysql_query($stmt, $link);
			
            echo "<a href=\"$PHP_SELF?ADD=1121&lead_id=$lead_id\">[ Return Back to Lead #$lead_id ]</a><br><br>\n";
	        echo "<b>Lead Information Modified.</b><br><br>\n";
				
	        ### inactivate osdial_callbacks record for this lead 
	        if ($dispo != $status and $dispo == 'CBHOLD') {
		        $stmt = sprintf("UPDATE osdial_callbacks SET status='INACTIVE' WHERE lead_id='%s' AND status='ACTIVE';", mres($lead_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
		        echo "<br>osdial_callback record inactivated: $lead_id<br>\n";
	        }

	        ### inactivate osdial_callbacks record for this lead 
	        if ($dispo != $status and $dispo == 'CALLBK') {
		        $stmt=sprintf("UPDATE osdial_callbacks SET status='INACTIVE' WHERE lead_id='%s' AND status IN('ACTIVE','LIVE');",mres($lead_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
		        echo "<br>osdial_callback record inactivated: $lead_id<br>\n";
	        }
			
	        ### add lead to the internal DNC list 
	        if ($dispo != $status and $status == 'DNC') {
                if ($LOG['multicomp_user'] > 0 and OSDpreg_match('/COMPANY|BOTH/',$LOG['company']['dnc_method'])) {
                    $stmt = sprintf("INSERT INTO osdial_dnc_company (company_id,phone_number) values('%s','%s');", mres($LOG['company_id']),mres($phone_number));
                } else {
                    $stmt = sprintf("INSERT INTO osdial_dnc (phone_number) values('%s');", mres($phone_number));
                }
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
		        echo "<br>Lead added to DNC List: $lead_id - $phone_number<br>\n";
	        }

	        ### update last record in osdial_log table
	        if ($dispo != $status and $modify_logs > 0) {
		        $stmt=sprintf("UPDATE osdial_log SET status='%s' WHERE lead_id='%s' ORDER BY call_date DESC LIMIT 1;",mres($status),mres($lead_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
	        }
			
	        ### update last record in osdial_closer_log table
	        if (($dispo != $status) and ($modify_closer_logs > 0)) {
		        $stmt=sprintf("UPDATE osdial_closer_log SET status='%s' WHERE lead_id='%s' ORDER BY call_date DESC LIMIT 1;",mres($status),mres($lead_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
	        }
			
	        ### update last record in osdial_agent_log table
	        if (($dispo != $status) and ($modify_agent_logs > 0)) {
		        $stmt=sprintf("UPDATE osdial_agent_log SET status='%s' where lead_id='%s' ORDER BY agent_log_id DESC LIMIT 1;",mres($status),mres($lead_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
	        }
			
	        ### insert a NEW record to the osdial_closer_log table 
	        if ($add_closer_record > 0) {
		        $stmt=sprintf("INSERT INTO osdial_closer_log (lead_id,list_id,campaign_id,call_date,start_epoch,end_epoch,length_in_sec,status,phone_code,phone_number,user,comments,processed) VALUES('%s','%s','%s','%s','%s','%s','1','%s','%s','%s','%s','%s','Y');",mres($lead_id),mres($list_id),mres($campaign_id),mres($parked_time),mres($SQLdate),mres($STARTtime),mres($status),mres($phone_code),mres($phone_number),mres($PHP_AUTH_USER),mres($comments));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
	        }
			
        } else {

            if ($callback_id>0) {
                $CBrecipient = get_variable('CBrecipient');
		        $stmt=sprintf("UPDATE osdial_callbacks SET recipient='%s',user='%s' where callback_id='%s';",mres($CBrecipient),mres($CBuser),mres($callback_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
		        echo "<br>osdial_callback record $callback_id changed to $CBrecipient for user $CBuser.<br>\n";
            }

            if (isset($VARclient) && $VARclient == 'OSDR') {
                if ($confirm_sale > 0) {
                    if (OSDstrlen($confirm_id) > 0) {
                        $stmt = sprintf("UPDATE osdial_list SET status='%s' WHERE lead_id='%s';",mres($confirm_status),mres($confirm_id));
                        $rslt = mysql_query($stmt, $link);
                    }
                }
            }
			
            $ld = get_first_record($link, 'osdial_list', '*', sprintf("lead_id='%s'",mres($lead_id)));
			
	        if ($ld['lead_id'] > 0) {
			
		        ##### grab osdial_log records #####
		        $stmt="select * from osdial_log where lead_id='" . mres($lead_id) . "' order by uniqueid desc limit 500;";
		        $rslt=mysql_query($stmt, $link);
		        $logs_to_print = mysql_num_rows($rslt);
			
		        $u=0;
		        $call_log = '';
		        $log_campaign = '';
		        while ($logs_to_print > $u) {
			        $row=mysql_fetch_row($rslt);
			        if (OSDstrlen($log_campaign)<1) $log_campaign = $row[3];
			        $u++;
			        $call_log .= "  <tr " . bgcolor($u) . " class=\"row font1\" title=\"Date/Time: $row[4]\" style=\"white-space:nowrap;\">\n";
			        $call_log .= "    <td>$u</td>\n";
			        $call_log .= "    <td>" . dateToLocal($link,$row[4],$row[4],$webClientAdjGMT,'',$webClientDST,1) . "</td>\n";
			        $call_log .= "    <td align=left>$row[7]</td>\n";
			        $call_log .= "    <td align=left>$row[8]</td>\n";
                    if ($LOG['view_agent_stats']) {
			            $call_log .= "    <td align=left><a href=\"admin.php?ADD=999999&SUB=21&agent=$row[11]&begin_date=".OSDsubstr($row[4],0,10)."&end_date=".OSDsubstr($row[4],0,10)."\" target=\"_blank\">$row[11]</a></td>\n";
                    } else {
			            $call_log .= "    <td align=left>$row[11]</td>\n";
                    }
			        $call_log .= "    <td align=right>$row[3]</td>\n";
			        $call_log .= "    <td align=right>$row[2]</td>\n";
			        $call_log .= "    <td align=right>$row[1]</td>\n";
			        $call_log .= "    <td align=right>$row[15]</td>\n";
			        $call_log .= "    <td align=right>$row[12]</td>\n";
                    $call_log .= "  </tr>\n";
			
			        $campaign_id = $row[3];
		        }
			
		        ##### grab osdial_agent_log records #####
		        $stmt="select * from osdial_agent_log where lead_id='" . mres($lead_id) . "' order by agent_log_id desc limit 500;";
		        $rslt=mysql_query($stmt, $link);
		        $Alogs_to_print = mysql_num_rows($rslt);
			
		        $y=0;
		        $agent_log = '';
		        $Alog_campaign = '';
		        while ($Alogs_to_print > $y) {
			        $row=mysql_fetch_row($rslt);<commit_msg>Fix off by one error on columns.<commit_after><?php
# modify_lead.php
#
# Copyright (C) 2008  <NAME> <<EMAIL>>      LICENSE: AGPLv2
# Copyright (C) 2010  <NAME>  <<EMAIL>>    LICENSE: AGPLv3
#
#     This file is part of OSDial.
#
#     OSDial is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as
#     published by the Free Software Foundation, either version 3 of
#     the License, or (at your option) any later version.
#
#     OSDial is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
#
#     You should have received a copy of the GNU Affero General Public
#     License along with OSDial.  If not, see <http://www.gnu.org/licenses/>.
#

# 
# This is near complete rewrite of the upstream admin_modify_lead..
#

if ($ADD==1121) {
    if ($LOG['modify_leads']==1 and $LOG['user_level'] > 7) {

        if (OSDstrlen($phone_number)<6) $phone_number=$old_phone;

        echo "<center><br><font class=top_header color=$default_text size=+1>LEAD MODIFICATION</font><br>\n";
        if ($LOG['view_lead_search']) echo "      <a target=\"_parent\" href=\"./admin.php?ADD=999999&SUB=27\">[ Basic Search ]</a>\n";
        echo "      &nbsp;&nbsp;|&nbsp;&nbsp;\n";
        if ($LOG['view_lead_search_advanced']) echo "      <a target=\"_parent\" href=\"./admin.php?ADD=999999&SUB=26\">[ Advanced Search ]</a>\n";
        echo "<br><br>\n";
			
        if ($end_call > 0) {
	        ### update the lead record in the osdial_list table 
	        $stmt = sprintf("UPDATE osdial_list SET status='%s',source_id='%s',title='%s',first_name='%s',middle_initial='%s',last_name='%s',address1='%s',address2='%s',address3='%s',city='%s',state='%s',province='%s',postal_code='%s',country_code='%s',alt_phone='%s',phone_code='%s',phone_number='%s',email='%s',custom1='%s',custom2='%s',external_key='%s',comments='%s',date_of_birth='%s',post_date='%s',cost='%s',organization='%s',organization_title='%s' WHERE lead_id='%s';", mres($status), mres($source_id), mres($title_field), mres($first_name), mres($middle_initial), mres($last_name), mres($address1), mres($address2), mres($address3), mres($city), mres($state), mres($province), mres($postal_code), mres($country_code), mres($alt_phone), mres($phone_code), mres($phone_number), mres($email), mres($custom1), mres($custom2), mres($external_key), mres($comments), mres($date_of_birth), mres($post_date), mres($cost), mres($organization), mres($organization_title),  mres($lead_id));
	        if ($DB) echo "|$stmt|\n";
	        $rslt=mysql_query($stmt, $link);
			
            echo "<a href=\"$PHP_SELF?ADD=1121&lead_id=$lead_id\">[ Return Back to Lead #$lead_id ]</a><br><br>\n";
	        echo "<b>Lead Information Modified.</b><br><br>\n";
				
	        ### inactivate osdial_callbacks record for this lead 
	        if ($dispo != $status and $dispo == 'CBHOLD') {
		        $stmt = sprintf("UPDATE osdial_callbacks SET status='INACTIVE' WHERE lead_id='%s' AND status='ACTIVE';", mres($lead_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
		        echo "<br>osdial_callback record inactivated: $lead_id<br>\n";
	        }

	        ### inactivate osdial_callbacks record for this lead 
	        if ($dispo != $status and $dispo == 'CALLBK') {
		        $stmt=sprintf("UPDATE osdial_callbacks SET status='INACTIVE' WHERE lead_id='%s' AND status IN('ACTIVE','LIVE');",mres($lead_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
		        echo "<br>osdial_callback record inactivated: $lead_id<br>\n";
	        }
			
	        ### add lead to the internal DNC list 
	        if ($dispo != $status and $status == 'DNC') {
                if ($LOG['multicomp_user'] > 0 and OSDpreg_match('/COMPANY|BOTH/',$LOG['company']['dnc_method'])) {
                    $stmt = sprintf("INSERT INTO osdial_dnc_company (company_id,phone_number) values('%s','%s');", mres($LOG['company_id']),mres($phone_number));
                } else {
                    $stmt = sprintf("INSERT INTO osdial_dnc (phone_number) values('%s');", mres($phone_number));
                }
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
		        echo "<br>Lead added to DNC List: $lead_id - $phone_number<br>\n";
	        }

	        ### update last record in osdial_log table
	        if ($dispo != $status and $modify_logs > 0) {
		        $stmt=sprintf("UPDATE osdial_log SET status='%s' WHERE lead_id='%s' ORDER BY call_date DESC LIMIT 1;",mres($status),mres($lead_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
	        }
			
	        ### update last record in osdial_closer_log table
	        if (($dispo != $status) and ($modify_closer_logs > 0)) {
		        $stmt=sprintf("UPDATE osdial_closer_log SET status='%s' WHERE lead_id='%s' ORDER BY call_date DESC LIMIT 1;",mres($status),mres($lead_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
	        }
			
	        ### update last record in osdial_agent_log table
	        if (($dispo != $status) and ($modify_agent_logs > 0)) {
		        $stmt=sprintf("UPDATE osdial_agent_log SET status='%s' where lead_id='%s' ORDER BY agent_log_id DESC LIMIT 1;",mres($status),mres($lead_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
	        }
			
	        ### insert a NEW record to the osdial_closer_log table 
	        if ($add_closer_record > 0) {
		        $stmt=sprintf("INSERT INTO osdial_closer_log (lead_id,list_id,campaign_id,call_date,start_epoch,end_epoch,length_in_sec,status,phone_code,phone_number,user,comments,processed) VALUES('%s','%s','%s','%s','%s','%s','1','%s','%s','%s','%s','%s','Y');",mres($lead_id),mres($list_id),mres($campaign_id),mres($parked_time),mres($SQLdate),mres($STARTtime),mres($status),mres($phone_code),mres($phone_number),mres($PHP_AUTH_USER),mres($comments));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
	        }
			
        } else {

            if ($callback_id>0) {
                $CBrecipient = get_variable('CBrecipient');
		        $stmt=sprintf("UPDATE osdial_callbacks SET recipient='%s',user='%s' where callback_id='%s';",mres($CBrecipient),mres($CBuser),mres($callback_id));
		        if ($DB) echo "|$stmt|\n";
		        $rslt=mysql_query($stmt, $link);
		        echo "<br>osdial_callback record $callback_id changed to $CBrecipient for user $CBuser.<br>\n";
            }

            if (isset($VARclient) && $VARclient == 'OSDR') {
                if ($confirm_sale > 0) {
                    if (OSDstrlen($confirm_id) > 0) {
                        $stmt = sprintf("UPDATE osdial_list SET status='%s' WHERE lead_id='%s';",mres($confirm_status),mres($confirm_id));
                        $rslt = mysql_query($stmt, $link);
                    }
                }
            }
			
            $ld = get_first_record($link, 'osdial_list', '*', sprintf("lead_id='%s'",mres($lead_id)));
			
	        if ($ld['lead_id'] > 0) {
			
		        ##### grab osdial_log records #####
		        $stmt="select * from osdial_log where lead_id='" . mres($lead_id) . "' order by uniqueid desc limit 500;";
		        $rslt=mysql_query($stmt, $link);
		        $logs_to_print = mysql_num_rows($rslt);
			
		        $u=0;
		        $call_log = '';
		        $log_campaign = '';
		        while ($logs_to_print > $u) {
			        $row=mysql_fetch_row($rslt);
			        if (OSDstrlen($log_campaign)<1) $log_campaign = $row[4];
			        $u++;
			        $call_log .= "  <tr " . bgcolor($u) . " class=\"row font1\" title=\"Date/Time: $row[5]\" style=\"white-space:nowrap;\">\n";
			        $call_log .= "    <td>$u</td>\n";
			        $call_log .= "    <td>" . dateToLocal($link,$row[5],$row[5],$webClientAdjGMT,'',$webClientDST,1) . "</td>\n";
			        $call_log .= "    <td align=left>$row[8]</td>\n";
			        $call_log .= "    <td align=left>$row[9]</td>\n";
                    if ($LOG['view_agent_stats']) {
			            $call_log .= "    <td align=left><a href=\"admin.php?ADD=999999&SUB=21&agent=$row[12]&begin_date=".OSDsubstr($row[5],0,10)."&end_date=".OSDsubstr($row[5],0,10)."\" target=\"_blank\">$row[12]</a></td>\n";
                    } else {
			            $call_log .= "    <td align=left>$row[12]</td>\n";
                    }
			        $call_log .= "    <td align=right>$row[4]</td>\n";
			        $call_log .= "    <td align=right>$row[3]</td>\n";
			        $call_log .= "    <td align=right>$row[2]</td>\n";
			        $call_log .= "    <td align=right>$row[16]</td>\n";
			        $call_log .= "    <td align=right>$row[13]</td>\n";
                    $call_log .= "  </tr>\n";
			
			        $campaign_id = $row[4];
		        }
			
		        ##### grab osdial_agent_log records #####
		        $stmt="select * from osdial_agent_log where lead_id='" . mres($lead_id) . "' order by agent_log_id desc limit 500;";
		        $rslt=mysql_query($stmt, $link);
		        $Alogs_to_print = mysql_num_rows($rslt);
			
		        $y=0;
		        $agent_log = '';
		        $Alog_campaign = '';
		        while ($Alogs_to_print > $y) {
			        $row=mysql_fetch_row($rslt);
{'fraction_non_alphanumeric': 0.1863667783272186, 'fraction_numerical': 0.011697772106130697, 'mean_word_length': 2.8956089478044738, 'pattern_counts': {'":': 0, '<': 129, '<?xml version=': 0, '>': 149, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3130836', 'n_tokens_mistral': 7097, 'n_tokens_neox': 6318, 'n_words': 1241}