Code

b83c7ba08fe09740627408052a705a2ade75fbe2
[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  */
23 class divListSudo extends MultiSelectWindow
24 {
26   /* Current base */
27   var $selectedBase       = "";
28   var $departments        = array();
30   /* Regex */
31   var $Regex              = "*";
32   var $UserRegex          = "*";
34   /* Subsearch checkbox */
35   var $SubSearch          = FALSE;
37   var $parent             ;
38   var $ui                 ;
40   function divListSudo (&$config, &$parent)
41   {
42     MultiSelectWindow::MultiSelectWindow($config, "sudo", "sudo");
43     
44     $this->parent       = &$parent;
45     $this->ui           = get_userinfo();
47     /* Set list strings */
48     $this->SetTitle(  _("List of sudo roles"));
49     $this->SetSummary(_("List of sudo roles"));
50     $this->EnableAplhabet(true);
52     /* Result page will look like a headpage */
53     $this->SetHeadpageMode();
54   
55     /* Disable buttonsm */
56     $this->EnableCloseButton(false);
57     $this->EnableSaveButton (false);
59     /* Dynamic action col, depending on snapshot icons */
60     $action_col_size = 80;
62     /* Toggle all selected / deselected */
63     $chk = "<input type='checkbox' id='select_all' name='select_all'
64                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
66     /* set Page header */
67     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
68     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
69     $this->AddHeader(array("string"=>_("Name")."&nbsp;/&nbsp;"._("Department")));
70     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
72     /* Add SubSearch checkbox */    
73     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"),msgPool::selectToView("","subsearch_small"), false);
74     $this->AddRegex   ("Regex"    , _("Regular expression for matching role names")       , 
75       "*" , true);
76     $this->AddRegex   ("UserRegex", _("Regular expression for matching role member names"),
77       "*" , FALSE,"images/search_user.png");
78   }
81   function GenHeader()
82   {
83     /* Prepare departments,
84        which are shown in the listbox on top of the listbox
85      */
86     $base  = $this->parent->base;
87     $acl   = $this->ui->get_category_permissions($base,"sudo"); 
88  
89     /* Add default header */
90     $listhead = MultiSelectWindow::get_default_header();
91     
92     /* Create Layers menu */
93     $s  = ".|"._("Actions")."|\n";
94     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
95       "&nbsp;"._("Create")."|\n";
97     /* Append create options */
98     if(preg_match("/c/",$acl)) {
99       $s.= "...|<input class='center' type='image' src='images/list_new_sudo.png' alt=''>&nbsp;"._("Role")."|new_role|\n";
100     }
102     /* Append multiple remove */
103     if(preg_match("/d/",$acl)){
104       $s.= "..|---|\n";
105       $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
106         "&nbsp;"._("Remove")."|"."del_role|\n";
107     }
109     $this->SetDropDownHeaderMenu($s);
110     $this->SetListHeader($listhead);
111   }
114   function execute()
115   {
116     $this->ClearElementsList();
117     $this->GenHeader();
118   }
121   function setEntries($list)
122   {
123     /* Prepare links */
124     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
125     $userimg  = "<img class='center' src='images/select_sudo.png' alt='Sudo' title='%s'>";
126     $ui       = get_userinfo();
128     $action_col_size = 80;
130     // Test Every Entry and generate divlist Array
131     foreach($list as $key => $val){
132     
133       /* Create action icons - copy & paste icons */
134       $acl    = $ui->get_permissions($val['dn'],"sudo/sudo");
136       /* Add edit icon */
137       $actions = "";
138       $actions.= "<input class='center' type='image'
139         src='images/edit.png' alt='"._("edit")."' name='sudo_edit_%KEY%' title='"._("Edit this entry")."'>";
141       if(preg_match("/d/",$acl)){
142         $actions.= "<input class='center' type='image'
143           src='images/edittrash.png' alt='"._("delete")."' name='sudo_del_%KEY%' title='"._("Delete this entry")."'>";
144       }
146       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
148       if(!isset($val['description'][0])){
149         $desc = "";
150       }else{
151         $desc = " - [ ".$val['description'][0]." ]";
152       }
154       $display = $val['cn'][0].$desc;
155       $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
156           "attach" => "style='width:20px;'");
157       $field2 = array("string" => sprintf($userimg,$val['dn']), 
158           "attach" => "style='text-align:center;width:20px;'");
159       $field3 = array("string" => sprintf($editlink,$key,$display), 
160           "attach" => "style='' ".$title);
161       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), 
162           "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
164       $this->AddElement(array($field1,$field2,$field3,$field4));
165     }
167     /* Create summary string for list footer */
168     $num     = count($list);
169     $num_str  = _("Number of listed roles");
170     $str = "<img class='center' src='images/select_sudo.png'
171               title='".$num_str."' alt='".$num_str."'>&nbsp;".$num."&nbsp;";
172     $this->set_List_Bottom_Info($str);
173   }
175   function Save()
176   {
177     MultiSelectWindow :: Save();  
178   }
180   function save_object()
181   {
182     /* Save automatic created POSTs like regex, checkboxes */
183     MultiSelectWindow::save_object();   
184   }
186 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
187 ?>