Code

Updated sudo
[gosa.git] / gosa-plugins / sudo / admin / sudo / class_divListSudo.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id: class_divListSudSudo.inc 9934 2008-03-18 20:26:47Z cajus $$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
24 /*! \brief  The sudo management class.
25             This class lists all configured sudo roles.
26  */
27 class divListSudo extends MultiSelectWindow
28 {
30   /* Current base */
31   var $selectedBase       = "";
32   var $departments        = array();
34   /* Regex */
35   var $Regex              = "*";
36   var $UserRegex          = "*";
38   /* Subsearch checkbox */
39   var $SubSearch          = FALSE;
40   var $parent             ;
41   var $ui                 ;
44   /*! \brief  Initialize this class 
45       @param  Object $config  The GOsa configuration object.
46       @param  Object $parent  The parent class.
47    */
48   function divListSudo (&$config, &$parent)
49   {
50     MultiSelectWindow::MultiSelectWindow($config, "sudo", "sudo");
51     
52     $this->parent       = &$parent;
53     $this->ui           = get_userinfo();
55     /* Set list strings */
56     $this->SetTitle(  _("List of sudo roles"));
57     $this->SetSummary(_("List of sudo roles"));
58     $this->EnableAplhabet(true);
60     /* Result page will look like a headpage */
61     $this->SetHeadpageMode();
62   
63     /* Disable buttonsm */
64     $this->EnableCloseButton(false);
65     $this->EnableSaveButton (false);
67     /* Dynamic action col, depending on snapshot icons */
68     $action_col_size = 80;
70     /* Toggle all selected / deselected */
71     $chk = "<input type='checkbox' id='select_all' name='select_all'
72                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
74     /* set Page header */
75     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
76     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
77     $this->AddHeader(array("string"=>_("Name")."&nbsp;/&nbsp;"._("Department")));
78     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
80     /* Add SubSearch checkbox */    
81     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"),msgPool::selectToView("","subsearch_small"), false);
82     $this->AddRegex   ("Regex"    , _("Regular expression for matching role names")       , 
83       "*" , true);
84     $this->AddRegex   ("UserRegex", _("Regular expression for matching role member names"),
85       "*" , FALSE,"images/search_user.png");
86   }
89   /*! \brief  Generate the list header.
90    */
91   function GenHeader()
92   {
93     /* Prepare departments,
94        which are shown in the listbox on top of the listbox
95      */
96     $base  = sudo::get_sudoers_ou($this->config);
97     $acl   = $this->ui->get_category_permissions($base,"sudo"); 
98  
99     /* Add default header */
100     $listhead = MultiSelectWindow::get_default_header();
101     
102     /* Create Layers menu */
103     $s  = ".|"._("Actions")."|\n";
104     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
105       "&nbsp;"._("Create")."|\n";
107     /* Append create options */
108     if(preg_match("/c/",$acl)) {
109       $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''>&nbsp;"._("Role")."|new_role|\n";
110       $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''>&nbsp;"._("Default")."|new_default|\n";
111     }
113     /* Append multiple remove */
114     if(preg_match("/d/",$acl)){
115       $s.= "..|---|\n";
116       $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
117         "&nbsp;"._("Remove")."|"."del_role|\n";
118     }
120     $this->SetDropDownHeaderMenu($s);
121     $this->SetListHeader($listhead);
122   }
125   /*! \brief  Prepare the plguin to list a set of objects 
126    */
127   function execute()
128   {
129     $this->ClearElementsList();
130     $this->GenHeader();
131   }
134   /*! \brief  Create a list of all objects that should be displayed 
135       @param  Array $list   The list of sudo roles, passed from the sudoManagement class.
136    */
137   function setEntries($list)
138   {
139     /* Prepare links */
140     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
141     $userimg  = "<img class='center' src='images/select_sudo.png' alt='Sudo' title='%s'>";
142     $ui       = get_userinfo();
144     $action_col_size = 80;
146     // Test Every Entry and generate divlist Array
147     foreach($list as $key => $val){
148     
149       /* Create action icons - copy & paste icons */
150       $acl    = $ui->get_permissions($val['dn'],"sudo/sudo");
152       /* Add edit icon */
153       $actions = "";
154       $actions.= "<input class='center' type='image'
155         src='images/edit.png' alt='".msgPool::editButton()."' name='sudo_edit_%KEY%' title='"._("Edit this entry")."'>";
157       if(preg_match("/d/",$acl)){
158         $actions.= "<input class='center' type='image'
159           src='images/edittrash.png' alt='".msgPool::delButton()."' name='sudo_del_%KEY%' title='"._("Delete this entry")."'>";
160       }
162       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
164       if(!isset($val['description'][0])){
165         $desc = "";
166       }else{
167         $desc = " - [ ".$val['description'][0]." ]";
168       }
170       $display = $val['cn'][0].$desc;
171      
172       /* Highlight defaults entry */ 
173       if(preg_match("/^defaults$/i",$val['cn'][0])){
174         $display = "<b>$display</b>";
175       }
177       $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
178           "attach" => "style='width:20px;'");
179       $field2 = array("string" => sprintf($userimg,$val['dn']), 
180           "attach" => "style='text-align:center;width:20px;'");
181       $field3 = array("string" => sprintf($editlink,$key,$display), 
182           "attach" => "style='' ".$title);
183       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), 
184           "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
186       $this->AddElement(array($field1,$field2,$field3,$field4));
187     }
189     /* Create summary string for list footer */
190     $num     = count($list);
191     $num_str  = _("Number of listed roles");
192     $str = "<img class='center' src='images/select_sudo.png'
193               title='".$num_str."' alt='".$num_str."'>&nbsp;".$num."&nbsp;";
194     $this->set_List_Bottom_Info($str);
195   }
197   
198   /*! \brief  Save this plugin. In this case nothing will be saved
199     */
200   function Save()
201   {
202     MultiSelectWindow :: Save();  
203   }
205   /*! \brief  Save all relevant HTML inputs for this plugin.
206     */
207   function save_object()
208   {
209     /* Save automatic created POSTs like regex, checkboxes */
210     MultiSelectWindow::save_object();   
211   }
213 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
214 ?>