Code

Fixed object Listing
[gosa.git] / plugins / admin / systems / class_divListSystem.inc
1 <?php
3 class divListSystem extends MultiSelectWindow
4 {
6   /* Current base */
7   var $selectedBase       = "";
8   var $departments        = array();
10   /* Regex */
11   var $Regex              = "*";
12   var $UserRegex          = "*";
14   /* CheckBoxes, to change default values modify $this->AddCheckBox */
15   var $ShowServers;
16   var $ShowTerminals;
17   var $ShowWorkstations;
18   var $ShowWinWorkstations;
19   var $ShowPrinters;
20   var $ShowDevices;
21   var $ShowPhones;
23   /* Subsearch checkbox */
24   var $SubSearch;
26   var $parent             ;
27   var $ui                 ;
29   function divListSystem ($config,$parent)
30   {
31     MultiSelectWindow::MultiSelectWindow($config, "System", array("server",
32                                                                   "workstation",
33                                                                   "terminal",
34                                                                   "phone",
35                                                                   "printer"));
37     $this->parent       = $parent;
38     $this->ui           = get_userinfo();
40     /* Set list strings */
41     $this->SetTitle(_("List of systems"));
42     $this->SetSummary(_("List of systems"));
44     /* Result page will look like a headpage */
45     $this->SetHeadpageMode();
46     $this->SetInformation(_("This menu allows you to add, remove and change the properties of specific systems. You can only add systems which have already been started once."));
48     $this->EnableAplhabet   (true);
50     /* Disable buttonsm */
51     $this->EnableCloseButton(false);
52     $this->EnableSaveButton (false);
54     /* Dynamic action col, depending on snapshot icons */
55     $action_col_size = 70;
56     if($this->parent->snapshotEnabled()){
57       $action_col_size += 38;
58     }
60     /* set Page header */
61     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
62     $this->AddHeader(array("string"=>_("System / Department")));
63     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
65     /*                  Text        ,Value    ,Name         ,Is selected */
66     $this->AddCheckBox("ShowServers",         _("Select to see servers"),            _("Show servers"),          true);
67     $this->AddCheckBox("ShowTerminals",       _("Select to see Linux terminals"),    _("Show terminals") ,       true);
68     $this->AddCheckBox("ShowWorkstations",    _("Select to see Linux workstations"), _("Show workstations"),     true);
69     $this->AddCheckBox("ShowWinWorkstations", _("Select to see MicroSoft Windows based workstations"), _("Show windows based workstations"),true);
70     $this->AddCheckBox("ShowPrinters",        _("Select to see network printers"),    _("Show network printers") ,true);
71     $this->AddCheckBox("ShowPhones",          _("Select to see VOIP phones"),         _("Show phones") ,          true);
72     $this->AddCheckBox("ShowDevices",         _("Select to see network devices"),     _("Show network devices"),  true);
74     /* Add SubSearch checkbox */
75     $this->AddCheckBox(SEPERATOR);
76     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
78     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
79     $this->AddRegex   ("Regex",     _("Display systems matching"),"*" , true);
80     $this->AddRegex   ("UserRegex", _("Display systems of user"), "*" , false, "images/search_user.png");
81   }
83   function GenHeader()
84   {
85    /* Prepare departments,
86        which are shown in the listbox on top of the listbox
87      */
88     $options= "";
90     /* Get all departments within this subtree */
91     $base = $this->config->current['BASE'];
92     $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
93                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
95     $tmp =array();
96     foreach($deps as $dep){
97       $tmp[$dep['dn']] = $dep;
98     }
99     $deps = $tmp;
101     /* Load possible departments */
102     $ui= get_userinfo();
103     $department = array();
104     foreach($this->module as $module){
105       $d = $ui->get_module_departments($module);      
106       foreach($d as $department){
107         $departments[$department] = $department;
108       }
109     }
111     $ids = $this->config->idepartments;
113     foreach($deps as $dep){
114       if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $departments)){
116         $value = $ids[$dep['dn']];
117         if ($this->selectedBase == $dep['dn']){
118           $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
119         } else {
120           $options.= "<option value='".$dep['dn']."'>$value</option>";
121         }
122       }
123     }
125     /* If there is at least one c (Create) and one w (Write) acl in this combination
126         display the snapshot paste icon. BUT check the correct acls in the management plugin */
127     $all_module_acls = "";
128     foreach($this->module as $module){
129       $all_module_acls .= $ui->has_complete_category_acls($this->selectedBase,$module)." | ".$module."<br>";
130     }
132     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
133       " <input class='center' type='image' src='images/list_root.png' align='middle'
134       title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
135       " <input class='center' type='image' align='middle' src='images/list_back.png'
136       title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
137       " <input class='center' type='image' align='middle' src='images/list_home.png'
138       title='"._("Go to users department")."' alt='"._("Home")."'                     name='dep_home'>&nbsp;".
139       " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='".          _("Submit")."'>&nbsp;".
140       " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
142     if(preg_match("/(c.*w|w.*c)/",$all_module_acls)){
143       $listhead .= $this->get_snapshot_header($this->selectedBase);
144     }
146     
147     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"terminal/termgeneric"))){
148       $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_terminal.png'
149         name='newsystem_terminal'    alt='"._("New Terminal template")."' title='"._("New Terminal")."'>&nbsp;";
150     }
152     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/workgeneric"))){
153       $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_workstation.png'
154         name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>&nbsp;";
155     }
157     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"server/servgeneric"))){
158       $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_server.png'     
159         name='newsystem_server' alt='"._("New Server")."' title='"._("New Server")."'>&nbsp;";
160     }
162     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"printer/printgenric"))){
163       $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_printer.png'    
164         name='newsystem_printer'     alt='"._("New Printer")."' title='"._("New Printer")."'>&nbsp;";
165     }
167     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"phone/phoneGeneric"))){
168       $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_phone.png'      
169         name='newsystem_phone' alt='"._("New Phone")."' title='"._("New Phone")."'>&nbsp;";
170     }
172     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"component/componentGeneric"))){
173       $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_component.png'  
174         name='newsystem_component' alt='"._("New Component")."' title='"._("New Component")."'>&nbsp;";
175     }
177     $listhead .= "<img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;"._("Base")."&nbsp;".
178       " <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
179       " <input class='center' type='image' src='images/list_submit.png' align='middle'
180       title='"._("Submit department")."' name='submit_department' alt='".           _("Submit")."'>&nbsp;".
181       "</div>";
182     $this->SetListHeader($listhead);
183   }
185   function execute()
186   {
187     $this->ClearElementsList();
188     $this->GenHeader();
189   }
192   function setEntries($terminals)
193   {
194     $img1  = "<img class='center' src='images/printer.png'            alt='C' title='"._("Cups Server")  ."'>";
195     $img2  = "<img class='center' src='images/scanner.png'            alt='L' title='"._("Log Db") ."'>";
196     $img3  = "<img class='center' src='images/select_terminal.png'    alt='L' title='"._("Syslog Server") ."'>";
197     $img4  = "<img class='center' src='images/mailto.png'             alt='M' title='"._("Mail Server")  ."'>";
198     $img5  = "<img class='center' src='images/select_phone.png'       alt='I' title='"._("Imap Server") ."'>";
199     $img6  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Nfs Server")   ."'>";
200     $img7  = "<img class='center' src='images/select_winstation.png'  alt='K' title='"._("Kerberos Server") ."'>";
201     $img8  = "<img class='center' src='images/select_phone.png'       alt='A' title='"._("Asterisk Server") ."'>";
202     $img9  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Fax Server") ."'>";
203     $img10 = "<img class='center' src='images/save.png'               alt='L' title='"._("Ldap Server") ."'>";
205     $empty    ="&nbsp;";
207     /* Dynamic action col, depending on snapshot icons */
208     $action_col_size = 50;
209     if($this->parent->snapshotEnabled()){
210       $action_col_size += 38;
211     }
213     // User and Template  Images
214     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
216     /* ACL mapping */
217     $acl_type = array("server"  => "ser");
218     $ui = get_userinfo();
220     // Test Every Entry and generate divlist Array
221     foreach($terminals as $key => $val){
223       /* Get system type, it is used to fetch the acls for the current object.
224           "winstation" acls are stored as 2winworkstation", so we have to map this here */
225       $type     = $this->parent->get_system_type($val['objectClass']);
226       if($type == "winstation") {
227         $acl_type = "winworkstation";
228       }else{
229         $acl_type = $type;
230       }
231       $acl_all  = $ui->has_complete_category_acls($val['dn'],$acl_type) ;
233       $action= "<input class='center' type='image' src='images/edit.png' 
234                     alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit system")."'>";
235       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
236         $action.= $this->GetSnapShotActions($val['dn']);
237       }
238       $action.= "<input class='center' type='image' src='images/edittrash.png' 
239                     alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete system")."'>";
241       /* Generate picture list, which is currently disabled */
242       if(in_array("goCupsServer"    ,$val['objectClass'])) $cups    = $img1;   else $cups  =$empty;
243       if(in_array("goLogDBServer"   ,$val['objectClass'])) $logdb   = $img2;   else $logdb =$empty;
244       if(in_array("goSyslogServer"  ,$val['objectClass'])) $syslog  = $img3;   else $syslog=$empty;
245       if(in_array("goImapServer"    ,$val['objectClass'])) $imap    = $img4;   else $imap  =$empty;
246       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba   = $img5;   else $samba =$empty;
247       if(in_array("goShareServer"   ,$val['objectClass'])) $nfs     = $img6;   else $nfs   =$empty;
248       if(in_array("goKrbServer"     ,$val['objectClass'])) $krb     = $img7;   else $krb   =$empty;
249       if(in_array("goFonServer"     ,$val['objectClass'])) $fon     = $img8;   else $fon   =$empty;
250       if(in_array("goFaxServer"     ,$val['objectClass'])) $fax     = $img9;   else $fax   =$empty;
251       if(in_array("goLdapServer"    ,$val['objectClass'])) $ldap     = $img10;   else $ldap   =$empty;
253       $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
254       $pics = ""; // Pictures currently hidden
256       $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
258       // Generate Array to Add
259       $dsc= "";
260       if (isset($val['description'][0])){
261         $dsc= " [".$val['description'][0]."]";
262       }
263       if((isset($val['is_new']))&&(!empty($val['is_new']))){
264         $display= $val["cn"][0]." ".$val['is_new'].$dsc;
265       }else{
266         $display= $val["cn"][0].$dsc;
267       }
269      
270       /* Check if this is a terminal/workstation && if we are allowed to change the gotoRootPasswd */
271       $pwd_acl =""; 
272       if(in_array("gotoWorkstation",$val['objectClass'])){
273         $pwd_acl = $ui->get_permissions($val['dn'],"workstation/workgeneric","gotoRootPasswd");
274       }    
275       if(in_array("gotoTerminal",$val['objectClass'])){
276         $pwd_acl = $ui->get_permissions($val['dn'],"terminal/termgeneric","gotoRootPasswd");
277       }    
278       if(preg_match("/w/",$pwd_acl)){
279         $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."'   name='user_setpwd_%KEY%' title='"._("Set root       password")."'>";
280       }else{
281         $action2 = "";
282       }
285       if(in_array("gotoWorkstation",$val['objectClass'])){
286         $action2= "<input class='center' type='image' src='images/cdrom.png' alt='"._("Create CD")."'   
287                       name='gen_cd_%KEY%' title='"._("Create FAI CD")."'>".$action2;
288       }
290       if(isset($val['message'])){
291         $display.= "  (".$val['message'].")";
292       }
294       $img    = $this->parent->convert_list($val);
295       $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
296       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
297       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
298       $this->AddElement( array($field1,$field2,$field3));
299     }
301   }
304   function Save()
305   {
306     MultiSelectWindow :: Save();  
307   }
310   function save_object()
311   {
312     /* Save automatic created POSTs like regex, checkboxes */
313     MultiSelectWindow :: save_object();  
316   }
318 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
319 ?>