Exemplo n.º 1
0
function addCustomer()
{
    $response = array('action' => 'addCustomer', 'message' => 'Lưu khách hàng thành công');
    $sNumber = trim(getParameter('phone'));
    $arrNumber = explode("\n", $sNumber);
    foreach ($arrNumber as $row) {
        if ($row == '' || is_null($row) || !is_numeric($row)) {
            $response['action'] = 'error';
            $response['message'] = 'Thêm khách hàng: Số điện thoại không được rỗng và chỉ ký tự số!';
            $json = new Services_JSON();
            Header('Content-Type: application/json');
            return $json->encode($response);
        }
    }
    global $arrConf;
    $oCustomer = new getInfoMainConsole();
    $oCustomer->callcenter_db_connect($arrConf['cadena_dsn']);
    // collect parameters
    $sFirstname = isset($_POST['firstname']) ? trim(getParameter('firstname')) : '';
    $sLastname = isset($_POST['lastname']) ? trim(getParameter('lastname')) : '';
    $sBirthday = isset($_POST['birthday']) ? date("Y-m-d", strtotime(trim(getParameter('birthday')))) : '';
    $sBirthplace = isset($_POST['birthplace']) ? trim(getParameter('birthplace')) : '';
    $sAddress = isset($_POST['address']) ? trim(getParameter('address')) : '';
    $sCmnd = isset($_POST['cmnd']) ? trim(getParameter('cmnd')) : '';
    $sPassport = isset($_POST['passport']) ? trim(getParameter('passport')) : '';
    $sId = isset($_POST['id']) ? trim(getParameter('id')) : '';
    $sMembership = isset($_POST['membership']) ? trim(getParameter('membership')) : '';
    $agentid = $oCustomer->getAgentId($_SESSION['callcenter']['extension']);
    $sEmail = isset($_POST['email']) ? trim(getParameter('email')) : '';
    $params = array($arrNumber, $sFirstname, $sLastname, $sBirthday, $sBirthplace, $sAddress, $sCmnd, $sPassport, $sMembership, $sEmail, $agentid);
    //tri working
    $result = $oCustomer->addCustomer($params, $sId);
    $oCustomer->callcenter_db_disconnect();
    // return json
    if (!$result) {
        $response['action'] = 'error';
        $response['message'] = 'Lỗi: ' . $oCustomer->errMsg;
    }
    $json = new Services_JSON();
    Header('Content-Type: application/json');
    return $json->encode($response);
}