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");
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();
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" => " ", "attach" => "style='text-align:center;width:20px;'"));
70 $this->AddHeader(array("string" => _("License")." / "._("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;
96 /* Get copy & paste icon */
97 $acls = $ui->get_permissions($this->selectedBase,"opsi/licenseGeneric");
98 $acl_all= $ui->has_complete_category_acls($this->selectedBase,"opsi");
100 /* Add default header */
101 $listhead = MultiSelectWindow::get_default_header();
103 /* Create Layers menu */
104 $s = ".|"._("Actions")."|\n";
106 /* Append create options */
107 if(preg_match("/c/",$acls)) {
108 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
109 " "._("Create")."|\n";
110 $s.= "...|<input class='center' type='image' src='plugins/opsiLicenses/images/new.png' alt=''>".
111 " "._("License")."|license_new|\n";
112 }
114 /* Multiple options */
115 $s.= "..|---|\n";
116 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
117 " "._("Remove")."|"."remove_multiple_licenses|\n";
119 $this->SetDropDownHeaderMenu($s);
120 $this->SetListHeader($listhead);
121 }
124 function execute()
125 {
126 $this->ClearElementsList();
127 $this->GenHeader();
128 }
130 function setEntries($list)
131 {
132 // Defining Links
133 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
135 // Dynamic action col, depending on snapshot icons
136 $action_col_size = 90;
137 if($this->parent->snapshotEnabled()){
138 $action_col_size += 38;
139 }
141 $ui = get_userinfo();
143 // Assigning licenses
144 foreach($list as $key => $val){
146 // Get object permissions
147 $acl = $ui->get_permissions($val['dn'],"opsi/licenseGeneric");
148 $acl_all= $ui->has_complete_category_acls($val['dn'],"opsi");
150 // Create edit and remove icon buttons
151 $actions = "<input class='center' type='image'
152 src='images/lists/edit.png' alt='"._("edit")."'
153 name='license_edit_%KEY%' title='"._("Edit this entry")."'>";
154 if(preg_match("/d/",$acl)){
155 $actions.= "<input class='center' type='image'
156 src='images/lists/trash.png' alt='"._("delete")."'
157 name='license_del_%KEY%' title='"._("Delete this entry")."'>";
158 }else{
159 $actions.= "<img class='center' src='images/empty.png' alt=' '
160 title='".msgPool::permDelete()."'>";
161 }
164 // Append license descriptio, if available
165 $title = "title='".preg_replace('/ /', ' ', LDAP::fix($val['dn']))."'";
166 if(!isset($val['description'][0])){
167 $desc = "";
168 }else{
169 $desc = " - [ ".$val['description'][0]." ]";
170 }
171 $display = $val['cn'][0].$desc;
173 // Append the entry to the divlist
174 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."'
175 name='item_selected_".$key."'>" ,
176 "attach" => "style='width:20px;'");
177 $field1 = array("string" => "<img src='plugins/opsiLicenses/images/license.png'
178 alt='"._("License")."' ".$title.">",
179 "attach" => "style='text-align:center;width: 20px;'");
180 $field2 = array("string" => sprintf($editlink,$key,$display),
181 "attach" => "style='' ".$title);
182 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions),
183 "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
185 $this->AddElement(array($field0,$field1,$field2,$field4));
186 }
188 // Create the list summary
189 $num_deps=0;
190 if(!$this->SubSearch){
191 $num_deps = count($this->Added_Departments);
192 }
193 $num_objs = count($list);
194 $num_obj_str = _("Number of listed licenses");
195 $str = "<img class='center' src='plugins/opsiLicenses/images/license.png'
196 title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
197 $this->set_List_Bottom_Info($str);
198 }
199 }
200 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
201 ?>