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,".get_ou('deviceou').$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 $listhead = MultiSelectWindow::get_default_header();
130 /* And at least add a department selection box */
131 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
132 " <input class='center' type='image' src='images/list_submit.png' align='middle'
133 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
135 /* Create Layers menu */
136 $s = ".|"._("Actions")."|\n";
137 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
138 " "._("Create")."|\n";
140 /* Append create options */
141 if(preg_match("/c/",$acl)) {
142 $s.= "...|<input class='center' type='image' src='images/list_new_device.png' alt=''>".
143 " "._("Device")."|device_new|\n";
144 }
146 /* Multiple options */
147 $s.= "..|---|\n";
148 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
149 " "._("Remove")."|"."remove_multiple|\n";
151 /* Add multiple copy & cut icons */
152 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
153 $s.= "..|---|\n";
154 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
155 " "._("Copy")."|"."multiple_copy_systems|\n";
156 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
157 " "._("Cut")."|"."multiple_cut_systems|\n";
159 if($this->parent->CopyPasteHandler->entries_queued()){
160 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
161 $s.="..|".$img." "._("Paste")."|editPaste|\n";
162 }else{
163 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
164 $s.="..|".$img." "._("Paste")."\n";
165 }
166 }
168 /* Add snapshot icons */
169 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
170 $s .= "..|---|\n";
171 $s .= $this->get_snapshot_header(TRUE);
172 }
174 $this->SetDropDownHeaderMenu($s);
176 $this->SetListHeader($listhead);
177 }
180 /* Some basic settings */
181 function execute()
182 {
183 $this->ClearElementsList();
184 $this->GenHeader();
185 }
188 function setEntries($list)
189 {
190 /********************
191 Variable init
192 ********************/
194 /* Create links */
195 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
196 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
197 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
198 $deviceimg = "<img class='center' src='images/select_device.png' alt='A' title='"._("Device")."'>";
199 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
201 /* set Page header */
202 $action_col_size = 80;
203 if($this->parent->snapshotEnabled()){
204 $action_col_size += 38;
205 }
207 /********************
208 Attach objects
209 ********************/
211 foreach($list as $key => $val){
213 $ui = get_userinfo();
214 $acl = $ui->get_permissions($val['dn'],"devices/deviceGeneric");
215 $acl_all = $ui->has_complete_category_acls($val['dn'],"devices") ;
217 /* Create action icons */
218 $actions = "";
219 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
220 $actions .= $this->GetSnapShotActions($val['dn']);
221 }
223 /* Get copy Paste icons */
224 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
225 $actions.= "<input class='center' type='image'
226 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
227 $actions.= "<input class='center' type='image'
228 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
229 }
231 $actions.= "<input class='center' type='image'
232 src='images/edit.png' alt='"._("edit")."' name='device_edit_%KEY%' title='"._("Edit this entry")."'>";
234 /* Add delete button */
235 if(preg_match("/d/",$acl)){
236 $actions.= "<input class='center' type='image'
237 src='images/edittrash.png' alt='"._("delete")."' name='device_del_%KEY%' title='"._("Delete this entry")."'>";
238 }else{
239 $actions.= "<img src='images/empty.png' alt=' ' class='center'>";
240 }
242 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
244 if(!isset($val['description'][0])){
245 $desc = "";
246 }else{
247 $desc = " - [ ".$val['description'][0]." ]";
248 }
250 /* Cutted objects should be displayed in light grey */
251 $display = $val['cn'][0].$desc;
252 if($this->parent->CopyPasteHandler){
253 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
254 if($queue_data['dn'] == $val['dn']) {
255 $display = "<font color='#999999'>".$display."</font>";
256 break;
257 }
258 }
259 }
262 /* Create each field */
263 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
264 "attach" => "style='width:20px;'");
265 $field1 = array("string" => sprintf($deviceimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
266 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
267 $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
268 $this->AddElement(array($field0,$field1,$field2,$field3));
269 }
272 /* Create summary string for list footer */
273 $num_deps=0;
274 if(!$this->SubSearch){
275 $num_deps = count($this->Added_Departments);
276 }
277 $num_objs = count($list);
279 $num_obj_str = _("Number of listed devices");
280 $num_dep_str = _("Number of listed departments");
282 $str = "<img class='center' src='images/select_devices.png'
283 title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
284 $str.= "<img class='center' src='images/folder.png'
285 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
287 $this->set_List_Bottom_Info($str);
288 }
290 function Save()
291 {
292 MultiSelectWindow::Save();
293 }
295 function save_object()
296 {
297 /* Save automatic created POSTs like regex, checkboxes */
298 MultiSelectWindow::save_object();
299 }
301 }
302 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
303 ?>