Code

Updated handler name
[gosa.git] / gosa-plugins / opsi / admin / opsiLicenses / class_divListLicenses.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_divListRole.inc 12852 2008-10-31 16:19:40Z 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 divListRole extends MultiSelectWindow
24 {
26   // Current base 
27   var $selectedBase       = "";
28   var $departments        = array();
30   // Regex 
31   var $Regex              = "*";
33   // Subsearch checkbox 
34   var $SubSearch          ;
35   var $parent             ;
36   var $ui                 ;
38   function divListRole (&$config,$parent)
39   {
40     MultiSelectWindow::MultiSelectWindow($config, "Licenses", "licenses");
41     
42     $this->parent       = $parent;
43     $this->ui           = get_userinfo();
45     // Dynamic action col, depending on snapshot icons 
46     $action_col_size = 90;
47     if($this->parent->snapshotEnabled()){
48       $action_col_size += 38;
49     }
51     // Set list strings 
52     $this->SetTitle(_("List of licenses"));
53     $this->SetSummary(_("List of licenses"));
54     $this->EnableAplhabet(true);
56     // Result page will look like a headpage 
57     $this->SetHeadpageMode();
58   
59     // Disable buttonsm 
60     $this->EnableCloseButton(false);
61     $this->EnableSaveButton (false);
63     // Add checkbox: Toggle all selected / deselected 
64     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
65                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
67     // Set Page col headers 
68     $this->AddHeader(array("string" => $chk,"attach"=>"style='width:20px;'"));
69     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
70     $this->AddHeader(array("string" => _("Role")." / "._("Department"), "attach" => "style=''"));
71     $this->AddHeader(array("string" => _("Actions"), 
72           "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
74     // Add SubSearch checkbox 
75     //$this->AddCheckBox(SEPERATOR);
76     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), 
77         msgPool::selectToView("","subsearch_small"), false);
79     // Add regex user input field
80     $this->AddRegex   ("Regex", _("Regular expression for matching license names"), "*" , true);
81   }
84   function GenHeader()
85   {
86     /* Get all departments within this subtree */
87     $ui= get_userinfo();
88     $first = "";
89     $found = FALSE;
90     $base = $this->config->current['BASE'];
91     $options  = $this->create_department_list($this->module);
93     /* Add a seperator after displaying c&p and snapshot icons ? */
94     $add_sep = false;
95   
96     /* Get copy & paste icon */
97     $acls  = $ui->get_permissions($this->selectedBase,"licenses/licenseGeneric");
98     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"licenses");
100     /* Add default header */
101     $listhead = MultiSelectWindow::get_default_header();
102   
103     /* Add department selector */
104     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' 
105       onChange='mainform.submit()' class='center'>$options</select>".
106       " <input class='center' type='image' src='images/lists/submit.png' align='middle' 
107       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
109     /* Create Layers menu */
110     $s  = ".|"._("Actions")."|\n";
112     /* Append create options */
113     if(preg_match("/c/",$acls)) {
114       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
115         "&nbsp;"._("Create")."|\n";
116       $s.= "...|<input class='center' type='image' src='plugins/licensemanagement/images/new.png' alt=''>".
117         "&nbsp;"._("Role")."|license_new|\n";
118     }
120     /* Multiple options */
121     $s.= "..|---|\n";
122     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
123       "&nbsp;"._("Remove")."|"."remove_multiple_licenses|\n";
125     /* Add Copy & Paste header */
126     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
128     /* Add snapshot icons */
129     $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
131     $this->SetDropDownHeaderMenu($s);
132     $this->SetListHeader($listhead);
133   }
136   function execute()
137   {
138     $this->ClearElementsList();
139     $this->GenHeader();
140   }
142   function setEntries($list)
143   {
144     // Defining Links
145     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
147     // Dynamic action col, depending on snapshot icons 
148     $action_col_size = 90;
149     if($this->parent->snapshotEnabled()){
150       $action_col_size += 38;
151     }
152   
153     $ui = get_userinfo();
155     // Assigning licenses
156     foreach($list as $key => $val){
157       
158       // Get object permissions
159       $acl    = $ui->get_permissions($val['dn'],"licenses/licenseGeneric");
160       $acl_all= $ui->has_complete_category_acls($val['dn'],"licenses");
163       // Add copy & cut functionality */
164       $actions = $this->parent->get_copypaste_action($val['dn'],"ogroups","ogroup");
165  
166       // Create edit and remove icon buttons
167       $actions.= "<input class='center' type='image'
168         src='images/lists/edit.png' alt='"._("edit")."' 
169         name='license_edit_%KEY%' title='"._("Edit this entry")."'>";
171       $actions.= $this->parent->get_snapshot_action($val['dn'],$this->module);
172       if(preg_match("/d/",$acl)){
173         $actions.= "<input class='center' type='image'
174           src='images/lists/trash.png' alt='"._("delete")."' 
175           name='license_del_%KEY%' title='"._("Delete this entry")."'>";
176       }else{
177         $actions.= "<img class='center' src='images/empty.png' alt='&nbsp;'
178           title='".msgPool::permDelete()."'>";
179       }
181       // Append license descriptio, if available
182       $title = "title='".preg_replace('/ /', '&nbsp;', LDAP::fix($val['dn']))."'";
183       if(!isset($val['description'][0])){
184         $desc = "";
185       }else{
186         $desc = " - [ ".$val['description'][0]." ]";
187       }
189       // Cutted entry are displayed in a light grey as indication.
190       $display = $val['cn'][0].$desc;
191       if($this->parent->CopyPasteHandler){
192         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
193           if($queue_data['dn'] == $val['dn']) {
194             $display = "<font color='#999999'>".$display."</font>";
195             break;
196           }
197         }
198       }
200       // Append the entry to the divlist
201       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' 
202           name='item_selected_".$key."'>" ,
203           "attach" => "style='width:20px;'");
204       $field1 = array("string" => "<img src='plugins/licensemanagement/images/license.png' 
205           alt='"._("Role")."' ".$title.">", 
206           "attach" => "style='text-align:center;width: 20px;'");
207       $field2 = array("string" => sprintf($editlink,$key,$display), 
208           "attach" => "style='' ".$title);
209       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), 
210           "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
212       $this->AddElement(array($field0,$field1,$field2,$field4));
213     }
214    
215  
216     // Create the list summary 
217     $num_deps=0;
218     if(!$this->SubSearch){
219       $num_deps = count($this->Added_Departments);
220     }
221     $num_objs = count($list);
222     $num_obj_str = _("Number of listed licenses");
223     $num_dep_str = _("Number of listed departments");
224     $str = "<img class='center' src='plugins/licensemanagement/images/license.png'
225               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
226     $str.= "<img class='center' src='images/lists/folder.png'
227               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
228     $this->set_List_Bottom_Info($str);
229   }
231 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
232 ?>