Code

Fixed inheritance problem
[gosa.git] / plugins / admin / systems / class_systemManagement.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 require "tabs_terminal.inc";
21 require "tabs_workstation.inc";
22 require "tabs_printers.inc";
23 require "tabs_phone.inc";
24 require "tabs_server.inc";
25 require "tabs_component.inc";
26 require "tabs_winstation.inc";
29 class systems extends plugin
30 {
31   /* Definitions */
32   var $plHeadline= "Systems";
33   var $plDescription= "This does something";
34   var $departments=array();
36   /* Dialog attributes */
37   var $systab= NULL;
38   var $terminals= array();
39   var $ui= NULL;
40   var $acl= "";
41   var $DivListSystem;
43   function systems ($config, $ui)
44   {
45     /* Save configuration for internal use */
46     $this->config= $config;
47     $this->ui= $ui;
49     /* Creat dialog object */
50     $this->DivListSystem = new divListSystem($this->config,$this);
51   }
53   function execute()
54   {
55     /* Call parent execute */
56     plugin::execute();
58     $_SESSION['LOCK_VARS_TO_USE'] = array("/^user_edit_/i","/^user_del_/","/^act/","/^id/");
60     /********************
61       Check for functional posts, edit|delete|add|... system devices 
62      ********************/
63     $s_action     = "";                       // Contains the action to proceed
64     $s_entry      = "";                       // The value for s_action
65     $base_back    = "";                       // The Link for Backbutton
66     $smarty       = get_smarty();
68     /* Test Posts */
69     foreach($_POST as $key => $val){
70       // Post for delete
71       if(preg_match("/user_del.*/",$key)){
72         $s_action = "del";
73         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
74         // Post for edit
75       }elseif(preg_match("/user_edit_.*/",$key)){
76         $s_action="edit";
77         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
78         // Post for new
79       }elseif(preg_match("/user_new.*/",$key)){
80         $s_action="new";
81       }elseif(preg_match("/user_tplnew.*/i",$key)){
82         $s_action="new_tpl";
83       }elseif(preg_match("/user_setpwd_.*/i",$key)){
84         $s_action="change_pw";
85         $s_entry  = preg_replace("/user_setpwd_/i","",$key);
86       }elseif(preg_match("/newsystem_.*/i",$key)){
87         $s_action="newsystem";
88         $s_entry  = preg_replace("/newsystem_/i","",$key);
89       }
90     }
92     /* Incoming handling  
93      * If someone made a systemtype and ogroup selection 
94      * Display the new requested entry type ... servtab  in case of server and so on.
95      */
96     if(isset($_POST['SystemTypeChoosen'])){
97       $s_action = "SelectedSystemType";
98       $s_entry  = $_POST['SystemType'];
99       $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
100       $this->systab = NULL;
101     }
103     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
104     $s_entry  = preg_replace("/_.$/","",$s_entry);
106     /* Edit was requested by pressing the name(link) of an item */
107     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
108       $s_action ="edit";
109       $s_entry  = $_GET['id'];
110     }
112     /* Check for exeeded sizelimit */
113     if (($message= check_sizelimit()) != ""){
114       return($message);
115     }
117     /* Try to get informations about what kind of system to create */
118     if ($s_action=="new") {
119       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
120     }
122     /********************
123       Create new system ...   
124      ********************/
125     /* Create new default terminal 
126      * Or create specified object of selected system type, from given incoming object  
127      */
129     $save_object_directly = false;
130     if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
131       $save_object_directly = true;
132     }
133     
134     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
136       /* If the current entry is an incoming object 
137        * $sw = System type as posted in new incoming handling dialog 
138        */ 
139       if($s_action == "SelectedSystemType") {
140         $sw         = $s_entry;
141       }else{
142         if(isset($_POST['system'])){
143           $sw = $_POST['system'];
144         }else{
145           $sw = $s_entry;
146         }
147         $this->dn= "new";
148       }
149       $this->acl= array(":all");
150       $tabs = array(
151           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs"),
152           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs"),
153           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs"),
154           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs"),
155           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phonegeneric",    "TABCLASS" =>"phonetabs"),
156           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs"));
158       if(isset($tabs[$sw])){
159         $class    = $tabs[$sw]["CLASS"];
160         $tabname  = $tabs[$sw]["TABNAME"];
161         $tabclass = $tabs[$sw]["TABCLASS"];
162         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
163         $this->systab->set_acl ($this->acl);
164         $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
165         $this->systab->base = $this->DivListSystem->selectedBase;
166       }
167     }
169     /********************
170       Edit system ...   
171      ********************/
173     /* User wants to edit data? */
174     if (($s_action == "edit") && (!isset($this->systab->config))){
176       $this->dn= $this->terminals[$s_entry]['dn'];
178       /* Check locking, save current plugin in 'back_plugin', so
179          the dialog knows where to return. */
180       if (($user= get_lock($this->dn)) != ""){
181         return(gen_locked_message ($user, $this->dn));
182       }
184       /* Set up the users ACL's for this 'dn' */
185       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
187       /* Find out more about the object type */
188       $ldap= $this->config->get_ldap_link();
189       $ldap->cat($this->dn, array('objectClass'));
190       $attrs= $ldap->fetch();
191       $type= $this->get_system_type($attrs['objectClass']);
193       /* Lock the current entry, so everyone will get the
194          above dialog */
195       $tabs = array(
196           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs"),
197           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs"),
198           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs"),
199           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs"),
200           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs"),
201           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs"),
202           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
205       if($type == "NewDevice"){
206         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
207       }elseif(isset($tabs[$type])){
209         $class    = $tabs[$type]["CLASS"];
210         $tabclass = $tabs[$type]["TABCLASS"];
212         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
213         $this->systab->set_acl($acl);
214         $_SESSION['objectinfo']= $this->dn;
215         add_lock ($this->dn, $this->ui->dn);
216       }else{ 
217         print_red (_("You can't edit this object type yet!"));
218         del_lock($this->dn);
219       }
220     }
223     /********************
224       Change password ...   
225      ********************/
227     /* Set terminals root password */
228     if ($s_action=="change_pw"){
229       $this->dn= $this->terminals[$s_entry]['dn'];
230       $_SESSION['objectinfo']= $this->dn;
231       return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
232     }
235     /********************
236       Password cahnge finish, but check if entered data is ok 
237      ********************/
239     /* Correctly specified? */
240     if (isset($_POST['password_finish'])){
241       if ($_POST['new_password'] != $_POST['repeated_password']){
242         print_red (_("Passwords entered as new and repeated do not match!"));
243         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
244       }
245     }
247     /********************
248       Password change finish
249      ********************/
251     /* Change terminal password */
252     if (isset($_POST['password_finish']) && 
253         $_POST['new_password'] == $_POST['repeated_password']){
255       /* Check if user is allowed to set password */
256       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
257       $acl= get_module_permission($acl, "terminal", $this->dn);
258       if (chkacl($acl, "password") != ""){
259         print_red (_("You are not allowed to set this systems password!"));
260       } else {
261         $ldap= $this->config->get_ldap_link();
262         $ldap->cd($this->dn);
264         $attrs= array();
265         if ($_POST['new_password'] == ""){
266           $attrs['gotoRootPasswd']= array();
267         } else {
268           $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
269               substr(session_id(),0,2));
270         }
271         $ldap->modify($attrs);
272         gosa_log ("Password for '".$this->dn."' has been changed");
273       }
274       unset($_SESSION['objectinfo']);
275     }
278     /********************
279       Delete system cancel
280      ********************/
282     /* Delete terminal canceled? */
283     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
284       del_lock ($this->dn);
285       unset($_SESSION['objectinfo']);
286     }
289     /********************
290       Delete system, confirm dialog
291      ********************/
293     /* Remove terminal was requested */
294     if ($s_action=="del"){
296       /* Get 'dn' from posted termlinst */
297       $this->dn= $this->terminals[$s_entry]['dn'];
299       /* Load permissions for selected 'dn' and check if
300          we're allowed to remove this 'dn' */
301       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
302       $this->acl= get_module_permission($acl, "terminal", $this->dn);
303       if (chkacl($this->acl, "delete") == ""){
305         /* Check locking, save current plugin in 'back_plugin', so
306            the dialog knows where to return. */
307         if (($user= get_lock($this->dn)) != ""){
308           return(gen_locked_message ($user, $this->dn));
309         }
311         /* Lock the current entry, so nobody will edit it during deletion */
312         add_lock ($this->dn, $this->ui->dn);
313         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
314         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
315       } else {
317         /* Obviously the user isn't allowed to delete. Show message and
318            clean session. */
319         print_red (_("You are not allowed to delete this component!"));
320       }
321     }
324     /********************
325       Delete system, confirmed
326      ********************/
327     /* Confirmation for deletion has been passed. Terminal should be deleted. */
328     if (isset($_POST['delete_terminal_confirm'])){
330       /* Some nice guy may send this as POST, so we've to check
331          for the permissions again. */
332       if (chkacl($this->acl, "delete") == ""){
334         /* Find out more about the object type */
335         $ldap= $this->config->get_ldap_link();
336         $ldap->cat($this->dn, array('objectClass'));
337         $attrs= $ldap->fetch();
338         $type= $this->get_system_type($attrs['objectClass']);
340         $tabs = array(
341             "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs"),
342             "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs"),
343             "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs"),
344             "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs"),
345             "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs"),
346             "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs"),
347             "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
349         /* get object type */
350         $tabtype  = "termtabs";
351         $tabobj   = "TERMTABS";
352         if(isset($tabs[$type])){
353           $tabtype = $tabs[$type]['TABCLASS'];
354           $tabobj  = $tabs[$type]['CLASS'];
355         }
357         /* Delete request is permitted, perform LDAP action */
358         if($tabtype=="phonetabs"){
359           $this->systab= new $tabtype($this->config,
360               $this->config->data['TABS'][$tabobj], $this->dn);
361           $this->systab->set_acl(array($this->acl));
362           $this->systab->by_object['phonegeneric']->remove_from_parent ();
363         }else{  
364           $this->systab= new $tabtype($this->config,
365               $this->config->data['TABS'][$tabobj], $this->dn);
366           $this->systab->set_acl(array($this->acl));
367           $this->systab->delete();
368 #$this->systab->by_object['termgeneric']->remove_from_parent ();
369         }
370         unset ($this->systab);
371         gosa_log ("System object'".$this->dn."' has been removed");
372         $this->systab= NULL;
374         /* Terminal list has changed, reload it. */
375       } else {
377         /* Normally this shouldn't be reached, send some extra
378            logs to notify the administrator */
379         print_red (_("You are not allowed to delete this component!"));
380         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
381             "deletion.");
382       }
384       /* Remove lock file after successfull deletion */
385       del_lock ($this->dn);
386     }
389     /********************
390       Edit system type finished, check if everything went ok 
391      ********************/
392     /* Finish user edit is triggered by the tabulator dialog, so
393        the user wants to save edited data. Check and save at this
394        point. */
395     if ((isset($_POST['edit_finish'])) && (isset($this->systab->config)) || $save_object_directly){
397       /* Check tabs, will feed message array */
398       $message = array();
399       if(!$save_object_directly){
400         $message = $this->systab->check();
401       }else{
402         $found = false;
403   
404         /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
405         foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"graphic") as $tab => $value){
406           if(isset($this->systab->by_object[$tab]->gotoMode)) {
407             $found = true;
408             $this->systab->by_object[$tab]->gotoMode = $value;
409           }
410         }   
411         if(!$found){
412           print_red(sprintf(_("Can't set gotoMode to status 'avtice', the current object couldn't be identified.")));
413         }
415       }
416       /* Save, or display error message? */
417       if (count($message) == 0){
419         /* Save terminal data to ldap */
420         if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
421           foreach (array("workservice", "termservice") as $cls){
422             if (isset($this->systab->by_object[$cls])){
423               $this->systab->by_object[$cls]->gotoXMouseport= "";
424               $this->systab->by_object[$cls]->gotoXMouseType= "";
425               $this->systab->by_object[$cls]->gotoXResolution= "";
426               $this->systab->by_object[$cls]->gotoXColordepth= "";
427             }
428           }
429         }
431         $this->systab->save();
432         gosa_log ("System object'".$this->dn."' has been saved");
434         /* Incoming behavior; you can select a system type and an ogroup membership. 
435          * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
436          * Check if we must add the new object to an object group.
437          * 
438          * If this is done, delete the old incoming entry... it is still there, because this is a new 
439          * entry and not an edited one, so we will delete it.
440          */
442         if(isset($_SESSION['SelectedSystemType'])){
443           $SelectedSystemType= $_SESSION['SelectedSystemType'];
444           unset($_SESSION['SelectedSystemType']);
445           if($SelectedSystemType['ogroup'] != "none"){
446             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
447             if($og){
448               $og->AddDelMembership($this->systab->dn);
449               $og->save();
450             }
451           }
452           if(!isset($ldap)){
453             $ldap = $this->config->get_ldap_link();
454           }
455           $ldap->cd ($this->dn);
456           $ldap->cat($this->dn, array('dn'));  
457           if(count($ldap->fetch())){
458             $ldap->cd($this->dn);
459             $ldap->rmDir($this->dn);
460           }
461           $ldap->cd($this->config->current['BASE']);
462         }
464         /* Terminal has been saved successfully, remove lock from
465            LDAP. */
466         if ($this->dn != "new"){
467           del_lock ($this->dn);
468         }
470         unset ($this->systab);
471         $this->systab= NULL;
472         unset($_SESSION['objectinfo']);
473       } else {
474         /* Ok. There seem to be errors regarding to the tab data,
475            show message and continue as usual. */
476         show_errors($message);
477       }
478     }
480     /********************
481       Edit system was canceled 
482      ********************/
483     /* Cancel dialogs */
484     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
485       if (isset($this->systab)){
486         del_lock ($this->systab->dn);
487         unset ($this->systab);
488       }
489       $this->systab= NULL;
490       unset($_SESSION['objectinfo']);
492       /* Remove ogroup selection, which was set while editing a new incoming entry */
493       if(isset($_SESSION['SelectedSystemType'])){
494         unset($_SESSION['SelectedSystemType']);
495       }
496     }
498     /********************
499       Display edit dialog, or some other
500      ********************/
502     /* Show tab dialog if object is present */
503     if (isset($this->systab->config)){
504       $display= $this->systab->execute();
506       /* Don't show buttons if tab dialog requests this */
507       if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
508         $display.= "<p style=\"text-align:right\">\n";
509         $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
510         $display.= "&nbsp;\n";
511         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
512         $display.= "</p>";
513       }
514       return ($display);
515     }
517     /* Display dialog with system list */
518     $this->DivListSystem->parent = $this;
519     $this->DivListSystem->execute();
521     /* Add departments if subsearch is disabled */
522     if(!$this->DivListSystem->SubSearch){
523       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
524     }
525     $this->reload();
526     $this->DivListSystem->setEntries($this->terminals);
527     return($this->DivListSystem->Draw());
528   }
532   function remove_from_parent()
533   {
534     /* Optionally execute a command after we're done */
535     $this->postremove();
536   }
539   /* Save data to object */
540   function save_object()
541   {
542     $this->DivListSystem->save_object();
543   }
546   /* Check values */
547   function check()
548   {
549   }
552   /* Save to LDAP */
553   function save()
554   {
555   }
557   function adapt_from_template($dn)
558   {
559   }
561   function password_change_needed()
562   {
563   }
565   function reload()
566   {
567     /* Load terminal shortcuts */
568     $responsible= array();
569     foreach ($this->config->departments as $key => $value){
570       if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
571             "terminal", $value) == "#all#"){
572         $responsible[$key]= $value;
573       }
574     }
576     /* some var init */
577     $res              = array();
578     $this->terminals  = array();
579     $userregex        = "";
581     /* Set base for all searches */
582     $base=  $this->DivListSystem->selectedBase;
584     /* Prepare samba class name */
585     $samba  ="";
586     if ($this->DivListSystem->ShowWinWorkstations){
587       if ($this->config->current['SAMBAVERSION'] == "3"){
588         $samba= "sambaSamAccount";
589       } else {
590         $samba= "sambaAccount";
591       }
592     }
594     /* This array represents the combination between checkboxes and search filters */
595     $objs = array( "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => "ou=servers,ou=systems," ),
596         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => "ou=terminals,ou=systems,"), 
597         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => "ou=printers,ou=systems," ),
598         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => "ou=netdevices,ou=systems," ),
599         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => "ou=phones,ou=systems," ),
600         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
601         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
603     /* Include the 'Display Systems of user' attribute */ 
604     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
605       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
606     }
608     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
609     foreach($objs as $checkBox => $oc){
610       if($this->DivListSystem->$checkBox){
611         if($this->DivListSystem->SubSearch){
612           if($oc['CLASS'] != ""){
613             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
614             $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $base,
615                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
616           }
617         }else{
618           /* User filter? */
619           if($oc['CLASS'] != ""){
620             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
621             $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $oc['TREE'].$base,
622                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
623           }
624         }
625       } 
626     }
628     /* Search for incoming objects */ 
629     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
630     $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, "ou=incoming,".$base,
631           array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
633     /* Get all gotoTerminal's */
634     foreach ($res as $value){
636       $tmp= $value['dn'];
637       $add= "";
639       /* Extract base */
640       foreach($objs as $obj){
641         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
642           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
643         }
644       }
646       /* check if current object is a new one */
647       if (preg_match ("/,ou=incoming,/i", $tmp)){
648         if (in_array_ics('gotoTerminal', $value['objectClass'])){
649           $add= "- "._("New terminal");
650         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
651           $add= "- "._("New workstation");
652         }elseif (in_array_ics('GOhard', $value['objectClass'])){
653           $add= "- "._("New Device");
654         }
655       } 
657       /* Detect type of object and create an entry for $this->terminals */
658       $terminal = array();
659       if ((in_array ($tmp, $responsible)) || ($add != "")){
660         if (in_array_ics('gotoTerminal', $value["objectClass"])){
661           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
662             $terminal             = $value;
663             $terminal['type']     = "T";
664             $terminal['is_new']   = $add;
665           } else {
666             $terminal             = $value;
667             $terminal['type']     = "D";
668             $terminal['message']  = _("Terminal template for");
669             $terminal['location'] = array_search($tmp, $this->config->departments); 
670           }
671         } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
672           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
673             $terminal             = $value;
674             $terminal['type']     = "L";
675             $terminal['is_new']   = $add;
676           } else {
677             $terminal             = $value;
678             $terminal['type']     = "D";
679             $terminal['location'] = array_search($tmp, $this->config->departments);
680             $terminal['message']  = _("Workstation template for");
681           }
682           if (isset($value["FAIstate"][0])){
683             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
684           }
685         } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
686           $terminal             = $value;
687           $terminal['type']     = "P";
688         } elseif (in_array_ics('goServer', $value["objectClass"])){
689           $terminal             = $value;
690           $terminal['type']     = "S";
691           if (isset($value["FAIstate"][0])){
692             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
693           }
694         } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
695           $terminal             = $value;
696           $terminal['type']     = "F";
697         }elseif (in_array_ics("GOhard",$value['objectClass'])){
698           $terminal = $value;
699           $terminal['type']   = "Q";
700           $terminal['is_new'] = $add;
701         } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
702           $terminal             = $value;
703           $terminal['type']     = "C";
704         } else{
705           $name= preg_replace('/\$$/', '', $value['cn'][0]);
706           if (isset($value['sambaDomainName'])){
707             $domain= " [".$value['sambaDomainName'][0]."]";
708           } else {
709             $domain= "";
710           }
711           $terminal=$value;
712           $terminal['type']     ="W";
713           $terminal['domain']   = $name.$domain;
714         }
715         $this->terminals[]=$terminal;
716       }
717     }
719     $tmp=array();
720     foreach($this->terminals as $tkey => $val ){
721       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
722     }
723     ksort($tmp);
724     $this->terminals=array();
725     foreach($tmp as $val){
726       $this->terminals[]=$val;
727     }
728     reset ($this->terminals);
729   }
731   function remove_lock()
732   {
733     if (isset($this->systab->dn)){
734       del_lock ($this->systab->dn);
735     }
736   }
739   function get_system_type($classes)
740   {
741     $type= "";
742     if (in_array_ics('ieee802Device', $classes)){
743       $type= "component";
744     }elseif (in_array_ics('gotoTerminal', $classes)){
745       $type= "terminal";
746     }elseif (in_array_ics('gotoWorkstation', $classes)){
747       $type= "workstation";
748     }elseif (in_array_ics('gotoPrinter', $classes)){
749       $type= "printer";
750     }elseif (in_array_ics('goFonHardware', $classes)){
751       $type= "phone";
752     }elseif (in_array_ics('goServer', $classes)){
753       $type= "server";
754     }elseif (in_array_ics('GOhard', $classes)){
755       $type= "NewDevice";
756     }elseif (in_array_ics('sambaAccount', $classes) ||
757         in_array_ics('sambaSamAccount', $classes)){
758       $type= "winstation";
759     }
760     return ($type);
761   }
764   function convert_list($input)
765   {
766     $temp= "";
767     $conv= array(       
768         "NQ" => array("select_newsystem.png",_("New System from incoming")),
769         "D" => array("select_default.png",_("Template")),
770         "T" => array("select_terminal.png",_("Terminal")),
771         "L" => array("select_workstation.png",_("Workstation")),
772         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
773         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
774         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
775         "F" => array("select_phone.png",_("Phone")),
776         "S" => array("select_server.png",_("Server")),
777         "GS" => array("select_server_green.png",_("Server is installing")),
778         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
779         "RS" => array("select_server_red.png",_("Server installation failed")),
780         "W" => array("select_winstation.png",_("Winstation")),
781         "C" => array("select_component.png",_("Network Device")),
782         "NT"=> array("select_new_terminal.png",_("New Terminal")),
783         "NL"=> array("select_new_workstation.png",_("New Workstation")),
784         "P" => array("select_printer.png",_("Printer")));
786     if((isset($input['is_new']))&&(!empty($input['is_new']))){
787       $input['type']="N".$input['type'];
788     }
789     foreach ($conv  as $key => $value){
790       if($input['type']==$key){
791         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
792         $tmp['class']=$key;
793         return $tmp;
794       }
795     }
796   }
798   
799   function getState($type, $state)
800   {
801     switch (preg_replace('/:.*$/', '', $state)) {
802       case 'installing':
803                 $type= 'G'.$type;
804                 break;
805       case 'error':
806                 $type= 'R'.$type;
807                 break;
808       case 'install':
809                 $type= 'Y'.$type;
810                 break;
811       case 'sysinfo':
812                 $type= 'Y'.$type;
813                 break;
814       case 'softupdate':
815                 $type= 'Y'.$type;
816                 break;
817     }
820     return ($type);
821   }
825 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
826 ?>