Code

Updated some plugins
[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     /* Get all departments within this subtree */
66     $ui= get_userinfo();
67     $first = "";
68     $found = FALSE;
69     $base = $this->config->current['BASE'];
70     $options  = $this->create_department_list($this->module);
72     /* Get acls */
73     $ui       = get_userinfo();
74     $acl      = $ui->get_permissions($this->selectedBase,"devices/deviceGeneric");
75     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"devices") ;
78     /* If this is true we add an additional seperator. Just look a few lines below */  
79     $listhead = MultiSelectWindow::get_default_header();
81     /* And at least add a department selection box */
82     $listhead .=  _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
83       " <input class='center' type='image' src='images/lists/submit.png' align='middle' 
84         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
86     /* Create Layers menu */
87     $s  = ".|"._("Actions")."|\n";
89     /* Append create options */
90     if(preg_match("/c/",$acl)) {
91       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
92         "&nbsp;"._("Create")."|\n";
93       $s.= "...|<input class='center' type='image' src='plugins/goto/images/list_new_device.png' alt=''>".
94         "&nbsp;"._("Device")."|device_new|\n";
95       $s.= "..|---|\n";
96     }
98     /* Multiple options */
99     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
100       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
102     /* Add Copy & Paste header */
103     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
105     /* Add snapshot icons */
106     $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
108     $this->SetDropDownHeaderMenu($s);
109                                                                        
110     $this->SetListHeader($listhead);
111   }
114   /* Some basic settings */
115   function execute()
116   {
117     $this->ClearElementsList();
118     $this->GenHeader();
119   }
122   function setEntries($list)
123   {
124     /********************
125       Variable init
126      ********************/
128     /* Create links */
129     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
130     $userimg  = "<img class='center' src='plugins/groups/images/groups.png' alt='User'    title='%s'>";
131     $deviceimg  = "<img class='center' src='plugins/goto/images/select_device.png' alt='A'  title='"._("Device")."'>";
132     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
134     /* set Page header */
135     $action_col_size = 80;
136     if($this->parent->snapshotEnabled()){
137       $action_col_size += 38;
138     }
140     /********************
141       Attach objects
142      ********************/
144     foreach($list as $key => $val){
146       $ui       = get_userinfo();
147       $acl      = $ui->get_permissions($val['dn'],"devices/deviceGeneric");
148       $acl_all  = $ui->has_complete_category_acls($val['dn'],"devices") ;
150       $actions = "";
151       
152       /* Add copy & cut functionality */
153       $actions.= $this->parent->get_copypaste_action($val['dn'],"devices","deviceGeneric");
154       
155       $actions.= "<input class='center' type='image'
156         src='images/lists/edit.png' alt='"._("edit")."' name='device_edit_%KEY%' title='"._("Edit this entry")."'>";
158       $actions.= $this->parent->get_snapshot_action($val['dn'],$this->module);
160       /* Add delete button */
161       if(preg_match("/d/",$acl)){
162         $actions.= "<input class='center' type='image'
163           src='images/lists/trash.png' alt='"._("delete")."' name='device_del_%KEY%' title='"._("Delete this entry")."'>";
164       }else{
165         $actions.= "<img src='images/empty.png' alt='&nbsp;' class='center'>";
166       }
168       $title = "title='".preg_replace('/ /', '&nbsp;', LDAP::fix($val['dn']))."'";
170       if(!isset($val['description'][0])){
171         $desc = "";
172       }else{
173         $desc = " - [ ".$val['description'][0]." ]";
174       }
176       /* Cutted objects should be displayed in light grey */
177       $display = $val['cn'][0].$desc;
178       if($this->parent->CopyPasteHandler){
179         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
180           if($queue_data['dn'] == $val['dn']) {
181             $display = "<font color='#999999'>".$display."</font>";
182             break;
183           }
184         }
185       }
188       /* Create each field */
189       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
190                       "attach" => "style='width:20px;'");
191       $field1 = array("string" => sprintf($deviceimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
192       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
193       $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
194       $this->AddElement(array($field0,$field1,$field2,$field3));
195     }
198     /* Create summary string for list footer */
199     $num_deps=0;
200     if(!$this->SubSearch){
201       $num_deps = count($this->Added_Departments);
202     }
203     $num_objs = count($list);
205     $num_obj_str = _("Number of listed devices");
206     $num_dep_str = _("Number of listed departments");
208     $str = "<img class='center' src='plugins/goto/images/select_device.png'
209               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
210     $str.= "<img class='center' src='images/lists/folder.png'
211               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
213     $this->set_List_Bottom_Info($str);
214   }
216   function Save()
217   {
218     MultiSelectWindow::Save();  
219   }
221   function save_object()
222   {
223     /* Save automatic created POSTs like regex, checkboxes */
224     MultiSelectWindow::save_object(); 
225   }
228 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
229 ?>