/** * 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; }
function formMutiEdit($searchContent, $searchField, $searchType, $table) { global $locate; $reselleroptions = ''; $reseller = astercrm::getAll('resellergroup'); if ($_SESSION['curuser']['usertype'] == 'admin') { $reselleroptions .= '<select id="resellerid" name="resellerid"'; if ($table != "resellerrate") { $reselleroptions .= 'onchange="setGroup();"'; } $reselleroptions .= '><option value=""></option>'; $reselleroptions .= '<option value="0">' . $locate->Translate("All") . '</option>'; while ($reseller->fetchInto($row)) { $reselleroptions .= "<OPTION value='" . $row['id'] . "'>" . $row['resellername'] . "</OPTION>"; } $reselleroptions .= '</select>'; } else { while ($reseller->fetchInto($row)) { if ($row['id'] == $_SESSION['curuser']['resellerid']) { $reselleroptions .= $row['resellername'] . '<input type="hidden" value="' . $row['id'] . '" name="resellerid" id="resellerid">'; break; } } } if ($table != "resellerrate") { $group = astercrm::getAll('accountgroup', 'resellerid', $_SESSION['curuser']['resellerid']); if ($_SESSION['curuser']['usertype'] == 'admin' || $_SESSION['curuser']['usertype'] == 'reseller') { $groupoptions .= '<select id="groupid" name="groupid">'; if ($_SESSION['curuser']['usertype'] == 'reseller') { $groupoptions .= "<OPTION value=''></OPTION>"; } $groupoptions .= "<OPTION value='0'>" . $locate->Translate("All") . "</OPTION>"; while ($group->fetchInto($row)) { $groupoptions .= "<OPTION value='" . $row['id'] . "'>" . $row['groupname'] . "</OPTION>"; } $groupoptions .= '</select>'; } else { while ($group->fetchInto($row)) { if ($row['id'] == $_SESSION['curuser']['groupid']) { $groupoptions .= $row['groupname'] . '<input type="hidden" value="' . $row['id'] . '" name="groupid" id="groupid">'; break; } } } } //可修改字段 $tableField = astercrm::getTableStructure('myrate'); foreach ($tableField as $row) { if ($row['name'] != 'id' && $row['name'] != 'resellerid' && $row['name'] != 'groupid' && $row['name'] != 'addtime') { $fieldOption .= '<option value="' . $row['name'] . ',' . $row['type'] . '">' . $row['name'] . '</option>'; } } //将条件重置成字符串,通过post传递 $i = 0; foreach ($searchContent as $content) { if (trim($content) != '' && trim($searchField[$i]) != '') { $searchContentStr .= $content . ","; $searchFieldStr .= $searchField[$i] . ","; $searchTypeStr .= $searchType[$i] . ","; } $i++; } //echo $searchContentStr.$searchFieldStr.$searchTypeStr;exit; //print_r($searchField);exit; $html = ' <!-- No edit the next line --> <form method="post" name="f" id="f"> <table border="1" width="100%" class="adminlist"> <tr> <td nowrap align="left">' . $locate->Translate("Option") . '</td> <td align="left"><input type="radio" name="multioption" id="multioption" value="modify" checked> ' . $locate->Translate("Modify") . ' <input type="radio" name="multioption" id="multioption" value="duplicate"> ' . $locate->Translate("Duplicate") . '</td> </tr> <tr> <td nowrap align="left">' . $locate->Translate("Change") . '</td> <td align="left"><select id="multieditField" name="multieditField" onchange=\'xajax_setMultieditType(this.value)\'>' . $fieldOption . '</select> <select id="multieditType" name="multieditType" > <option value="to">' . $locate->Translate("to") . '</option> </select> <input type="text" id="multieditcontent" name="multieditcontent" size="15"></td> </tr> <tr> <td nowrap align="left">' . $locate->Translate("Reseller") . '</td> <td align="left">' . $reselleroptions . '</td> </tr>'; if ($table != "resellerrate") { $html .= '<tr><td nowrap align="left">' . $locate->Translate("Group") . '</td><td align="left">' . $groupoptions . '</td></tr>'; } $html .= '<tr> <td colspan="2" align="center"> <button id="submitButton" onClick=\'xajax_multiEditUpdate("' . $searchContentStr . '","' . $searchFieldStr . '","' . $searchTypeStr . '","' . $table . '",xajax.getFormValues("f"));return false;\'>' . $locate->Translate("Continue") . '</button> </td> </tr> </table> '; $html .= ' </form>'; //echo $html;exit; return $html; }
/** * 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; }