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");
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();
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"=>" ","attach"=>"style='width:20px;'"));
82 $this->AddHeader(array("string"=>_("Name")." / "._("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");
105 /* Add default header */
106 $listhead = MultiSelectWindow::get_default_header(false);
108 /* Create Layers menu */
109 $s = ".|"._("Actions")."|\n";
110 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
111 " "._("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=''> "._("Role")."|new_role|\n";
116 $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''> "._("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 " "._("Remove")."|"."del_role|\n";
124 }
126 if(is_object($this->parent->CopyPasteHandler) && preg_match("/r/",$acl_all)){
127 $s.= "..|---|\n";
128 $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
129 " "._("Copy")."|"."multiple_copy_systems|\n";
130 }
132 /* Copy & paste icons */
133 if(is_object($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler->entries_queued()){
134 $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
135 $s.="..|".$img." "._("Paste")."|editPaste|\n";
136 }else{
137 $img = "<img border='0' class='center' src='images/lists/paste-grey.png' alt=''>";
138 $s.="..|".$img." "._("Paste")."\n";
139 }
141 /* Add snapshot icons */
142 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
143 $s .= "..|---|\n";
144 $s .= $this->get_snapshot_header(TRUE);
145 }
147 $this->SetDropDownHeaderMenu($s);
148 $this->SetListHeader($listhead);
149 }
152 /*! \brief Prepare the plguin to list a set of objects
153 */
154 function execute()
155 {
156 $this->ClearElementsList();
157 $this->GenHeader();
158 }
161 /*! \brief Create a list of all objects that should be displayed
162 @param Array $list The list of sudo roles, passed from the sudoManagement class.
163 */
164 function setEntries($list)
165 {
166 /* Prepare links */
167 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
168 $userimg = "<img class='center' src='images/select_sudo.png' alt='Sudo' title='%s'>";
169 $ui = get_userinfo();
171 $action_col_size = 54;
172 if($this->parent->snapshotEnabled()){
173 $action_col_size += 32;
174 }
175 if($this->parent->CopyPasteHandler){
176 $action_col_size += 20;
177 }
179 // Test Every Entry and generate divlist Array
180 foreach($list as $key => $val){
182 /* Create action icons - copy & paste icons */
183 $acl = $ui->get_permissions($val['dn'],"sudo/sudo");
184 $acl_all= $this->ui->get_category_permissions($val['dn'],"sudo");
186 /* Add edit icon */
187 $actions= "";
188 if($ui->is_copyable($val['dn'],"sudo","sudo") && $this->parent->CopyPasteHandler){
189 $actions.= "<input class='center' type='image'
190 src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
191 }else{
192 $actions.="<img src='images/empty.png' alt=' ' class='center'> ";
193 }
195 $actions.= "<input class='center' type='image'
196 src='images/lists/edit.png' alt='".msgPool::editButton()."' name='sudo_edit_%KEY%' title='"._("Edit this entry")."'>";
198 /* Add snapshot icon */
199 if(preg_match("/(r.*w|w.*r)/",$acl_all)){
200 $actions.= $this->GetSnapShotActions($val['dn']);
201 }else{
202 $actions.="<img src='images/empty.png' alt=' ' class='center'> ";
203 $actions.="<img src='images/empty.png' alt=' ' class='center'> ";
204 }
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('/ /', ' ', @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;
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."'> ".$num." ";
254 $this->set_List_Bottom_Info($str);
255 }
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 }
272 }
273 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
274 ?>