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 "incoming",
36 "printer"));
38 $this->parent = $parent;
39 $this->ui = get_userinfo();
41 /* Set list strings */
42 $this->SetTitle(_("List of systems"));
43 $this->SetSummary(_("List of systems"));
45 /* Result page will look like a headpage */
46 $this->SetHeadpageMode();
47 $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."));
49 $this->EnableAplhabet (true);
51 /* Disable buttonsm */
52 $this->EnableCloseButton(false);
53 $this->EnableSaveButton (false);
55 /* Dynamic action col, depending on snapshot icons */
56 $action_col_size = 70;
57 if($this->parent->snapshotEnabled()){
58 $action_col_size += 38;
59 }
61 /* Toggle all selected / deselected */
62 $chk = "<input type='checkbox' id='select_all' name='select_all'
63 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
65 /* set Page header */
66 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
67 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
68 $this->AddHeader(array("string"=>_("System / Department")));
69 $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
71 /* Text ,Value ,Name ,Is selected */
72 $this->AddCheckBox("ShowServers", _("Select to see servers"), _("Show servers"), true);
73 $this->AddCheckBox("ShowTerminals", _("Select to see Linux terminals"), _("Show terminals") , true);
74 $this->AddCheckBox("ShowWorkstations", _("Select to see Linux workstations"), _("Show workstations"), true);
75 $this->AddCheckBox("ShowWinWorkstations", _("Select to see MicroSoft Windows based workstations"), _("Show windows based workstations"),true);
76 $this->AddCheckBox("ShowPrinters", _("Select to see network printers"), _("Show network printers") ,true);
77 $this->AddCheckBox("ShowPhones", _("Select to see VOIP phones"), _("Show phones") , true);
78 $this->AddCheckBox("ShowDevices", _("Select to see network devices"), _("Show network devices"), true);
80 /* Add SubSearch checkbox */
81 $this->AddCheckBox(SEPERATOR);
82 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
84 /* Name ,Text ,Default , Connect with alphabet */
85 $this->AddRegex ("Regex", _("Display systems matching"),"*" , true);
86 $this->AddRegex ("UserRegex", _("Display systems of user"), "*" , false, "images/search_user.png");
87 }
89 function GenHeader()
90 {
91 /* Prepare departments,
92 which are shown in the listbox on top of the listbox
93 */
94 $options= "";
96 /* Get all departments within this subtree */
97 $base = $this->config->current['BASE'];
99 /* Add base */
100 $deps[] = array("dn"=>$this->config->current['BASE']);
101 $deps= array_merge($deps,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
102 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
104 $tmp =array();
105 foreach($deps as $dep){
106 $tmp[$dep['dn']] = $dep;
107 }
108 $deps = $tmp;
110 /* Load possible departments */
111 $ui= get_userinfo();
112 $first = "";
113 $found = FALSE;
114 $department = $departments = array();
115 foreach($this->module as $module){
116 $d = $ui->get_module_departments($module);
117 foreach($d as $department){
118 $departments[$department] = $department;
119 }
120 }
122 $ids = $this->config->idepartments;
124 foreach($deps as $dep){
125 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $departments)){
127 /* Keep first base dn in mind, we could need this
128 * info if no valid base was found
129 */
130 if(empty($first)) {
131 $first = $dep['dn'];
132 }
134 $value = $ids[$dep['dn']];
135 if ($this->selectedBase == $dep['dn']){
136 $found = TRUE;
137 $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
138 } else {
139 $options.= "<option value='".$dep['dn']."'>$value</option>";
140 }
141 }
142 }
144 /* The currently used base is not visible with your acl setup.
145 * Set base to first useable base.
146 */
147 if(!$found){
148 $this->selectedBase = $first;
149 }
151 /* If there is at least one c (Create) and one w (Write) acl in this combination
152 display the snapshot paste icon. BUT check the correct acls in the management plugin */
153 $all_module_acls = "";
154 foreach($this->module as $module){
155 $all_module_acls .= $ui->has_complete_category_acls($this->selectedBase,$module);
156 }
158 /* Must we add an additional seperator */
159 $add_sep = false;
161 /* Add default header */
162 $listhead = MultiSelectWindow::get_default_header();
164 /* Add snapshot icons */
165 if(preg_match("/(c.*w|w.*c)/",$all_module_acls)){
166 $listhead .= $this->get_snapshot_header($this->selectedBase);
167 $add_sep = true;
168 }
170 /* Handle create icons */
171 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"terminal/termgeneric"))){
172 $add_sep = true;
173 $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_terminal.png'
174 name='newsystem_terminal' alt='"._("New Terminal template")."' title='"._("New Terminal")."'> ";
175 }
177 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/workgeneric"))){
178 $add_sep = true;
179 $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_workstation.png'
180 name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'> ";
181 }
183 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"server/servgeneric"))){
184 $add_sep = true;
185 $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_server.png'
186 name='newsystem_server' alt='"._("New Server")."' title='"._("New Server")."'> ";
187 }
189 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"printer/printgeneric"))){
190 $add_sep = true;
191 $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_printer.png'
192 name='newsystem_printer' alt='"._("New Printer")."' title='"._("New Printer")."'> ";
193 }
195 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"phone/phoneGeneric"))){
196 $add_sep = true;
197 $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_phone.png'
198 name='newsystem_phone' alt='"._("New Phone")."' title='"._("New Phone")."'> ";
199 }
201 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"component/componentGeneric"))){
202 $add_sep = true;
203 $listhead .= "<input class='center' type='image' align='middle' src='images/select_new_component.png'
204 name='newsystem_component' alt='"._("New Component")."' title='"._("New Component")."'> ";
205 }
207 /* Should we add a seperator ? */
208 if($add_sep){
209 $listhead .= "<img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
210 }
212 /* Add base selection */
213 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
214 " <input class='center' type='image' src='images/list_submit.png' align='middle'
215 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
217 /* Multiple options */
218 $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
219 title='"._("Remove selected systems")."' alt='"._("Remove systems")."' name='remove_multiple_systems'> ";
221 $listhead .="</div>";
223 $this->SetListHeader($listhead);
224 }
226 function execute()
227 {
228 $this->ClearElementsList();
229 $this->GenHeader();
230 }
233 function setEntries($terminals)
234 {
235 $img1 = "<img class='center' src='images/printer.png' alt='C' title='"._("Cups Server") ."'>";
236 $img2 = "<img class='center' src='images/scanner.png' alt='L' title='"._("Log Db") ."'>";
237 $img3 = "<img class='center' src='images/select_terminal.png' alt='L' title='"._("Syslog Server") ."'>";
238 $img4 = "<img class='center' src='images/mailto.png' alt='M' title='"._("Mail Server") ."'>";
239 $img5 = "<img class='center' src='images/select_phone.png' alt='I' title='"._("Imap Server") ."'>";
240 $img6 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Nfs Server") ."'>";
241 $img7 = "<img class='center' src='images/select_winstation.png' alt='K' title='"._("Kerberos Server") ."'>";
242 $img8 = "<img class='center' src='images/select_phone.png' alt='A' title='"._("Asterisk Server") ."'>";
243 $img9 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Fax Server") ."'>";
244 $img10 = "<img class='center' src='images/save.png' alt='L' title='"._("Ldap Server") ."'>";
246 $empty ="<img src='images/empty.png' style='width:16px ; height: 16px;' class='center' alt=''>";
248 /* Dynamic action col, depending on snapshot icons */
249 $action_col_size = 70;
250 if($this->parent->snapshotEnabled()){
251 $action_col_size += 38;
252 }
254 // User and Template Images
255 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
257 /* ACL mapping */
258 $ui = get_userinfo();
259 $tabs = array(
260 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
261 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
262 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
263 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
264 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
265 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
266 "incoming" => array("CLASS"=>"", "TABCLASS" =>"", "ACL"=> "incoming/systems"),
267 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
270 // Test Every Entry and generate divlist Array
271 foreach($terminals as $key => $val){
273 /* Get system type, it is used to fetch the acls for the current object.
274 "winstation" acls are stored as 2winworkstation", so we have to map this here */
275 $type = $this->parent->get_system_type($val['objectClass']);
276 if($type == "winstation") {
277 $acl_type = "winworkstation";
278 }else{
279 $acl_type = $type;
280 }
282 /* Map NewDevice acls to workstation acls */
283 if($type == "NewDevice"){
284 $type = "incoming";
285 $acl_type = "incoming";
286 }
288 /* Get complete category acls */
289 $acl_all = $ui->has_complete_category_acls($val['dn'],$acl_type) ;
291 /* Get specific generic acls */
292 $acl = $ui->get_permissions($val['dn'],$tabs[$type]['ACL']);
294 $action= "<input class='center' type='image' src='images/edit.png'
295 alt='"._("edit")."' name='system_edit_%KEY%' title='"._("Edit system")."'>";
296 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
297 $action.= $this->GetSnapShotActions($val['dn']);
298 }else{
299 $action.= $empty." ".$empty." ";
300 }
302 if(preg_match("/d/",$acl)){
303 $action.= "<input class='center' type='image' src='images/edittrash.png'
304 alt='"._("delete")."' name='system_del_%KEY%' title='"._("Delete system")."'>";
305 }else{
306 $action.= $empty;
307 }
309 /* Generate picture list, which is currently disabled */
310 if(in_array("goCupsServer" ,$val['objectClass'])) $cups = $img1; else $cups =$empty;
311 if(in_array("goLogDBServer" ,$val['objectClass'])) $logdb = $img2; else $logdb =$empty;
312 if(in_array("goSyslogServer" ,$val['objectClass'])) $syslog = $img3; else $syslog=$empty;
313 if(in_array("goImapServer" ,$val['objectClass'])) $imap = $img4; else $imap =$empty;
314 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $img5; else $samba =$empty;
315 if(in_array("goShareServer" ,$val['objectClass'])) $nfs = $img6; else $nfs =$empty;
316 if(in_array("goKrbServer" ,$val['objectClass'])) $krb = $img7; else $krb =$empty;
317 if(in_array("goFonServer" ,$val['objectClass'])) $fon = $img8; else $fon =$empty;
318 if(in_array("goFaxServer" ,$val['objectClass'])) $fax = $img9; else $fax =$empty;
319 if(in_array("goLdapServer" ,$val['objectClass'])) $ldap = $img10; else $ldap =$empty;
321 $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
322 $pics = ""; // Pictures currently hidden
324 $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
326 // Generate Array to Add
327 $dsc= "";
328 if (isset($val['description'][0])){
329 $dsc= " [".$val['description'][0]."]";
330 }
331 if((isset($val['is_new']))&&(!empty($val['is_new']))){
332 $display= $val["cn"][0]." ".$val['is_new'].$dsc;
333 }else{
334 $display= $val["cn"][0].$dsc;
335 }
338 /* Check if this is a terminal/workstation && if we are allowed to change the gotoRootPasswd */
339 $pwd_acl ="";
340 if(in_array("gotoWorkstation",$val['objectClass'])){
341 $pwd_acl = $ui->get_permissions($val['dn'],"workstation/workgeneric","gotoRootPasswd");
342 }
343 if(in_array("gotoTerminal",$val['objectClass'])){
344 $pwd_acl = $ui->get_permissions($val['dn'],"terminal/termgeneric","gotoRootPasswd");
345 }
346 if(preg_match("/w/",$pwd_acl)){
347 $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."' name='system_setpwd_%KEY%' title='"._("Set root password")."'>";
348 }else{
349 $action2 = $empty;
350 }
353 if(in_array("gotoWorkstation",$val['objectClass'])){
354 $action2= "<input class='center' type='image' src='images/cdrom.png' alt='"._("Create CD")."'
355 name='gen_cd_%KEY%' title='"._("Create FAI CD")."'> ".$action2;
356 }else{
357 $action2= $empty.$action2;
358 }
360 if(isset($val['message'])){
361 $display.= " (".$val['message'].")";
362 }
364 $img = $this->parent->convert_list($val);
366 /* Create each field */
367 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
368 "attach" => "style='width:20px;'");
370 $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
371 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
372 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
373 $this->AddElement( array($field0,$field1,$field2,$field3));
374 }
376 }
379 function Save()
380 {
381 MultiSelectWindow :: Save();
382 }
385 function save_object()
386 {
387 /* Save automatic created POSTs like regex, checkboxes */
388 MultiSelectWindow :: save_object();
391 }
392 }
393 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
394 ?>