From dab2f257de7938771da74e8a32614d22bc28e660 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sat, 2 Mar 2013 21:07:42 -0800 Subject: [PATCH] Closes #134. Also added Ajax Modal Window --- e107_admin/db.php | 2 +- e107_admin/header.php | 83 ++++--- e107_admin/menus.php | 201 +++++++++++++++- e107_handlers/menumanager_class.php | 335 +++++++++++++++++--------- e107_themes/bootstrap/admin_style.css | 2 +- e107_web/js/core/admin.jquery.js | 28 +-- 6 files changed, 481 insertions(+), 170 deletions(-) diff --git a/e107_admin/db.php b/e107_admin/db.php index 523fc8a32..e20ca9f52 100644 --- a/e107_admin/db.php +++ b/e107_admin/db.php @@ -481,7 +481,7 @@ class system_tools
".DBLAN_10." - +
diff --git a/e107_admin/header.php b/e107_admin/header.php index 3ea9ed996..834d22edd 100644 --- a/e107_admin/header.php +++ b/e107_admin/header.php @@ -35,47 +35,62 @@ else require_once (e_BASE.$e107->getFolder('themes').'templates/admin_template.php'); } -if(e_PAGE != 'menus.php') // Quick fix for Menu Manager inactive drop-down problem. + + +function loadJSAddons() { + + if(e_PAGE == 'menus.php' && vartrue($_GET['configure'])) // Quick fix for Menu Manager inactive drop-down problem. + { + return; + } + e107::js('core', 'colorbox/jquery.colorbox-min.js', 'jquery', 2); e107::css('core', 'colorbox/colorbox.css', 'jquery'); -} + // e107::js('core', 'bootstrap/js/bootstrap-modal.js', 'jquery', 2); // Special Version see: https://github.com/twitter/bootstrap/pull/4224 + -e107::css('core', 'bootstrap-editable/css/bootstrap-editable.css', 'jquery'); -e107::js('core', 'bootstrap-editable/js/bootstrap-editable.min.js', 'jquery', 2); + e107::css('core', 'bootstrap-editable/css/bootstrap-editable.css', 'jquery'); + e107::js('core', 'bootstrap-editable/js/bootstrap-editable.min.js', 'jquery', 2); + + e107::css('core', 'bootstrap-select/bootstrap-select.min.css', 'jquery'); + e107::js('core', 'bootstrap-select/bootstrap-select.min.js', 'jquery', 2); + + e107::css('core', 'bootstrap-multiselect/css/bootstrap-multiselect.css', 'jquery'); + e107::js('core', 'bootstrap-multiselect/js/bootstrap-multiselect.js', 'jquery', 2); + + e107::js('core', 'bootstrap-jasny/js/jasny-bootstrap.js', 'jquery', 2); + + //e107::css('core', 'bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css', 'jquery'); + //e107::js('core', 'bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js', 'jquery', 2); + + e107::js('core', 'jquery.elastic.js', 'jquery', 2); + + e107::js('core', 'jquery-ui-timepicker-addon.js', 'jquery', 2); + + + //e107::css('core', 'chosen/chosen.css', 'jquery'); + //e107::js('core', 'chosen/chosen.jquery.min.js', 'jquery', 2); + + e107::js('core', 'password/jquery.pwdMeter.js', 'jquery', 2); + + + e107::js("core", "tags/jquery.tagit.js","jquery",3); + e107::css('core', 'tags/jquery.tagit.css', 'jquery'); + + e107::css('core', 'core/admin.jquery.css', 'jquery'); + e107::js("core", "core/admin.jquery.js","jquery",4); // Load all default functions. + e107::css('core', 'core/all.jquery.css', 'jquery'); -e107::css('core', 'bootstrap-select/bootstrap-select.min.css', 'jquery'); -e107::js('core', 'bootstrap-select/bootstrap-select.min.js', 'jquery', 2); + e107::js("core", "core/all.jquery.js","jquery",4); // Load all default functions. +} -e107::css('core', 'bootstrap-multiselect/css/bootstrap-multiselect.css', 'jquery'); -e107::js('core', 'bootstrap-multiselect/js/bootstrap-multiselect.js', 'jquery', 2); - -e107::js('core', 'bootstrap-jasny/js/jasny-bootstrap.js', 'jquery', 2); - -//e107::css('core', 'bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css', 'jquery'); -//e107::js('core', 'bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js', 'jquery', 2); - -e107::js('core', 'jquery.elastic.js', 'jquery', 2); - -e107::js('core', 'jquery-ui-timepicker-addon.js', 'jquery', 2); +loadJSAddons(); -//e107::css('core', 'chosen/chosen.css', 'jquery'); -//e107::js('core', 'chosen/chosen.jquery.min.js', 'jquery', 2); -e107::js('core', 'password/jquery.pwdMeter.js', 'jquery', 2); - - -e107::js("core", "tags/jquery.tagit.js","jquery",3); -e107::css('core', 'tags/jquery.tagit.css', 'jquery'); - - -e107::css('core', 'core/admin.jquery.css', 'jquery'); -e107::css('core', 'core/all.jquery.css', 'jquery'); -e107::js("core", "core/admin.jquery.js","jquery",4); // Load all default functions. -e107::js("core", "core/all.jquery.js","jquery",4); // Load all default functions. @@ -400,11 +415,17 @@ echo getModal(); function getModal($caption = '', $type='') { + if(e_PAGE == 'menus.php' && vartrue($_GET['configure'])) // Menu Manager iFrame disable + { + return; + } + + return '
+
-
Parameters (query string format): - ".$frm->text('menu_parms', $row['menu_parms'], 900)." + ".$frm->text('menu_parms', $row['menu_parms'], 900, 'class=e-save span8')."
-
"; - $text .= $frm->admin_button('parms_submit', LAN_SAVE, 'update'); - $text .= " -
+ "; + /* + + $text .= " +
"; + $text .= $frm->admin_button('parms_submit', LAN_SAVE, 'update'); + $text .= " +
"; + + */ + $text .= $frm->hidden('mode','parms'); + $text .= $frm->hidden('menu_id',$id); + $text .= "
"; + return $text; //$caption = MENLAN_7." ".$row['menu_name']; //$ns->tablerender($caption, $text); @@ -497,49 +506,82 @@ class e_menuManager { { if(!vartrue($_GET['vis'])) return; - global $sql,$ns,$frm; + $sql = e107::getDb(); + $ns = e107::getRender(); + $frm = e107::getForm(); + require_once(e_HANDLER."userclass_class.php"); - if(!$sql->db_Select("menus", "*", "menu_id=".intval($_GET['vis']))) + + if(!$sql->select("menus", "*", "menu_id=".intval($_GET['vis']))) { $this->menuAddMessage("Couldn't Load Menu",E_MESSAGE_ERROR); return; - }; - $row = $sql->db_Fetch(); - $listtype = substr($row['menu_pages'], 0, 1); + } + + $row = $sql->fetch(); + + $listtype = substr($row['menu_pages'], 0, 1); $menu_pages = substr($row['menu_pages'], 2); $menu_pages = str_replace("|", "\n", $menu_pages); - $text = "
-
-
- ". MENLAN_7." ".$row['menu_name']." - - - - - +
- - ".MENLAN_4." ". - r_userclass('menu_class', $row['menu_class'], "off", "public,member,guest,admin,main,classes,nobody")." -

"; + $text = "
+ +
+ ". MENLAN_7." ".$row['menu_name']." + + + + + -
+ + ".MENLAN_4." ". + r_userclass('menu_class', $row['menu_class'], "off", "public,member,guest,admin,main,classes,nobody")." +
+ "; $checked = ($listtype == 1) ? " checked='checked' " : ""; - $text .= " ".MENLAN_26."
"; + + $text .= $frm->radio('listtype', 1, $checked, array('label'=>MENLAN_26, 'class'=> 'e-save')); + // $text .= "
"; + // $text .= " ".MENLAN_26."
"; $checked = ($listtype == 2) ? " checked='checked' " : ""; - $text .= " ".MENLAN_27."

".MENLAN_28."
"; - $text .= ""; - $text .= "
+ + $text .= $frm->radio('listtype', 2, $checked, array('label'=>MENLAN_27, 'class'=> 'e-save')); + + + // $text .= " ".MENLAN_27."
"; + + $text .= "
+
+ +
+ + +
+
".MENLAN_28."
+
"; + + $text .= $frm->hidden('mode','visibility'); + $text .= $frm->hidden('menu_id',intval($_GET['vis'])); // ""; + + /* + $text .= "
"; $text .= $frm->admin_button('class_submit', MENLAN_6, 'update'); - $text .= " -
+ +
"; + */ + $text .= " "; + + return $text; - $caption = MENLAN_7." ".$row['menu_name']; - $ns->tablerender($caption, $text); + //$caption = MENLAN_7." ".$row['menu_name']; + //$ns->tablerender($caption, $text); + //echo $text; } @@ -560,12 +602,12 @@ class e_menuManager { foreach($this->menuActivateIds as $sel_mens) { //Get info from menu being activated - if($sql->db_Select("menus", 'menu_name, menu_path' , "menu_id = ".intval($sel_mens)." ")) + if($sql->select("menus", 'menu_name, menu_path' , "menu_id = ".intval($sel_mens)." ")) { - $row=$sql->db_Fetch(); + $row=$sql->fetch(); //If menu is not already activated in that area, add the record. //$query = "SELECT menu_name,menu_path FROM #menus WHERE menu_name='".$row['menu_name']."' AND menu_layout = '".$this->dbLayout."' AND menu_location = ".$location." LIMIT 1 "; - //if(!$sql->db_Select_gen($query, $this->debug)) + //if(!$sql->gen($query, $this->debug)) { $insert = array( @@ -676,25 +718,32 @@ class e_menuManager { { $sql = e107::getDb(); $parms = $sql->escape(strip_tags($_POST['menu_parms'])); - $check = $sql->db_Update("menus", "menu_parms='".$parms."' WHERE menu_id=".$this->menuId); + + $check = $sql->db_Update("menus", "menu_parms='".$parms."' WHERE menu_id=".intval($_POST['menu_id'])." LIMIT 1"); + if($check) { + return array('msg'=>'All Okay','error'=>false); // FIXME - menu log //$admin_log->log_event('MENU_02',$_POST['menu_parms'].'[!br!]'.$parms.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); - $this->menuAddMessage(LAN_SAVED,E_MESSAGE_SUCCESS); + // $this->menuAddMessage(LAN_SAVED,E_MESSAGE_SUCCESS); } elseif(false === $check) { - $this->menuAddMessage(LAN_UPDATED_FAILED,E_MESSAGE_ERROR); + return array('msg'=>LAN_UPDATED_FAILED,'error'=>true); + + } + else + { + return array('msg'=>'No Changes Made','error'=>false); // $this->menuAddMessage(LAN_NOCHANGE_NOTSAVED,E_MESSAGE_INFO); } - else $this->menuAddMessage(LAN_NOCHANGE_NOTSAVED,E_MESSAGE_INFO); } // -------------------------------------------------------------------------- - function menuSaveVisibility() + function menuSaveVisibility() // Used by Ajax { global $admin_log; $sql = e107::getDb(); @@ -709,41 +758,48 @@ class e_menuManager { $pageparms = preg_replace("#\|$#", "", $pageparms); $pageparms = (trim($_POST['pagelist']) == '') ? '' : $pageparms; - if($sql->db_Update("menus", "menu_class='".$_POST['menu_class']."', menu_pages='{$pageparms}' WHERE menu_id=".intval($this->menuId))) + if($sql->db_Update("menus", "menu_class='".intval($_POST['menu_class'])."', menu_pages='{$pageparms}' WHERE menu_id=".intval($_POST['menu_id']))) { $admin_log->log_event('MENU_02',$_POST['menu_class'].'[!br!]'.$pageparms.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); - $message = "
".MENLAN_8."
"; - $this->menuAddMessage($message,E_MESSAGE_SUCCESS); + + return array('msg'=>LAN_UPDATED, 'error'=> false); + //$this->menuAddMessage($message,E_MESSAGE_SUCCESS); } else { - $message = "the update failed"; - $this->menuAddMessage($message,E_MESSAGE_ERROR); + return array('msg'=>LAN_UPDATED_FAILED, 'error'=> true, 'posted'=>$_POST); + // $this->menuAddMessage($message,E_MESSAGE_ERROR); } } - + function setMenuId($id) + { + $this->menuId = intval($id); + } // ----------------------------------------------------------------------- function menuDeactivate() { // Get current menu name - global $sql,$admin_log; + global $admin_log; + $sql = e107::getDb(); //echo "FOUND= ".$this->menuId; + $error = false; - if($sql->db_Select('menus', 'menu_name', 'menu_id='.$this->menuId, 'default')) + if($sql->gen('SELECT menu_name FROM #menus WHERE menu_id = '.$this->menuId.' LIMIT 1')) { - $row = $sql->db_Fetch(); + $row = $sql->fetch(); //Check to see if there is already a menu with location = 0 (to maintain BC) - if($sql->db_Select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = 0 AND menu_layout ='".$this->dbLayout."' LIMIT 1")) + if($sql->select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = 0 AND menu_layout ='".$this->dbLayout."' LIMIT 1")) { //menu_location=0 already exists, we can just delete this record if(!$sql->db_Delete('menus', 'menu_id='.$this->menuId)) { $message = "Deletion Failed"; + $error = true; } } else @@ -752,6 +808,7 @@ class e_menuManager { if(!$sql->db_Update("menus", "menu_location=0, menu_order=0, menu_class=0, menu_pages='' WHERE menu_id=".$this->menuId)) { $message = "FAILED"; + $error = true; } } //Move all other menus up @@ -760,10 +817,12 @@ class e_menuManager { } else { - $message = "NO CHANGES MADE"; + $message = "NO CHANGES MADE : ".$this->menuId; + $error = true; + } - echo $message; + return array('msg'=>$message,'error'=>$error); } @@ -774,11 +833,11 @@ class e_menuManager { global $admin_log,$sql; - if($sql->db_Select('menus', 'menu_name', 'menu_id='.$this->menuId, 'default')) + if($sql->select('menus', 'menu_name', 'menu_id='.$this->menuId, 'default')) { - $row = $sql->db_Fetch(); + $row = $sql->fetch(); //Check to see if menu is already active in the new area, if not then move it - if(!$sql->db_Select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = ".$this->menuNewLoc." AND menu_layout='".$this->dbLayout ."' LIMIT 1")) + if(!$sql->select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = ".$this->menuNewLoc." AND menu_layout='".$this->dbLayout ."' LIMIT 1")) { $menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location=".$this->menuNewLoc); $sql->db_Update("menus", "menu_location='{$this->menuNewLoc}', menu_order=".($menu_count+1)." WHERE menu_id=".$this->menuId); @@ -799,6 +858,7 @@ class e_menuManager { $sql = e107::getDb(); $tp = e107::getParser(); $ns = e107::getRender(); + $frm = e107::getForm(); //FIXME - XHTML cleanup, front-end standards (elist, forms etc) echo "
"; @@ -810,18 +870,20 @@ class e_menuManager { echo "
"; echo $rs->form_open("post", e_SELF."?configure=".$this->curLayout, "menuActivation"); - $text = ""; + $text = "
"; - $text .= ""; - $text .= " + "; + $text .= "
".MENLAN_36."......".MENLAN_37."
"; + $text .= "
".MENLAN_36."......".MENLAN_37."
"; - $sql->db_Select("menus", "menu_name, menu_id, menu_pages, menu_path", "1 GROUP BY menu_name ORDER BY menu_name ASC"); + $sql->select("menus", "menu_name, menu_id, menu_pages, menu_path", "1 GROUP BY menu_name ORDER BY menu_name ASC"); if(!$this->dragDrop) { - $text .= "
"; - $text .= "\n"; + $text .= "
"; + $text .= "
+ \n"; } else @@ -830,7 +892,7 @@ class e_menuManager { } $color = ""; - while ($row = $sql->db_Fetch()) + while ($row = $sql->fetch()) { $pdeta = ""; $color = ($color == "white") ? "#DDDDDD" : "white"; @@ -851,10 +913,20 @@ class e_menuManager { { $menuInf = (strlen($row['menu_path']) > 1) ? ' ('.substr($row['menu_path'],0,-1).')' : ''; $text .= " - - + + \n"; - } + } else { // Menu Choices box. @@ -863,13 +935,13 @@ class e_menuManager { $text .= "\n"; } } - $text .= (!$this->dragDrop) ? "
".$pdeta." "; + + + // $text .= " + //// + // "; + + $text .= $frm->checkbox('menuselect[]',$row['menu_id'],'',array('label'=>$row['menu_name'].$menuInf)); + + $text .= " +   ".$pdeta." 
" : ""; + $text .= (!$this->dragDrop) ? "
" : ""; $text .= "
"; $text .= "
"; foreach ($this->menu_areas as $menu_act) { - $text .= "

\n"; + $text .= "

\n"; } @@ -877,7 +949,7 @@ class e_menuManager { { if(isset($pref['sitetheme_layouts'][$layout]['menuPresets'])) { - $text .= "toJS(MENLAN_41)."')\" />

\n"; // Use Menu Presets + $text .= "toJS(MENLAN_41)."')\" />

\n"; // Use Menu Presets $text .= ""; } $text .= ""; @@ -913,8 +985,8 @@ class e_menuManager { // onchange=\"urljump(this.options[selectedIndex].value);\" $text = "
"; - $text .= "
".MENLAN_30." "; - $text .= "\n"; // window.frames['menu_iframe'].location=this.options[selectedIndex].value ??? $search = array("_","legacyDefault","legacyCustom"); @@ -937,6 +1009,9 @@ class e_menuManager { $text .= "
"; + + // $text .= "
Something here
"; + return $text; } @@ -1087,13 +1162,13 @@ class e_menuManager { $MODE = 1; - $sql9->db_Select("menus", "*", "menu_location='$menu' AND menu_layout='" . $this->dbLayout . "' ORDER BY menu_order"); + $sql9->select("menus", "*", "menu_location='$menu' AND menu_layout='" . $this->dbLayout . "' ORDER BY menu_order"); $menu_count = $sql9->db_Rows(); $cl = ($this->dragDrop) ? "'portlet" : "regularMenu"; $menuText .= "\n
\n\n"; - while($row = $sql9->db_Fetch(MYSQL_ASSOC)) + while($row = $sql9->fetch(MYSQL_ASSOC)) { $menuText .= "\n\n\n \n"; $menuText .= "
\n"; @@ -1190,10 +1265,12 @@ class e_menuManager { { $conf = "{$menu_path}config"; } - +// + // $text = "
"; + $text .= '" : ""; - + $text .= "
"; if(!$this->dragDrop) { @@ -1262,12 +1344,7 @@ class e_menuManager { return $ns->tablerender($caption, $text,'', true); - ob_start(); - $THEX = ob_get_contents(); - ob_end_clean(); - - return $THEX; } else { @@ -1281,25 +1358,55 @@ class e_menuManager { } - function menuSaveAjax() + function menuSaveAjax($mode = null) { - - - $this->debug = TRUE; - global $sql; - - - list($tmp,$area) = explode("-",$_POST['area']); - if($_POST['area'] == 'remove') + if($mode == 'visibility') { - list($tmp,$deleteID) = explode("-",$_POST['removeid']); - $this->menuId = $deleteID; - $this->menuDeactivate(); - echo "Removed {$deleteId}"; + + $ret = $this->menuSaveVisibility(); + echo json_encode($ret); + return; + } + + if($mode == 'delete') + { + list($tmp,$area) = explode("-",$_POST['area']); + + if($_POST['area'] == 'remove') + { + list($tmp,$deleteID) = explode("-",$_POST['removeid']); + $this->menuId = $deleteID; + + $ret = $this->menuDeactivate(); + echo json_encode($ret); + + return; + } + + } + + + if($mode == 'parms') + { + $ret = $this->menuSaveParameters(); + echo json_encode($ret); return; } + + + + print_r($_POST); + return; + + + $this->debug = TRUE; + + $sql = e107::getDb(); + + + // Allow deletion by ajax, but not the rest when drag/drop disabled. @@ -1309,7 +1416,7 @@ class e_menuManager { list($tmp,$insertID) = explode("-",$_POST['insert']); $insert[] = $insertID; - print_r($_POST); + if($_POST['mode'] == 'insert' && count($insert) && $area) // clear out everything before rewriting everything to db. { @@ -1351,8 +1458,8 @@ class e_menuManager { $sql = e107::getDb(); $pref = e107::getPref(); - $sql -> db_Select("menus", "*", "menu_location != 0 ORDER BY menu_path,menu_name"); - while($row = $sql-> db_Fetch()) + $sql -> select("menus", "*", "menu_location != 0 ORDER BY menu_path,menu_name"); + while($row = $sql-> fetch()) { $link = ""; diff --git a/e107_themes/bootstrap/admin_style.css b/e107_themes/bootstrap/admin_style.css index 498b101fc..9bd533968 100644 --- a/e107_themes/bootstrap/admin_style.css +++ b/e107_themes/bootstrap/admin_style.css @@ -83,7 +83,7 @@ a.brand:hover img { } -.modal { min-width:800px } +.modal { min-width:800px; left:42% } @media (min-width: 1500px) { diff --git a/e107_web/js/core/admin.jquery.js b/e107_web/js/core/admin.jquery.js index 77bfc889b..080d52a17 100644 --- a/e107_web/js/core/admin.jquery.js +++ b/e107_web/js/core/admin.jquery.js @@ -34,14 +34,21 @@ $(document).ready(function() $('body').on('hidden', '.modal', function () { $(this).removeData('modal'); $('#uiModal .modal-label').text('Loading...'); - $('#uiModal .modal-body').text(' '); + $('#uiModal .modal-body').html(' '); }); + $('a[data-toggle="modal"]').on('click', function() { var link = $(this).attr('href'); + // $('#uiModal .modal-body').html(link); alert(link); } ); + + + + + /* $('a[data-toggle="modal"]').on('click', function() @@ -333,24 +340,7 @@ $(document).ready(function() $(function() { //$(".e-menumanager-delete").live("click", function(e){ - $(".e-menumanager-delete").click(function(e){ - e.preventDefault(); - var area = 'remove'; - var remove = $(this).attr('id'); - var opt = remove.split('-'); - var hidem = "#block-" + opt[1] +'-' + opt[2]; - $(hidem).hide("slow"); - // alert(hidem); - $.ajax({ - type: "POST", - url: "menus.php?ajax_used=1", - data: { removeid: remove, area: area } - // data: { linkid: linkid, neworder: neworder } - }).done(function( msg ) { - - // alert(msg ); - }); - }); + $( ".column" ).sortable({ connectWith: ".column",