diff --git a/config/zentaopms.php b/config/zentaopms.php index 9616cd1dc5..51e229b026 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -241,6 +241,8 @@ $config->openMethods[] = 'testcase.getxmindimport'; $config->openMethods[] = 'testcase.showxmindimport'; $config->openMethods[] = 'testcase.savexmindimport'; $config->openMethods[] = 'search.buildzinform'; +$config->openMethods[] = 'search.buildzinquery'; +$config->openMethods[] = 'search.savezinquery'; $config->openMethods[] = 'space.createapplication'; $config->openModules = array(); diff --git a/module/common/model.php b/module/common/model.php index 18b45fd9a7..e7651a66ea 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -3305,7 +3305,7 @@ EOF; curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); - curl_setopt($curl, CURLOPT_HEADER, $httpCode ? true : false); + curl_setopt($curl, CURLOPT_HEADER, $httpCode); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 2); curl_setopt($curl, CURLINFO_HEADER_OUT, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); diff --git a/module/gitlab/js/binduser.ui.js b/module/gitlab/js/binduser.ui.js index ccad8e6b64..75a44a8fa8 100644 --- a/module/gitlab/js/binduser.ui.js +++ b/module/gitlab/js/binduser.ui.js @@ -1,6 +1,5 @@ $('table').on('change', '.pick-value', function() { var user = zentaoUsers[$(this).val()]; - console.log(111, $(this).val(), user, $(this).attr('id')) $('#' + $(this).attr('id').replace('users', 'zentaoEmail')).text(user.email); }) \ No newline at end of file diff --git a/module/search/control.php b/module/search/control.php index 314207223b..5dc5e6fcd4 100644 --- a/module/search/control.php +++ b/module/search/control.php @@ -67,13 +67,51 @@ class search extends control * @access public * @return void */ - public function buildZinForm($module = '', $fields = '', $params = '', $actionURL = '', $queryID = 0) + 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; - $this->view->formSession = $_SESSION[$module . 'Form']; - $this->buildForm($module, $fields, $params, $actionURL, $queryID); + $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 = $_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(); + } } /** @@ -105,6 +143,37 @@ class search extends control echo js::locate($actionURL, 'parent'); } + /** + * Build query + * + * @access public + * @return void + */ + public function buildZinQuery() + { + if(!commonModel::hasPriv('search', 'buildForm')) $this->loadModel('common')->deny('search', 'buildForm', false); + + $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; + } + + return print(json_encode(array('load' => $actionURL))); + } + /** * Save search query. * @@ -131,6 +200,39 @@ class search extends control $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', 'buildForm', false); + + if($_POST) + { + $queryID = $this->search->saveZinQuery(); + if(!$queryID) return print(js::error(dao::getError())); + + $data = fixer::input('post')->get(); + $shortcut = empty($data->onMenuBar) ? 0 : 1; + + if($this->viewType == 'json') + { + echo 'success'; + return; + } + return print(js::closeModal('parent.parent', '', "function(){parent.parent.loadQueries($queryID, $shortcut, '{$data->title}')}")); + } + + $this->view->module = $module; + $this->view->onMenuBar = $onMenuBar; + $this->display(); + } + /** * Delete current search query. * diff --git a/module/search/model.php b/module/search/model.php index be524f2151..be3099885e 100644 --- a/module/search/model.php +++ b/module/search/model.php @@ -287,6 +287,36 @@ class searchModel extends model $this->session->set($formSessionName, $queryForm); } + /** + * Init the search session for the first time search. + * + * @param string $module + * @param array $fields + * @param array $fieldParams + * @access public + * @return array + */ + public function initZinSession($module, $fields, $fieldParams) + { + if(is_object($fields)) $fields = get_object_vars($fields); + $formSessionName = $module . 'Form'; + + $queryForm = array(); + for($i = 1; $i <= $this->config->search->groupItems * 2; $i ++) + { + $currentField = key($fields); + $currentParams = zget($fieldParams, $currentField, array()); + $operator = zget($currentParams, 'operator', '='); + $queryForm[] = array('field' => $currentField, 'andOr' => 'and', 'operator' => $operator, 'value' => ''); + + if(!next($fields)) reset($fields); + } + $queryForm[] = array('groupAndOr' => 'and'); + $this->session->set($formSessionName, $queryForm); + + return $queryForm; + } + /** * Set default params for selection. * @@ -366,6 +396,85 @@ class searchModel extends model return $params; } + /** + * Set default params for selection. + * + * @param array $fields + * @param array $params + * @access public + * @return array + */ + public function setZinDefaultParams($fields, $params) + { + $hasProduct = false; + $hasExecution = false; + $hasUser = false; + + $appendUsers = array(); + $module = $_SESSION['searchParams']['module']; + $formSessionName = $module . 'Form'; + if(isset($_SESSION[$formSessionName])) + { + for($i = 1; $i <= $this->config->search->groupItems; $i ++) + { + if(!isset($_SESSION[$formSessionName][$i - 1])) continue; + + $fieldName = $_SESSION[$formSessionName][$i - 1]['field']; + if(isset($params[$fieldName]) and $params[$fieldName]['values'] == 'users') + { + if($_SESSION[$formSessionName][$i - 1]['value']) $appendUsers[] = $_SESSION[$formSessionName][$i - 1]['value']; + } + } + } + + $fields = array_keys($fields); + foreach($fields as $fieldName) + { + if(empty($params[$fieldName])) continue; + if($params[$fieldName]['values'] == 'products') $hasProduct = true; + if($params[$fieldName]['values'] == 'users') $hasUser = true; + if($params[$fieldName]['values'] == 'executions') $hasExecution = true; + } + + if($hasUser) + { + $users = $this->loadModel('user')->getPairs('realname|noclosed', $appendUsers, $this->config->maxCount); + $users['$@me'] = $this->lang->search->me; + } + if($hasProduct) $products = $this->loadModel('product')->getPairs('', $this->session->project); + if($hasExecution) $executions = $this->loadModel('execution')->getPairs($this->session->project); + + foreach($fields as $fieldName) + { + if(!isset($params[$fieldName])) $params[$fieldName] = array('operator' => '=', 'control' => 'input', 'values' => ''); + if($params[$fieldName]['values'] == 'users') + { + if(!empty($this->config->user->moreLink)) $this->config->moreLinks["field{$fieldName}"] = $this->config->user->moreLink; + $params[$fieldName]['values'] = $users; + } + if($params[$fieldName]['values'] == 'products') $params[$fieldName]['values'] = $products; + if($params[$fieldName]['values'] == 'executions') $params[$fieldName]['values'] = $executions; + if(is_array($params[$fieldName]['values'])) + { + /* For build right sql when key is 0 and is not null. e.g. confirmed field. */ + if(isset($params[$fieldName]['values'][0]) and $params[$fieldName]['values'][0] !== '') + { + $params[$fieldName]['values'] = array('ZERO' => $params[$fieldName]['values'][0]) + $params[$fieldName]['values']; + unset($params[$fieldName]['values'][0]); + } + elseif(empty($params[$fieldName]['values'])) + { + $params[$fieldName]['values'] = array('' => '', 'null' => $this->lang->search->null); + } + elseif(empty($params[$fieldName]['nonull'])) + { + $params[$fieldName]['values'] = $params[$fieldName]['values'] + array('null' => $this->lang->search->null); + } + } + } + return $params; + } + /** * Get a query. * @@ -440,6 +549,38 @@ class searchModel extends model return false; } + /** + * Save current query to db of zin ui. + * + * @access public + * @return void + */ + public function saveZinQuery() + { + $sqlVar = $this->post->module . 'Query'; + $formVar = $this->post->module . 'Form'; + $sql = $_SESSION[$sqlVar]; + if(!$sql) $sql = ' 1 = 1 '; + + $query = fixer::input('post') + ->add('account', $this->app->user->account) + ->add('form', serialize($_SESSION[$formVar])) + ->add('sql', $sql) + ->skipSpecial('sql,form') + ->remove('onMenuBar') + ->get(); + if($this->post->onMenuBar) $query->shortcut = '1'; + $this->dao->insert(TABLE_USERQUERY)->data($query)->autoCheck()->check('title', 'notempty')->exec(); + + if(!dao::isError()) + { + $queryID = $this->dao->lastInsertID(); + if(!dao::isError()) $this->loadModel('score')->create('search', 'saveQuery', $queryID); + return $queryID; + } + return false; + } + /** * Delete current query from db. * @@ -1431,12 +1572,12 @@ class searchModel extends model public function buildSearchFormOptions($module, $fieldParams, $fields, $queries) { $opts = new stdClass(); - $opts->formConfig = static::buildFormConfig(); - $opts->fields = static::buildFormFields($fieldParams, $fields); - $opts->operators = static::buildFormOperators($this->lang->search->operators); - $opts->andOr = static::buildFormAndOrs($this->lang->search->andor); - $opts->saveSearch = static::buildFormSaveSearch($module); - $opts->savedQuery = static::buildFormSavedQuery($queries, $this->app->user->account); + $opts->formConfig = static::buildFormConfig(); + $opts->fields = static::buildFormFields($fieldParams, $fields); + $opts->operators = static::buildFormOperators($this->lang->search->operators); + $opts->andOr = static::buildFormAndOrs($this->lang->search->andor); + $opts->saveSearch = static::buildFormSaveSearch($module); + $opts->searchConditions = static::buildFormSavedQuery($queries, $actionURL); return $opts; } @@ -1450,7 +1591,7 @@ class searchModel extends model public static function buildFormConfig() { $config = new stdClass(); - $config->action = helper::createLink('search', 'buildQuery'); + $config->action = helper::createLink('search', 'buildZinQuery'); $config->method = 'post'; return $config; diff --git a/module/search/ui/buildzinform.html.php b/module/search/ui/buildzinform.html.php index 76b254ab1b..e7a060f334 100644 --- a/module/search/ui/buildzinform.html.php +++ b/module/search/ui/buildzinform.html.php @@ -1,25 +1,21 @@ search->buildSearchFormOptions($module, $fieldParams, $fields, $queries); +$opts = $this->search->buildSearchFormOptions($module, $fieldParams, $fields, $queries, $actionURL); $opts->groupName = array($lang->search->group1, $lang->search->group2); $opts->savedQueryTitle = $lang->search->savedQuery; -$opts->applyQueryURL = $actionURL; -$opts->deleteQueryURL = createLink('search', 'deleteQuery', 'queryID=myQueryID'); $opts->formSession = $formSession; $opts->module = $module; $opts->actionURL = $actionURL; $opts->groupItems = $groupItems; -$opts->onApplyQuery = jsRaw('window.onApplyQuery'); -$opts->onDeleteQuery = jsRaw('window.onDeleteQuery'); +$opts->onSubmit = jsRaw('window.onSubmit'); if(empty($opts->savedQuery)) unset($opts->savedQuery); $formName = empty($formName) ? '#searchFormPanel[data-module="' . $module . '"]' : $formName; zui::searchform(set((array)$opts), set::_to($formName), set::className('shadow')); -jsVar('onDeleteQueryURL', $opts->deleteQueryURL); jsVar('options', isset($options) ? $options : null); jsVar('canSaveQuery', !empty($_SESSION[$module . 'Query'])); jsVar('formSession', $_SESSION[$module . 'Form']); diff --git a/module/search/ui/savezinquery.html.php b/module/search/ui/savezinquery.html.php new file mode 100644 index 0000000000..d6714e4742 --- /dev/null +++ b/module/search/ui/savezinquery.html.php @@ -0,0 +1,50 @@ +search->setCondName) + ), + checkbox + ( + set::id('common'), + set::name('common'), + set::value(1), + set::class('w-3/12'), + $lang->search->setCommon + ), + checkbox + ( + set::id('onMenuBar'), + set::name('onMenuBar'), + set::class('w-3/12'), + $lang->search->onMenuBar + ), + btn( + setClass('w-1/12 primary'), + set::type('submit'), + set('data-type', 'submit'), + $lang->save + ), + input + ( + set::type('hidden'), + set::name('module'), + set::value($module) + ) + ) +); + +render();