1 <?php
3 class divListDevices extends MultiSelectWindow
4 {
5 /* Current base */
6 var $selectedBase = "";
7 var $departments = array();
8 var $parent ;
9 var $ui ;
11 /* Regex */
12 var $Regex = "*";
14 /* Subsearch checkbox */
15 var $SubSearch;
17 function divListDevices (&$config, &$parent)
18 {
19 /* Create divlist and setup */
20 MultiSelectWindow::MultiSelectWindow($config, "Devices", "devices");
22 /* initialize required attributes */
23 $this->parent = &$parent;
24 $this->ui = get_userinfo();
26 /* set Page header */
27 $action_col_size = 80;
28 if($this->parent->snapshotEnabled()){
29 $action_col_size += 38;
30 }
32 /* Set list strings */
33 $this->SetTitle (_("List of defined devices"));
34 $this->SetSummary (_("List of defined devices"));
35 $this->SetInformation (_("This menu allows you to add, edit and remove selected devices. You may want to use the range selector on top of the device listbox, when working with a large number of devices."));
37 /* Result page will look like a headpage */
38 $this->SetHeadpageMode();
39 $this->EnableAplhabet(true);
41 /* Disable buttonsm */
42 $this->EnableCloseButton(false);
43 $this->EnableSaveButton (false);
45 /* Toggle all selected / deselected */
46 $chk = "<input type='checkbox' id='select_all' name='select_all'
47 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
49 /* set Page header */
50 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
51 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
52 $this->AddHeader(array("string" => _("Device name")." / "._("Department"), "attach" => "style=''"));
53 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
55 /* Add SubSearch checkbox */
56 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
58 /* Name ,Text ,Default , Connect with alphabet */
59 $this->AddRegex ("Regex", _("Display devices matching"),"*" , true);
60 }
63 /* Create list header, with create / copy & paste etc*/
64 function GenHeader()
65 {
66 /* Prepare departments,
67 which are shown in the listbox on top of the listbox
68 */
69 $options= "";
71 /* Get all departments within this subtree */
72 $ui= get_userinfo();
73 $first = "";
74 $found = FALSE;
75 $base = $this->config->current['BASE'];
77 /* Add base */
78 $tmp = array();
79 $tmp[] = array("dn"=>$this->config->current['BASE']);
80 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
81 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
83 $deps = array();
84 foreach($tmp as $tm){
85 $deps[$tm['dn']] = $tm['dn'];
86 }
88 /* Load possible departments */
89 $ui= get_userinfo();
90 $tdeps= $ui->get_module_departments($this->module);
91 $ids = $this->config->idepartments;
92 $first = "";
93 $found = FALSE;
94 foreach($ids as $dep => $name){
95 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
97 /* Keep first base dn in mind, we could need this
98 * info if no valid base was found
99 */
100 if(empty($first)) {
101 $first = $dep['dn'];
102 }
104 $value = $ids[$dep];
105 if ($this->selectedBase == $dep){
106 $found = TRUE;
107 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
108 } else {
109 $options.= "<option value='".$dep."'>$value</option>";
110 }
111 }
112 }
114 /* The currently used base is not visible with your acl setup.
115 * Set base to first useable base.
116 */
117 if(!$found){
118 $this->selectedBase = $first;
119 }
121 /* Get acls */
122 $ui = get_userinfo();
123 $acl = $ui->get_permissions("cn=dummy,ou=devices,".$this->selectedBase,"devices/deviceGeneric");
124 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"devices") ;
127 /* If this is true we add an additional seperator. Just look a few lines below */
128 $add_sep = false;
130 /* Get copy & paste icon */
131 $Copy_Paste ="";
132 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
133 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
134 $add_sep = true;
135 }
137 /* Add default header */
138 $listhead = MultiSelectWindow::get_default_header();
140 /* Create snapshot icons */
141 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
142 $listhead .= $this->get_snapshot_header($this->selectedBase);
143 $add_sep = true;
144 }
146 /* Add create icon */
147 if(preg_match("/c/",$acl)){
148 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_device.png' alt='"._("new").
149 "' title='"._("Create new device")."' name='device_new'> ";
150 $add_sep = true;
151 }
153 /* Add copy & paste icons */
154 $listhead .= $Copy_Paste;
156 /* Add a seperator ? */
157 if($add_sep) {
158 $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
159 }
161 /* And at least add a department selection box */
162 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
163 " <input class='center' type='image' src='images/list_submit.png' align='middle'
164 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
166 /* Multiple options */
167 $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
168 title='"._("Remove selected device")."' alt='"._("Remove device")."' name='remove_multiple_devices'> ";
170 /* Add multiple copy & cut icons */
171 if(is_object($this->parent->CopyPasteHandler)){
172 $listhead .= " <input class='center' type='image' align='middle' src='images/editcopy.png'
173 title='"._("Copy selected object")."' alt='"._("Copy object")."' name='multiple_copy_devices'> ";
174 $listhead .= " <input class='center' type='image' align='middle' src='images/editcut.png'
175 title='"._("cut selected object")."' alt='"._("Cut object")."' name='multiple_cut_devices'> ";
176 }
178 $listhead .="</div>";;
180 $this->SetListHeader($listhead);
181 }
184 /* Some basic settings */
185 function execute()
186 {
187 $this->ClearElementsList();
188 $this->GenHeader();
189 }
192 function setEntries($list)
193 {
194 /********************
195 Variable init
196 ********************/
198 /* Create links */
199 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
200 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
201 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
202 $deviceimg = "<img class='center' src='images/select_device.png' alt='A' title='"._("Device")."'>";
203 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
205 /* set Page header */
206 $action_col_size = 80;
207 if($this->parent->snapshotEnabled()){
208 $action_col_size += 38;
209 }
211 /********************
212 Attach objects
213 ********************/
215 foreach($list as $key => $val){
217 $ui = get_userinfo();
218 $acl = $ui->get_permissions($val['dn'],"devices/deviceGeneric");
219 $acl_all = $ui->has_complete_category_acls($val['dn'],"devices") ;
221 /* Create action icons */
222 $actions = "";
223 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
224 $actions .= $this->GetSnapShotActions($val['dn']);
225 }
227 /* Get copy Paste icons */
228 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
229 $actions.= "<input class='center' type='image'
230 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
231 $actions.= "<input class='center' type='image'
232 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
233 }
235 $actions.= "<input class='center' type='image'
236 src='images/edit.png' alt='"._("edit")."' name='device_edit_%KEY%' title='"._("Edit this entry")."'>";
238 /* Add delete button */
239 if(preg_match("/d/",$acl)){
240 $actions.= "<input class='center' type='image'
241 src='images/edittrash.png' alt='"._("delete")."' name='device_del_%KEY%' title='"._("Delete this entry")."'>";
242 }else{
243 $actions.= "<img src='images/empty.png' alt=' ' class='center'>";
244 }
246 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
248 if(!isset($val['description'][0])){
249 $desc = "";
250 }else{
251 $desc = " - [ ".$val['description'][0]." ]";
252 }
254 /* Cutted objects should be displayed in light grey */
255 $display = $val['cn'][0].$desc;
256 if($this->parent->CopyPasteHandler){
257 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
258 if($queue_data['dn'] == $val['dn']) {
259 $display = "<font color='#999999'>".$display."</font>";
260 break;
261 }
262 }
263 }
266 /* Create each field */
267 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
268 "attach" => "style='width:20px;'");
269 $field1 = array("string" => sprintf($deviceimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
270 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
271 $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
272 $this->AddElement(array($field0,$field1,$field2,$field3));
273 }
276 /* Create summary string for list footer */
277 $num_deps=0;
278 if(!$this->SubSearch){
279 $num_deps = count($this->Added_Departments);
280 }
281 $num_objs = count($list);
283 $num_obj_str = _("Number of listed devices");
284 $num_dep_str = _("Number of listed departments");
286 $str = "<img class='center' src='images/select_devices.png'
287 title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
288 $str.= "<img class='center' src='images/folder.png'
289 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
291 $this->set_List_Bottom_Info($str);
292 }
294 function Save()
295 {
296 MultiSelectWindow::Save();
297 }
299 function save_object()
300 {
301 /* Save automatic created POSTs like regex, checkboxes */
302 MultiSelectWindow::save_object();
303 }
305 }
306 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
307 ?>