Ejemplo n.º 1
0
function searchFormSubmit($searchFormValue, $numRows, $limit, $id, $type)
{
    global $locate, $db, $config;
    $objResponse = new xajaxResponse();
    $searchField = array();
    $searchContent = array();
    $optionFlag = $searchFormValue['optionFlag'];
    $deleteFlag = $searchFormValue['deleteFlag'];
    $exportFlag = $searchFormValue['exportFlag'];
    $searchContent = $searchFormValue['searchContent'];
    //搜索内容 数组
    $searchField = $searchFormValue['searchField'];
    //搜索条件 数组
    $searchType = $searchFormValue['searchType'];
    //搜索方式 数组
    $divName = "grid";
    if ($optionFlag == "export") {
        $sql = astercrm::getSql($searchContent, $searchField, $searchType, 'myrate');
        //得到要导出的sql语句
        $_SESSION['export_sql'] = $sql;
        $objResponse->addAssign("hidSql", "value", $sql);
        //赋值隐含域
        $objResponse->addScript("document.getElementById('exportForm').submit();");
    } elseif ($optionFlag == "delete") {
        if (empty($_SESSION['curuser']['usertype'])) {
            $objResponse->addAlert($locate->Translate("Session time out,please try again"));
            return $objResponse->getXML();
        }
        if ($_SESSION['curuser']['usertype'] == 'groupadmin') {
            $searchContent[] = $_SESSION['curuser']['groupid'];
            $searchField[] = 'groupid';
            $searchType[] = 'equal';
        } elseif ($_SESSION['curuser']['usertype'] == 'reseller') {
            $searchContent[] = $_SESSION['curuser']['resellerid'];
            $searchField[] = 'resellerid';
            $searchType[] = 'equal';
        }
        if ($config['synchronize']['delete_by_use_history']) {
            astercrm::deleteToHistoryFromSearch($searchContent, $searchField, $searchType, 'myrate');
        } else {
            astercrm::deletefromsearch($searchContent, $searchField, $searchType, 'myrate');
        }
        $html = createGrid($searchFormValue['numRows'], $searchFormValue['limit'], '', '', '', $divName, "", 1, 1, '');
        $objResponse->addClear("msgZone", "innerHTML");
        $objResponse->addAssign($divName, "innerHTML", $html);
    } elseif ($optionFlag == "multiEdit") {
        $html = createGrid($numRows, $limit, $searchField, $searchContent, $searchField, $divName, "", 1, 1, $searchType);
        $showMutiEdit = Table::Top($locate->Translate("Multi Edit"), "formDiv");
        $showMutiEdit .= astercrm::formMutiEdit($searchContent, $searchField, $searchType, 'myrate');
        $showMutiEdit .= Table::Footer();
        $objResponse->addClear("msgZone", "innerHTML");
        $objResponse->addAssign($divName, "innerHTML", $html);
        $objResponse->addAssign('formDiv', "innerHTML", $showMutiEdit);
        $objResponse->addAssign('formDiv', "style.visibility", 'visible');
    } else {
        if ($type == "delete") {
            if (empty($_SESSION['curuser']['usertype'])) {
                $objResponse->addAlert($locate->Translate("Session time out,please try again"));
                return $objResponse->getXML();
            }
            if ($config['synchronize']['delete_by_use_history']) {
                $res = astercrm::deleteRecordToHistory('id', $id, 'myrate');
            } else {
                $res = Customer::deleteRecord($id, 'myrate');
            }
            if ($res) {
                $html = createGrid($searchFormValue['numRows'], $searchFormValue['limit'], $searchField, $searchContent, $searchField, $divName, "", 1, 1, $searchType);
                $objResponse->addAssign("msgZone", "innerHTML", $locate->Translate("record deleted"));
            } else {
                $objResponse->addAssign("msgZone", "innerHTML", $locate->Translate("record cannot be deleted"));
            }
        } else {
            $html = createGrid($numRows, $limit, $searchField, $searchContent, $searchField, $divName, "", 1, 1, $searchType);
        }
        $objResponse->addClear("msgZone", "innerHTML");
        $objResponse->addAssign($divName, "innerHTML", $html);
    }
    return $objResponse->getXML();
}