1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

Admin-ui: Additional checks for valid parent value when editing parent/child record. eg. download_category etc.

This commit is contained in:
Cameron 2017-03-30 08:57:01 -07:00
parent f7639dd282
commit 7ab368076f
4 changed files with 88 additions and 17 deletions

View File

@ -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

View File

@ -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('<span class="required">*&nbsp;</span>');
}
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."<span{$required_class}>".defset(vartrue($att['title']), vartrue($att['title']))."</span>".$label;
$rightCell = $this->renderElement($keyName, $model->getIfPosted($valPath), $att, varset($model_required[$key], array()), $model->getId())." {$help}";

View File

@ -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]");

View File

@ -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("&nbsp;&nbsp;",$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':