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 = 50;
69     if($this->parent->snapshotEnabled()){
70       $action_col_size += 38;
71     }
73     /* Toggle all selected / deselected */
74     $chk = "<input type='checkbox' id='select_all' name='select_all'
75                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
77     /* set Page header */
78     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
79     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
80     $this->AddHeader(array("string"=>_("Name")."&nbsp;/&nbsp;"._("Department")));
81     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
83     /* Add SubSearch checkbox */    
84     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"),msgPool::selectToView("","subsearch_small"), false);
85     $this->AddRegex   ("Regex"    , _("Regular expression for matching role names")       , 
86       "*" , true);
87     $this->AddRegex   ("UserRegex", _("Regular expression for matching role member names"),
88       "*" , FALSE,"images/search_user.png");
89   }
92   /*! \brief  Generate the list header.
93    */
94   function GenHeader()
95   {
96     /* Prepare departments,
97        which are shown in the listbox on top of the listbox
98      */
99     $base  = sudo::get_sudoers_ou($this->config);
100     $acl   = $this->ui->get_category_permissions($base,"sudo"); 
101  
102     /* Add default header */
103     $listhead = MultiSelectWindow::get_default_header();
104     
105     /* Create Layers menu */
106     $s  = ".|"._("Actions")."|\n";
107     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
108       "&nbsp;"._("Create")."|\n";
110     /* Append create options */
111     if(preg_match("/c/",$acl)) {
112       $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''>&nbsp;"._("Role")."|new_role|\n";
113       $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''>&nbsp;"._("Default")."|new_default|\n";
114     }
116     /* Append multiple remove */
117     if(preg_match("/d/",$acl)){
118       $s.= "..|---|\n";
119       $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
120         "&nbsp;"._("Remove")."|"."del_role|\n";
121     }
123     /* Add snapshot icons */
124     if(preg_match("/(c.*w|w.*c)/",$acl)){
125       $s .= "..|---|\n";
126       $s .= $this->get_snapshot_header(TRUE);
127     }
130     $this->SetDropDownHeaderMenu($s);
131     $this->SetListHeader($listhead);
132   }
135   /*! \brief  Prepare the plguin to list a set of objects 
136    */
137   function execute()
138   {
139     $this->ClearElementsList();
140     $this->GenHeader();
141   }
144   /*! \brief  Create a list of all objects that should be displayed 
145       @param  Array $list   The list of sudo roles, passed from the sudoManagement class.
146    */
147   function setEntries($list)
148   {
149     /* Prepare links */
150     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
151     $userimg  = "<img class='center' src='images/select_sudo.png' alt='Sudo' title='%s'>";
152     $ui       = get_userinfo();
154     $action_col_size = 50;
155     if($this->parent->snapshotEnabled()){
156       $action_col_size += 38;
157     }
159     // Test Every Entry and generate divlist Array
160     foreach($list as $key => $val){
161     
162       /* Create action icons - copy & paste icons */
163       $acl    = $ui->get_permissions($val['dn'],"sudo/sudo");
165       /* Add edit icon */
166       $actions = "";
167       $actions.= "<input class='center' type='image'
168         src='images/edit.png' alt='".msgPool::editButton()."' name='sudo_edit_%KEY%' title='"._("Edit this entry")."'>";
170       if(preg_match("/(c.*w|w.*c)/",$acl)){
171         $actions.= $this->GetSnapShotActions($val['dn']);
172       }
174       if(preg_match("/d/",$acl)){
175         $actions.= "<input class='center' type='image'
176           src='images/edittrash.png' alt='".msgPool::delButton()."' name='sudo_del_%KEY%' title='"._("Delete this entry")."'>";
177       }
179       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
181       if(!isset($val['description'][0])){
182         $desc = "";
183       }else{
184         $desc = " - [ ".$val['description'][0]." ]";
185       }
187       $display = $val['cn'][0].$desc;
188      
189       /* Highlight defaults entry */ 
190       if(preg_match("/^defaults$/i",$val['cn'][0])){
191         $display = "<b>$display</b>";
192       }
194       $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
195           "attach" => "style='width:20px;'");
196       $field2 = array("string" => sprintf($userimg,$val['dn']), 
197           "attach" => "style='text-align:center;width:20px;'");
198       $field3 = array("string" => sprintf($editlink,$key,$display), 
199           "attach" => "style='' ".$title);
200       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), 
201           "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
203       $this->AddElement(array($field1,$field2,$field3,$field4));
204     }
206     /* Create summary string for list footer */
207     $num     = count($list);
208     $num_str  = _("Number of listed roles");
209     $str = "<img class='center' src='images/select_sudo.png'
210               title='".$num_str."' alt='".$num_str."'>&nbsp;".$num."&nbsp;";
211     $this->set_List_Bottom_Info($str);
212   }
214   
215   /*! \brief  Save this plugin. In this case nothing will be saved
216     */
217   function Save()
218   {
219     MultiSelectWindow :: Save();  
220   }
222   /*! \brief  Save all relevant HTML inputs for this plugin.
223     */
224   function save_object()
225   {
226     /* Save automatic created POSTs like regex, checkboxes */
227     MultiSelectWindow::save_object();   
228   }
230 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
231 ?>