Code

Updated snapshot stuff, check acls here too.
[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   private $departments        = array();
33   /* Regex */
34   public $Regex              = "*";
35   public $UserRegex          = "*";
37   /* Subsearch checkbox */
38   public $SubSearch          = FALSE;
39   protected $parent             ;
40   public $ui                 ;
43   /*! \brief  Initialize this class 
44       @param  Object $config  The GOsa configuration object.
45       @param  Object $parent  The parent class.
46    */
47   function divListSudo (&$config, &$parent)
48   {
49     MultiSelectWindow::MultiSelectWindow($config, "sudo", "sudo");
50     
51     $this->parent       = &$parent;
52     $this->ui           = get_userinfo();
54     /* Set list strings */
55     $this->SetTitle(  _("List of sudo roles"));
56     $this->SetSummary(_("List of sudo roles"));
57     $this->EnableAplhabet(true);
59     /* Result page will look like a headpage */
60     $this->SetHeadpageMode();
61   
62     /* Disable buttonsm */
63     $this->EnableCloseButton(false);
64     $this->EnableSaveButton (false);
66     /* Dynamic action col, depending on snapshot icons */
67     $action_col_size = 54;
68     if($this->parent->snapshotEnabled()){
69       $action_col_size += 32;
70     }
71     if($this->parent->CopyPasteHandler){
72       $action_col_size += 20;
73     }
75     /* Toggle all selected / deselected */
76     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
77                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
79     /* set Page header */
80     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
81     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
82     $this->AddHeader(array("string"=>_("Name")."&nbsp;/&nbsp;"._("Department")));
83     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
85     /* Add SubSearch checkbox */    
86     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"),msgPool::selectToView("","subsearch_small"), false);
87     $this->AddRegex   ("Regex"    , _("Regular expression for matching role names")       , 
88       "*" , true);
89     $this->AddRegex   ("UserRegex", _("Regular expression for matching role member names"),
90       "*" , FALSE,"images/lists/search-user.png");
91   }
94   /*! \brief  Generate the list header.
95    */
96   function GenHeader()
97   {
98     /* Prepare departments,
99        which are shown in the listbox on top of the listbox
100      */
101     $base  = sudo::get_sudoers_ou($this->config);
102     $acl    = $this->ui->get_permissions($base,"sudo/sudo"); 
103     $acl_all= $this->ui->get_category_permissions($base,"sudo"); 
104  
105     /* Add default header */
106     $listhead = MultiSelectWindow::get_default_header(false);
107     
108     /* Create Layers menu */
109     $s  = ".|"._("Actions")."|\n";
110     $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
111       "&nbsp;"._("Create")."|\n";
113     /* Append create options */
114     if(preg_match("/c/",$acl)) {
115       $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''>&nbsp;"._("Role")."|new_role|\n";
116       $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''>&nbsp;"._("Default")."|new_default|\n";
117     }
119     /* Append multiple remove */
120     if(preg_match("/r/",$acl)){
121       $s.= "..|---|\n";
122       $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
123         "&nbsp;"._("Remove")."|"."del_role|\n";
124     }
126     /* Add Copy & Paste header */
127     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
129     /* Add snapshot icons */
130     $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);   
131  
132     $this->SetDropDownHeaderMenu($s);
133     $this->SetListHeader($listhead);
134   }
137   /*! \brief  Prepare the plguin to list a set of objects 
138    */
139   function execute()
140   {
141     $this->ClearElementsList();
142     $this->GenHeader();
143   }
146   /*! \brief  Create a list of all objects that should be displayed 
147       @param  Array $list   The list of sudo roles, passed from the sudoManagement class.
148    */
149   function setEntries($list)
150   {
151     /* Prepare links */
152     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
153     $userimg  = "<img class='center' src='images/select_sudo.png' alt='Sudo' title='%s'>";
154     $ui       = get_userinfo();
156     $action_col_size = 54;
157     if($this->parent->snapshotEnabled()){
158       $action_col_size += 32;
159     }
160     if($this->parent->CopyPasteHandler){
161       $action_col_size += 20;
162     }
164     // Test Every Entry and generate divlist Array
165     foreach($list as $key => $val){
166     
167       /* Create action icons - copy & paste icons */
168       $acl    = $ui->get_permissions($val['dn'],"sudo/sudo");
169       $acl_all= $this->ui->get_category_permissions($val['dn'],"sudo"); 
171       /* Add copy & cut functionality */
172       $actions = $this->parent->get_copypaste_action($val['dn'],"sudo","sudo",TRUE,FALSE);
174       $actions.= "<input class='center' type='image'
175         src='images/lists/edit.png' alt='".msgPool::editButton()."' name='sudo_edit_%KEY%' title='"._("Edit this entry")."'>";
177       /* Add snapshot icon */
178       $actions.= $this->parent->get_snapshot_action($val['dn'],$this->module);
180       if(preg_match("/d/",$acl)){
181         $actions.= "<input class='center' type='image'
182           src='images/lists/trash.png' alt='".msgPool::delButton()."' name='sudo_del_%KEY%' title='"._("Delete this entry")."'>";
183       }
185       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
187       if(!isset($val['description'][0])){
188         $desc = "";
189       }else{
190         $desc = " - [ ".$val['description'][0]." ]";
191       }
193       $display = $val['cn'][0].$desc;
194      
195       /* Highlight defaults entry */ 
196       if(preg_match("/^defaults$/i",$val['cn'][0])){
197         $display = "<b>$display</b>";
198       }
200       /* Cutted objects should be displayed in light grey */
201       if($this->parent->CopyPasteHandler){
202         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
203           if($queue_data['dn'] == $val['dn']) {
204             $display = "<font color='#999999'>".$display."</font>";
205             break;
206           }
207         }
208       }
210       $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
211           "attach" => "style='width:20px;'");
212       $field2 = array("string" => sprintf($userimg,$val['dn']), 
213           "attach" => "style='text-align:center;width:20px;'");
214       $field3 = array("string" => sprintf($editlink,$key,$display), 
215           "attach" => "style='' ".$title);
216       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), 
217           "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
219       $this->AddElement(array($field1,$field2,$field3,$field4));
220     }
222     /* Create summary string for list footer */
223     $num     = count($list);
224     $num_str  = _("Number of listed roles");
225     $str = "<img class='center' src='images/select_sudo.png'
226               title='".$num_str."' alt='".$num_str."'>&nbsp;".$num."&nbsp;";
227     $this->set_List_Bottom_Info($str);
228   }
230   
231   /*! \brief  Save this plugin. In this case nothing will be saved
232     */
233   function Save()
234   {
235     MultiSelectWindow :: Save();  
236   }
238   /*! \brief  Save all relevant HTML inputs for this plugin.
239     */
240   function save_object()
241   {
242     /* Save automatic created POSTs like regex, checkboxes */
243     MultiSelectWindow::save_object();   
244   }
246 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
247 ?>