Code

Updated sudo stuff
[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 = 54;
69     if($this->parent->snapshotEnabled()){
70       $action_col_size += 32;
71     }
72     if($this->parent->CopyPasteHandler){
73       $action_col_size += 20;
74     }
76     /* Toggle all selected / deselected */
77     $chk = "<input type='checkbox' id='select_all' name='select_all'
78                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
80     /* set Page header */
81     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
82     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
83     $this->AddHeader(array("string"=>_("Name")."&nbsp;/&nbsp;"._("Department")));
84     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
86     /* Add SubSearch checkbox */    
87     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"),msgPool::selectToView("","subsearch_small"), false);
88     $this->AddRegex   ("Regex"    , _("Regular expression for matching role names")       , 
89       "*" , true);
90     $this->AddRegex   ("UserRegex", _("Regular expression for matching role member names"),
91       "*" , FALSE,"images/search_user.png");
92   }
95   /*! \brief  Generate the list header.
96    */
97   function GenHeader()
98   {
99     /* Prepare departments,
100        which are shown in the listbox on top of the listbox
101      */
102     $base  = sudo::get_sudoers_ou($this->config);
103     $acl   = $this->ui->get_category_permissions($base,"sudo"); 
104  
105     /* Add default header */
106     $listhead = MultiSelectWindow::get_default_header();
107     
108     /* Create Layers menu */
109     $s  = ".|"._("Actions")."|\n";
110     $s .= "..|<img src='images/list_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("/d/",$acl)){
121       $s.= "..|---|\n";
122       $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
123         "&nbsp;"._("Remove")."|"."del_role|\n";
124     }
126     /* Add multiple copy & cut icons */
127     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl)){
128       $s.= "..|---|\n";
129       $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
130         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
131 #      $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
132 #        "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
134       if($this->parent->CopyPasteHandler->entries_queued()){
135         $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
136         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
137       }else{
138         $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
139         $s.="..|".$img."&nbsp;"._("Paste")."\n";
140       }
141     }
144     /* Add snapshot icons */
145     if(preg_match("/(c.*w|w.*c)/",$acl)){
146       $s .= "..|---|\n";
147       $s .= $this->get_snapshot_header(TRUE);
148     }
151     $this->SetDropDownHeaderMenu($s);
152     $this->SetListHeader($listhead);
153   }
156   /*! \brief  Prepare the plguin to list a set of objects 
157    */
158   function execute()
159   {
160     $this->ClearElementsList();
161     $this->GenHeader();
162   }
165   /*! \brief  Create a list of all objects that should be displayed 
166       @param  Array $list   The list of sudo roles, passed from the sudoManagement class.
167    */
168   function setEntries($list)
169   {
170     /* Prepare links */
171     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
172     $userimg  = "<img class='center' src='images/select_sudo.png' alt='Sudo' title='%s'>";
173     $ui       = get_userinfo();
175     $action_col_size = 54;
176     if($this->parent->snapshotEnabled()){
177       $action_col_size += 32;
178     }
179     if($this->parent->CopyPasteHandler){
180       $action_col_size += 20;
181     }
183     // Test Every Entry and generate divlist Array
184     foreach($list as $key => $val){
185     
186       /* Create action icons - copy & paste icons */
187       $acl    = $ui->get_permissions($val['dn'],"sudo/sudo");
189       /* Add edit icon */
190       $actions = "";
192       $actions= "";
193       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl)){
194 #        $actions.= "<input class='center' type='image'
195 #          src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
196         $actions.= "<input class='center' type='image'
197           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
198       }
201       $actions.= "<input class='center' type='image'
202         src='images/edit.png' alt='".msgPool::editButton()."' name='sudo_edit_%KEY%' title='"._("Edit this entry")."'>";
204       if(preg_match("/(c.*w|w.*c)/",$acl)){
205         $actions.= $this->GetSnapShotActions($val['dn']);
206       }
208       if(preg_match("/d/",$acl)){
209         $actions.= "<input class='center' type='image'
210           src='images/edittrash.png' alt='".msgPool::delButton()."' name='sudo_del_%KEY%' title='"._("Delete this entry")."'>";
211       }
213       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
215       if(!isset($val['description'][0])){
216         $desc = "";
217       }else{
218         $desc = " - [ ".$val['description'][0]." ]";
219       }
221       $display = $val['cn'][0].$desc;
222      
223       /* Highlight defaults entry */ 
224       if(preg_match("/^defaults$/i",$val['cn'][0])){
225         $display = "<b>$display</b>";
226       }
228       /* Cutted objects should be displayed in light grey */
229       if($this->parent->CopyPasteHandler){
230         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
231           if($queue_data['dn'] == $val['dn']) {
232             $display = "<font color='#999999'>".$display."</font>";
233             break;
234           }
235         }
236       }
238       $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
239           "attach" => "style='width:20px;'");
240       $field2 = array("string" => sprintf($userimg,$val['dn']), 
241           "attach" => "style='text-align:center;width:20px;'");
242       $field3 = array("string" => sprintf($editlink,$key,$display), 
243           "attach" => "style='' ".$title);
244       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), 
245           "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
247       $this->AddElement(array($field1,$field2,$field3,$field4));
248     }
250     /* Create summary string for list footer */
251     $num     = count($list);
252     $num_str  = _("Number of listed roles");
253     $str = "<img class='center' src='images/select_sudo.png'
254               title='".$num_str."' alt='".$num_str."'>&nbsp;".$num."&nbsp;";
255     $this->set_List_Bottom_Info($str);
256   }
258   
259   /*! \brief  Save this plugin. In this case nothing will be saved
260     */
261   function Save()
262   {
263     MultiSelectWindow :: Save();  
264   }
266   /*! \brief  Save all relevant HTML inputs for this plugin.
267     */
268   function save_object()
269   {
270     /* Save automatic created POSTs like regex, checkboxes */
271     MultiSelectWindow::save_object();   
272   }
274 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
275 ?>