Exemple #1
0
/**
*  function to insert data to database from excel
*
*  	@param $aFormValues	(array)			insert form excel
	if import datas to diallist					$aFormValues['chkAdd']
	if assign extnesion to phone numbers		$aFormValues['chkAssign']
	assign which extensions to phone numbers	$aFormValues['assign']
	import which field							$aFormValues['dialListField']
*	@return $objResponse
*
*/
function submitForm($aFormValues)
{
    global $locate, $db, $config;
    $objResponse = new xajaxResponse();
    $order = $aFormValues['order'];
    //得到的排序数字,数组形式,要添加到数据库的列
    $fileName = $aFormValues['hidFileName'];
    $tableName = $aFormValues['hidTableName'];
    $flag = 0;
    foreach ($order as $value) {
        //判断是否有要导入的数据
        if (trim($value) != '') {
            $flag = 1;
            break;
        }
    }
    //如果没有任何选择, 就退出
    if ($flag != 1) {
        $objResponse->addScript('init();');
        return $objResponse;
    }
    //对提交的数据进行校验
    $orderNum = count($order);
    if ($orderNum > 0) {
        $arrRepeat = array_count_values($order);
        foreach ($arrRepeat as $key => $value) {
            if ($key != '' && $value > 1) {
                //数据重复
                $objResponse->addAlert($locate->Translate('field_cant_repeat'));
                $objResponse->addScript('init();');
                return $objResponse;
            }
        }
    }
    for ($j = 0; $j < $orderNum; $j++) {
        if (trim($order[$j]) != '') {
            if (trim($order[$j]) > $aFormValues['hidMaxTableColumnNum']) {
                //最大值校验
                $objResponse->addAlert($locate->Translate('field_overflow'));
                $objResponse->addScript('init();');
                return $objResponse;
            }
            if (!ereg("[0-9]+", trim($order[$j]))) {
                //是否为数字
                $objResponse->addAlert($locate->Translate('field_must_digits'));
                $objResponse->addScript('init();');
                return $objResponse;
            }
        }
    }
    $tableStructure_source = astercrm::getTableStructure($tableName);
    $tableStructure = array();
    foreach ($tableStructure_source as $row) {
        $type_arr = explode(' ', $row['flags']);
        if (!in_array('auto_increment', $type_arr)) {
            if ($row['name'] == "creby" || $row['name'] == "cretime" || $row['name'] == "groupid") {
            } else {
                $tableStructure[] = $row;
            }
        } else {
            if ($row['name'] == 'id' && $config['synchronize']['id_autocrement_byset']) {
                $tableStructure[] = $row;
            }
        }
    }
    $filePath = $config['system']['upload_file_path'] . $fileName;
    //数据文件存放路径
    $affectRows = 0;
    //计数据库影响结果变量
    $x = 0;
    //计数变量
    $date = date('Y-m-d H:i:s');
    //当前时间
    $groupid = $aFormValues['groupid'];
    $resellerid = $aFormValues['resellerid'];
    //$campaignid = $aFormValues['campaignid'];
    //print $groupid;
    $x = 0;
    $affectRows = importResource($filePath, $order, $tableName, $tableStructure, $dialListField, $date, $groupid, $resellerid);
    if ($affectRows < 0) {
        $affectRows = 0;
    }
    $resultMsg = $tableName . ' : ' . $affectRows . ' ' . $locate->Translate('records_inserted') . "<br>";
    //delete upload file
    //@ unlink($filePath);
    $objResponse->addAlert($locate->Translate('success'));
    $objResponse->addScript("document.getElementById('btnImportData').disabled = false;");
    $objResponse->addAssign("divResultMsg", "innerHTML", $resultMsg);
    $objResponse->addScript("init();");
    return $objResponse;
}
Exemple #2
0
/**
*  function to insert data to database from excel
*
*  	@param $aFormValues	(array)			insert form excel
	if import datas to diallist					$aFormValues['chkAdd']
	if assign extnesion to phone numbers		$aFormValues['chkAssign']
	assign which extensions to phone numbers	$aFormValues['assign']
	import which field							$aFormValues['dialListField']
*	@return $objResponse
*
*/
function submitForm($aFormValues)
{
    global $locate, $db, $config;
    $objResponse = new xajaxResponse();
    $order = $aFormValues['order'];
    //得到的排序数字,数组形式,要添加到数据库的列
    $fileName = $aFormValues['hidFileName'];
    $tableName = $aFormValues['hidTableName'];
    $flag = 0;
    foreach ($order as $value) {
        //判断是否有要导入的数据
        if (trim($value) != '') {
            $flag = 1;
            break;
        }
    }
    if ($flag != 1) {
        //判断是否要添加分区
        if (trim($aFormValues['dialListField']) == '' && trim($aFormValues['assign']) == '') {
            $flag = 0;
        } else {
            $flag = 1;
        }
    }
    //如果没有任何选择, 就退出
    if ($flag != 1) {
        $objResponse->addScript('init();');
        return $objResponse;
    }
    //对提交的数据进行校验
    $orderNum = count($order);
    if ($orderNum > 0) {
        $arrRepeat = array_count_values($order);
        foreach ($arrRepeat as $key => $value) {
            if ($key != '' && $value > 1) {
                //数据重复
                $objResponse->addAlert($locate->Translate('field_cant_repeat'));
                $objResponse->addScript('init();');
                return $objResponse;
            }
        }
    }
    for ($j = 0; $j < $orderNum; $j++) {
        if (trim($order[$j]) != '') {
            if (trim($order[$j]) > $aFormValues['hidMaxTableColumnNum']) {
                //最大值校验
                $objResponse->addAlert($locate->Translate('field_overflow'));
                $objResponse->addScript('init();');
                return $objResponse;
            }
            if (!ereg("[0-9]+", trim($order[$j]))) {
                //是否为数字
                $objResponse->addAlert($locate->Translate('field_must_digits'));
                $objResponse->addScript('init();');
                return $objResponse;
            }
        }
    }
    $tableStructure_source = astercrm::getTableStructure($tableName);
    $tableStructure = array();
    foreach ($tableStructure_source as $row) {
        $type_arr = explode(' ', $row['flags']);
        if (!in_array('auto_increment', $type_arr)) {
            if ($row['name'] == "creby" || $row['name'] == "cretime" || $row['name'] == "groupid" || $row['name'] == "campaignid") {
            } else {
                $tableStructure[] = $row;
            }
        }
    }
    //print_r($tableStructure);exit;
    $filePath = $config['system']['upload_file_path'] . $fileName;
    //数据文件存放路径
    $affectRows = 0;
    //计数据库影响结果变量
    $x = 0;
    //计数变量
    $date = date('Y-m-d H:i:s');
    //当前时间
    $groupid = $aFormValues['groupid'];
    $campaignid = $aFormValues['campaignid'];
    if ($tableName == 'diallist') {
        $aFormValues['chkAdd'] = '1';
        foreach ($order as $key => $value) {
            if ($value == '0') {
                $aFormValues['dialListField'] = $key;
                break;
            }
        }
        //echo $aFormValues['dialListField'];exit;
        if (!is_numeric($aFormValues['dialListField'])) {
            $objResponse->addAlert($locate->Translate('must select a cloumn for dialnumer'));
            return $objResponse;
        }
    }
    if ($aFormValues['chkAdd'] != '' && $aFormValues['chkAdd'] == '1') {
        //是否添加到拨号列表
        $dialListField = trim($aFormValues['dialListField']);
        //数字,得到将哪列添加到拨号列表
        $dialListTime = trim($aFormValues['dialListTime']);
        //数字,下拉列表选择将哪列做为dialtime添加到拨号列表
        $dialTimeInput = trim($aFormValues['dialtime']);
        //手动指定唯一的拨号时间组拨号列表
        if ($aFormValues['chkAssign'] != '' && $aFormValues['chkAssign'] == '1') {
            //是否添加分区assign
            $tmpStr = trim($aFormValues['assign']);
            //分区,以','号分隔的字符串
            if ($tmpStr != '') {
                $arryAssign = explode(',', $tmpStr);
                //判断这些分机是否在该组管理范围内
                if ($_SESSION['curuser']['usertype'] != 'admin') {
                    foreach ($arryAssign as $key => $myAssign) {
                        if (!in_array(trim($myAssign), $_SESSION['curuser']['memberExtens'])) {
                            //该组不包含该分机
                            unset($arryAssign[$key]);
                        }
                    }
                }
                //exit;
                $assignNum = count($arryAssign);
                //得到手动添加分区个数
                //print_r($arryAssign);
                //print $assignNum;
            } else {
                if ($_SESSION['curuser']['usertype'] == 'admin') {
                    $res = astercrm::getGroupMemberListByID($groupid);
                    while ($row = $res->fetchRow()) {
                        $arryAssign[] = $row['extension'];
                        //$array_extension数组,存放extension数据
                    }
                    $assignNum = count($arryAssign);
                    //extension数据的个数
                } else {
                    $arryAssign = $_SESSION['curuser']['memberExtens'];
                    $assignNum = count($arryAssign);
                    //extension数据的个数
                }
            }
        } else {
            $arryAssign[] = '';
            $assignNum = 0;
        }
    }
    $x = 0;
    $affectRows = importResource($filePath, $order, $tableName, $tableStructure, $dialListField, $dialListTime, $date, $groupid, $dialTimeInput, $assignNum, $arryAssign, $campaignid);
    $tableAffectRows = $affectRows['table'];
    $diallistAffectRows = $affectRows['diallist'];
    if ($tableAffectRows < 0) {
        $tableAffectRows = 0;
    }
    if ($diallistAffectRows < 0) {
        $diallistAffectRows = 0;
    }
    $resultMsg = $tableName . ' : ' . $tableAffectRows . ' ' . $locate->Translate('records_inserted') . "<br>";
    $resultMsg .= 'diallist : ' . $diallistAffectRows . ' ' . $locate->Translate('records_inserted');
    //delete upload file
    //@ unlink($filePath);
    $objResponse->addAlert($locate->Translate('success'));
    $objResponse->addScript("document.getElementById('btnImportData').disabled = false;");
    $objResponse->addAssign("divResultMsg", "innerHTML", $resultMsg);
    $objResponse->addScript("init();");
    return $objResponse;
}