From af5c0b2ead3d3a87a618261f14c51338bc0ccd0b Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 1 Feb 2015 18:45:33 -0800 Subject: [PATCH] Fixes #851 - Admin-UI - when the listQry doesn't contain backticks around table names. --- e107_handlers/admin_ui.php | 27 ++++++++++++++++++++++++-- e107_plugins/gallery/admin_gallery.php | 11 +++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index 2c15573cf..67d57f1ea 100644 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -3411,6 +3411,7 @@ class e_admin_controller_ui extends e_admin_controller } } + // check for table & field aliases $fields = array(); // preserve order foreach ($this->fields as $field => $att) @@ -3488,7 +3489,7 @@ class e_admin_controller_ui extends e_admin_controller $this->fields = $fields; - + $this->_alias_parsed = true; return $this; } @@ -3544,6 +3545,23 @@ class e_admin_controller_ui extends e_admin_controller } + /** + * Quick fix for bad custom $listQry; + */ + protected function parseCustomListQry($qry) + { + if(strpos($qry,'`')===false) + { + $ret = preg_replace("/FROM\s*(#[\w]*/","FROM `$1`", $qry); // backticks missing, so add them. + e107::getMessage()->addDebug('Your $listQry is missing `backticks` around the table name!'); + return $ret; + } + + return $qry; + + } + + // TODO - abstract, array return type, move to parent? protected function _modifyListQry($raw = false, $isfilter = false, $forceFrom = false, $forceTo = false, $listQry = '') { @@ -3741,7 +3759,7 @@ class e_admin_controller_ui extends e_admin_controller } else { - $qry = $listQry ? $listQry : "SELECT SQL_CALC_FOUND_ROWS ".$tableSFields." FROM ".$tableFrom; + $qry = $this->parseCustomListQry($listQry) ? $listQry : "SELECT SQL_CALC_FOUND_ROWS ".$tableSFields." FROM ".$tableFrom; } // group field - currently auto-added only if there are joins @@ -3843,7 +3861,12 @@ class e_admin_controller_ui extends e_admin_controller } // Debug Filter Query. + if($listQry) + { + e107::getMessage()->addDebug('Using Custom listQry '); + } e107::getMessage()->addDebug('QRY='.str_replace('#', MPREFIX, $qry)); + // echo $qry.'
'; // print_a($this->fields); // print_a($_GET); diff --git a/e107_plugins/gallery/admin_gallery.php b/e107_plugins/gallery/admin_gallery.php index aef7c4722..6f7d4c33a 100644 --- a/e107_plugins/gallery/admin_gallery.php +++ b/e107_plugins/gallery/admin_gallery.php @@ -86,7 +86,13 @@ class plugin_gallery_admin extends e_admin_dispatcher */ protected $menuTitle = 'Gallery'; - + function init() + { + if(E107_DEBUG_LEVEL > 0) + { + $this->adminMenu['main/list'] = array('caption'=> LAN_CATEGORY, 'perm' => 'P'); + } + } } @@ -99,7 +105,8 @@ class gallery_cat_admin_ui extends e_admin_ui protected $perPage = 10; //no limit protected $listOrder = 'media_cat_order'; - protected $listQry = "SELECT * FROM #core_media_cat WHERE media_cat_owner = 'gallery' "; // without any Order or Limit. + protected $listQry = "SELECT * FROM #core_media_cat WHERE media_cat_owner = 'gallery' "; // without any Order or Limit. + // protected $listQry = "SELECT * FROM #core_media "; // without any Order or Limit. // protected $editQry = "SELECT * FROM #faq_info WHERE faq_info_id = {ID}"; protected $fields = array(