DialFuction出错!期望TypeError对象

时间:2016-07-13 12:48:32

标签: php html forms

我有一个HTML表单,我可以在其中添加first name, last name and phone number。当我尝试在电话号码字段中插入一个值时,我收到此错误:

message from webpage

对于名字和姓氏字段,它每次都有效。我正在使用谷歌浏览器。可能是浏览器错误还是代码错误?

这是代码的一部分,其中包含以下形式:

   require('libraries/Interview.class.php');
require('libraries/PhoneBook.class.php');
require('libraries/Beneficiari.class.php');
require('libraries/Marci.class.php');
require('libraries/Modele.class.php');
require_once('connect.php');
require('libraries/Agentii.class.php');
require ("include/callcenter-header.php");
$_SESSION['username'] = 'admin';

$phone_no ="";
if (strlen($phone_no) == 9) {
    $contact = PhoneBook::listBYPhoneNo($phone_no, $conn);
    $selected_contact = null;
    $beneficiari = Beneficiari::listAllNoOwner($db);
    $content_agentii = "<option value=''>Alege agentie</option>";
    $content_beneficiari = "<option value=''>Alege beneficiar</option>";
    $btn_add_new = "";
    $selected_bname = "";
    $selected_aname = "";
    if ($contact) {
        if (count($contact) == 0) {
            $selected_contact = $contact[0];
        } else {
            for ($x = 0; $x < count($contact); $x++) {
                if ($contact[$x]['default'] == 0) {
                    $selected_contact = $contact[$x];
                }
            }
        }
        $agentii = Agentii::listAll_byBeneficiar($selected_contact['id_beneficiar'], $db);
        for ($b = 0; $b < count($beneficiari); $b++) {
            if ($selected_contact['id_beneficiar'] == $beneficiari[$b]['id']) {
                $selected_bname = $beneficiari[$b]['nume'];
            };
            $selected = ($selected_contact['id_beneficiar'] == $beneficiari[$b]['id'] ? "selected = 'selected'" : '');
            $content_beneficiari .= "<option " . $selected . " value='" . $beneficiari[$b]['id'] . "'>" . $beneficiari[$b]['nume'] . "</option>";
        }
        for ($a = 0; $a < count($agentii); $a++) {
            if ($selected_contact['agency_id'] == $agentii[$a]['id']) {
                $selected_aname = $agentii[$a]['nume'];
            };
            $selected = ($selected_contact['agency_id'] == $agentii[$a]['id'] ? "selected = 'selected'" : '');
            $content_agentii .= "<option " . $selected . " value='" . $agentii[$a]['id'] . "'>" . $agentii[$a]['nume'] . "</option>";
        }

        $btn_upd = "<button class='upd_pb'>Actualizeaza info</button>";
    } else {
        for ($b = 0; $b < count($beneficiari); $b++) {
            $content_beneficiari .= "<option value='" . $beneficiari[$b]['id'] . "'>" . $beneficiari[$b]['nume'] . "</option>";
        }
        $selected_contact = null;
        $agentii = null;
        $btn_add_new = "<button class='add_new_pb'>Inregistreaza contact</button>";
    }
}
?>
<script>
    function OnNewCall(myCallTraceId, callParams)
    {
        $.ajax({
            type: "POST",
            url: "dynamic/dynamic.functions.cc_interview.php",
            data: {ck_new_call: myCallTraceId, callParams: callParams},
            success: function (response) {
                $('#contact_info_form').html(response);
                $('#flt9_assets').val($("#res_client_company option:selected").html());
                $('#flt10_assets').val($("#res_client_agency option:selected").html().split(",")[0]);
                filterData(1);
            }
        });
    }

</script>
<br/>
<div style="text-align: left" class="contact_info">
    <fieldset>
        <legend>Informatii client</legend>
        <table id="contact_info_form">
            <tr>
                <td><label>Call Trace ID :</label><br/><input type="text" id="res_ctid" value="-" /></td>
            </tr>
            <tr>
                <td><label>Nume :</label><br/><input type="text" id="res_client_firstname" value="<?php echo @$selected_contact['first_name']; ?>" /></td>
                <td><label>Prenume :</label><br/><input type="text" id="res_client_lastname" value="<?php echo @$selected_contact['last_name']; ?>"/></td>         
                <td><label>Telefon :</label><br/><input type="text" readonly="readonly" id="res_client_phone" value="<?php echo $phone_no; ?>"/></td>
                <td><label>Email :</label><br/><input type="text" id="res_client_email" value="<?php echo @$selected_contact['email']; ?>"/></td>
            </tr>
            <tr>     
                <td><label>Beneficiar :</label><br/><select id="res_client_company"><?php echo $content_beneficiari; ?></select></td>
                <td><label>Agentia :</label><br/><select id="res_client_agency" ><?php echo $content_agentii; ?></select></td>            
                <td><label>Adresa :</label><br/><input type="text" id="res_client_address" value="<?php echo @$selected_contact['adresa_agentie']; ?>"/></td>
                <td><span id="contact_info_act_btn"><?php echo $btn_add_new; ?><?php echo $btn_upd; ?></span></br><span id="btn_act_resp"></span></td>
            </tr>
        </table>
    </fieldset>
    <script>

        $('#contact_info_form').on('change', '#res_client_company', function () {
            $('#flt9_assets').val($("#res_client_company option:selected").html());
            $('#flt10_assets').val('');
            filterData(1);
            $.ajax({
                type: "POST",
                url: "dynamic/dynamic.functions.agentii.php",
                data: {req_benef: $(this).val()},
                beforeSend: function () {
                    $('#res_client_agency').html('');
                },
                success: function (response) {
                    $('#res_client_agency').html(JSON.parse(response));
                }
            });
        });
        $('#contact_info_form').on('change', '#res_client_agency', function () {
            if ($("#res_client_agency option:selected") !== null) {
                $('#flt10_assets').val($("#res_client_agency option:selected").html().split(",")[0]);
                filterData(1);
            }
        });
        $('#contact_info_form').on('click', '.add_new_pb', function () {
            var request = {
                first_name: $('#res_client_firstname').val(),
                last_name: $('#res_client_lastname').val(),
                phone: $('#res_client_phone').val(),
                email: $('#res_client_email').val(),
                company: $('#res_client_company').val(),
                agency: $('#res_client_agency').val(),
                address: $('#res_client_address').val()
            };
            $.ajax({
                type: "POST",
                url: "dynamic/dynamic.functions.cc_interview.php",
                data: {req_new_pb_entry: JSON.stringify(request)},
                beforeSend: function () {
                    $('#contact_info_act_btn').html('');
                },
                success: function (response) {
                    var resp = JSON.parse(response);
                    if (resp['result']) {
                        $('#contact_info_act_btn').html(resp['html']);
                        $('#btn_act_resp').html("Contactul a fost inregistrat cu succes !");
                    } else {
                        $('#contact_info_act_btn').html(resp['html']);
                        $('#btn_act_resp').html("Contactul nu a putut fi inregistrat !");
                    }
                }
            });
        });
        $('#contact_info_form').on('click', '.upd_pb', function () {
            var request = {
                first_name: $('#res_client_firstname').val(),
                last_name: $('#res_client_lastname').val(),
                phone: $('#res_client_phone').val(),
                email: $('#res_client_email').val(),
                company: $('#res_client_company').val(),
                agency: $('#res_client_agency').val(),
                address: $('#res_client_address').val()
            };
            $.ajax({
                type: "POST",
                url: "dynamic/dynamic.functions.cc_interview.php",
                data: {req_upd_pb_entry: JSON.stringify(request)},
                beforeSend: function () {
                    $('#contact_info_act_btn').html('');
                },
                success: function (response) {
                    var resp = JSON.parse(response);
                    if (resp['result']) {
                        $('#contact_info_act_btn').html(resp['html']);
                        $('#btn_act_resp').html("Contactul a fost actualizat cu succes !");
                    } else {
                        $('#contact_info_act_btn').html(resp['html']);
                        $('#btn_act_resp').html("Contactul nu a putut fi actualizat !");
                    }
                }
            });
        });
        $('#res_client_phone').on('click', '', function () {

            try
            {
                window.external.Dial($('#res_client_phone').val(), 0, -1);
            } catch (err)
            {
                alert("Error on Dial Function !" + err);
            }

        });
    </script>
</div>

这是dynamic.functions.cc_interview.php代码:

require '../connect.php';



/*
 * WHEN user selects an equipment
 */
if (isset($_POST['cci_set_et'])) {
    $echipID = str_replace('act_lnk_', '', $_POST['cci_set_et']);

    require '../libraries/Interview.class.php';
    require '../libraries/Echipamente.class.php';
    require '../libraries/Ingineri_service.class.php';

    $echipament = Echip::listEchipId($echipID, $db);
    $ingineri = Ingineri_service::listAllDistinct($db);
    $question = Interview::listFirstQuestionByEchip($echipID, $conn);
    @$answers = Interview::listAnswers($question[0]['id'], $conn);

    $response = array();
    $html = "";
    $html .= "<tr class='qRow' id='qRow-" . $_POST['q_count'] . "'><td>" . @$question[0]['text'] . "</td>";
    $html .= "<td><input type='hidden' id='qR-" . @$question[0]['id'] . "' value=''><input type='hidden' id='qRid-" . $question[0]['id'] . "' value=''>";
    for ($x = 0; $x < count($answers); $x++) {
        switch (@$question[0]['multiple_choice']) {
            case 0 :
                $name = "q" . $question[0]['id'] . "";
                break;
            case 1 : $name = "q" . $question[0]['id'] . "-" . $answers[$x]['id'];
                break;
            default : $name = "q" . $question[0]['id'] . "";
        }

        $html .= "<div>" . $answers[$x]['text'] . " <input class='in_qResp' name='" . $name . "' type='" . $answers[$x]['input_type'] . "' id='R-" . $answers[$x]['id'] . "-" . $answers[$x]['next_question_id'] . "' value='" . $answers[$x]['text'] . "' /> ";
        if ($answers[$x]['has_hint'] == 1) {
            $html .= " | <a class='ahint'>HINT</a><div class='tooltip'>content</div>";
        }
        $html .= "</div>";
    }
    $html .= "<button class='qSubmit' id='qS-" . @$question[0]['id'] . "'>Submit</buton></td></tr>";

    $ingineri_html = "";
    for ($i = 0; $i < count($ingineri); $i++) {
        $selected = ($ingineri[$i]['inginer_service'] == $echipament[0]['inginer_service'] ? "selected='selected'" : "");
        $ingineri_html .= "<option " . $selected . " value='" . $ingineri[$i]['inginer_service'] . "'>" . ucwords(str_replace('.', ' ', $ingineri[$i]['inginer_service'])) . "</option>";
    }

    $response['question']['id'] = $question[0]['id'];

    $response['equip_class'] = $echipament[0]['categorie'];
    $response['equip_mark'] = $echipament[0]['numeMarca'];
    $response['equip_model'] = $echipament[0]['numeModel'];
    $response['equip_serial'] = $echipament[0]['serie'];
    $response['equip_cod'] = $echipament[0]['cod'];

    $response['agency_id'] = $echipament[0]['agentie'];

    $response['question']['text'] = $question[0]['text'];
    $response['question']['response'] = "";

    $response['engineer_html'] = $ingineri_html;
    $response['html'] = $html;

    echo json_encode($response);
}


/*
 * When user submits an answer
 */
if (isset($_POST['cci_set_nq'])) {
    $answer_token = explode('-', $_POST['cci_set_nq']);

    $answer_id = $answer_token[1];

    require '../libraries/Interview.class.php';
    $selected_answer = Interview::findAnswer($answer_id, $conn);

    $question = Interview::listNextQuestionByAnswer($answer_id, $conn);
    $answers = Interview::listAnswers($question[0]['id'], $conn);

    $response = array();
    $html = "";
    $html .= "<tr class='qRow'><td>" . $question[0]['text'] . "</td>";
    $html .= "<td><input type='hidden' id='qR-" . $question[0]['id'] . "' value=''><input type='hidden' id='qRid-" . $question[0]['id'] . "' value=''>";

    for ($x = 0; $x < count($answers); $x++) {
        switch ($question[0]['multiple_choice']) {
            case 0 :
                $name = "q" . $question[0]['id'] . "";
                break;
            case 1 : $name = "q" . $question[0]['id'] . "-" . $answers[$x]['id'];
                break;
            default : $name = "q" . $question[0]['id'] . "";
        }

        $html .= "<div>" . $answers[$x]['text'] . " <input class='in_qResp' name='" . $name . "' type='" . $answers[$x]['input_type'] . "' id='R-" . $answers[$x]['id'] . "-" . $answers[$x]['next_question_id'] . "' value='" . $answers[$x]['text'] . "' /> ";
        if ($answers[$x]['has_hint'] == 1) {
            $html .= " | <a class='a_hint'>HINT</a><div class='tooltip'></div>";
        }
        $html .= "</div>";
    }
    $html .= "<button class='qSubmit' id='qS-" . $question[0]['id'] . "'>Submit</buton></td></tr>";

    $response['question']['id'] = $question[0]['id'];
    $response['question']['text'] = $question[0]['text'];
    $response['question']['response'] = "";
    $response['action'] = $selected_answer['action'];
    $response['html'] = $html;

    echo json_encode($response);
}
/*
 * Function to insert new action into table actuni when agent decides so .
 */
if (isset($_POST['cci_set_aNi'])) {
    require '../libraries/Actiuni.class.php';

    $request = json_decode($_POST['cci_set_aNi']);
    $request->equip_id = str_replace('act_lnk_', '', $request->equip_id);
    $request->resolution->interview_string = "Reprezentant client : " . $request->client_first_name . " " . $request->client_last_name . " \n " .
            "Telefon client : " . $request->call_id . " \n" .
            "Rezultat interviu : \n" . $request->resolution->interview_string . " \n";

    // $id_sesizare = Actiuni::insert('call_incident', date('Y-m-d H:i'), $request->deadline, $request->engineer, $request->equip_id, $request->resolution->interview_string, 'nevalidata', date('H:i'), $_SESSION['username'], $request->agency_id, '0', 'RON', $db);
    $id_sesizare = 212312;
    echo $id_sesizare;
}

/*
 * Function to insert new Phone Book entry into table phone_book
 */

if (isset($_POST['req_new_pb_entry'])) {
    require '../libraries/PhoneBook.class.php';
    $request = json_decode($_POST['req_new_pb_entry']);
    $inserted = PhoneBook::insert($request->first_name, $request->last_name, $request->phone, $request->email, $request->agency, $conn);
    if ($inserted) {
        $response['result'] = TRUE;
        $response['html'] = "<button class='upd_pb'>Actualizeaza info</button>";
    } else {
        $response['result'] = FALSE;
        $response['html'] = "<button class='add_new_pb'>Inregistreaza contact</button>";
    }
    echo json_encode($response);
}
if (isset($_POST['req_upd_pb_entry'])) {
    require '../libraries/PhoneBook.class.php';
    $request = json_decode($_POST['req_upd_pb_entry']);
    $updated = PhoneBook::update($request->first_name, $request->last_name, $request->phone, $request->email, $request->agency, $conn);
    $response = array();
    if ($updated) {
        $response['result'] = TRUE;
        $response['html'] = "<button class='upd_pb'>Actualizeaza info</button>";
    } else {
        $response['result'] = FALSE;
        $response['html'] = "<button class='upd_pb'>Actualizeaza info</button>";
    }
    echo json_encode($response);
}

if (isset($_POST['ck_new_call'])) {

    $callTraceId = $_POST['ck_new_call'];
    $callParams = $_POST['callParams'];

    parse_str($callParams, $callParams_arr);

    require('../libraries/PhoneBook.class.php');
    require('../libraries/Beneficiari.class.php');
    require('../libraries/Agentii.class.php');
    $phone_no = intval($callParams_arr['MCC_ANI']);
    if (strlen($phone_no) == 9) {
        $contact = PhoneBook::listBYPhoneNo($phone_no, $conn);
        $selected_contact = null;
        $beneficiari = Beneficiari::listAllNoOwner($db);
        $content_agentii = "<option value=''>Alege agentie</option>";
        $content_beneficiari = "<option value=''>Alege beneficiar</option>";
        $btn_add_new = "";
        $selected_bname = "";
        $selected_aname = "";
        if ($contact) {
            if (count($contact) == 0) {
                $selected_contact = $contact[0];
            } else {
                for ($x = 0; $x < count($contact); $x++) {
                    if ($contact[$x]['default'] == 0) {
                        $selected_contact = $contact[$x];
                    }
                }
            }
            $agentii = Agentii::listAll_byBeneficiar($selected_contact['id_beneficiar'], $db);
            for ($b = 0; $b < count($beneficiari); $b++) {
                if ($selected_contact['id_beneficiar'] == $beneficiari[$b]['id']) {
                    $selected_bname = $beneficiari[$b]['nume'];
                };
                $selected = ($selected_contact['id_beneficiar'] == $beneficiari[$b]['id'] ? "selected = 'selected'" : '');
                $content_beneficiari .= "<option " . $selected . " value='" . $beneficiari[$b]['id'] . "'>" . $beneficiari[$b]['nume'] . "</option>";
            }
            for ($a = 0; $a < count($agentii); $a++) {
                if ($selected_contact['agency_id'] == $agentii[$a]['id']) {
                    $selected_aname = $agentii[$a]['nume'];
                };
                $selected = ($selected_contact['agency_id'] == $agentii[$a]['id'] ? "selected = 'selected'" : '');
                $content_agentii .= "<option " . $selected . " value='" . $agentii[$a]['id'] . "'>" . $agentii[$a]['nume'] . "</option>";
            }
            $btn_upd = "<button class='upd_pb'>Actualizeaza info</button>";
        } else {
            for ($b = 0; $b < count($beneficiari); $b++) {
                $content_beneficiari .= "<option value='" . $beneficiari[$b]['id'] . "'>" . $beneficiari[$b]['nume'] . "</option>";
            }
            $selected_contact = null;
            $agentii = null;
            $btn_add_new = "<button class='add_new_pb'>Inregistreaza contact</button>";
        }
        $response = "";
        $response .="<tr>"; 
        $response .="<td colspan=\"2\"><label>CALL TRACEID :</label><br/><input type=\"text\" id=\"res_ctid\" value=\"" .$callTraceId. "\" /></td>";
        $response .="</tr>";        
        $response .="<tr>"; 
        $response .="<td><label>Nume :</label><br/><input type=\"text\" id=\"res_client_firstname\" value=\"" . @$selected_contact['first_name'] . "\" /></td>";
        $response .="<td><label>Prenume :</label><br/><input type=\"text\" id=\"res_client_lastname\" value=\"" . @$selected_contact['last_name'] . "\"/></td>  ";
        $response .="<td><label>Telefon :</label><br/><input type=\"text\" id=\"res_client_phone\" value=\"" . $phone_no . "\"/></td>";
        $response .="<td><label>Email :</label><br/><input type=\"text\" id=\"res_client_email\" value=\"" . @$selected_contact['email'] . "\"/></td>";
        $response .="</tr>";
        $response .="<tr>";
        $response .="<td><label>Beneficiar :</label><br/><select id=\"res_client_company\">" . $content_beneficiari . "</select></td>";
        $response .="<td><label>Agentia :</label><br/><select id=\"res_client_agency\" >" . $content_agentii . "</select></td>";
        $response .="<td><label>Adresa :</label><br/><input type=\"text\" id=\"res_client_address\" value=\"" . @$selected_contact['adresa_agentie'] . "\"/></td>";
        $response .="<td><span id=\"contact_info_act_btn\">" . $btn_add_new . "" . $btn_upd . "</span></br><span id=\"btn_act_resp\"></span></td>";
        $response .="</tr>";
        error_log($response);
        echo $response;
    }
}
?>

0 个答案:

没有答案