* @package search * @version $Id: control.php 4129 2013-01-18 01:58:14Z wwccss $ * @link http://www.zentao.net */ class search extends control { /** * Build search form. * * @param string $module * @param array $fields * @param array $params * @param string $actionURL * @param int $queryID * @access public * @return void */ public function buildForm($module = '', $fields = '', $params = '', $actionURL = '', $queryID = 0) { $module = empty($module) ? $this->session->searchParams['module'] : $module; $searchParams = $module . 'searchParams'; $queryID = (empty($module) and empty($queryID)) ? $_SESSION[$searchParams]['queryID'] : $queryID; $fields = empty($fields) ? json_decode($_SESSION[$searchParams]['searchFields'], true) : $fields; $params = empty($params) ? json_decode($_SESSION[$searchParams]['fieldParams'], true) : $params; $actionURL = empty($actionURL) ? $_SESSION[$searchParams]['actionURL'] : $actionURL; $style = isset($_SESSION[$searchParams]['style']) ? $_SESSION[$searchParams]['style'] : ''; $onMenuBar = isset($_SESSION[$searchParams]['onMenuBar']) ? $_SESSION[$searchParams]['onMenuBar'] : ''; $_SESSION['searchParams']['module'] = $module; $this->search->initSession($module, $fields, $params); if(in_array($module, $this->config->search->searchObject) and $this->session->objectName) { $space = common::checkNotCN() ? ' ' : ''; $this->lang->search->common = $this->lang->search->common . $space . $this->session->objectName; } $this->view->module = $module; $this->view->groupItems = $this->config->search->groupItems; $this->view->searchFields = $fields; $this->view->actionURL = $actionURL; $this->view->fieldParams = $this->search->setDefaultParams($fields, $params); $this->view->queries = $this->search->getQueryList($module); $this->view->queryID = $queryID; $this->view->style = empty($style) ? 'full' : $style; $this->view->onMenuBar = empty($onMenuBar) ? 'no' : $onMenuBar; $this->app->loadModuleConfig('action'); $this->display(); } /** * Build search form of 20 version. * * @param string $module * @param array $fields * @param array $params * @param string $actionURL * @param int $queryID * @access public * @return void */ public function buildZinForm($module = '', $fields = '', $params = '', $actionURL = '', $queryID = 0, $formName = '') { if(!commonModel::hasPriv('search', 'buildForm')) $this->loadModel('common')->deny('search', 'buildForm', false); $module = empty($module) ? $this->session->searchParams['module'] : $module; $searchParams = $module . 'searchParams'; $searchForm = $module . 'Form'; $queryID = (empty($module) and empty($queryID)) ? $_SESSION[$searchParams]['queryID'] : $queryID; $fields = empty($fields) ? json_decode($_SESSION[$searchParams]['searchFields'], true) : $fields; $params = empty($params) ? json_decode($_SESSION[$searchParams]['fieldParams'], true) : $params; $actionURL = empty($actionURL) ? $_SESSION[$searchParams]['actionURL'] : $actionURL; $style = isset($_SESSION[$searchParams]['style']) ? $_SESSION[$searchParams]['style'] : ''; $onMenuBar = isset($_SESSION[$searchParams]['onMenuBar']) ? $_SESSION[$searchParams]['onMenuBar'] : ''; $_SESSION['searchParams']['module'] = $module; if(empty($_SESSION[$searchForm])) $this->search->initZinSession($module, $fields, $params); if(in_array($module, $this->config->search->searchObject) and $this->session->objectName) { $space = common::checkNotCN() ? ' ' : ''; $this->lang->search->common = $this->lang->search->common . $space . $this->session->objectName; } $this->view->module = $module; $this->view->groupItems = $this->config->search->groupItems; $this->view->searchFields = $fields; $this->view->actionURL = $actionURL; $this->view->fieldParams = $this->search->setZinDefaultParams($fields, $params); $this->view->queries = $this->search->getQueryList($module); $this->view->queryID = $queryID; $this->view->style = empty($style) ? 'full' : $style; $this->view->onMenuBar = empty($onMenuBar) ? 'no' : $onMenuBar; $this->view->formSession = $this->search->convertFormFrom18To20($_SESSION[$module . 'Form']); $this->view->fields = $fields; $this->view->formName = $formName; if($module == 'program') { $this->view->options = $this->search->setOptions($fields, $this->view->fieldParams, $this->view->queries); $this->render(); } else { $this->display(); } } /** * Build query * * @access public * @return void */ public function buildQuery() { $this->search->buildQuery(); $actionURL = $this->post->actionURL; $parsedURL = parse_url($actionURL); if(isset($parsedURL['host'])) return; if($this->config->requestType != 'GET') { $path = $parsedURL['path']; $path = str_replace($this->config->webRoot, '', $path); if(strpos($path, '.') !== false) $path = substr($path, 0, strpos($path, '.')); if(preg_match("/^\w+{$this->config->requestFix}\w+/", $path) == 0) return; } else { $query = $parsedURL['query']; if(preg_match("/^{$this->config->moduleVar}=\w+\&{$this->config->methodVar}=\w+/", $query) == 0) return; } echo js::locate($actionURL, 'parent'); } /** * Build query * * @access public * @return void */ public function buildZinQuery() { if(!commonModel::hasPriv('search', 'buildQuery')) $this->loadModel('common')->deny('search', 'buildQuery', false); $this->search->buildZinQuery(); $actionURL = $this->post->actionURL; $parsedURL = parse_url($actionURL); if(isset($parsedURL['host'])) return; if($this->config->requestType != 'GET') { $path = $parsedURL['path']; $path = str_replace($this->config->webRoot, '', $path); if(strpos($path, '.') !== false) $path = substr($path, 0, strpos($path, '.')); if(preg_match("/^\w+{$this->config->requestFix}\w+/", $path) == 0) return; } else { $query = $parsedURL['query']; if(preg_match("/^{$this->config->moduleVar}=\w+\&{$this->config->methodVar}=\w+/", $query) == 0) return; } return print(json_encode(array('load' => $actionURL))); } /** * Save search query. * * @param string $module * @param string $onMenuBar * @access public * @return void */ public function saveQuery($module, $onMenuBar = 'no') { if($_POST) { $queryID = $this->search->saveQuery(); if(!$queryID) return print(js::error(dao::getError())); $data = fixer::input('post')->get(); $shortcut = empty($data->onMenuBar) ? 0 : 1; return print(js::closeModal('parent.parent', '', "function(){parent.parent.loadQueries($queryID, $shortcut, '{$data->title}')}")); } $this->view->module = $module; $this->view->onMenuBar = $onMenuBar; $this->display(); } /** * Save search query of zin ui. * * @param string $module * @param string $onMenuBar * @access public * @return void */ public function saveZinQuery($module, $onMenuBar = 'no') { if(!commonModel::hasPriv('search', 'saveQuery')) $this->loadModel('common')->deny('search', 'saveQuery', false); if($_POST) { $queryID = $this->search->saveZinQuery(); if(!$queryID) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $data = fixer::input('post')->get(); $shortcut = empty($data->onMenuBar) ? 0 : 1; if($this->viewType == 'json') { echo 'success'; return; } return $this->send(array('closeModal' => true, 'callback' => '$(\'#searchFormPanel form button[type="submit"]\').trigger("click")')); } $this->view->module = $module; $this->view->onMenuBar = $onMenuBar; $this->display(); } /** * Delete current search query. * * @param int $queryID * @access public * @return void */ public function deleteQuery($queryID) { $this->search->deleteQuery($queryID); if(dao::isError()) return print(js::error(dao::getError())); echo 'success'; } /** * Delete current search query. * * @param int $queryID * @access public * @return void */ public function deleteZinQuery($queryID) { if(!commonModel::hasPriv('search', 'deleteQuery')) $this->loadModel('common')->deny('search', 'deleteQuery', false); $this->search->deleteQuery($queryID); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); echo $this->send(array('result' => 'success', 'load' => true)); } /** * Ajax get search query. * * @param string $module * @param int $queryID * @access public * @return void */ public function ajaxGetQuery($module = '', $queryID = 0) { $query = $queryID ? $queryID : ''; $module = empty($module) ? $this->session->searchParams['module'] : $module; $queries = $this->search->getQueryList($module); $html = ''; foreach($queries as $query) { if(empty($query->id)) continue; $html .= '