diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index cfd80f7a6..1a534b826 100644 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -4040,7 +4040,7 @@ class e_admin_controller_ui extends e_admin_controller elseif($this->sortField && $this->sortParent) // automated 'tree' sorting. { // $qry = "SELECT SQL_CALC_FOUND_ROWS a. *, CASE WHEN a.".$this->sortParent." = 0 THEN a.".$this->sortField." ELSE b.".$this->sortField." + (( a.".$this->sortField.")/1000) END AS treesort FROM `#".$this->table."` AS a LEFT JOIN `#".$this->table."` AS b ON a.".$this->sortParent." = b.".$this->pid; - $qry = $this->getParentChildQuery(); + $qry = $this->getParentChildQry(); $this->listOrder = '_treesort '; // .$this->sortField; // $this->orderStep = ($this->orderStep === 1) ? 100 : $this->orderStep; } @@ -4166,7 +4166,12 @@ class e_admin_controller_ui extends e_admin_controller } - protected function getParentChildQuery() + /** + * Return a Parent/Child SQL Query based on sortParent and sortField variables + * @param bool|false $orderby - include 'ORDER BY' in the qry. + * @return string + */ + public function getParentChildQry($orderby=false) { $parent= $this->getSortParent(); @@ -4188,9 +4193,10 @@ class e_admin_controller_ui extends e_admin_controller SET depth=1; WHILE project_id > 0 DO + SELECT IFNULL(".$parent.",-1) INTO project_id - FROM ( SELECT ".$parent." FROM `#".$table."` WHERE ".$pid." = project_id) t; + FROM ( SELECT ".$parent." FROM `#".$table."` WHERE ".$pid." = project_id) AS t; IF project_id > 0 THEN SET depth = depth + 1; @@ -4232,10 +4238,14 @@ class e_admin_controller_ui extends e_admin_controller e107::getDb()->gen($sql); - return "SELECT *, getTreeSort(".$pid.") as _treesort, getDepth(".$pid.") as _depth FROM `#".$table."` "; - + $qry = "SELECT *, getTreeSort(".$pid.") as _treesort, getDepth(".$pid.") as _depth FROM `#".$table."` "; + if($orderby === true) + { + $qry .= " ORDER BY _treesort"; + } + return $qry; } @@ -4289,7 +4299,26 @@ class e_admin_controller_ui extends e_admin_controller // - Autoincrement sortField on 'Create'. - if(($_posted['etrigger_submit'] === 'create') && !empty($this->sortField) && empty($this->sortParent) && empty($_posted[$this->sortField]) ) + + // Prevent parent being assigned as self. + if(!empty($this->sortParent) && $this->getAction() === 'edit' && ($model->getId() == $_posted[$this->sortParent] ) ) + { + $vars = array( + 'x'=> $this->getFieldAttr($this->sortParent,'title'), + 'y'=> $this->getFieldAttr($this->pid,'title'), + ); + + $message = e107::getParser()->lanVars(LAN_UI_X_CANT_EQUAL_Y, $vars); + $model->addMessageWarning($message); + $model->setMessages(); + $this->getUI()->addWarning($this->sortParent); + return false; + } + + + + + if(($this->getAction() === 'create') && !empty($this->sortField) && empty($this->sortParent) && empty($_posted[$this->sortField]) ) { $incVal = e107::getDb()->max($this->table, $this->sortField) + 1; @@ -5956,6 +5985,7 @@ class e_admin_form_ui extends e_form protected $_controller = null; + /** * Constructor * @param e_admin_ui $controller diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 509e47e8e..83e2a61fd 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -66,6 +66,7 @@ class e_form protected $_tabindex_counter = 0; protected $_tabindex_enabled = true; protected $_cached_attributes = array(); + protected $_field_warnings = array(); @@ -84,6 +85,13 @@ class e_form $this->setRequiredString(''); } + + public function addWarning($field) + { + $this->_field_warnings[] = $field; + + } + /** * Open a new form * @param string name @@ -5967,7 +5975,17 @@ class e_form } */ - + if(in_array($key,$this->_field_warnings)) + { + if(is_string($writeParms)) + { + parse_str($writeParms,$writeParms); + } + + $writeParms['tdClassRight'] .= ' has-warning'; + + } + $leftCell = $required."".defset(vartrue($att['title']), vartrue($att['title']))."".$label; $rightCell = $this->renderElement($keyName, $model->getIfPosted($valPath), $att, varset($model_required[$key], array()), $model->getId())." {$help}"; diff --git a/e107_languages/English/admin/lan_admin.php b/e107_languages/English/admin/lan_admin.php index 0208b1b52..32f664c12 100644 --- a/e107_languages/English/admin/lan_admin.php +++ b/e107_languages/English/admin/lan_admin.php @@ -524,3 +524,5 @@ define("LAN_ENGINE", "Engine"); define("LAN_SOURCE", "Source"); define("LAN_ERROR_CONNECTION","Unable to connect for updates. Please check firewall and/or internet connection."); + +define("LAN_UI_X_CANT_EQUAL_Y", "[x] cannot be the same as [y]"); diff --git a/e107_plugins/download/includes/admin.php b/e107_plugins/download/includes/admin.php index fcc234ade..c86337d00 100644 --- a/e107_plugins/download/includes/admin.php +++ b/e107_plugins/download/includes/admin.php @@ -158,6 +158,7 @@ class download_cat_ui extends e_admin_ui protected $fieldpref = array('download_category_icon', 'download_category_id', 'download_category_name', 'download_category_sef', 'download_category_class', 'download_category_order'); + protected $downloadCats = array(); function init() { @@ -166,27 +167,47 @@ class download_cat_ui extends e_admin_ui $this->fields['download_category_order']['nolist'] = false; } + $this->setDownloadCategoryTree(); + } - function getDownloadCategoryTree($id = false, $default = 'n/a') + private function setDownloadCategoryTree() { - // TODO get faq category tree + + $sql = e107::getDb(); - $sql -> gen('SELECT * FROM #download_category ORDER BY download_category_order'); - $cats = array(); - $cats[0] = $default; + $qry = $this->getParentChildQry(true); + $sql->gen($qry); + + $this->downloadCats[0] = LAN_NONE; + while($row = $sql->fetch()) { - $cats[$row['download_category_id']] = $row['download_category_name']; + $num = $row['_depth'] - 1; + $id = $row['download_category_id']; + $this->downloadCats[$id] = str_repeat("  ",$num).$row['download_category_name']; } - + + if($this->getAction() === 'edit') // make sure parent is not the same as ID. + { + $r = $this->getId(); + unset($this->downloadCats[$r]); + } + + } + + + + function getDownloadCategoryTree($id = false) + { + if($id) { - return $cats[$id]; + return $this->downloadCats[$id]; } - return $cats; + return $this->downloadCats; } } @@ -205,7 +226,7 @@ class download_cat_form_ui extends e_admin_form_ui break; case 'write': - return $this->selectbox('download_category_parent', $controller->getDownloadCategoryTree(), $curVal); + return $this->select('download_category_parent', $controller->getDownloadCategoryTree(), $curVal); break; case 'filter':