Code

Updated opsiLicense Mangement
[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_divListLicense.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 divListLicense 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 divListLicense (&$config,$parent)
39   {
40     MultiSelectWindow::MultiSelectWindow($config, "opsi", "licenseGeneric");
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 license pools"));
53     $this->SetSummary(_("List of license pools"));
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" => _("License pools"), "attach" => "style=''"));
71     $this->AddHeader(array("string" => _("Actions"), 
72           "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
74     // Add regex user input field
75     $this->AddRegex   ("Regex", _("Regular expression for matching license pools"), "*" , true);
76   }
79   function GenHeader()
80   {
81     /* Get all departments within this subtree */
82     $ui= get_userinfo();
83     $first = "";
84     $found = FALSE;
85     $base = $this->config->current['BASE'];
86     $options  = $this->create_department_list($this->module);
88     /* Get copy & paste icon */
89     $acls  = $ui->get_permissions($this->selectedBase,"opsi/licenseGeneric");
90     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"opsi");
92     /* Add default header */
93     $listhead = MultiSelectWindow::get_default_header(false);
94   
95     /* Create Layers menu */
96     $s  = ".|"._("Actions")."|\n";
98     /* Append create options */
99     if(preg_match("/c/",$acls)) {
100       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
101         "&nbsp;"._("Create")."|\n";
102       $s.= "...|<input class='center' type='image' src='plugins/opsiLicenses/images/new.png' alt=''>".
103         "&nbsp;"._("License")."|license_new|\n";
104     }
106     /* Multiple options */
107     $s.= "..|---|\n";
109     if(preg_match("/d/",$acls)) {
110       $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
111         "&nbsp;"._("Remove")."|"."remove_multiple_licenses|\n";
112     }
113   
114     $this->SetDropDownHeaderMenu($s);
115     $this->SetListHeader($listhead);
116   }
119   function execute()
120   {
121     $this->ClearElementsList();
122     $this->GenHeader();
123   }
125   function setEntries($list)
126   {
127     // Defining Links
128     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
130     // Dynamic action col, depending on snapshot icons 
131     $action_col_size = 90;
132     if($this->parent->snapshotEnabled()){
133       $action_col_size += 38;
134     }
135   
136     $ui = get_userinfo();
138     // Assigning licenses
139     foreach($list as $key => $val){
140      
141       // Get object permissions
142       $acl    = $ui->get_permissions($val['dn'],"opsi/licenseGeneric");
143       $acl_all= $ui->has_complete_category_acls($val['dn'],"opsi");
145       // Create edit and remove icon buttons
146       $actions = "<input class='center' type='image'
147         src='images/lists/edit.png' alt='"._("edit")."' 
148         name='license_edit_%KEY%' title='"._("Edit this entry")."'>";
149       if(preg_match("/d/",$acl)){
150         $actions.= "<input class='center' type='image'
151           src='images/lists/trash.png' alt='"._("delete")."' 
152           name='license_del_%KEY%' title='"._("Delete this entry")."'>";
153       }else{
154         $actions.= "<img class='center' src='images/empty.png' alt='&nbsp;'
155           title='".msgPool::permDelete()."'>";
156       }
159       // Append license descriptio, if available
160       $title = "title='".preg_replace('/ /', '&nbsp;', LDAP::fix($val['dn']))."'";
161       if(!isset($val['description'][0])){
162         $desc = "";
163       }else{
164         $desc = " - [ ".$val['description'][0]." ]";
165       }
166       $display = $val['cn'][0].$desc;
168       // Append the entry to the divlist
169       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' 
170           name='item_selected_".$key."'>" ,
171           "attach" => "style='width:20px;'");
172       $field1 = array("string" => "<img src='plugins/opsi/images/license.png' 
173           alt='"._("License")."' ".$title.">", 
174           "attach" => "style='text-align:center;width: 20px;'");
175       $field2 = array("string" => sprintf($editlink,$key,$display), 
176           "attach" => "style='' ".$title);
177       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), 
178           "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
180       $this->AddElement(array($field0,$field1,$field2,$field4));
181     }
182    
183     // Create the list summary 
184     $num_deps=0;
185     if(!$this->SubSearch){
186       $num_deps = count($this->Added_Departments);
187     }
188     $num_objs = count($list);
189     $num_obj_str = _("Number of listed license pools");
190     $str = "<img class='center' src='plugins/opsi/images/license.png'
191               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
192     $this->set_List_Bottom_Info($str);
193   }
195 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
196 ?>