<commit_before><?php
# lead_search_advanced.php
#
# 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/>.
#

# $lsa_seg can be "form" or "data".

function report_lead_search_advanced($lsa_seg='form') {
    # Bring all globals into this scope.
    foreach ($GLOBALS as $key => $val) { global $$key; }

    $html = '';

    if ($LOGmodify_lists==1 and $LOGuser_level > 7) {
        $form = '';
        $form .= "<table align=center><tr><td>\n";
        $form .= "<font face=\"dejavu sans,verdana,sans-serif\" color=$default_text size=2>";
        $form .= "<center><br><font color=$default_text size=+1>ADVANCED LEAD SEARCH</font><br>\n";
        $form .= "<center><font color=$default_text size=2>\n";
        if ($LOG['view_lead_search']) $form .= "<a target=\"_parent\" href=\"./admin.php?ADD=999999&SUB=27\">[ Basic Search ]</a>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
        $form .= "[ Advanced Search ]<br></font></center>\n";

        $last_name = get_variable("last_name");
        $first_name = get_variable("first_name");
        $phone_number = get_variable("phone_number");
        $phone_search_alt = get_variable("phone_search_alt");
        $lead_id = get_variable("lead_id");
        $city = get_variable("city");
        $postal_code = get_variable("postal_code");
        $email = get_variable("email");
        $custom1 = get_variable("custom1");
        $custom2 = get_variable("custom2");
        $external_key = get_variable("external_key");
        $entry_date_start = get_variable("entry_date_start");
        $entry_date_end = get_variable("entry_date_end");
        $modify_date_start = get_variable("modify_date_start");
        $modify_date_end = get_variable("modify_date_end");
        $lastcall_date_start = get_variable("lastcall_date_start");
        $lastcall_date_end = get_variable("lastcall_date_end");
        $use_osdial_log = get_variable("use_osdial_log");
        $use_osdial_agent_log = get_variable("use_osdial_agent_log");
        $use_osdial_closer_log = get_variable("use_osdial_closer_log");

        $orig_entry_date_start = "";
        $orig_entry_date_end = "";
        if ($entry_date_start != "" and $entry_date_end == "") $entry_date_end = $entry_date_start;
        if ($entry_date_start != "") {
            $entry_date_start .= " 00:00:00";
            $entry_date_end .= " 23:59:59";
            $tmp1 = explode(" ",$entry_date_start);
            $orig_entry_date_start = $tmp1[0];
            $tmp2 = explode(" ",$entry_date_end);
            $orig_entry_date_end = $tmp2[0];
        }

        $orig_modify_date_start = "";
        $orig_modify_date_end = "";
        if ($modify_date_start != "" and $modify_date_end == "") $modify_date_end = $modify_date_start;
        if ($modify_date_start != "") {
            $modify_date_start .= " 00:00:00";
            $modify_date_end .= " 23:59:59";
            $tmp1 = explode(" ",$modify_date_start);
            $orig_modify_date_start = $tmp1[0];
            $tmp2 = explode(" ",$modify_date_end);
            $orig_modify_date_end = $tmp2[0];
        }

        $orig_lastcall_date_start = "";
        $orig_lastcall_date_end = "";
        if ($lastcall_date_start != "" and $lastcall_date_end == "") $lastcall_date_end = $lastcall_date_start;
        if ($lastcall_date_start != "") {
            $lastcall_date_start .= " 00:00:00";
            $lastcall_date_end .= " 23:59:59";
            $tmp1 = explode(" ",$lastcall_date_start);
            $orig_lastcall_date_start = $tmp1[0];
            $tmp2 = explode(" ",$lastcall_date_end);
            $orig_lastcall_date_end = $tmp2[0];
        }

        $phone_number = ereg_replace("[^0-9]","",$phone_number);

        # groups
        $campaigns = get_variable("campaigns");
        $lists = get_variable("lists");
        $statuses = get_variable("statuses");
        $agents = get_variable("agents");
        $states = get_variable("states");
        $timezones = get_variable("timezones");
        $sources = get_variable("sources");
        $vendor_codes = get_variable("vendor_codes");
        $fields = get_variable("fields");
        $affields = get_variable("affields");
        $scbuttons = get_variable("scbuttons");

        $numresults = get_variable("numresults");
        if ($numresults == "" or $numresults == 0)
            $numresults = 100;
        $page = get_variable("page");
        if ($page < 1)
            $page = 1;
        $count = get_variable("count");
        if ($page == 1)
            $count = 0;
        $sort = get_variable("sort");
        if ($sort == "")
            $sort = "called_count";
        $direction = get_variable("direction");
        if ($direction == "")
            $direction = "ASC";

        $searchWHR = " WHERE 1=1";

        $pageURL ="?ADD=$ADD&SUB=$SUB&last_name=$last_name&first_name=$first_name&phone_number=$phone_number&phone_search_alt=$phone_search_alt&lead_id=$lead_id&city=$city&postal_code=$postal_code&email=$email";
        $pageURL.="&entry_date_start=$orig_entry_date_start&entry_date_end=$orig_entry_date_end&modify_date_start=$orig_modify_date_start&modify_date_end=$orig_modify_date_end";
        $pageURL.="&lastcall_date_start=$orig_lastcall_date_start&lastcall_date_end=$orig_lastcall_date_end&use_osdial_closer_log=$use_osdial_closer_log";
        $pageURL.="&custom1=$custom1&custom2=$custom2&external_key=$external_key&numresults=$numresults";


        if ($phone_number) {
            $notac = "%";
            if (strlen($phone_number) == 3) $notac="";
            if ($use_osdial_log) {
                $searchWHR .= " AND osdial_log.phone_number LIKE '" . $notac . mres($phone_number) . "%'";
            } elseif ($use_osdial_closer_log) {
                $searchWHR .= " AND osdial_closer_log.phone_number LIKE '" . $notac . mres($phone_number) . "%'";
            } elseif ($phone_search_alt) {
                $searchWHR .= " AND (osdial_list.phone_number LIKE '" . $notac . mres($phone_number) . "%'";
                $searchWHR .= " OR osdial_list.alt_phone LIKE '" . $notac . mres($phone_number) . "%'";
                $searchWHR .= " OR osdial_list.address3 LIKE '" . $notac . mres($phone_number) . "%')";
            } else {<commit_msg>Fix missing use_log parameters in First/Prev/Next/Last links.<commit_after><?php
# lead_search_advanced.php
#
# 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/>.
#

# $lsa_seg can be "form" or "data".

function report_lead_search_advanced($lsa_seg='form') {
    # Bring all globals into this scope.
    foreach ($GLOBALS as $key => $val) { global $$key; }

    $html = '';

    if ($LOGmodify_lists==1 and $LOGuser_level > 7) {
        $form = '';
        $form .= "<table align=center><tr><td>\n";
        $form .= "<font face=\"dejavu sans,verdana,sans-serif\" color=$default_text size=2>";
        $form .= "<center><br><font color=$default_text size=+1>ADVANCED LEAD SEARCH</font><br>\n";
        $form .= "<center><font color=$default_text size=2>\n";
        if ($LOG['view_lead_search']) $form .= "<a target=\"_parent\" href=\"./admin.php?ADD=999999&SUB=27\">[ Basic Search ]</a>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
        $form .= "[ Advanced Search ]<br></font></center>\n";

        $last_name = get_variable("last_name");
        $first_name = get_variable("first_name");
        $phone_number = get_variable("phone_number");
        $phone_search_alt = get_variable("phone_search_alt");
        $lead_id = get_variable("lead_id");
        $city = get_variable("city");
        $postal_code = get_variable("postal_code");
        $email = get_variable("email");
        $custom1 = get_variable("custom1");
        $custom2 = get_variable("custom2");
        $external_key = get_variable("external_key");
        $entry_date_start = get_variable("entry_date_start");
        $entry_date_end = get_variable("entry_date_end");
        $modify_date_start = get_variable("modify_date_start");
        $modify_date_end = get_variable("modify_date_end");
        $lastcall_date_start = get_variable("lastcall_date_start");
        $lastcall_date_end = get_variable("lastcall_date_end");
        $use_osdial_log = get_variable("use_osdial_log");
        $use_osdial_agent_log = get_variable("use_osdial_agent_log");
        $use_osdial_closer_log = get_variable("use_osdial_closer_log");

        $orig_entry_date_start = "";
        $orig_entry_date_end = "";
        if ($entry_date_start != "" and $entry_date_end == "") $entry_date_end = $entry_date_start;
        if ($entry_date_start != "") {
            $entry_date_start .= " 00:00:00";
            $entry_date_end .= " 23:59:59";
            $tmp1 = explode(" ",$entry_date_start);
            $orig_entry_date_start = $tmp1[0];
            $tmp2 = explode(" ",$entry_date_end);
            $orig_entry_date_end = $tmp2[0];
        }

        $orig_modify_date_start = "";
        $orig_modify_date_end = "";
        if ($modify_date_start != "" and $modify_date_end == "") $modify_date_end = $modify_date_start;
        if ($modify_date_start != "") {
            $modify_date_start .= " 00:00:00";
            $modify_date_end .= " 23:59:59";
            $tmp1 = explode(" ",$modify_date_start);
            $orig_modify_date_start = $tmp1[0];
            $tmp2 = explode(" ",$modify_date_end);
            $orig_modify_date_end = $tmp2[0];
        }

        $orig_lastcall_date_start = "";
        $orig_lastcall_date_end = "";
        if ($lastcall_date_start != "" and $lastcall_date_end == "") $lastcall_date_end = $lastcall_date_start;
        if ($lastcall_date_start != "") {
            $lastcall_date_start .= " 00:00:00";
            $lastcall_date_end .= " 23:59:59";
            $tmp1 = explode(" ",$lastcall_date_start);
            $orig_lastcall_date_start = $tmp1[0];
            $tmp2 = explode(" ",$lastcall_date_end);
            $orig_lastcall_date_end = $tmp2[0];
        }

        $phone_number = ereg_replace("[^0-9]","",$phone_number);

        # groups
        $campaigns = get_variable("campaigns");
        $lists = get_variable("lists");
        $statuses = get_variable("statuses");
        $agents = get_variable("agents");
        $states = get_variable("states");
        $timezones = get_variable("timezones");
        $sources = get_variable("sources");
        $vendor_codes = get_variable("vendor_codes");
        $fields = get_variable("fields");
        $affields = get_variable("affields");
        $scbuttons = get_variable("scbuttons");

        $numresults = get_variable("numresults");
        if ($numresults == "" or $numresults == 0)
            $numresults = 100;
        $page = get_variable("page");
        if ($page < 1)
            $page = 1;
        $count = get_variable("count");
        if ($page == 1)
            $count = 0;
        $sort = get_variable("sort");
        if ($sort == "")
            $sort = "called_count";
        $direction = get_variable("direction");
        if ($direction == "")
            $direction = "ASC";

        $searchWHR = " WHERE 1=1";

        $pageURL ="?ADD=$ADD&SUB=$SUB&last_name=$last_name&first_name=$first_name&phone_number=$phone_number&phone_search_alt=$phone_search_alt&lead_id=$lead_id&city=$city&postal_code=$postal_code&email=$email";
        $pageURL.="&entry_date_start=$orig_entry_date_start&entry_date_end=$orig_entry_date_end&modify_date_start=$orig_modify_date_start&modify_date_end=$orig_modify_date_end";
        $pageURL.="&lastcall_date_start=$orig_lastcall_date_start&lastcall_date_end=$orig_lastcall_date_end&use_osdial_log=$use_osdial_log&use_osdial_closer_log=$use_osdial_closer_log&use_osdial_agent_log=$use_osdial_agent_log";
        $pageURL.="&custom1=$custom1&custom2=$custom2&external_key=$external_key&numresults=$numresults";


        if ($phone_number) {
            $notac = "%";
            if (strlen($phone_number) == 3) $notac="";
            if ($use_osdial_log) {
                $searchWHR .= " AND osdial_log.phone_number LIKE '" . $notac . mres($phone_number) . "%'";
            } elseif ($use_osdial_closer_log) {
                $searchWHR .= " AND osdial_closer_log.phone_number LIKE '" . $notac . mres($phone_number) . "%'";
            } elseif ($phone_search_alt) {
                $searchWHR .= " AND (osdial_list.phone_number LIKE '" . $notac . mres($phone_number) . "%'";
                $searchWHR .= " OR osdial_list.alt_phone LIKE '" . $notac . mres($phone_number) . "%'";
                $searchWHR .= " OR osdial_list.address3 LIKE '" . $notac . mres($phone_number) . "%')";
            } else {
{'fraction_non_alphanumeric': 0.14814283665567188, 'fraction_numerical': 0.013623978201634877, 'mean_word_length': 2.967852062588905, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '2766399', 'n_tokens_mistral': 4689, 'n_tokens_neox': 4498, 'n_words': 802}