Code

Added missing attribute
[gosa.git] / gosa-plugins / goto / admin / devices / class_divListDevices.inc
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");
21  
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"));
36     /* Result page will look like a headpage */
37     $this->SetHeadpageMode();
38     $this->EnableAplhabet(true);
39   
40     /* Disable buttonsm */
41     $this->EnableCloseButton(false);
42     $this->EnableSaveButton (false);
44     /* Toggle all selected / deselected */
45     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
46                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
48     /* set Page header */
49     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
50     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
51     $this->AddHeader(array("string" => _("Device name")." / "._("Department"), "attach" => "style=''"));
52     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
54     /* Add SubSearch checkbox */
55     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
57     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
58     $this->AddRegex   ("Regex",     _("Display devices matching"),"*" , true);
59   }
62   /* Create list header, with create / copy & paste etc*/
63   function GenHeader()
64   {
65     /* Prepare departments,
66        which are shown in the listbox on top of the listbox
67      */
68     $options= "";
70     /* Get all departments within this subtree */
71     $ui= get_userinfo();
72     $first = "";
73     $found = FALSE;
74     $base = $this->config->current['BASE'];
76     /* Add base */
77     $tmp = array();
78     $tmp[] = array("dn"=>$this->config->current['BASE']);
79     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
80                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
82     $deps = array();
83     foreach($tmp as $tm){
84       $deps[$tm['dn']] = $tm['dn'];
85     }
87     /* Load possible departments */
88     $ui= get_userinfo();
89     $tdeps= $ui->get_module_departments($this->module);
90     $ids = $this->config->idepartments;
91     $first = "";
92     $found = FALSE;
93     foreach($ids as $dep => $name){
94       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
96         /* Keep first base dn in mind, we could need this
97          *  info if no valid base was found
98          */
99         if(empty($first)) {
100           $first = $dep['dn'];
101         }
103         $value = $ids[$dep];
104         if ($this->selectedBase == $dep){
105           $found = TRUE;
106           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
107         } else {
108           $options.= "<option value='".$dep."'>$value</option>";
109         }
110       }
111     }
113     /* The currently used base is not visible with your acl setup.
114      * Set base to first useable base.
115      */
116     if(!$found){
117       $this->selectedBase = $first;
118     }
120     /* Get acls */
121     $ui       = get_userinfo();
122     $acl      = $ui->get_permissions("cn=dummy,".get_ou('deviceou').$this->selectedBase,"devices/deviceGeneric");
123     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"devices") ;
126     /* If this is true we add an additional seperator. Just look a few lines below */  
127     $listhead = MultiSelectWindow::get_default_header();
129     /* And at least add a department selection box */
130     $listhead .=  _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
131       " <input class='center' type='image' src='images/lists/submit.png' align='middle' 
132         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
134     /* Create Layers menu */
135     $s  = ".|"._("Actions")."|\n";
137     /* Append create options */
138     if(preg_match("/c/",$acl)) {
139       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
140         "&nbsp;"._("Create")."|\n";
141       $s.= "...|<input class='center' type='image' src='images/list_new_device.png' alt=''>".
142         "&nbsp;"._("Device")."|device_new|\n";
143       $s.= "..|---|\n";
144     }
146     /* Multiple options */
147     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
148       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
150     if(is_object($this->parent->CopyPasteHandler) && preg_match("/r/",$acl_all)){
151       $s.= "..|---|\n";
152       $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
153         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
154       $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
155         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
156     }
158     /* Copy & paste icons */
159     if(is_object($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler->entries_queued()){
160       $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
161       $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
162     }else{
163       $img = "<img border='0' class='center' src='images/lists/paste-grey.png' alt=''>";
164       $s.="..|".$img."&nbsp;"._("Paste")."\n";
165     }
167     /* Add snapshot icons */
168     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
169       $s .= "..|---|\n";
170       $s .= $this->get_snapshot_header(TRUE);
171     }
173     $this->SetDropDownHeaderMenu($s);
174                                                                        
175     $this->SetListHeader($listhead);
176   }
179   /* Some basic settings */
180   function execute()
181   {
182     $this->ClearElementsList();
183     $this->GenHeader();
184   }
187   function setEntries($list)
188   {
189     /********************
190       Variable init
191      ********************/
193     /* Create links */
194     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
195     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
196     $userimg  = "<img class='center' src='plugins/groups/images/groups.png' alt='User'    title='%s'>";
197     $deviceimg  = "<img class='center' src='images/select_device.png' alt='A'  title='"._("Device")."'>";
198     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
200     /* set Page header */
201     $action_col_size = 80;
202     if($this->parent->snapshotEnabled()){
203       $action_col_size += 38;
204     }
206     /********************
207       Attach objects
208      ********************/
210     foreach($list as $key => $val){
212       $ui       = get_userinfo();
213       $acl      = $ui->get_permissions($val['dn'],"devices/deviceGeneric");
214       $acl_all  = $ui->has_complete_category_acls($val['dn'],"devices") ;
216       $actions = "";
217       if(preg_match("/(r.*d|r.*d)/",$acl_all) && $this->parent->CopyPasteHandler){
218         $actions .= "<input class='center' type='image'
219           src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
220       }else{
221         $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
222       }
224       if(preg_match("/r/",$acl_all) && $this->parent->CopyPasteHandler){
225         $actions.= "<input class='center' type='image'
226           src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
227       }else{
228         $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
229       }
231       $actions.= "<input class='center' type='image'
232         src='images/lists/edit.png' alt='"._("edit")."' name='device_edit_%KEY%' title='"._("Edit this entry")."'>";
234 #     /* Add snapshot icon */
235 #     if(preg_match("/(r.*w|w.*r)/",$acl_all)){
236 #       $actions.= $this->GetSnapShotActions($val['dn']);
237 #     }else{
238 #       $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
239 #       $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
240 #     }
242       /* Add delete button */
243       if(preg_match("/d/",$acl)){
244         $actions.= "<input class='center' type='image'
245           src='images/lists/trash.png' alt='"._("delete")."' name='device_del_%KEY%' title='"._("Delete this entry")."'>";
246       }else{
247         $actions.= "<img src='images/empty.png' alt='&nbsp;' class='center'>";
248       }
250       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
252       if(!isset($val['description'][0])){
253         $desc = "";
254       }else{
255         $desc = " - [ ".$val['description'][0]." ]";
256       }
258       /* Cutted objects should be displayed in light grey */
259       $display = $val['cn'][0].$desc;
260       if($this->parent->CopyPasteHandler){
261         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
262           if($queue_data['dn'] == $val['dn']) {
263             $display = "<font color='#999999'>".$display."</font>";
264             break;
265           }
266         }
267       }
270       /* Create each field */
271       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
272                       "attach" => "style='width:20px;'");
273       $field1 = array("string" => sprintf($deviceimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
274       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
275       $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
276       $this->AddElement(array($field0,$field1,$field2,$field3));
277     }
280     /* Create summary string for list footer */
281     $num_deps=0;
282     if(!$this->SubSearch){
283       $num_deps = count($this->Added_Departments);
284     }
285     $num_objs = count($list);
287     $num_obj_str = _("Number of listed devices");
288     $num_dep_str = _("Number of listed departments");
290     $str = "<img class='center' src='images/select_devices.png'
291               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
292     $str.= "<img class='center' src='images/lists/folder.png'
293               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
295     $this->set_List_Bottom_Info($str);
296   }
298   function Save()
299   {
300     MultiSelectWindow::Save();  
301   }
303   function save_object()
304   {
305     /* Save automatic created POSTs like regex, checkboxes */
306     MultiSelectWindow::save_object(); 
307   }
310 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
311 ?>