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