diff --git a/e107_core/templates/admin_icons_template.php b/e107_core/templates/admin_icons_template.php
index 89f7176e8..760ff12eb 100644
--- a/e107_core/templates/admin_icons_template.php
+++ b/e107_core/templates/admin_icons_template.php
@@ -440,7 +440,7 @@ if (!defined('E_16_FAILEDLOGIN')) {
define("E_32_TRUE", "");
- define("ADMIN_CHILD_ICON", '
'); // must use single quotes.
+ define("ADMIN_CHILD_ICON", '
'); // must use single quotes.
define("ADMIN_TRUE_ICON", "");
define("ADMIN_FALSE_ICON", "");
define("ADMIN_WARNING_ICON", "");
diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php
index d2b9debb5..0e8fd6ec6 100644
--- a/e107_handlers/admin_ui.php
+++ b/e107_handlers/admin_ui.php
@@ -2420,6 +2420,10 @@ class e_admin_controller_ui extends e_admin_controller
*/
protected $sortField = null;
+ /**
+ * @var string field containing the order number
+ */
+ protected $treePrefix = null;
/**
* @var string field containing the parent field
@@ -2621,6 +2625,26 @@ class e_admin_controller_ui extends e_admin_controller
{
return $this->sortField;
}
+
+ /**
+ * Get Sort Field data
+ * @return string
+ */
+ public function getSortParent()
+ {
+ return $this->sortParent;
+ }
+
+
+
+ /**
+ * Get Sort Field data
+ * @return string
+ */
+ public function getTreePrefix()
+ {
+ return $this->treePrefix;
+ }
/**
* Get Tab data
@@ -4015,9 +4039,10 @@ 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;
- $this->listOrder = 'treesort,'.$this->sortField;
- $this->orderStep = ($this->orderStep === 1) ? 100 : $this->orderStep;
+ // $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();
+ $this->listOrder = '_treesort '; // .$this->sortField;
+ // $this->orderStep = ($this->orderStep === 1) ? 100 : $this->orderStep;
}
else
{
@@ -4140,6 +4165,75 @@ class e_admin_controller_ui extends e_admin_controller
return $qry;
}
+
+ protected function getParentChildQuery()
+ {
+
+ $parent= $this->getSortParent();
+ $table = $this->getTableName();
+ $pid = $this->getPrimaryName();
+ $order = $this->getSortField();
+
+ $sql = "
+
+ DROP FUNCTION IF EXISTS `getDepth` ;
+ CREATE FUNCTION `getDepth` (project_id INT) RETURNS int
+ BEGIN
+ DECLARE depth INT;
+ 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;
+
+ IF project_id > 0 THEN
+ SET depth = depth + 1;
+ END IF;
+
+ END WHILE;
+
+ RETURN depth;
+
+ END
+ ;
+
+
+
+ DROP FUNCTION IF EXISTS `getTreeSort`;
+ CREATE FUNCTION getTreeSort(incid INT)
+ RETURNS CHAR(255)
+ BEGIN
+ SET @parentstr = CONVERT(incid, CHAR);
+ SET @parent = -1;
+ label1: WHILE @parent != 0 DO
+ SET @parent = (SELECT ".$parent." FROM `#".$table."` WHERE ".$pid." =incid);
+ SET @order = (SELECT ".$order." FROM `#".$table."` WHERE ".$pid." =incid);
+ SET @parentstr = CONCAT(if(@parent = 0,'',@parent), LPAD(@order,3,0), @parentstr);
+ SET incid = @parent;
+ END WHILE label1;
+
+ RETURN @parentstr;
+ END
+ ;
+
+ ";
+
+ // FIXME - make order work correctly (modify @order) when twin digits or higher are used.
+
+ e107::getDb()->gen($sql);
+
+ return "SELECT *, getTreeSort(".$pid.") as _treesort, getDepth(".$pid.") as _depth FROM `#".$table."` ";
+
+
+
+ }
+
+
+
+
+
+
/**
* Manage submit item
* Note: $callbackBefore will break submission if returns false
@@ -4318,6 +4412,7 @@ class e_admin_ui extends e_admin_controller_ui
protected $sortField;
protected $sortParent;
protected $orderStep;
+ protected $treePrefix;
/**
@@ -5276,10 +5371,18 @@ class e_admin_ui extends e_admin_controller_ui
$updated[] = "#".$id." -- ".$this->sortField." = ".$c;
}
// echo($sql->getLastQuery()."\n");
- $c += $step;
+ $c++; // += $step;
}
+
+ if(!empty($this->sortParent) && !empty($this->sortField) )
+ {
+ return null;
+ }
+
+ //file_put_contents(e_LOG."sortAjax.log", print_r($_POST['all'],true));
+
// Increment every other record after the current page of records.
// $changed = (intval($_POST['neworder']) * $step) + $from ;
$changed = $c - $step;
@@ -5289,10 +5392,10 @@ class e_admin_ui extends e_admin_controller_ui
// ------------ Fix Child Order when parent is used. ----------------
-
+/*
if(!empty($this->sortParent) && !empty($this->sortField) ) // Make sure there is space for at least 99
{
-
+ $parent = array();
$data2 = $sql->retrieve($this->table,$this->pid.','.$this->sortField,$this->sortParent .' = 0',true);
foreach($data2 as $val)
@@ -5322,7 +5425,7 @@ class e_admin_ui extends e_admin_controller_ui
$sql->update($this->table, $this->sortField . ' = '.$c.' WHERE '.$this->pid.' = '.intval($row[$this->pid]).' LIMIT 1');
}
-
+*/
@@ -5897,6 +6000,76 @@ class e_admin_form_ui extends e_form
{
}
+
+ /**
+ * @todo Get a 'depth/level' field working with mysql and change the 'level' accordingly
+ * @param mixed $curVal
+ * @param string $mode read|write|inline
+ * @param array $parm
+ * @return array|string
+ */
+ public function treePrefix($curVal, $mode, $parm)
+ {
+ $controller = $this->getController();
+ $parentField = $controller->getSortParent();
+ $treePrefixField = $controller->getTreePrefix();
+ $parent = $controller->getListModel()->get($parentField);
+ $level = $controller->getListModel()->get("_depth");
+
+
+ if($mode === 'read')
+ {
+
+ $inline = $this->getController()->getFieldAttr($treePrefixField,'inline');
+
+ if($inline === true)
+ {
+ return $curVal;
+ }
+
+ $level_image = $parent ? str_replace('level-x','level-'.$level, ADMIN_CHILD_ICON) : '';
+
+ return ($parent) ? $level_image.$curVal : $curVal;
+
+ }
+
+
+ if($mode === 'inline')
+ {
+ $ret = array('inlineType'=>'text');
+
+ if(!empty($parent))
+ {
+ $ret['inlineParms'] = array('pre'=> str_replace('level-x','level-'.$level, ADMIN_CHILD_ICON));
+ }
+
+
+ return $ret;
+ }
+
+
+/*
+ if($mode == 'write') // not used.
+ {
+ // return $frm->text('forum_name',$curVal,255,'size=xxlarge');
+ }
+
+ if($mode == 'filter')
+ {
+ return;
+ }
+ if($mode == 'batch')
+ {
+ return;
+ }
+*/
+
+
+
+
+ }
+
+
/**
* Generic DB Record Creation Form.
* @return string
@@ -6052,6 +6225,22 @@ class e_admin_form_ui extends e_form
$fields['options']['sort'] = false;
}
+ if($treefld = $controller->getTreePrefix())
+ {
+ $fields[$treefld]['type'] = 'method';
+ $fields[$treefld]['method'] = 'treePrefix'; /* @see e_admin_form_ui::treePrefix(); */
+
+ $tr = $controller->getTreeModel()->toArray();
+
+ foreach($tr as $row)
+ {
+ e107::getDebug()->log($row[$treefld].' > '.$row['_treesort']);
+ }
+
+ }
+
+
+
// ------------------------------------------
$coreBatchOptions = array(
diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php
index 605052814..509e47e8e 100644
--- a/e107_handlers/form_handler.php
+++ b/e107_handlers/form_handler.php
@@ -4031,6 +4031,7 @@ class e_form
}
+
if(!empty($attributes['inline'])) $parms['editable'] = true; // attribute alias
if(!empty($attributes['sort'])) $parms['sort'] = true; // attribute alias
@@ -4872,11 +4873,11 @@ class e_form
}
// print_a($attributes);
// Inline Editing.
- if(!vartrue($attributes['noedit']) && vartrue($parms['editable'])) // avoid bad markup, better solution coming up
+ if(empty($attributes['noedit']) && !empty($parms['editable'])) // avoid bad markup, better solution coming up
{
$mode = preg_replace('/[^\w]/', '', vartrue($_GET['mode'], ''));
- $methodParms = call_user_func_array(array($this, $method), array($value, 'inline', $parms));
+ $methodParms = call_user_func_array(array($this, $meth), array($value, 'inline', $parms));
$inlineParms = (!empty($methodParms['inlineParms'])) ? $methodParms['inlineParms'] : null;
diff --git a/e107_plugins/download/includes/admin.php b/e107_plugins/download/includes/admin.php
index 241799620..fcc234ade 100644
--- a/e107_plugins/download/includes/admin.php
+++ b/e107_plugins/download/includes/admin.php
@@ -131,31 +131,43 @@ class download_cat_ui extends e_admin_ui
protected $table = "download_category";
protected $pid = "download_category_id";
protected $perPage = 0; //no limit
- // protected $listOrder = 'download_category_parent,download_category_order';
protected $batchCopy = true;
// initiate as a parent/child tree.
protected $sortField = 'download_category_order';
protected $sortParent = 'download_category_parent';
-
- protected $listOrder = null; // automatic
+ protected $treePrefix = 'download_category_name';
+ // protected $orderStep = 1000;
+ // protected $listOrder = null; // automatic
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'download_category_icon' => array('title'=> LAN_ICON, 'type' => 'method', 'width' => '5%', 'thclass' => 'center','class'=>'center','writeParms'=>'glyphs=1' ),
'download_category_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE),
- 'download_category_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'inline' => true, 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>'size=xxlarge'),
- 'download_category_sef' => array('title'=> LAN_SEFURL, 'type' => 'text', 'inline' => true, 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>'size=xxlarge'),
+ 'download_category_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data'=>'str', 'inline' => true, 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>'size=xxlarge'),
+ 'download_category_sef' => array('title'=> LAN_SEFURL, 'type' => 'text', 'data'=>'str', 'inline' => true, 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>'size=xxlarge'),
- 'download_category_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name
+ 'download_category_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'data'=>'str', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name
'download_category_parent' => array('title'=> LAN_PARENT, 'type' => 'method', 'width' => '5%', 'batch' => TRUE, 'filter'=>TRUE),
'download_category_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'inline' => true, 'width' => 'auto', 'data' => 'int', 'batch' => TRUE, 'filter'=>TRUE),
- 'download_category_order' => array('title'=> LAN_ORDER, 'type' => 'number', 'data'=>'int', 'width' => '5%', 'thclass' => 'right', 'class'=> 'right' ),
+ 'download_category_order' => array('title'=> LAN_ORDER, 'type' => 'number', 'nolist'=>true, 'data'=>'int', 'width' => '5%', 'thclass' => 'right', 'class'=> 'right' ),
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center', 'sort'=>1)
);
-
+
+ protected $fieldpref = array('download_category_icon', 'download_category_id', 'download_category_name', 'download_category_sef', 'download_category_class', 'download_category_order');
+
+
+ function init()
+ {
+ if(deftrue('e_DEBUG'))
+ {
+ $this->fields['download_category_order']['nolist'] = false;
+ }
+
+ }
+
function getDownloadCategoryTree($id = false, $default = 'n/a')
{
diff --git a/e107_themes/bootstrap3/admin_style.css b/e107_themes/bootstrap3/admin_style.css
index ab3893018..bd0b3bb98 100644
--- a/e107_themes/bootstrap3/admin_style.css
+++ b/e107_themes/bootstrap3/admin_style.css
@@ -1552,8 +1552,12 @@ body#admin-menus #sc-admin-help .panel-body {
td img.thumbnail { margin-bottom:0 }
-
-
+/* Parent/Child Indicator */
+.treeprefix {margin-right:4px}
+.treeprefix.level-2 { margin-left:10px }
+.treeprefix.level-3 { margin-left:30px }
+.treeprefix.level-4 { margin-left:50px }
+.treeprefix.level-5 { margin-left:70px }