Code

Added additional check for ogroup activation
[gosa.git] / gosa-plugins / goto / admin / systems / goto / class_workstationStartup.inc
1 <?php
2 class workstartup extends plugin
3 {
4   /* Ldap server list */
5   var $gotoLdapServers    = array();
6   var $gotoLdapServerList = array();
7   var $gotoLdap_inherit   = FALSE;
9   /* Generic terminal attributes */
10   var $bootmode             = "G";
11   var $gotoBootKernel       = "default-inherited";
12   var $gotoKernelParameters = "";
13   var $gotoLdapServer       = "default-inherited";
14   var $gotoModules          = array();
15   var $gotoAutoFs           = array();
16   var $gotoFilesystem       = array();
17   var $gotoTerminalPath     = "";
18   var $gotoBootKernels      = array();
20   /* attribute list for save action */
21   var $attributes           = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", 
22                                     "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
23   var $objectclasses        = array("GOhard", "FAIobject");
25   /* Share */
26   var $gotoShares         = array();// Currently Share Option
27   var $gotoShare          = "";     // currently selected Share Option
28   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
29   var $gotoAvailableShares= array();// Available Shares for this account
31   /* Helper */
32   var $customParameters   = "";
33   var $orig_dn            = "";
34   var $ignore_account     = TRUE;
35  
36   /* FAI class selection */ 
37   var $FAIclass           = array();  // The currently selected classes 
38   var $FAIrelease         = "";
39   var $FAIdebianMirror    = "auto";
40   var $si_active            = FALSE;
41   var $si_fai_action_failed = FALSE;
43   var $cache              = array(); // Used as cache in fai mehtods
45   var $FAIstatus          = "";
46   var $FAIclasses         = array();
48   var $view_logged        = FALSE;
49   
50   /* FAI class selection */
51   var $InheritedFAIclass       = array();
52   var $InheritedFAIrelease     = "";
53   var $InheritedFAIdebianMirror= "auto";
55   var $CopyPasteVars    = array("gotoModules","gotoShares");
56   var $fai_activated    = FALSE;
57   var $o_group_dn       = "";
58   var $member_of_ogroup = FALSE;
60   function workstartup (&$config, $dn= NULL, $parent= NULL)
61   {
62     /* Check if FAI is active */
63     $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
64     if(!empty($tmp)){
65       $this->fai_activated = TRUE;
66     }else{
67       $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
68       $this->objectclasses  = array("GOhard");
69     }
71     plugin::plugin ($config, $dn, $parent);
73     /* Check for si daemon */
74     $this->si_active = isset($this->config->current['GOSA_SI']) && !empty($this->config->current['GOSA_SI']);
76     /* Check object group membership */
77     if(!isset($this->parent->by_object['ogroup'])){
78       $ldap = $this->config->get_ldap_link();
79       $ldap->cd ($this->config->current['BASE']);
80       $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
81       if($ldap->count()){
82         $this->member_of_ogroup = TRUE;
83         $attrs = $ldap->fetch();
84         $this->o_group_dn = $attrs['dn'];
85       }
86     }
88     /* Creating a list of valid Mirrors 
89      * none will not be saved to ldap.
90      */
91     $ldap   = $this->config->get_ldap_link();
92     $ldap->cd($this->config->current['BASE']);
93     foreach($this->config->data['SERVERS']['LDAP'] as $server) {
94       $this->gotoLdapServerList[]= $server; 
95     }
97     /* Get list of assigned ldap servers 
98      */ 
99     if(isset($this->attrs['gotoLdapServer'])){
100       unset($this->attrs['gotoLdapServer']['count']);
101       sort($this->attrs['gotoLdapServer']);
102       foreach($this->attrs['gotoLdapServer'] as $value){
103         $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
104       }
105     } 
106     if(!count($this->gotoLdapServers) && $this->member_of_ogroup){ 
107       $this->gotoLdap_inherit = TRUE;
108     }
110     /* FAI Initialization
111        Skip this if FAI is not activated 
112      */
113     if($this->fai_activated) {
115       $this->update_fai_cache(TRUE);
117       /* Parse used FAIclasses (stored as string).
118        * The single classes are seperated by ' '.
119        * There is also the release type given, after first
120        *  occurrence of ':'.
121        */
122       $this->FAIclass =array();
123       if(isset($this->attrs['FAIclass'][0])){
124         $tmp = split(" ",$this->attrs['FAIclass'][0]);
125         $tmp2 =array();  
127         foreach($tmp as $class){
128           if( ":" == $class[0] ) {
129             $this->FAIrelease = trim(substr($class, 1));
130           }else{
131             $tmp2[$class] = $class;
132           }
133         }
134         $this->FAIclass = $tmp2;
135       }
136     }
138     /* Get arrays */
139     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
140       if (isset($this->attrs["$val"]["count"])){
141         for ($i= 0; $i<$this->attrs["count"]; $i++){
142           if (isset($this->attrs["$val"][$i])){
143             array_push($this->$val, $this->attrs["$val"][$i]);
144           }
145         }
146       }
147       sort ($this->$val);
148       $this->$val= array_unique($this->$val);
149     }
151     /* Parse Kernel Parameters to decide what boot mode is enabled */
152     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
153       $this->bootmode= "G";
154     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
155       $this->bootmode= "D";
156     } elseif ($this->gotoKernelParameters == "") {
157       $this->bootmode= "G";
158     } else {
159       $this->bootmode= "T";
160     }
161     if (preg_match("/ o /", $this->gotoKernelParameters)){
162       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
163     } else {
164       $this->customParameters= "";
165     }
167     /* Prepare Shares */
168     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
169       unset($this->attrs['gotoShare']['count']);
170       foreach($this->attrs['gotoShare'] as $share){
171         $tmp = $tmp2 = array();
172         $tmp = split("\|",$share);
173         $tmp2['server']      =$tmp[0];
174         $tmp2['name']        =$tmp[1];
175         $tmp2['mountPoint']  =$tmp[2];
176         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
177       }
178     }
180     $this->gotoShareSelections= $config->getShareList(true);
181     $this->gotoAvailableShares= $config->getShareList(false);
182     $tmp2 = array();
183   
185     $this->orig_dn= $this->dn;
187     /* Handle inheritance value "default" */
188     if ($this->member_of_ogroup){
189       $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']'); 
190     }
192     /* If we are member in an object group,
193      *  we have to handle inherited values.
194      * So you can see what is inherited.
195      */
196     if ($this->member_of_ogroup){
198       if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
199         $this->FAIdebianMirror = "inherited";
200       }
202       if($this->fai_activated){
203         $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
204       }else{
205         $map= array("gotoBootKernel");
206       }
208       $ldap = $this->config->get_ldap_link();
209       $ldap->cat($this->o_group_dn);
210       $attrs= $ldap->fetch();
212       foreach ($map as $name){
213         if (!isset($attrs[$name][0])){
214           continue;
215         }
217         switch ($name){
218           case 'gotoBootKernel':
219             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
220             break;
222           case 'FAIclass':
223             $str = split(":",$attrs[$name][0]);
224             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
225             $this->InheritedFAIrelease  = trim($str[1]);
226             break;
228           case 'FAIdebianMirror':
229             $this->InheritedFAIdebianMirror = $attrs[$name][0];
230             break;
231         }
232       }
233     }
236     if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
238       /* Check if the current mirror is available 
239        */
240       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
241         if(count($this->FAIclass)){
242           msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
243         }
244         $this->FAIdebianMirror = "auto";
245         $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
246         $this->cache =array();
247         $this->update_fai_cache();
248         
249       }
250   
251       /* Check if the current mirror is available 
252        */
253       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
254         $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]); 
255         if(count($this->FAIclass)){
256           msg_dialog::display(_("Error"), sprintf(_("FAI release '%s' is not available on mirror '%s' - setting to release '%s'!"), $this->FAIrelease, $this->FAIdebianMirror,$new_release), ERROR_DIALOG);
257         }
258         $this->FAIrelease = $new_release;
259         $this->cache =array();
260         $this->update_fai_cache();
261       }
262     }
264 #   /* Get list of boot kernels */
265 #   if (isset($this->config->data['TABS'])){
266 #     $command= $this->config->search(get_class($this), "KERNELS",array('tabs'));
267 #     if (!check_command($command)){
268 #       $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
269 #           get_class($this));
270 #     } else {
271 #       $fh= popen($command, "r");
272 #       while (!feof($fh)) {
273 #         $buffer= trim(fgets($fh, 256));
274 #         if(!empty($buffer)){
275 #           $name=$value = $buffer;
276 #           if(preg_match("/:/",$buffer)){
277 #             $name = preg_replace("/:.*$/","",$buffer);
278 #             $value= preg_replace("/^.*:/","",$buffer);
279 #             $this->gotoBootKernels[$name]= $name.":".$value;
280 #           }else{
281 #             $this->gotoBootKernels[$name]= $value;
282 #           }
283 #         }
284 #       }
285 #       pclose($fh);
286 #     }
287 #   }
289 #    /* Turn to default, if we've nothing to inherit */
290 #    if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
291 #      $this->gotoBootKernel= "default";
292 #    }
293   }
295   
296   function check()
297   {
298     $messages = array();
299     
300     /* Call common method to give check the hook */
301     $messages= plugin::check();
303     /* If there are packages selected, but no mirror show error */   
304     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
305       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
306     }
308     return($messages);
309   }
311   function execute()
312   {
313         /* Call parent execute */
314         plugin::execute();
316     if($this->is_account && !$this->view_logged){
317       $this->view_logged = TRUE;
318       new log("view","workstation/".get_class($this),$this->dn);
319     }
321     /* Do we need to flip is_account state? */
322     if(isset($_POST['modify_state'])){
323       if($this->is_account && $this->acl_is_removeable()){
324         $this->is_account= FALSE;
325       }elseif(!$this->is_account && $this->acl_is_createable()){
326         $this->is_account= TRUE;
327       }
328     }
330     /* Do we represent a valid terminal? */
331     if (!$this->is_account && $this->parent === NULL){
332       $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
333         msgPool::noValidExtension(_("workstation"))."</b>";
334       return ($display);
335     }
337     /* Add module */
338     if (isset ($_POST['add_module'])){
339       if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
340         $this->add_list ($this->gotoModules, $_POST['module']);
341       }
342     }
344     /* Delete module */
345     if (isset ($_POST['delete_module'])){
346       if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
347         $this->del_list ($this->gotoModules, $_POST['modules_list']);
348       }
349     }
351     /* FAI class management */
352     if($this->fai_activated){
353       if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
354         $found = 0 ; 
356         /* If this new class/profile will attach a second partition table
357          * to our list of classes, abort and show a message.
358          */
359         foreach($this->FAIclass as $name){
360           if(isset($this->FAIclassInfo[$name])){
361             foreach($this->FAIclassInfo[$name] as $atr){
362               if(isset($atr['obj'])){
363                 if($atr['obj'] == "FAIpartitionTable"){
364                   $found ++ ; 
365                 }
366               }
367             }
368           }
369         }
371         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
372           msg_dialog(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
373         }else{
374           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
375         }
376       }
378       $sort = false;
380       /* Move one used class class one position up or down */
381       if($this->acl_is_writeable("FAIclass")){
382         foreach($_POST as $name => $val){
384           $sort_type = false;
385           if((preg_match("/sort_up/",$name))&&(!$sort)){
386             $sort_type = "sort_up_";
387           }
388           if((preg_match("/sort_down/",$name))&&(!$sort)){
389             $sort_type = "sort_down_";
390           }
392           if(($sort_type)&&(!$sort)){
393             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
394             $sort = true;
396             $last = -1;
397             $change_down  = -1;
399             /* Create array with numeric index */ 
400             $tmp = array();
401             foreach($this->FAIclass as $class){
402               $tmp [] = $class;
403             }
405             /* Walk trough array */
406             foreach($tmp as $key => $faiName){
407               if($faiName == $value){
408                 if($sort_type == "sort_up_"){
409                   if($last != -1){
410                     $change_down= $last;
411                   }
412                 }else{
413                   if(isset($tmp[$key+1])){
414                     $change_down = $key;
415                   }
416                 }
417               }
418               $last = $key;
419             }
421             $tmp2 = array();
422             $skip = false;    
424             foreach($tmp as $ky => $vl){
426               if($ky == $change_down){
427                 $skip = $vl;
428               }else{
429                 $tmp2[$vl] = $vl;
430               }
431               if(($skip != false)&&($ky != $change_down)){
432                 $tmp2[$skip]  = $skip;
433                 $skip =false;
434               }
435             }   
436             $this->FAIclass = $tmp2; 
437           }
439           if(preg_match("/fai_remove/i",$name)){
440             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
441             unset($this->FAIclass[$value]);
442           }
443         }
444       }
446       /* Delete selected class from our list */
447       if($this->acl_is_writeable("FAIclass")){
448         if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
449           if(isset($this->FAIclass[$_POST['FAIclassSel']])){
450             unset($this->FAIclass[$_POST['FAIclassSel']]);
451           }
452         }
453       }
454     }// END fai handling
456     /* Show main page */
457     $smarty= get_smarty();
459     /* Assign ACLs to smarty */
460     $tmp = $this->plInfo();
461     foreach($tmp['plProvidedAcls'] as $name => $translation){
462       $smarty->assign($name."ACL",$this->getacl($name));
463     } 
465     $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
467     /* In this section server shares will be defined
468      * A user can select one of the given shares and a mount point
469      *  and attach this combination to his setup.
470      */
471     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
472     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
474     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
475      * This entry will be, a combination of mountPoint and sharedefinitions
476      */
477     if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
478       /* We assign a share to this user, if we don't know where to mount the share */
479       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
480         msg_dialog(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
481       }else{
482         if(count($this->gotoAvailableShares)){
483           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
484           $s_mount = $_POST['gotoShareMountPoint'];
485           /* Preparing the new assignment */
486           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
487           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
488         }
489       }
490     }
492     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
493      * If there is no defined share selected, we will abort the deletion without any message
494      */
495     if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
496       unset($this->gotoShares[$_POST['gotoShare']]);
497     }
499     $smarty->assign("gotoShares",$this->printOutAssignedShares());
500     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
501     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
502     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
504     /* Create divSelectBox for ldap server selection
505      */
506     $SelectBoxLdapServer = new divSelectBox("LdapServer");
507     $SelectBoxLdapServer->SetHeight(130);
509     /* Add new ldap server to the list */
510     if(!$this->gotoLdap_inherit && isset($_POST['add_ldap_server']) && isset($_POST['ldap_server_to_add'])){
511       if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
512         $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
513         if(!in_array($to_add,$this->gotoLdapServers)){
514           $this->gotoLdapServers[] = $to_add;
515         }
516       }
517     }
518     
519     /* Move ldap servers up and down */
520     if(!$this->gotoLdap_inherit){
521       foreach($_POST as $name => $value){
522         if(preg_match("/sort_ldap_up_/",$name)){
523           $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
524           $from =  $id;  
525           $to   =  $id -1;
526           $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
527           if($tmp){
528             $this->gotoLdapServers = $tmp;
529           }
530           break;
531         }
532         if(preg_match("/sort_ldap_down_/",$name)){
533           $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
534           $from =  $id;  
535           $to   =  $id +1;
536           $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
537           if($tmp){
538             $this->gotoLdapServers = $tmp;
539           }
540           break;
541         }
542         if(preg_match("/gotoLdapRemove_/",$name)){
543           $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
544           $value = $this->gotoLdapServers[$id];
545           $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
546           break;
547         }
548       } 
549     }
550   
551     /* Add Entries */
552     foreach($this->gotoLdapServers as $key => $server){
553       /* Announce missing entries */
554       if(!in_array($server,$this->gotoLdapServerList)){
555         $server = $server."&nbsp;<font style='color:red'>(missing)</font>";
556       }
558       /* Convert old style entry */
559       if (!preg_match('%:ldap://%', $server)){
560         $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
562       /* Beautify new style entries */
563       } else {
564         $server= preg_replace("/^[^:]+:/", "", $server);
565       }
567       $SelectBoxLdapServer->AddEntry(
568           array(array("string" => $server),
569             array("string" => 
570               "<input class='center' type='image' src='images/lists/sort-up.png' name='sort_ldap_up_".$key."'>&nbsp;".
571               "<input class='center' type='image' src='images/lists/sort-down.png' name='sort_ldap_down_".$key."'>&nbsp;".
572               "<input class='center' type='image' src='images/lists/trash.png' name='gotoLdapRemove_".$key."'>",
573               "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
574     }    
576     if($this->gotoLdap_inherit){
577       $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
578     }else{
579       $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
580     }
581     
582     $list = array();
583     foreach($this->gotoLdapServerList as $key => $entry){
584       if(!in_array($entry,$this->gotoLdapServers)){
586         /* Convert old style entry */
587         if (!preg_match('%:ldap://%', $entry)){
588           $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
590         /* Beautify new style entries */
591         } else {
592           $entry= preg_replace("/^[^:]+:/", "", $entry);
593         }
595         $list[$key] = $entry;
596       }
597     }
598     $smarty->assign("gotoLdapServers",    $SelectBoxLdapServer->DrawList());
599     $smarty->assign("gotoLdapServerList", $list);
600     $smarty->assign("gotoLdap_inherit",   $this->gotoLdap_inherit);
601     $smarty->assign("JS",  session::get('js'));
603     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
604       $smarty->assign("$val", $this->$val);
605     }
607     /* Values */
608     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
609       $smarty->assign($val, $this->$val);
610     }
612     $smarty->assign("fai_activated",$this->fai_activated);
614     /* Create FAI output */
615     $this->update_fai_cache();
616     $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
617     $smarty->assign("si_active",$this->si_active);
618   
619     if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
621       $smarty->assign("FAIservers"  , $this->cache['SERVERS']);
622       $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
623       $smarty->assign("FAIrelease"  , $this->FAIrelease);
624       $smarty->assign("FAIclasses"  , $this->selectable_classes());
626       /* Get classes for release from cache.
627        * Or build cache
628        */
629       if($this->FAIdebianMirror == "inherited"){
630         $release = $this->InheritedFAIrelease;
631       }else{
632         $release = $this->FAIrelease;
633       }
635       $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
636       $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
638       $div = new divSelectBox("WSFAIscriptClasses");
639       $div -> SetHeight("110");
640       $str_up     = " &nbsp;<input type='image' src='images/lists/sort-up.png'    name='sort_up_%s'    value='%s'>";
641       $str_down   = " &nbsp;<input type='image' src='images/lists/sort-down.png'  name='sort_down_%s'  value='%s'>";
642       $str_remove = " &nbsp;<input type='image' src='images/lists/trash.png'  name='fai_remove_%s' value='%s'>";
643       $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
645       /* Get classes */
646       if($this->FAIdebianMirror == "inherited"){
647         $tmp = $this->InheritedFAIclass;
648       }else{
649         $tmp = $this->FAIclass;
650       }
652       /* Get invalid classes */
653       $invalid = $this->get_invalid_classes($tmp);
655       /* Draw every single entry */
656       $i = 1;
657       foreach($tmp as $class){
659         /* Mark invalid classes. (Not in selected release)
660          */
661         $marker = "";
662         if(in_array_ics($class,$invalid)){
663           $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
664         }
666         /* Create up/down priority icons  
667          * Skip this, if we have inherited the FAI classes.
668          */
669         if($this->FAIdebianMirror == "inherited"){
670           $str = "";
671         }else{
672           if($i==1){
673             $str = $str_empty.$str_down.$str_remove;
674           }elseif($i == count($this->FAIclass)){
675             $str = $str_up.$str_empty.$str_remove;
676           }else{
677             $str = $str_up.$str_down.$str_remove;
678           }
679         }
680         $i ++ ; 
682         /* Get Description tag 
683          *  There may be several FAI objects with the same class name, 
684          *   use the description from FAIprofile, if possible.
685          */  
686         $desc = ""; 
687         if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
688           foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
689             if(isset($types['Desc'])){
690               $desc= $types['Desc'];
691               if($types['Type'] == "FAIprofile"){
692                 break;
693               }
694             }
695           }
696         }
697         if(!empty($desc)){
698           $desc = "&nbsp;[".trim($desc)."]";
699         }        
701         $div->AddEntry(array(
702               array("string"=>$class.$desc.$marker),
703               array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
704               ));
705       }  
706       $smarty->assign("FAIScriptlist",$div->DrawList()); 
707     }// END FAI output generation 
709     /* Radio button group */
710     if (preg_match("/G/", $this->bootmode)) {
711       $smarty->assign("graphicalbootup", "checked");
712     } else {
713       $smarty->assign("graphicalbootup", "");
714     }
715     if (preg_match("/T/", $this->bootmode)) {
716       $smarty->assign("textbootup", "checked");
717     } else {
718       $smarty->assign("textbootup", "");
719     }
720     if (preg_match("/D/", $this->bootmode)) {
721       $smarty->assign("debugbootup", "checked");
722     } else {
723       $smarty->assign("debugbootup", "");
724     }
726     /* Show main page */
727     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
728   }
731   function remove_from_parent()
732   {
733     $this->handle_post_events("remove");
734     new log("remove","workstation/".get_class($this),$this->dn);
735   }
738   /* Save data to object */
739   function save_object()
740   {
741     $old_mirror  = $this->FAIdebianMirror;
742     plugin::save_object();
744     /* Update release */
745     if($old_mirror != $this->FAIdebianMirror){
746       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
747         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
748       }
749     }
751     if(isset($_POST['WorkstationStarttabPosted'])){
752       if(isset($_POST['gotoLdap_inherit'])){
753         $this->gotoLdap_inherit = TRUE;
754       }else{
755         $this->gotoLdap_inherit = FALSE;
756       }
758       /* Save group radio buttons */
759       if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
760         $this->bootmode= $_POST["bootmode"];
761       }
763       /* Save kernel parameters */
764       if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
765         $this->customParameters= $_POST["customParameters"];
766       }
767     }
768   }
771   /* Save to LDAP */
772   function save()
773   {
775     /* Depending on the baseobject (Ogroup / WS) we
776      *  use another set of objectClasses
777      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
778      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
779      */
780     if(isset($this->parent->by_object['ogroup'])){
781       $this->objectclasses = array("gotoWorkstationTemplate");
782     }elseif(isset($this->parent->by_object['workgeneric'])){
783       $this->objectclasses = array("GOhard");
784     }elseif(isset($this->parent->by_object['servgeneric'])){
785       $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
786     }else{
787       print "Object Type Configuration : unknown";
788       exit();
789     }
791     /* Append FAI class */
792     if($this->fai_activated){
793       $this->objectclasses[]  = "FAIobject";
794     }
796     /* Find proper terminal path for tftp configuration
797        FIXME: This is suboptimal when the default has changed to
798        another location! */
799     if (($this->gotoTerminalPath == "default")){
800       $ldap= $this->config->get_ldap_link();
802       /* Strip relevant part from dn, keep trailing ',' */
803       $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalou')."/i", "", $this->dn);
804       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
806       /* Walk from top to base and try to load default values for
807          'gotoTerminalPath'. Abort when an entry is found. */
808       while (TRUE){
809         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
811         $ldap->cat("cn=default,".get_ou('terminalou').$tmp.
812             $this->config->current['BASE'], array('gotoTerminalPath'));
813         $attrs= $ldap->fetch();
814         if (isset($attrs['gotoTerminalPath'])){
815           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
816           break;
817         }
819         /* Nothing left? */
820         if ($tmp == ""){
821           break;
822         }
823       }
824     }
826     /* Add semi automatic values */
827     // FIXME: LDAP Server may not be set here...
828     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
830     switch ($this->bootmode){
831       case "D":
832         $this->gotoKernelParameters.= " debug";
833       break;
834       case "G":
835         $this->gotoKernelParameters.= " splash=silent";
836       break;
837     }
838     if ($this->customParameters != ""){
839       $this->gotoKernelParameters.= " o ".$this->customParameters;
840     }
842     plugin::save();
844     unset( $this->attrs['FAIrelease'] );
845     $str = "";
847     /* Skip FAI attribute handling if not necessary */
848     if($this->fai_activated && !$this->si_fai_action_failed){
849       if($this->FAIdebianMirror == "inherited"){
850         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array();
851       }else{
852         foreach($this->FAIclass as $class){
853           $str .= $class." ";
854         }
855         $str = trim($str);
856         if(empty($this->attrs['FAIclass'])){
857           $this->attrs['FAIclass'] = array();
858         }else{
859           $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
860         }
861       }
862     }
864     /* Add missing arrays */
865     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
866       if (isset ($this->$val) && count ($this->$val) != 0){
867     
868         $this->attrs["$val"]= array_unique($this->$val);
869       }
870       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
871     }
873     /* Prepare list of ldap servers */
874     $this->attrs['gotoLdapServer'] = array();
875     if(!$this->gotoLdap_inherit){
876       $i = 0;
877       foreach($this->gotoLdapServers as $server){
878         $i ++;
879         $this->attrs['gotoLdapServer'][] = $i.":".$server;
880       }
881     }
883     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
884       $this->attrs['gotoBootKernel']= array();
885     }
887     /* if mirror == none stop saving this attribute */
888     if($this->FAIdebianMirror == "none"){
889       $this->FAIdebianMirror = "";
890     }
891    
892     /* Get FAIstate from object, the generic tab could have changed it during execute */
893     $ldap= $this->config->get_ldap_link();
894     $ldap->cd($this->dn);
897     /* Skip FAI attribute handling if not necessary */
898     if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
899       $ldap->cat($this->dn,array("FAIstate"));
900       $checkFAIstate = $ldap->fetch();
902       /* Remove FAI objects if no FAI class is selected */ 
903       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
904         $this->attrs['FAIclass']        = array();
905         $this->attrs['FAIdebianMirror'] = array();
906       }
907     }
910     /* prepare share settings */
911     $tmp = array();
912     foreach($this->gotoShares as $name => $settings){
913       $tmp2= split("\|",$name);
914       $name = $tmp2[0];
915       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
916     }
917     $this->attrs['gotoShare']=$tmp;
918     $this->cleanup();
919     $ldap->modify ($this->attrs); 
920     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
922     if (!$ldap->success()){
923       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
924     }
925     $this->handle_post_events("modify");
927     /* Check if LDAP server has changed */
928     if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent"))){
929       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
930       $o_queue = new gosaSupportDaemon();
931       if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
932         $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
933         $macs = array();
934     
935         /* Get list of macAddresses 
936          */
937         if(isset($this->parent->by_object['ogroup'])){
938         
939           /* If we are an object group, add all member macs 
940            */
941           $p = $this->parent->by_object['ogroup'];
942           foreach($p->memberList as $dn => $obj){
943             if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
944               $macs[] = $p->objcache[$dn]['macAddress'];
945             }
946           }
947         }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
949           /* We are a workstation. Add current mac.
950            */
951           $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
952           if(!empty($mac)){
953             $macs[] = $mac;
954           }          
955         }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
957           /* We are a server. Add current mac.
958            */
959           $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
960           if(!empty($mac)){
961             $macs[] = $mac;
962           }          
963         }
965         /* Trigger event for all member objects 
966          */
967 print_a ($macs);
968 #        foreach($macs as $mac){
969 #          $tmp = new $evt['CLASS_NAME']($this->config);
970 #          $tmp->set_type(TRIGGERED_EVENT);
971 #          $tmp->add_targets(array($mac));
972 #          if(!$o_queue->append($tmp)){
973 #            msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
974 #          }
975 #        }
976       }
977     }
978   }
981   /* Add value to array, check if unique */
982   function add_list (&$array, $value)
983   {
984     if ($value != ""){
985       $array[]= $value;
986       sort($array);
987       array_unique ($array);
988     }
989   }
992   /* Delete value to array, check if unique */
993   function del_list (&$array, $list)
994   {
995     $tmp= array();
996     foreach ($array as $mod){
997       if (!in_array($mod, $list)){
998         $tmp[]= $mod;
999       }
1000     }
1001     $array= $tmp;
1002   }
1004   /* Generate ListBox frindly output for the defined shares
1005    * Possibly Add or remove an attribute here,
1006    */
1007   function printOutAssignedShares()
1008   {
1009     $a_return = array();
1010     if(is_array($this->gotoShares)){
1011       foreach($this->gotoShares as $share){
1012         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1013       }
1014     }
1015     return($a_return);
1016   }
1020   function PrepareForCopyPaste($source)
1021   {
1022     plugin::PrepareForCopyPaste($source);    
1023     $source_o = new workstartup ($this->config, $source['dn']);
1024     foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
1025           "gotoKernelParameters","gotoShares","customParameters") as $attr){
1026       $this->$attr = $source_o->$attr;
1027     }
1028   }
1030   
1031   function array_switch_item($ar,$from,$to)
1032   {
1033     if(!is_array($ar)){
1034       return(false);
1035     }
1036     if(!isset($ar[$from])){
1037       return(false);
1038     }
1039     if(!isset($ar[$to])){
1040       return(false);
1041     }
1043     $tmp = $ar[$from];
1044     $ar[$from] = $ar[$to];    
1045     $ar[$to] = $tmp;    
1046     return($ar);
1047   }
1050   /* Return plugin informations for acl handling */ 
1051   static function plInfo()
1052   {
1053     return (array( 
1054           "plShortName"   => _("Startup"),
1055           "plDescription" => _("System startup"),
1056           "plSelfModify"  => FALSE,
1057           "plDepends"     => array(),
1058           "plPriority"    => 9,
1059           "plSection"     => array("administration"),           
1060           "plCategory"    => array("workstation","server","ogroups"),
1062           "plProvidedAcls"=> array(
1063             "gotoLdapServer"        => _("Ldap server"),
1064             "gotoBootKernel"        => _("Boot kernel"),
1065             "gotoKernelParameters"  => _("Kernel parameter"),
1067             "gotoModules"           => _("Kernel modules"),
1068             "gotoShare"             => _("Shares"),
1070             "FAIclass"              => _("FAI classes"),
1071             "FAIdebianMirror"       => _("Debian mirror"),
1072             "FAIrelease"            => _("Debian release"),
1074             "FAIstatus"             => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1075           ));
1076   }
1079   /* Updates release dns 
1080    *  and reads all classes for the current release, 
1081    *  if not already done ($this->cache).
1082    */
1083   function update_fai_cache($first_call = FALSE)
1084   {
1085     $force = FALSE;
1086     if(!$this->si_active) return; 
1087     $start = microtime(TRUE);  
1089     if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1091     $this->si_fai_action_failed = FALSE;
1093     /* Get the list of available servers and their releases. 
1094      */
1095     if($force || !isset($this->cache['SERVERS'])){
1097       /* Only add inherit option, if we are part in an object group
1098        */
1099       if($this->member_of_ogroup){
1100         $this->cache['SERVERS']['inherited']=array();
1101       }
1103       $o_queue = new gosaSupportDaemon();
1104       $tmp = $o_queue->FAI_get_server(); 
1105       if($o_queue->is_error()){
1106         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1107         $this->si_fai_action_failed = TRUE;
1108         $this->cache = array();
1109         return;
1110       }else{
1111         foreach($tmp as $entry){
1112           $rel = $entry['RELEASE'];
1113           $this->cache['SERVERS']['auto'][$rel] = $rel;
1114           $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
1115         }
1116       }
1117     }
1119     /* Build up arrays, without checks */
1120     if(!$first_call){
1122       /* Check if the selected mirror is available */
1123       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1124         $this->FAIdebianMirror = "auto";
1125         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1126         trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1127       }
1129       /* Check if the selected release is available */
1130       if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1131         trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1132         $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1133       }
1134     }
1136     /* Get classes for release from cache. 
1137      * Or build cache
1138      */
1139     if($this->FAIdebianMirror == "inherited"){
1140       $release = $this->InheritedFAIrelease;
1141     }else{
1142       $release = $this->FAIrelease;
1143     }
1145     if($force || !isset($this->cache['CLASSES'][$release])){
1147       /* Get the list of available servers and their releases.
1148        */
1149       $o_queue = new gosaSupportDaemon();
1150       $tmp = $o_queue->FAI_get_classes($release);
1151       $this->cache['CLASSES'][$release] = array();
1152       if($o_queue->is_error()){
1153         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1154         $this->si_fai_action_failed = TRUE;
1155         $this->cache=array();
1156         return;
1157       }else{
1158         foreach($tmp as $entry){
1159           $class = $entry['CLASS'];
1160           $this->cache['CLASSES'][$release][$class] = $this->analyse_fai_object($entry); 
1161         }
1162       }
1164       /* Add object caught from external hook
1165        */
1166       $lines= $this->GetHookElements();
1167       foreach ($lines as $hline){
1168         $entries= split(";", $hline);
1169         $server = $entries['0'];
1170         $url    = $entries['1'];
1171         if (!empty($url)){
1173           /* Split releases */
1174           if (isset($entries[2])){
1175             $releases= split(",", $entries[2]);
1177             foreach ($releases as $release_data){
1178               $release_c  = preg_replace('/:.*$/', '', $release_data);
1179               $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1180               $classes_c  = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1182               if($release_c == $release){
1183                 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1184                 $this->cache['SERVERS']['auto'][$release_c]=$release_c; 
1185                 foreach ($classes_c as $class){
1186                   if ($class != ""){
1187                     $this->cache['CLASSES'][$release_c][$class]= array();
1188                   }
1189                 }
1190               }
1191             }
1192           }
1193         }
1194       }
1195     }
1197     /* Get list of available kernel for this release 
1198      */
1199     $force = TRUE;
1200     if($force || !isset($this->cache['KERNELS'][$release])){
1201       $o_queue = new gosaSupportDaemon();
1202       $tmp = $o_queue->FAI_get_kernels($release);
1203       $this->cache['KERNELS'][$release] = array();
1204       foreach($this->gotoBootKernels as $name => $default){
1205         $this->cache['KERNELS'][$release][$name] = $default;
1206       }
1207       foreach($tmp as $kernel){
1208         if(empty($kernel)) continue;
1209         $this->cache['KERNELS'][$release][$kernel]=$kernel;
1210       }
1211     }
1212   }
1215   /* This function return an array containing all 
1216    *  invalid classes for the selected server/release
1217    */
1218   function get_invalid_classes($classes)
1219   {
1220     $this->update_fai_cache();
1221     if($this->FAIdebianMirror == "inherited"){
1222       $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1223     }else{
1224       $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1225     }
1228     /* Detect all classes that are not valid 
1229      *  for the selected release 
1230      */
1231     $NA = array();
1232     foreach($classes as $class){
1233       if(!isset($release_classes[$class])){
1234         $NA[] = $class;
1235       }
1236     }
1237     return($NA);
1238   }  
1240   
1241   /* Get all selectable classes for the ui select box
1242    */
1243   function selectable_classes()
1244   {
1245     $this->update_fai_cache();
1247     if($this->FAIdebianMirror == "inherited"){
1248       $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1249     }else{
1250       $classes = $this->cache['CLASSES'][$this->FAIrelease];
1251     }
1253     $Abbr ="";
1254     $ret= array();
1255     foreach($classes as $class_name => $class_types){
1256       if(!in_array($class_name,$this->FAIclass)){
1257         foreach($class_types as $type){
1258           if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1259             $Abbr .= $type['Abbr']." ";
1260           }
1261         }
1262         $ret[$class_name] = trim($Abbr);
1263       }
1264     }
1265     uksort($ret, 'strnatcasecmp');
1266     return($ret);
1267   }
1270   /* Analyse FAI object and return an array with usefull informations like 
1271    *  FAIobject type.
1272    */
1273   function analyse_fai_object($attr)
1274   {
1275     $tmp = array();
1276     switch($attr['TYPE']){
1278       case 'FAIpackageList':
1279         $tmp["Type"]= 'FAIpackageList';
1280         $tmp["Abbr"]= 'Pl';
1281         break;
1282       case 'FAItemplate': 
1283         $tmp["Type"]= 'FAItemplate'; 
1284         $tmp["Abbr"]= 'T'; 
1285         break;
1286       case 'FAIvariable':
1287         $tmp["Type"]= 'FAIvariable'; 
1288         $tmp["Abbr"]= 'V'; 
1289         break;
1290       case 'FAIscript':
1291         $tmp["Type"]= 'FAIscript'; 
1292         $tmp["Abbr"]= 'S'; 
1293         break;
1294       case 'FAIhook':
1295         $tmp["Type"]= 'FAIhook'; 
1296         $tmp["Abbr"]= 'H'; 
1297         break;
1298       case 'FAIpartitionTable':
1299         $tmp["Type"]= 'FAIpartitionTable'; 
1300         $tmp["Abbr"]= 'Pt'; 
1301         break;
1302       case 'FAIprofile':
1303         $tmp["Type"]= 'FAIprofile'; 
1304         $tmp["Abbr"]= 'P'; 
1305         break;
1306       default: trigger_error("Unknown FAI object type!");;
1307     }
1308     return($tmp);
1309   }
1312   /* Return repository hook output, if possible.
1313    */
1314   function GetHookElements()
1315   {
1316     $ret = array();
1317     $cmd= $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
1318     if(!empty($cmd)){
1319       $res = shell_exec($cmd);
1320       $res2 = trim($res);
1321       if((!$res)){
1322         msg_dialog(_("Configuration error"), msgPool::cmdexecfailed("REPOSITORY_HOOK", $cmd), ERROR_DIALOG);
1323       }elseif(empty($res2)){
1324         msg_dialog(_("Configuration error"), _("REPOSITORY_HOOK returned no result!"), ERROR_DIALOG);
1325       }else{
1326         $tmp = split("\n",$res);
1327         foreach($tmp as $line){
1328           if(empty($line)) continue;
1329           $ret[]= $line;
1330         }
1331       }
1332     }
1333     return($ret);
1334   }
1337   /* This function creates the release name out of a dn 
1338    *  e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1339    */
1340   function dn_to_release_name($dn)
1341   {
1342     $relevant = preg_replace("/,".normalizePreg(get_ou("faiou")).".*$/","",$dn);
1343     $parts    = array_reverse(split("\,",$relevant));
1344     $str ="";
1345     foreach($parts as $part){
1346       $str .= preg_replace("/^ou=/","",$part)."/";
1347     }
1348     return(preg_replace("/\/$/","",$str)); 
1349   }
1352 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1353 ?>