Code

list base image migration for gosa-plugins
[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'
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/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_category_permissions($base,"sudo"); 
103  
104     /* Add default header */
105     $listhead = MultiSelectWindow::get_default_header();
106     
107     /* Create Layers menu */
108     $s  = ".|"._("Actions")."|\n";
109     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
110       "&nbsp;"._("Create")."|\n";
112     /* Append create options */
113     if(preg_match("/c/",$acl)) {
114       $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''>&nbsp;"._("Role")."|new_role|\n";
115       $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''>&nbsp;"._("Default")."|new_default|\n";
116     }
118     /* Append multiple remove */
119     if(preg_match("/d/",$acl)){
120       $s.= "..|---|\n";
121       $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
122         "&nbsp;"._("Remove")."|"."del_role|\n";
123     }
125     /* Add multiple copy & cut icons */
126     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl)){
127       $s.= "..|---|\n";
128       $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
129         "&nbsp;"._("Copy")."|"."multiple_copy_sudo|\n";
130 #      $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
131 #        "&nbsp;"._("Cut")."|"."multiple_cut_sudo|\n";
133       if($this->parent->CopyPasteHandler->entries_queued()){
134         $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
135         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
136       }else{
137         $img = "<img border='0' class='center' src='images/cant_lists/paste.png' alt=''>";
138         $s.="..|".$img."&nbsp;"._("Paste")."\n";
139       }
140     }
143     /* Add snapshot icons */
144     if(preg_match("/(c.*w|w.*c)/",$acl)){
145       $s .= "..|---|\n";
146       $s .= $this->get_snapshot_header(TRUE);
147     }
150     $this->SetDropDownHeaderMenu($s);
151     $this->SetListHeader($listhead);
152   }
155   /*! \brief  Prepare the plguin to list a set of objects 
156    */
157   function execute()
158   {
159     $this->ClearElementsList();
160     $this->GenHeader();
161   }
164   /*! \brief  Create a list of all objects that should be displayed 
165       @param  Array $list   The list of sudo roles, passed from the sudoManagement class.
166    */
167   function setEntries($list)
168   {
169     /* Prepare links */
170     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
171     $userimg  = "<img class='center' src='images/select_sudo.png' alt='Sudo' title='%s'>";
172     $ui       = get_userinfo();
174     $action_col_size = 54;
175     if($this->parent->snapshotEnabled()){
176       $action_col_size += 32;
177     }
178     if($this->parent->CopyPasteHandler){
179       $action_col_size += 20;
180     }
182     // Test Every Entry and generate divlist Array
183     foreach($list as $key => $val){
184     
185       /* Create action icons - copy & paste icons */
186       $acl    = $ui->get_permissions($val['dn'],"sudo/sudo");
188       /* Add edit icon */
189       $actions = "";
191       $actions= "";
192       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl)){
193 #        $actions.= "<input class='center' type='image'
194 #          src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
195         $actions.= "<input class='center' type='image'
196           src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
197       }
200       $actions.= "<input class='center' type='image'
201         src='images/edit.png' alt='".msgPool::editButton()."' name='sudo_edit_%KEY%' title='"._("Edit this entry")."'>";
203       if(preg_match("/(c.*w|w.*c)/",$acl)){
204         $actions.= $this->GetSnapShotActions($val['dn']);
205       }
207       if(preg_match("/d/",$acl)){
208         $actions.= "<input class='center' type='image'
209           src='images/lists/trash.png' alt='".msgPool::delButton()."' name='sudo_del_%KEY%' title='"._("Delete this entry")."'>";
210       }
212       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
214       if(!isset($val['description'][0])){
215         $desc = "";
216       }else{
217         $desc = " - [ ".$val['description'][0]." ]";
218       }
220       $display = $val['cn'][0].$desc;
221      
222       /* Highlight defaults entry */ 
223       if(preg_match("/^defaults$/i",$val['cn'][0])){
224         $display = "<b>$display</b>";
225       }
227       /* Cutted objects should be displayed in light grey */
228       if($this->parent->CopyPasteHandler){
229         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
230           if($queue_data['dn'] == $val['dn']) {
231             $display = "<font color='#999999'>".$display."</font>";
232             break;
233           }
234         }
235       }
237       $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
238           "attach" => "style='width:20px;'");
239       $field2 = array("string" => sprintf($userimg,$val['dn']), 
240           "attach" => "style='text-align:center;width:20px;'");
241       $field3 = array("string" => sprintf($editlink,$key,$display), 
242           "attach" => "style='' ".$title);
243       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), 
244           "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
246       $this->AddElement(array($field1,$field2,$field3,$field4));
247     }
249     /* Create summary string for list footer */
250     $num     = count($list);
251     $num_str  = _("Number of listed roles");
252     $str = "<img class='center' src='images/select_sudo.png'
253               title='".$num_str."' alt='".$num_str."'>&nbsp;".$num."&nbsp;";
254     $this->set_List_Bottom_Info($str);
255   }
257   
258   /*! \brief  Save this plugin. In this case nothing will be saved
259     */
260   function Save()
261   {
262     MultiSelectWindow :: Save();  
263   }
265   /*! \brief  Save all relevant HTML inputs for this plugin.
266     */
267   function save_object()
268   {
269     /* Save automatic created POSTs like regex, checkboxes */
270     MultiSelectWindow::save_object();   
271   }
273 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
274 ?>