Hide Administrator options

otografias

Joined: 2011-10-20
Posts: 41
Posted: Wed, 2013-10-30 17:28

Hello everybody!
Im making a gallery site that will be administrate for another photographs. they are so good photographers as bumbling in computer, so i don't want to be worried about what are they doing in the site.
I try to hide links in administrator menu, all links except admin users, manage comments, Edit Tags, and maintenance.

At the time:

1) Duplicate theme, and in a new theme, in "screen.CSS" file of my new theme folder copy this code that i find in forums

#g-site-menu li:nth-child(4) {
display: none;
}
its and works great!

2) Duplicate admin theme too, and hide all menu, removing <?= $theme->admin_menu() ?> from admin.html.php

3) Hide home link and

4) Use Custom menus to make a new administrator menu linked to
/admin/user
/admin/manage_comments
etc...

all ok but have two bugs (known at this time).
this menu its visible for all users (only admin can use but its is very ugly)
when admin session expires and and displays the page "reautenticate" the original admin menu reappears mysteriously.

At the moment I´m tried to add the same of "custom menus" links to a "pages settings" module. a new page only visible by admin. its posible?
any other help would be welcome

thanks to all

 
tempg

Joined: 2005-12-17
Posts: 1857
Posted: Wed, 2013-10-30 18:11
otografias wrote:
this menu its visible for all users (only admin can use but its is very ugly)

I think you can wrap the admin part in an if statement that shows only if $user->admin or is_admin is true.

I'm not 100% sure, but try if($user->admin){ ADMIN MENU HERE; }

EDIT: As a side note, couldn't you just add them as a user with all of the permissions they'll need? You'd be the only true admin, but they could do whatever else needs to be done on the site.

 
otografias

Joined: 2011-10-20
Posts: 41
Posted: Wed, 2013-10-30 18:46

Not sure about how to do it.

adding code to module "custom menu" will hide menu to no admin users?

sorry for dumbs questions but I'm just a photographer, and is a little hard for me to work with programming... :-S

Quote:
EDIT: As a side note, couldn't you just add them as a user with all of the permissions they'll need? You'd be the only true admin, but they could do whatever else needs to be done on the site.

I don´t know the way to make a user permission to admins users....
I would like to build the site, assign one admin, to administrate content, users and comments, and forget the site in assured that I will not give me problems.
thanks
:-).

 
tempg

Joined: 2005-12-17
Posts: 1857
Posted: Wed, 2013-10-30 18:54
otografias wrote:
adding code to module "custom menu" will hide menu to no admin users?

I don't know the details of how you made the custom menu.
Go to whatever file you made the menu in. Then go to the line where the code for the menu starts and add this line BEFORE the menu code: if($user->admin){. Then go to the end of the code for the custom menu and add this line AFTER the code: }
See if it works.

otografias wrote:
and forget the site in assured that I will not give me problems

You still need to make periodic backups of the site contents/code and database.

 
otografias

Joined: 2011-10-20
Posts: 41
Posted: Thu, 2013-10-31 09:46

I give up! :-P
i made my own administrator menu with a module "Custom Menus", i tried to insert your code in in several different sites of "admin_custom_menus.html.php" file in "Controllers" folder, but it´s too extensive and complicate language to me.... (I am very happy to keep things running yet... after so many changes... xD

If somebody would find the site where the code print the menu on page... i would be so grateful!

Quote:
<?php defined("SYSPATH") or die("No direct script access.");
if($user->admin){
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Admin_Custom_Menus_Controller extends Admin_Controller {
public function index() {
// Display the admin page, which contains a list of existing menu items.
$view = new Admin_View("admin.html");
$view->page_title = t("Manage menus");
$view->content = new View("admin_custom_menus.html");
$view->content->menu_list = $this->get_html_list(0);
print $view;
}

public function form_create($id) {
// Display the create new menu form.
print $this->get_new_menu_form($id);
}

public function form_edit($id) {
// Display the edit menu form.
print $this->get_edit_menu_form($id);
}

static function get_new_menu_form($id) {
// Generate the create new menu form.
$form = new Forge("admin/custom_menus/create/$id", "", "post", array("id" => "g-create-menu-form"));
$group = $form->group("create_menu")
->label(t("Add new menu"));
$group->input("menu_title")
->label(t("Title"));
$group->input("menu_url")
->label(t("URL (Leave blank if this menu will have sub-menus)"));
$group->submit("")->value(t("Create menu"));
return $form;
}

static function get_edit_menu_form($id) {
// Generate the edit menu form.
$existing_menu = ORM::factory("custom_menu", $id);
$form = new Forge("admin/custom_menus/edit/$id", "", "post", array("id" => "g-edit-menu-form"));
$group = $form->group("edit_menu")
->label(t("Edit menu"));
$group->input("menu_title")
->label(t("Title"))
->value($existing_menu->title);
$group->input("menu_url")
->label(t("URL (Leave blank if this menu will have sub-menus)"))
->value($existing_menu->url);
$group->submit("")->value(t("Save changes"));
return $form;
}

public function create($id) {
// Save a new menu to the database.

access::verify_csrf();

// Save form variables to the database.
$new_menu = ORM::factory("custom_menu");
$new_menu->title = Input::instance()->post("menu_title");
$new_menu->url = Input::instance()->post("menu_url");
$new_menu->parent_id = $id;

// Set menu's location to the last position.
$existing_menu = ORM::factory("custom_menu")
->where("parent_id", "=", $id)
->order_by("order_by", "DESC")
->find_all(1);
if (count($existing_menu) > 0) {
$int_position = $existing_menu[0]->order_by;
$int_position++;
$new_menu->order_by = $int_position;
} else {
$new_menu->order_by = 0;
}

// Save new menu to the database.
$new_menu->save();
message::success(t("Menu %menu_name created", array("menu_name" => $new_menu->title)));
log::success("custom_menus", t("Menu %menu_name created", array("menu_name" => $new_menu->title)));
json::reply(array("result" => "success"));
}

public function edit($id) {
// Save a new menu to the database.

access::verify_csrf();

// Load the existing menu and save changes.
$existing_menu = ORM::factory("custom_menu", $id);
if ($existing_menu->loaded()) {
$existing_menu->title = Input::instance()->post("menu_title");
$existing_menu->url = Input::instance()->post("menu_url");
$existing_menu->save();
message::success(t("Menu %menu_name saved", array("menu_name" => $existing_menu->title)));
log::success("custom_menus", t("Menu %menu_name saved", array("menu_name" => $existing_menu->title)));
json::reply(array("result" => "success"));
} else {
message::error(t("Unable to load menu %menu_id", array("menu_id" => $id)));
log::success("custom_menus", t("Unable to load menu %menu_id", array("menu_id" => $id)));
json::reply(array("result" => "success"));
}
}

function get_html_list($parent_id) {
// Generate an HTML list of existing menu items.
$existing_menu = ORM::factory("custom_menu")
->where("parent_id", "=", $parent_id)
->order_by("order_by", "ASC")
->find_all();
$str_html = "";
if (count($existing_menu) > 0) {
$str_html = "<ul style=\"margin-bottom: 0em; margin-left: 2.5em;\">\n";
foreach ($existing_menu as $one_menu) {
$str_html .= "<li style=\"list-style:disc outside none; margin: 1em; line-height: 1em;\">" . $one_menu->title .
" <a href=\"" . url::site("admin/custom_menus/form_create/" . $one_menu->id) .
"\" class=\"g-dialog-link ui-icon-plus g-button ui-icon-left\" title=\"" . t("Add sub menu") .
"\"><span class=\"ui-icon ui-icon-plus\"></span></a>" .
" <a href=\"" . url::site("admin/custom_menus/form_edit/" . $one_menu->id) .
"\" class=\"g-dialog-link ui-icon-pencil g-button ui-icon-left\" title=\"" . t("Edit menu") .
"\"><span class=\"ui-icon ui-icon-pencil\"></span></a>" .
" <a href=\"" . url::site("admin/custom_menus/form_delete/" . $one_menu->id) .
"\" class=\"g-dialog-link ui-icon-trash g-button ui-icon-left\" title=\"" . t("Delete menu") .
"\"><span class=\"ui-icon ui-icon-trash\"></span></a>" .
" <a href=\"" . url::site("admin/custom_menus/move_menu_up/" . $one_menu->id) .
"\" class=\"g-button ui-icon-left\" title=\"" . t("Move menu up") .
"\">^</a>" .
" <a href=\"" . url::site("admin/custom_menus/move_menu_down/" . $one_menu->id) .
"\" class=\"g-button ui-icon-left\" title=\"" . t("Move menu down") .
"\">v</a>" .
"</li>\n";
$str_html .= $this->get_html_list($one_menu->id);
}
$str_html .= "</ul>\n";
}
return $str_html;
}

public function form_delete($id) {
// Display a form asking the user if they want to delete a menu.
$one_menu = ORM::factory("custom_menu", $id);
if ($one_menu->loaded()) {
print $this->get_delete_form($one_menu);
}
}

public function delete($id) {
// Delete the specified menu.

access::verify_csrf();

// Make sure $id belongs to an actual menu.
$one_menu = ORM::factory("custom_menu", $id);
if (!$one_menu->loaded()) {
throw new Kohana_404_Exception();
}

// If the form validates, delete the specified menu.
$form = $this->get_delete_form($one_menu);
if ($form->validate()) {
$name = $one_menu->title;
$this->delete_sub_menus($one_menu->id);
$one_menu->delete();
message::success(t("Deleted menu %menu_name", array("menu_name" => $name)));
log::success("custom_menus", t("Deleted menu %menu_name", array("menu_name" => $name)));
json::reply(array("result" => "success", "location" => url::site("admin/custom_menus")));
} else {
print $form;
}
}

function delete_sub_menus($parent_id) {
// Delete all sub menus associated with $parent_id.
$existing_menu = ORM::factory("custom_menu")
->where("parent_id", "=", $parent_id)
->order_by("title", "ASC")
->find_all();
foreach ($existing_menu as $one_menu) {
$this->delete_sub_menus($one_menu->id);
$one_menu->delete();
}
}

static function get_delete_form($one_menu) {
// Generate a new form asking the user if they want to delete a menu.
$form = new Forge("admin/custom_menus/delete/$one_menu->id", "", "post", array("id" => "g-delete-menu-form"));
$group = $form->group("delete_menu")
->label(t("Really delete menu %menu_name & sub-menus?", array("menu_name" => $one_menu->title)));
$group->submit("")->value(t("Delete Menu"));
return $form;
}

public function move_menu_up($id) {
// Move the specified menu item up one position.
$one_menu = ORM::factory("custom_menu", $id);
if ($one_menu->loaded()) {
$existing_menu = ORM::factory("custom_menu")
->where("parent_id", "=", $one_menu->parent_id)
->where("order_by", "<", $one_menu->order_by)
->order_by("order_by", "DESC")
->find_all(1);
if (count($existing_menu) > 0) {
$second_menu = ORM::factory("custom_menu", $existing_menu[0]->id);
$temp_position = $one_menu->order_by;
$one_menu->order_by = $second_menu->order_by;
$second_menu->order_by = $temp_position;
$one_menu->save();
$second_menu->save();
message::success(t("Menu %menu_title moved up", array("menu_title" => $one_menu->title)));
log::success("custom_menus", t("Menu %menu_title moved up", array("menu_title" => $one_menu->title)));
}
}
url::redirect("admin/custom_menus");
}

public function move_menu_down($id) {
// Move the specified menu item down one position.
$one_menu = ORM::factory("custom_menu", $id);
if ($one_menu->loaded()) {
$existing_menu = ORM::factory("custom_menu")
->where("parent_id", "=", $one_menu->parent_id)
->where("order_by", ">", $one_menu->order_by)
->order_by("order_by", "ASC")
->find_all(1);
if (count($existing_menu) > 0) {
$second_menu = ORM::factory("custom_menu", $existing_menu[0]->id);
$temp_position = $one_menu->order_by;
$one_menu->order_by = $second_menu->order_by;
$second_menu->order_by = $temp_position;
$one_menu->save();
$second_menu->save();
message::success(t("Menu %menu_title moved down", array("menu_title" => $one_menu->title)));
log::success("custom_menus", t("Menu %menu_title moved down", array("menu_title" => $one_menu->title)));
}
}
url::redirect("admin/custom_menus");
}
}
}

 
tempg

Joined: 2005-12-17
Posts: 1857
Posted: Thu, 2013-10-31 12:55

Restore that file back to its original state.

Open the views file.

Try adding <? if($user->admin){ ?> between the first and second lines.
Then add <? } ?> to the end of the file.

 
otografias

Joined: 2011-10-20
Posts: 41
Posted: Fri, 2013-11-01 19:15

Ups... nothing change

in folder

/modules/Custom_menus/view/admin_custom_menus.html.php

I would be modify to this way:

Quote:
<?php defined("SYSPATH") or die("No direct script access.") ?>
<? if($user->admin){ ?>
<div class="g-block">
<h1> <?= t("Manage menus") ?> </h1>
<div class="g-block-content">
<a href="<?= url::site("admin/custom_menus/form_create/0") ?>" class="g-dialog-link g-create-link"><?= t("Add new menu") ?></a>
<?= $menu_list ?>
</div>
</div>
<? } ?>

i think its ok... but nothing change
you can see in

bodas.otografias.com

thanks for your time :-)

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Fri, 2013-11-01 21:41
Quote:
4) Use Custom menus to make a new administrator menu linked to
/admin/user
/admin/manage_comments
etc...

Why? Why not just use the regular menu for access these functions then they show properly checking permissions along the way.

Your going to have to edit the module to remove them. Then I suspect in the future your going to add items to the menu that the guest or others will have access to and then your going to wonder why they don;t show up for them.
The custom menu module was not really designed for adding shortcuts to the menu for admin functions. Perhaps bookmarks in your browser is a better way to go?

one could hide the li with jquery :
$( ".target" ).hide();
where .target this the jquery selector you want to hide.

lots of jquery tutorials on selectors on the web.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
otografias

Joined: 2011-10-20
Posts: 41
Posted: Mon, 2013-11-04 17:54

I tried with all my might, but i´m afraid jquery its to mess to me. don´t understand anything, its more easy to me try to do in a classical html.

think its possible?

 
otografias

Joined: 2011-10-20
Posts: 41
Posted: Sun, 2013-11-10 16:46

I´m very delighted. you used Jquery to delete options?

 
otografias

Joined: 2011-10-20
Posts: 41
Posted: Fri, 2013-11-15 19:39

Im Very Near to get it!
last news,

I Resume :

1) I change the theme to clean-canvas.
2) Delete admin menu in same way:

Quote:
#g-site-menu li:nth-child(4) {
display: none;

3) In Module Pages create a Page called "Administrator_Menu" and hide in top menu bar (put only in sidebar)
4) In the page paste links only to admin users and moderate comments

Problems:
when go to the created "Administrator menu" Page, in the "top menu" returns admin options!!... of course. i Hide only "nth-child(4)", and menu its now child(1) Ups!

i find the code to hide this menu definitely, using "Safari Develop menu" but... I can´t find in themes files.

Here you can see a graphical explain of the problem and a possible solution
thanks!

 
otografias

Joined: 2011-10-20
Posts: 41
Posted: Fri, 2013-12-20 20:59

thanks Temp!!!

i make my own admin menu with "Pages" module, adding link in sidebar, and it´s only visible for admins because insert your code in module Pages/views/pages_sidebar.html.php

Quote:
<?php defined("SYSPATH") or die("No direct script access.") ?>
<? if($user->admin){ ?>
<?= $links ?>
<? } ?>

all ok!!
:-)

only need the way to permanently hide the admin menu for all users

in the next Post may be...
:-) thanks to all