Code

Fixed hotplug remove
[gosa.git] / plugins / personal / environment / class_environment.inc
1 <?php
3 class environment extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary          = "Manage server basic objects";
7   var $cli_description      = "Some longer text\nfor help";
8   var $cli_parameters       = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   var $ignore_account       = FALSE;
12   var $plHeadline           = "Environment";
13   var $plDescription        = "This does something";
14   var $dialog               = false;    // Indicates that we are currently editing in an seperate dialog
15   
16   var $in_dialog            = false;
17   var $uid                  = "";
19   var $is_group             = false;
20   var $view_logged = FALSE;
21   
22   /* Attribute definition
23    */
25   /* profile management */
26   var $useProfile         = false;  // Specifies if we want to use a Server 
27   var $gotoProfileServer  = "";     // Specifies the selected profile server
28   var $gotoProfileServers = array();// Specifies all available and selectable servers
29   var $gotoProfileFlags   = "";     // Flags enabled  ? only used to set ACL and save 
30   var $gotoProfileFlagC  = "";     // Flag is set to C if we have the profile caching fucntion enabled 
31   
32   var $gotoXResolution    = "auto";     // The selected resolution eg: 1024x768
33   var $gotoXResolutions   = array();// Contains all available resolutions for this account
34   var $gotoProfileFlagL  = "";     // Flag is set to L to enable runtime resolution change 
35   var $gotoProfileQuota   = "";     // User Quota Settings
37   /* Logon script section*/
38   var $gotoLogonScripts   = array();// Contains all available Logon Scripts  
39   var $gotoLogonScript    = "";     // The selected Logon Script
41   /* Printer */
42   var $gotoPrinter        = array();// All available Printer, with their configurations
43   var $gotoPrinterSel     = "";     //  The selected Printer
44   var $gosaDefaultPrinter = "";     // Default printer
46   /* Share */
47   var $gotoShares         = array();// Current Share Options
48   var $gotoShare          = "";     // currently selected Share Option
49   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
50   var $gotoAvailableShares= array();// Available Shares for this account
52   /* Kiosk profile */
53   var $kiosk_enabled      = FALSE;
54   var $gotoKioskProfile   = "";     // The selected Kiosk Profile
55   var $gotoKioskiProfile_Server    = "";     // The selected Kiosk Profile
56   var $gotoKioskiProfile_Profile   = "";     // The selected Kiosk Profile
57   var $gotoKioskProfiles  = array();// All available Kiosk profiles
59   /* Hotplug Devices */
60   var $gotoHotplugDevice  = array();     // Selected hotplug
61   var $gotoHotplugDevices = array();// Already configured hotplug devices 
62   var $gotoHotplugDeviceDN= array();
64   var $NewAddedPrinters   = array();
65   var $NewDeletedPrinters = array();
67   /* general settings */
68   // Sets the attributes which will kept on page reload, which will be saved, ...
70   var $CopyPasteVars      = array("gotoHotplugDevices","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn");
72   var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN",
73       "gotoXResolution","gotoProfileQuota",
74       "gotoLogonScripts","gotoLogonScript",
75       "gotoPrinter", "gosaDefaultPrinter",
76       "gotoShares","gotoShare",
77       "gotoKioskProfile");
78   var $objectclasses      = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here 
79   var $cn;
80   var $OrigCn;
81   var $add_del_printer_member_was_called = false;
83   function environment (&$config, $dn= NULL)
84   {
85     plugin::plugin ($config, $dn);
87     /* Setting uid to default */
88     if(isset($this->attrs['uid'][0])){
89       $this->uid = $this->attrs['uid'][0];
90     }
92     /* Check : Are we currently editing a group or user dialog */
93     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
94       $suffix="Group";
95       $this->uid          = $this->attrs['cn'][0];
96       $this->attrs['uid'] = $this->attrs['cn'][0];
97       $this->OrigCn = $this->attrs['cn'][0];
98     }else{
99       $suffix="User";
100     }
102     /* Get all Printer assignments */
103     $ldap = $this->config->get_ldap_link();
104     $ldap->cd($this->config->current['BASE']);
105     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
106     while($printer = $ldap->fetch()){
107       $this->gotoPrinter[$printer['cn'][0]]=$printer;
108       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
109     }
110     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
111     while($printer = $ldap->fetch()){
112       $this->gotoPrinter[$printer['cn'][0]]=$printer;
113       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
114     }
117     /* Prepare hotplugs */
118     if(isset($this->attrs['gotoHotplugDeviceDN']) && is_array($this->attrs['gotoHotplugDeviceDN'])){
119       $ldap = $this->config->get_ldap_link();
120       $ldap->cd($this->config->current['BASE']);
121       for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
122         $ldap->cat($this->attrs['gotoHotplugDeviceDN'][$i]);
123         if($ldap->count()){
124           $attrs = $ldap->fetch(); 
126           if(isset($attrs['gotoHotplugDevice'][0])){
127             $tmp      = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]);
128             $tmp2     = array();
129             $tmp2['name']         = $attrs['cn'][0];
130             $tmp2['description']  = $tmp[0];
131             $tmp2['id']           = $tmp[1];
132             $tmp2['produkt']      = $tmp[2];
133             $tmp2['vendor']       = $tmp[3];
134             $tmp2['dn']           = $attrs['dn'];
135             $this->gotoHotplugDevices[] = $tmp2; 
136           }
137         }else{
138           print_red(sprintf(_("The selected hotplug device %s is no longer available, it will be removed when you save this account."),$this->attrs['gotoHotplugDeviceDN'][$i]));
139         }
140       }
141     }
143  
144     /* prepare LogonScripts */
145     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
146       unset($this->attrs['gotoLogonScript']['count']);
147       foreach($this->attrs['gotoLogonScript'] as $device){
148         $tmp = $tmp2 = array();
149         $tmp = split("\|",$device);
150         $tmp2['LogonName']        = $tmp[0]; 
151         $tmp2['LogonPriority']    = $tmp[2]; 
152         if(preg_match("/O/i",$tmp[1])){
153           $tmp2['LogonOverload'] = "O";
154         }else{
155           $tmp2['LogonOverload'] = "";
156         }
157         if(preg_match("/L/i",$tmp[1])){
158           $tmp2['LogonLast'] = "L";
159         }else{
160           $tmp2['LogonLast'] = "";
161         }
162         $tmp2['LogonData']        = base64_decode($tmp[3]); 
163         $tmp2['LogonDescription'] = $tmp[4];
164         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
165       }
166     }
168     /* Prepare Shares */
169     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
170       unset($this->attrs['gotoShare']['count']);
171       foreach($this->attrs['gotoShare'] as $share){
172         $tmp = $tmp2 = array();
173         $tmp = split("\|",$share);
174         $tmp2['server']      =$tmp[0];
175         $tmp2['name']        =$tmp[1];
177         /* Decode base64 if needed */
178         if (!preg_match('%/%', $tmp[2])){
179           $tmp2['mountPoint']  =base64_decode($tmp[2]);
180         } else {
181           $tmp2['mountPoint']  =$tmp[2];
182         }
184         if(isset($tmp[3])){
185           $tmp2['PwdHash']  =$tmp[3];
186         }else{
187           $tmp2['PwdHash']  ="";
188         }
189         if(isset($tmp[4])){
190           $tmp2['Username']  =$tmp[4];
191         }else{
192           $tmp2['Username']  ="";
193         }
194         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
195       }
196     }
198     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
199       $chr = $this->gotoProfileFlags[$i];
200       $name = "gotoProfileFlag".$chr;
201       $this->$name=$chr;
202     }
204     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
205       $this->useProfile = true;
206     }else{
207       $this->useProfile = false;
208     }
210     /* Set resolutions */
211     $this->gotoXResolutions = array("auto"=>_("auto"),
212                                     "640x480"   =>  "640x480",
213                                     "800x600"   =>  "800x600",
214                                     "1024x768"  =>  "1024x768",
215                                     "1152x864"  =>  "1152x864",
216                                     "1280x768"  =>  "1280x768",
217                                     "1280x1024" =>  "1280x1024");
219     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
220       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
222       if(is_readable($file)){
223         $str = file_get_contents($file);
224         $lines = split("\n",$str);
225         foreach($lines as $line){
226           $line = trim($line);
227           if(!empty($line)){
228             $this->gotoXResolutions[$line]=$line;
229           }
230         }
231         //natcasesort($this->gotoXResolutions);
232       }else{
233         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
234       }
235     }
237     $this->gotoProfileServers= $config->getShareServerList() ;
238     $this->gotoShareSelections= $config->getShareList(true);
239     $this->gotoAvailableShares= $config->getShareList(false);  
241     $this->update_kiosk_profiles();
242   
243     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
244   }
247   function update_kiosk_profiles()
248   { 
249     $tmp1  = array("none" => array(_("disabled")));
250     $tmp2  = array("none" => _("disabled"));
251     $ldap = $this->config->get_ldap_link();
252     $ldap->cd($this->config->current['BASE']);
253     $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
254     $cnt = 0;
255     while($attrs = $ldap->fetch()){
256       for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
257         $name = preg_replace("/^.*kiosk\//","",$attrs['gotoKioskProfile'][$i]);
258         $tmp1[$attrs['cn'][0]][] = $name;
259       }
260       $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
261       $cnt ++;
262     }
264     if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
265       $this->kiosk_enabled = TRUE;
266     }
268     $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
269     $this->gotoKioskProfiles['SERVERS']   = $tmp2;
270   
271     $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
272     $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
274     $error = false;
275     if(!in_array($this->gotoKioskProfile_Server, $this->gotoKioskProfiles['SERVERS'])){
276       $this->gotoKioskProfile_Server = key($this->gotoKioskProfiles['SERVERS']);
277       $error = true;
278     }
279     if(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
280       $this->gotoKioskProfile_Profile = $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server][0];
281       $error = true;
282     }
283     if($error && !empty($this->gotoKioskProfile)){
284       print_red(sprintf(_("The selected kiosk profile wasn't available anymore. The current profile is now 'none'."),
285             $this->gotoKioskProfile_Server,$this->gotoKioskProfile_Profile));
286     }
287   }
290   /* Detect type of edited object (user|group)*/
291   function detect_grouptype()
292   {
293     if((!isset($this->parent))&&(!$this->is_account)){
294       $this->is_group     = false;
295     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
296       $this->is_group     = true;
297     }else{
298       $this->is_group     = false;
299     }
300   }
303   function execute()
304   {
306     /* Call parent execute */
307     plugin::execute();
308     /* Log view */
309     if($this->is_account && !$this->view_logged){
310       $this->view_logged = TRUE;
311       if(in_array("gosaAccount",$this->attrs['objectClass'])){
312         new log("view","users/".get_class($this),$this->dn);
313       }else{
314         new log("view","groups/".get_class($this),$this->dn);
315       }
316     }
318     /* Are we editing from MyAccount and not editing a user */
319     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
321     /* Check profile server */
322     if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
323       if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
324         if(count($this->gotoProfileServers)){
326           /* Get First Profile */
327           $new = key($this->gotoProfileServers);
329           /* Another profile server found */
330           print_red(sprintf(_("Your selected profile server '%s' is no longer available. Setting profile server to '%s'."),
331                 $this->gotoProfileServer,$new));
332         }else{
334           /* No other profile servers found */
335           print_red(sprintf(_("Your selected profile server '%s' is no longer available. Profile server configuration is resetted."),
336                 $this->gotoProfileServer));
337           $this->gotoProfileServer = "";
338         }
339       }
340     }    
342     $this->detect_grouptype();
344     /* Fill templating stuff */
345     $smarty= get_smarty();
346     $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
347     $display= "";
349     $smarty->assign("is_group",$this->is_group);
351     /* Prepare all variables for smarty */
352     foreach($this->attributes as $s_attr){
353       /* Set value*/
354       $smarty->assign($s_attr,$this->$s_attr);
356       /* Set checkbox state*/
357       if(empty($this->$s_attr)){
358         $smarty->assign($s_attr."CHK","");
359       }else{
360         $smarty->assign($s_attr."CHK"," checked ");
361       }
363       /* Prepare ACL settings*/
364       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
365     }
367     /* Is accout enabled | are we editing from usermenu or admin menu 
368        All these tab management is done here
369      */
372     /* Working from Usermenu an the Account is currently disbled
373      * this->parent :  is only set if we are working in a list of tabs
374      * is_account   :  is only true if the needed objectClass is given
375      */
376     if((!isset($this->parent))&&(!$this->is_account)){
377       /* We are currently editing this tab from usermenu, but this account is not enabled */
378       $smarty->assign("is_account",$this->is_account);
379       /* Load template */
380       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
381       /* Avoid the "You are currently editing ...." message when you leave this tab */
382       $display .= back_to_main(); 
383       /* Display our message to the user */
384       return $display;
387       /* We are currently editing from group tabs, because 
388        * $this->parent is set
389        * posixAccount is not set, so we are not in usertabs.
390        */
391     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
392       $smarty->assign("is_account","true");
393       $this->uid          = $this->cn;
394       $this->attrs['uid'] = $this->cn;
396       /* Change state if needed */
397       if (isset($_POST['modify_state'])){
398         if(($this->acl_is_createable() && !$this->is_account) || 
399             ($this->acl_is_removeable() &&  $this->is_account)){
400           $this->is_account= !$this->is_account;
401         }
402       }
403       /* Group Dialog with enabled environment options */
404       if ($this->is_account){
405         $display= $this->show_enable_header(_("Remove environment extension"),
406             _("Environment extension enabled. You can disable it by clicking below."));
407       } else {
409         /* Environment is disabled 
410            If theres is no posixAccount enabled, you won't be able to enable 
411            environment extensions
412          */
413         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
414           // 4. There is a PosixAccount
415           $display= $this->show_enable_header(_("Add environment extension"),
416               _("Environment extension disabled. You can enable it by clicking below."));
417           return $display;
418         }else{
419           // 4. There is no PosixAccount
420           $display= $this->show_enable_header(_("Add environment extension"),
421               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
422           return $display;
423         }
424       }
425     }else{
426       /* Editing from Usermenu 
427        *  Tell smarty that this accoutn is enabled 
428        */
429       $smarty->assign("is_account","true");
431       /* Change state if needed */
432       if (isset($_POST['modify_state'])){
433         if(($this->acl_is_createable() && !$this->is_account) || 
434             ($this->acl_is_removeable() &&  $this->is_account)){
435           $this->is_account= !$this->is_account;
436         }
437       }
439       if(isset($this->parent)){
441         // 3. Account enabled . Editing from adminmenu
442         if ($this->is_account){
443           $display= $this->show_disable_header(_("Remove environment extension"),
444               _("Environment extension enabled. You can disable it by clicking below."));
445         } else {
447           if($this->parent->by_object['posixAccount']->is_account==true){
448             // 4. There is a PosixAccount
449             $display= $this->show_disable_header(_("Add environment extension"),
450                 _("Environment extension disabled. You can enable it by clicking below."));
451             return $display;
452           }else{
453             // 4. There is a PosixAccount
454             $display= $this->show_disable_header(_("Add environment extension"),
455                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
456             return $display;
457           }
458         }
459       }
460     }
461     /* Account is Account : is_accounbt=true.
462      * Else we won't reach this. 
463      */
465     /* Prepare all variables for smarty */
466     foreach($this->attributes as $s_attr){
467       /* Set value*/
468       $smarty->assign($s_attr,$this->$s_attr);
470       /* Set checkbox state*/
471       if(empty($this->$s_attr)){
472         $smarty->assign($s_attr."CHK","");
473       }else{
474         $smarty->assign($s_attr."CHK"," checked ");
475       }
477       /* Prepare ACL settings*/
478       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
479     }
481     foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
482       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
483     }
485     if($WriteOnly) {
486       $smarty->assign("gotoPrinterACL","r");
487     }else{
488       $smarty->assign("gotoPrinterACL","rw");
489     }
491     if(empty($this->useProfile)){
492       $smarty->assign("useProfileCHK","");
493       $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
494       $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
495       $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
496     }else{
497       $smarty->assign("useProfileCHK"," checked ");
498     }
499     
500     $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
501     $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
503     /* HANDLE Profile Settings here 
504      * Assign available Quota and resolution settings
505      * Get all available profile server
506      * Get cache checkbox
507      * Assign this all to Smarty 
508      */
510     if(empty($this->gotoProfileFlagL)){
511       $smarty->assign("gotoProfileFlagLCHK"," ");
512     }else{
513       $smarty->assign("gotoProfileFlagLCHK"," checked ");
514     }
516     if(empty($this->gotoProfileFlagC)){
517       $smarty->assign("gotoProfileFlagCCHK"," ");
518     }else{
519       $smarty->assign("gotoProfileFlagCCHK"," checked ");
520     }
523     $smarty->assign("gotoXResolutions"    , $this->gotoXResolutions);
524     $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
526     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
527     if(!is_array($this->gotoProfileServers)){
528       $this->gotoProfileServers =array();
529     }
530     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
532     /* Handle kiosk profiles*/
533     $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
534     $smarty->assign("kiosk_server" ,  $this->gotoKioskProfile_Server);
535     $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
536     $smarty->assign("kiosk_profile" ,  $this->gotoKioskProfile_Profile);
537   
539     /* Logonscript Management
540      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
541      * Perform add Delete edit Posts 
542      */
544     /* Dialog Save */
545     if(isset($_POST['LogonSave'])){
547       if(!$this->acl_is_writeable("gotoLogonScript")){
548         print_red(_("You are not allowed to write Logon scripts."));
549         unset($this->dialog);
550         $this->dialog=FALSE;
551         $this->is_dialog=false;
552       }else{
553         $this->dialog->save_object();
554         if(count($this->dialog->check())!=0){
555           foreach($this->dialog->check() as $msg){
556             print_red($msg);
557           }
558         }else{
559           $tmp = $this->dialog->save();
560           unset($this->dialog);
561           $this->dialog=FALSE;
562           $this->is_dialog=false;
563           $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
564         }
565       }
566     }
567     
569     /* Dialog Quit without saving */
570     if(isset($_POST['LogonCancel'])){
571       $this->is_dialog= false;
572       unset($this->dialog);
573       $this->dialog= FALSE;
574     }
576     /* Check Edit Del New Posts for a selected LogonScript */ 
577     if($this->acl_is_writeable("gotoLogonScript") && 
578         (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
580       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
581        * In this case we create a new Logon Script.
582        */
583       if(isset($_POST['gotoLogonScriptNew'])){
584         $this->is_dialog = true;
585         $this->dialog = new logonManagementDialog($this->config,$this->dn);
586       }
588       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
589        * We only can delete if there is an entry selected.
590        */
591       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
592         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
593       }
595       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
596        * There must be an entry selected to perform edit request.
597        */
598       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
599         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
600         $this->is_dialog = true;
601         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
602       }
603     }
605     /* Append List to smarty*/
606     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
607     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
609     /* In this section server shares will be defined 
610      * A user can select one of the given shares and a mount point
611      *  and attach this combination to his setup.
612      */
614     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
615     if(!is_array($this->gotoShareSelections)){
616       print $this->gotoShareSelections;
617       $this->gotoShareSelections = array();
618     }
619     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
621     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
622      * This entry will be, a combination of mountPoint and sharedefinitions 
623      */
624     if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
626       /* We assign a share to this user, if we don't know where to mount the share */
627       if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
628         print_red(_("You must select a valid share."));
629       }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
630         print_red(_("You must specify a valid mount point."));
631       }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
632         print_red(_("Spaces are not allowed in the mount path!"));
633       }elseif(!(
634             preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
635             preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
636             preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
637             preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
638             preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
639             preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
640             preg_match("/^%/",$_POST['gotoShareMountPoint'])
641             )
642           ){
643         print_red(_("You must specify a valid mount point.")); 
644       }else{
645         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
646         $s_mount = $_POST['gotoShareMountPoint'];
647         $s_user  = $_POST['ShareUser'];
648         /* Preparing the new assignment */ 
649         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
650         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
651         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
652         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
653       }
654     }  
656     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
657      * If there is no defined share selected, we will abort the deletion without any message 
658      */
659     $once = true;
660     if($this->acl_is_writeable("gotoShare")){
661       foreach($_POST as $name => $value){
662         if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
663           $once = false;  
664           $key  = preg_replace("/^gotoShareDel_/","",$name);
665           $key  = preg_replace("/_+[xy]$/","",$key);
666           $key  = base64_decode($key);
667           if(isset($this->gotoShares[$key])) {
668             unset($this->gotoShares[$key]);
669           }
671           /* Remove corresponding password entry, too. This is a workaround
672              to get rid of old-style entries. */
673           $key= preg_replace("/\|/", "|!", $key);
674           if(isset($this->gotoShares[$key])) {
675             unset($this->gotoShares[$key]);
676           }
677         }
678         if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
679           $once = false;
680           $key  = preg_replace("/^gotoShareResetPwd_/","",$name);
681           $key  = preg_replace("/_+[xy]$/","",$key);
682           $key  = base64_decode($key);
683           $this->gotoShares[$key]['PwdHash'] = "";
684           if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
685             unset($this->gotoShares[$key]);
686           }
687         }
688       }
689     }
690     $divlistShares = new divSelectBox("gotoShares");
691     $divlistShares->SetHeight(100);
694     $tmp = array();
695     if($this->acl_is_readable("gotoShares")){
696       $tmp = $this->printOutAssignedShares();
697     }
699     
700     foreach($tmp as $key => $value){
701       $img = "";
703       /* Check if entry starts with an ! */
704       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
706         /* If we are currently editing groups environment, skip those ! entries */ 
707         if($this->is_group) continue;
709         /* Create pwd reset images */
710         if($this->gotoShares[$key]['PwdHash'] != ""){
711           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
712             title='"._("Reset password hash")."'>";
713         }
714         $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
715         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
716       }else{
718         /* Create pwd reset img && delete image */
719         if($this->gotoShares[$key]['PwdHash'] != ""){
720           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
721             title='"._("Reset password hash")."'>";
722           $img.= "&nbsp;";
723         }
724         $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."' 
725           title='"._("Delete share entry")."'>";
726         $field1 = array("string" => $value);
727         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
728       }
729       $divlistShares->AddEntry(array($field1,$field2));
730     }
731     $smarty->assign("divlistShares",$divlistShares->DrawList());
733     /* Hotplug devices will be handled here 
734      * There are 3 possible methods for this feature
735      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
736      * Delete will erase an entry, the entry must be selcted in the ListBox first
737      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
738      */
740     /* We have to delete the selected hotplug from the list*/
741     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
742       if($this->acl_is_writeable("gotoHotplugDevice")){
743         foreach($_POST['gotoHotplugDevice_post'] as $name){
744           unset($this->gotoHotplugDevices[$name]);
745         }
746       }
747     }
749     /* There are already defined hotplugs from other users we could use */
750     if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
751       $tmp  =array();
752       foreach($this->gotoHotplugDevices as $plugs){
753         $tmp[] = $plugs['name'];
754       }
755       $this->dialog = new hotplugDialog($this->config,$tmp);
756       $this->is_dialog = true;
757     }
759     /* Dialog Aborted */
760     if(isset($_POST['HotPlugCancel'])){
761       unset($this->dialog);
762       $this->dialog= FALSE;
763       $this->is_dialog = false;
764     }
766     /* Dialod saved */
767     if(isset($_POST['HotPlugSave'])){
769       $this->dialog->save_object();
770       if(count($this->dialog->check())!=0){
771         foreach($this->dialog->check() as $msg){
772           print_red($msg);
773         }
774       }else{
775         $this->dialog->save_object();
776         $a_tmp = $this->dialog->save();
778         if(is_array($a_tmp)){
779           foreach($a_tmp as $name => $hotplug){
780             $this->gotoHotplugDevices[$name]= $hotplug; 
781           }
782         }
783         unset($this->dialog);
784         $this->dialog= FALSE;
785         $this->is_dialog = false;
786       }
787     }
788     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
789     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
791     /* Printer Assignment will managed below 
792      * A printer can be assigned in two different ways and two different types
793      * There are 2 types of users assigned to a printer : user and admin
794      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
795      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
796      */ 
798     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
799     if(isset($_POST['gotoPrinterAdd'])){
801       $this->is_dialog=true;
802       $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
803     }
805     if(isset($_POST['PrinterCancel'])){
806       $this->is_dialog=false;
807       unset($this->dialog);
808       $this->dialog=FALSE;
809     }
811     if(isset($_POST['PrinterSave'])){
812       if(count($this->dialog->check())!=0){
813         $tmp = $this->dialog->check();
814         foreach($tmp as $msg){
815           print_red($msg);
816         } 
817       }else{
818         $this->dialog->save_object();
819         $tmp = $this->dialog->save();
820         $tmp2= $this->dialog->getPrinter(true);
822         foreach($tmp as $pname){
823           $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
824           $printerObj->set_acl_base($tmp2[$pname]['dn']);
826           $type = false;
828           if($this->is_group){
830             if(isset($this->NewDeletedPrinters[$pname])){
831               $type = "AddGroup";
832             }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
833               $type = "AddGroup";
834             }
835           }else{
836             if(isset($this->NewDeletedPrinters[$pname])){
837               $type = "AddUser";
838             }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
839               $type = "AddUser";
840             }
841           }
843           if($type){
844             $this->gotoPrinter[$pname]=$tmp2[$pname];
845             $this->gotoPrinter[$pname]['mode']="user";
846             $this->add_del_printer_member_was_called = true;
848             $this->NewAddedPrinters[$pname] = $pname;
849             if(isset($this->NewDeletedPrinters[$pname])){
850               unset($this->NewDeletedPrinters[$pname]);
851             }
852           }
853         }
855         $this->is_dialog=false;
856         unset($this->dialog);
857         $this->dialog   =FALSE;
858       }
859     }
861     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
862       $printer = $_POST['gotoPrinterSel'];
863       foreach($printer as $pname){
865         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
866         $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
868         $type = false;
869         if($this->is_group){
870           if(isset($this->NewAddedPrinters[$pname])){
871             $type = "Group";
872           }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
873             $type = "Group";
874           }
875         }else{
876           if(isset($this->NewAddedPrinters[$pname])){
877             $type = "User";
878           }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
879             $type = "User";
880           }
881         }
882         if($type){
883           $this->add_del_printer_member_was_called = true;
884           unset($this->gotoPrinter[$pname]);
886           $this->NewDeletedPrinters[$pname] = $pname;
887           if(isset($this->NewAddedPrinters[$pname])){
888             UNSET($this->NewAddedPrinters[$pname]);
889           }
890         }
891       }
892     }
894     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
895       $printers = $_POST['gotoPrinterSel'];
896       $this->add_del_printer_member_was_called = true;
897       foreach($printers as $printer){
898         if($this->gotoPrinter[$printer]['mode']=="user"){
899           $this->gotoPrinter[$printer]['mode']="admin";
900         }else{
901           $this->gotoPrinter[$printer]['mode']="user";
902         }
903       }
904     }
906     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
907       if($this->is_group){
908         print_red(_("GOsa default printer flag is not allowed within groups."));
909       }else{
910         if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
911           $this->gosaDefaultPrinter= "";
912         } else {
913           $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
914         }
915       }
916     }
918     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
919     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
921     /* General behavior */
922     if(is_object($this->dialog)){
923       $this->dialog->save_object();
924       $disp =$this->dialog->execute();
925       return($disp);
926     }
928     /* Als smarty vars are set. Get smarty template and generate output */
929     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
930     return($display);
931   }
933   function remove_from_parent()
934   {
935     /* only if it was an account*/
936     if (!$this->initially_was_account){
937       return;
938     }
940     /* include global link_info */
941     $ldap= $this->config->get_ldap_link();
943     /* Remove and write to LDAP */
944     plugin::remove_from_parent();
946     /* Don't save our template variables */
947     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
949     /* Skip all these attributes */
950     foreach($skip as $del){
951       unset($this->attrs[$del]);
952     }
954     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
956     $ldap->cd($this->dn);
957     $this->cleanup();
958     $ldap->modify ($this->attrs); 
960     if($this->is_group){
961       new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
962     }else{
963       new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
964     }
966     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
968     /* Optionally execute a command after we're done */
969     $this->handle_post_events("remove",array("uid" => $this->uid));
970   }
973   /* Save data to object */
974   function save_object()
975   {
976     /* Get all Posted vars 
977      * Setup checkboxes 
978      */
979     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
980     if(isset($_POST['iamposted'])){
982       $PACL =  $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
984       if(isset($_POST['kiosk_server'])){
985         $tmp = $_POST['kiosk_server'];
986         if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
987           $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
988         }
989       }
990       if(isset($_POST['kiosk_profile'])){
991         $tmp = $_POST['kiosk_profile'];
992         if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
993           $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
994         }
995       }
997       if(preg_match("/w/",$PACL)){
998         if(isset($_POST['useProfile'])){
999           $this->useProfile = true;
1000         }else{
1001           $this->useProfile = false;
1002         }
1003       }
1005       if($this->acl_is_writeable("gotoProfileFlagC")){
1006         if(isset($_POST['gotoProfileFlagC'])){
1007           $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1008         }else{
1009           $this->gotoProfileFlagC = false;
1010         }
1011       }
1013       if($this->acl_is_writeable("gotoProfileFlagL")){
1014         if(isset($_POST['gotoProfileFlagL'])){
1015           $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1016         }else{
1017           $this->gotoProfileFlagL = false;
1018         }
1019       }
1021       plugin::save_object();
1022       foreach($this->attributes as $s_attr){
1023         if((!isset($_POST[$s_attr])) || 
1024             in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1025         if(!$this->acl_is_writeable($s_attr)){
1026           continue;
1027         }else{ 
1028           if(isset($_POST[$s_attr])){
1029             $this->$s_attr = $_POST[$s_attr];
1030           }else{
1031             $this->$s_attr = false;
1032           }
1033         }
1034       }
1035     }
1036   }
1039   /* Check supplied data */
1040   function check()
1041   {
1042     /* Call common method to give check the hook */
1043     $message= plugin::check();
1045     $this->detect_grouptype();
1047     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1048       $message[]=_("Please set a valid profile quota size.");
1049     } 
1050     if(!isset($this->attrs['objectClass'])){
1051       $this->attrs['objectClass']=array();
1052     } 
1053     if(!$this->is_group){
1054       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1055         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
1056       }
1057     }
1058     return ($message);
1059   }
1062   /* Save to LDAP */
1063   function save()
1064   {
1065     /* If group was renamed, all printer settings get lost
1066      */ 
1067     /* only save changed variables ....*/
1068     if ($this->gotoKioskProfile_Server != "none"){
1069       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
1070         $method="https://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1071       }else{
1072         $method="http://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1073       }
1074       $this->gotoKioskProfile= $method;
1075     }else{
1076       $this->gotoKioskProfile= array();
1077     }
1079     plugin::save();
1080     $ldap= $this->config->get_ldap_link();
1082     $realyUsedAttrs= array();
1084     /* Save already used objectClasses */
1085     $ocs        = $this->attrs['objectClass'];
1086     unset($ocs['count']);
1087     $this->attrs = array();
1088     $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1090     /* 1. Search all printers that have our uid/cn as member 
1091      * 2. Delete this uid/cn from every single entry and save it again.
1092      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1093      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
1094      */
1095     
1096     $this->detect_grouptype();
1098     if($this->add_del_printer_member_was_called){
1100       $types = array( "gotoUserPrinter"       => "AddUser",
1101           "gotoGroupPrinter"      => "AddGroup",
1102           "gotoUserAdminPrinter"  => "AddAdminUser",
1103           "gotoGroupAdminPrinter" => "AddAdminGroup");
1105       if($this->is_group){
1106         $s_suffix = "Group";
1107         $useVar   = "cn";
1108       }else{
1109         $useVar   = "uid";
1110         $s_suffix = "User";
1111       }
1113       /* Remove old entries */
1114       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1115       while($attr = $ldap->fetch()){
1116         $printerObj = NULL;
1117         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1118         $printerObj->set_acl_base($attr['dn']);
1119         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1120         $printerObj->by_object['printgeneric']->save();
1121       }
1123       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1124       while($attr = $ldap->fetch()){
1125         $printerObj = NULL;
1126         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1127         $printerObj->set_acl_base($attr['dn']);
1128         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1129         $printerObj->by_object['printgeneric']->save();
1130       }
1132       foreach($this->gotoPrinter as $printer){
1133         $printerObj = NULL;
1134         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1135         $printerObj->set_acl_base($printer['dn']);
1138         if($printer['mode'] == "admin") {
1139           $attribute = "goto".$s_suffix."AdminPrinter";
1140         }else{
1141           $attribute = "goto".$s_suffix."Printer";
1142         }
1144         $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1145         $printerObj->by_object['printgeneric']->save();
1146       }
1147     }    
1149     /* Prepare HotPlug devices */
1150     $this->attrs['gotoHotplugDeviceDN'] = array();
1151     foreach($this->gotoHotplugDevices as $name => $device){
1152       $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1153     }
1155     /* Prepare LogonScripts */
1156     $this->attrs['gotoLogonScript'] = array();
1157     foreach($this->gotoLogonScripts as $name => $script){
1158       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1159         $script['LogonOverload'].$script['LogonLast']."|".
1160         $script['LogonPriority']."|".
1161         base64_encode($script['LogonData'])."|".
1162         $script['LogonDescription'];
1163     }
1165     /* Prepare Shares */
1166     $this->attrs['gotoShare']=array();
1167     foreach($this->gotoShares as $name => $share){
1168       $mntp= $share['mountPoint'];
1169       if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1170         $mntp= base64_encode($mntp);
1171       }
1172       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1173     }
1176     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1177     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1179     foreach($saveThis as $tosave){
1180       if(!empty($this->$tosave)){
1181         $this->attrs[$tosave]=$this->$tosave;
1182       }else{
1183         $this->attrs[$tosave]=array();
1184       }
1185     }
1187     /* Prepare Flags */
1188     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1189     if(empty($this->attrs['gotoProfileFlags'][0])){
1190       $this->attrs['gotoProfileFlags']=array();
1191     }
1193     if($this->useProfile == false){
1194       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1195       $this->attrs['gotoProfileServer']= array(); 
1196     }
1198     $ldap->cat ($this->dn, array('dn'));
1199     if ($ldap->fetch()){
1200       $mode= "modify";
1201     } else {
1202       $mode= "add";
1203       $ldap->cd($this->config->current['BASE']);
1204       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1205     }
1207     $ldap->cd($this->dn);
1208     $this->cleanup();
1209     $ldap->$mode($this->attrs);
1210   
1211     $cat = "users";
1212     if($this->is_group){
1213       $cat = "groups";
1214     }
1216     /* Log last action */ 
1217     if($this->initially_was_account){
1218       new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1219     }else{
1220       new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1221     }
1223     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1224     $this->handle_post_events($mode,array("uid"=>$this->uid));
1225   }
1227   /* Generate ListBox frindly output for the defined shares 
1228    * Possibly Add or remove an attribute here, 
1229    */
1230   function printOutAssignedShares()
1231   {
1232     $a_return = array();
1233     if(is_array($this->gotoShares)){
1234       foreach($this->gotoShares as $share){
1235         if(preg_match("/^!/",$share['server'])){
1236           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1237         }else{
1238           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1239         }
1240       }
1241       natcasesort($a_return);
1242     }
1243     return($a_return);
1244   }
1246   /* Generate ListBox frindly output for the definedhotplugs 
1247    * Possibly Add or remove an attribute here,
1248    */
1249   function printOutHotPlugDevices()
1250   {
1251     $a_return= array();
1252     if(is_array($this->gotoHotplugDevices)){
1253       foreach($this->gotoHotplugDevices as $key=>$device){
1254         $a_return[$key] = $device['name']." - ".$device['id'];
1255       }
1256     }
1257     return($a_return);
1258   }
1260   /* Generates ListBox frienly output of used printer devices 
1261    * Append ' - admin' if printer is used in admin mode
1262    */
1263   function printOutPrinterDevices()
1264   {
1265     $a_return = array();
1266     
1267     if($this->acl_is_readable("gotoPrinter")){
1269       if(is_array($this->gotoPrinter)){
1270         foreach($this->gotoPrinter as $printer){
1271           if($printer['mode'] == "admin"){
1272             $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1273           }else{
1274             $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1275           }
1276           if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1277             $a_return[$printer['cn'][0]].=" - "._("Default printer");
1278           }
1279         }
1280       }
1281     }
1282     return($a_return);
1283   }
1286   function saveCopyDialog()
1287   {
1288     if(isset($_POST['cn'])){
1289       $this->cn = $_POST['cn'];
1290       $this->uid = $_POST['cn'];
1291     }
1292   }
1295   /* Generates ListBox frienly output of used logonscripts 
1296    */
1297   function printOutLogonScripts()
1298   {
1299     $a_return = array();
1300     if(is_array($this->gotoLogonScripts)){
1301       foreach($this->gotoLogonScripts as $script){
1302         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1303       }
1304     }
1305     return($a_return);
1306   }
1309   /* Return plugin informations for acl handling 
1310 #FIXME these ACLs should work for groups too */ 
1311   function plInfo()
1312   {
1313     return (array("plShortName"     => _("Environment"),
1314           "plDescription"   => _("Environment settings"),         // Description
1315           "plSelfModify"    => TRUE,                              
1316           "plDepends"       => array("user", "posixAccount"),     // This plugin depends on 
1317           "plPriority"      => 3,                                 // Position in tabs 
1318           "plSection"     => array("personal" => _("My account")),
1319           "plCategory"    => array("users",
1320                                    "groups"),
1321           "plOptions"       => array("resolution_hook" => array("type" => "string",
1322               "description" => _("Command to extend the list of possible screen resolutions"))),
1324           "plProvidedAcls"  => array(
1326             "gotoProfileFlagL"    => _("Resolution changeable during session") ,
1327             "gotoProfileFlagC"    => _("Cache profile localy") ,
1329             "gotoProfileQuota"    => _("Profile quota") ,
1330             "gotoProfileServer"   => _("Profile server") ,
1332             "gotoXResolution"     => _("Resolution") ,
1333             "gotoKioskProfile"    => _("Kiosk profile") ,
1335             "gosaDefaultPrinter"  => _("Default printer") ,
1336             "gotoLogonScript"     => _("Logon script") ,
1337             "gotoHotplugDevice"   => _("Hotplug devices"),
1338             "gotoShare"           => _("Shares"))
1339             ));
1340   }
1343 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1344 ?>