Code

Fixed white page
[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   
21   /* Attribute definition
22    */
24   /* profile management */
25   var $useProfile         = false;  // Specifies if we want to use a Server 
26   var $gotoProfileServer  = "";     // Specifies the selected profile server
27   var $gotoProfileServers = array();// Specifies all available and selectable servers
28   var $gotoProfileFlags   = "";     // Flags enabled  ? only used to set ACL and save 
29   var $gotoProfileFlagC  = "";     // Flag is set to C if we have the profile caching fucntion enabled 
30   
31   var $gotoXResolution    = "auto";     // The selected resolution eg: 1024x768
32   var $gotoXResolutions   = array();// Contains all available resolutions for this account
33   var $gotoProfileFlagL  = "";     // Flag is set to L to enable runtime resolution change 
34   var $gotoProfileQuota   = "";     // User Quota Settings
36   /* Logon script section*/
37   var $gotoLogonScripts   = array();// Contains all available Logon Scripts  
38   var $gotoLogonScript    = "";     // The selected Logon Script
40   /* Printer */
41   var $gotoPrinter        = array();// All available Printer, with their configurations
42   var $gotoPrinterSel     = "";     //  The selected Printer
43   var $gosaDefaultPrinter = "";     // Default printer
45   /* Share */
46   var $gotoShares         = array();// Current Share Options
47   var $gotoShare          = "";     // currently selected Share Option
48   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
49   var $gotoAvailableShares= array();// Available Shares for this account
51   /* Kiosk profile */
52   var $gotoKioskProfile   = "none";     // The selected Kiosk Profile
53   var $gotoKioskProfiles  = array();// All available Kiosk profiles
54   var $newKioskProfiles   = array();
56   /* Hotplug Devices */
57   var $gotoHotplugDevice  = array();     // Selected hotplug
58   var $gotoHotplugDevices = array();// Already configured hotplug devices 
61   /* general settings */
62   // Sets the attributes which will kept on page reload, which will be saved, ...
64   var $CopyPasteVars      = array("gotoHotplugDevices","newKioskProfiles","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn");
66   var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags",
67       "gotoXResolution","gotoProfileQuota",
68       "gotoLogonScripts","gotoLogonScript",
69       "gotoPrinter", "gosaDefaultPrinter",
70       "gotoShares","gotoShare",
71       "gotoKioskProfile","gotoKioskProfiles"
72       );
73   var $objectclasses      = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here 
74   var $cn;
75   var $OrigCn;
77   function environment ($config, $dn= NULL)
78   {
79     plugin::plugin ($config, $dn);
81     /* Check : Are we currently editing a group or user dialog */
82     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
83       $suffix="Group";
84       $this->uid          = $this->attrs['cn'][0];
85       $this->attrs['uid'] = $this->attrs['cn'][0];
86       $this->OrigCn = $this->attrs['cn'][0];
87     }else{
88       $suffix="User";
89     }
91     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
93     /* Get all Printer assignments */
94     $ldap = $this->config->get_ldap_link();
95     $ldap->cd($this->config->current['BASE']);
96     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
97     while($printer = $ldap->fetch()){
98       $this->gotoPrinter[$printer['cn'][0]]=$printer;
99       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
100     }
101     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
102     while($printer = $ldap->fetch()){
103       $this->gotoPrinter[$printer['cn'][0]]=$printer;
104       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
105     }
107     /* prepare hotplugs */
108     if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
109       unset($this->attrs['gotoHotplugDevice']['count']);
110       foreach($this->attrs['gotoHotplugDevice'] as $device){
111         $tmp = $tmp2 = array();
112         $tmp = split("\|",$device);
113         $tmp2['name']        = $tmp[0]; 
114         $tmp2['description'] = $tmp[1]; 
115         $tmp2['id']          = $tmp[2]; 
117         /* Produkt ID */
118         if(!isset($tmp[3])){
119           $tmp[3] = "";
120         }
121         /* Vendor ID */
122         if(!isset($tmp[4])){
123           $tmp[4] = "";
124         }
126         $tmp2['produkt']     = $tmp[3]; 
127         $tmp2['vendor']      = $tmp[4];
129         $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
130       }
131     }
133     /* prepare LogonScripts */
134     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
135       unset($this->attrs['gotoLogonScript']['count']);
136       foreach($this->attrs['gotoLogonScript'] as $device){
137         $tmp = $tmp2 = array();
138         $tmp = split("\|",$device);
139         $tmp2['LogonName']        = $tmp[0]; 
140         $tmp2['LogonPriority']    = $tmp[2]; 
141         if(preg_match("/O/i",$tmp[1])){
142           $tmp2['LogonOverload'] = "O";
143         }else{
144           $tmp2['LogonOverload'] = "";
145         }
146         if(preg_match("/L/i",$tmp[1])){
147           $tmp2['LogonLast'] = "L";
148         }else{
149           $tmp2['LogonLast'] = "";
150         }
151         $tmp2['LogonData']        = base64_decode($tmp[3]); 
152         $tmp2['LogonDescription'] = $tmp[4];
153         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
154       }
155     }
157     /* Prepare Shares */
158     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
159       unset($this->attrs['gotoShare']['count']);
160       foreach($this->attrs['gotoShare'] as $share){
161         $tmp = $tmp2 = array();
162         $tmp = split("\|",$share);
163         $tmp2['server']      =$tmp[0];
164         $tmp2['name']        =$tmp[1];
166         /* Decode base64 if needed */
167         if (!preg_match('%/%', $tmp[2])){
168           $tmp2['mountPoint']  =base64_decode($tmp[2]);
169         } else {
170           $tmp2['mountPoint']  =$tmp[2];
171         }
173         if(isset($tmp[3])){
174           $tmp2['PwdHash']  =$tmp[3];
175         }else{
176           $tmp2['PwdHash']  ="";
177         }
178         if(isset($tmp[4])){
179           $tmp2['Username']  =$tmp[4];
180         }else{
181           $tmp2['Username']  ="";
182         }
183         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
184       }
185     }
187     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
188       $chr = $this->gotoProfileFlags[$i];
189       $name = "gotoProfileFlag".$chr;
190       $this->$name=$chr;
191     }
193     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
194       $this->useProfile = true;
195     }else{
196       $this->useProfile = false;
197     }
199     /* Set to group environment if we editing a group */
200     if(!isset($this->parent)){
201       $this->is_group = true;
202     }
204     /* Set resolutions */
205     $this->gotoXResolutions = array("auto"=>_("auto"),
206                                     "640x480"   =>  "640x480",
207                                     "800x600"   =>  "800x600",
208                                     "1024x768"  =>  "1024x768",
209                                     "1152x864"  =>  "1152x864",
210                                     "1280x768"  =>  "1280x768",
211                                     "1280x1024" =>  "1280x1024");
213     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
214       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
216       if(is_readable($file)){
217         $str = file_get_contents($file);
218         $lines = split("\n",$str);
219         foreach($lines as $line){
220           $line = trim($line);
221           if(!empty($line)){
222             $this->gotoXResolutions[$line]=$line;
223           }
224         }
225         //natcasesort($this->gotoXResolutions);
226       }else{
227         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
228       }
229     }
232     $this->gotoProfileServers= $config->getShareServerList() ;
233     $this->gotoShareSelections= $config->getShareList(true);
234     $this->gotoAvailableShares= $config->getShareList(false);  
236   }
238   function execute()
239   {
240     /* Call parent execute */
241     plugin::execute();
243     /* Fill templating stuff */
244     $smarty= get_smarty();
245     $display= "";
247     /* Are we editing from MyAccount and not editing a user */
248     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
250     /* Prepare all variables for smarty */
251     foreach($this->attributes as $s_attr){
252       /* Set value*/
253       $smarty->assign($s_attr,$this->$s_attr);
255       /* Set checkbox state*/
256       if(empty($this->$s_attr)){
257         $smarty->assign($s_attr."CHK","");
258       }else{
259         $smarty->assign($s_attr."CHK"," checked ");
260       }
262       /* Prepare ACL settings*/
263       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
264     }
266     /* Is accout enabled | are we editing from usermenu or admin menu 
267        All these tab management is done here
268      */
271     /* Working from Usermenu an the Account is currently disbled
272      * this->parent :  is only set if we are working in a list of tabs
273      * is_account   :  is only true if the needed objectClass is given
274      */
275     if((!isset($this->parent))&&(!$this->is_account)){
276       /* We are currently editing this tab from usermenu, but this account is not enabled */
277       $smarty->assign("is_account",$this->is_account);
278       /* Load template */
279       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
280       /* Avoid the "You are currently editing ...." message when you leave this tab */
281       $display .= back_to_main(); 
282       /* Display our message to the user */
283       return $display;
286       /* We are currently editing from group tabs, because 
287        * $this->parent is set
288        * posixAccount is not set, so we are not in usertabs.
289        */
290     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
291       $smarty->assign("is_account","true");
292       $this->is_group     = true;
293       $this->uid          = $this->cn;
294       $this->attrs['uid'] = $this->cn;
296       /* Change state if needed */
297       if (isset($_POST['modify_state'])){
298         if(($this->acl_is_createable() && !$this->is_account) || 
299             ($this->acl_is_removeable() &&  $this->is_account)){
300           $this->is_account= !$this->is_account;
301         }
302       }
303       /* Group Dialog with enabled environment options */
304       if ($this->is_account){
305         $display= $this->show_enable_header(_("Remove environment extension"),
306             _("Environment extension enabled. You can disable it by clicking below."));
307       } else {
309         /* Environment is disabled 
310            If theres is no posixAccount enabled, you won't be able to enable 
311            environment extensions
312          */
313         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
314           // 4. There is a PosixAccount
315           $display= $this->show_enable_header(_("Add environment extension"),
316               _("Environment extension disabled. You can enable it by clicking below."));
317           return $display;
318         }else{
319           // 4. There is no PosixAccount
320           $display= $this->show_enable_header(_("Add environment extension"),
321               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
322           return $display;
323         }
324       }
325     }else{
326       /* Editing from Usermenu 
327        *  Tell smarty that this accoutn is enabled 
328        */
329       $smarty->assign("is_account","true");
331       $this->is_group = false;
333       /* Change state if needed */
334       if (isset($_POST['modify_state'])){
335         if(($this->acl_is_createable() && !$this->is_account) || 
336             ($this->acl_is_removeable() &&  $this->is_account)){
337           $this->is_account= !$this->is_account;
338         }
339       }
341       if(isset($this->parent)){
343         // 3. Account enabled . Editing from adminmenu
344         if ($this->is_account){
345           $display= $this->show_disable_header(_("Remove environment extension"),
346               _("Environment extension enabled. You can disable it by clicking below."));
347         } else {
349           if($this->parent->by_object['posixAccount']->is_account==true){
350             // 4. There is a PosixAccount
351             $display= $this->show_disable_header(_("Add environment extension"),
352                 _("Environment extension disabled. You can enable it by clicking below."));
353             return $display;
354           }else{
355             // 4. There is a PosixAccount
356             $display= $this->show_disable_header(_("Add environment extension"),
357                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
358             return $display;
359           }
360         }
361       }
362     }
363     /* Account is Account : is_accounbt=true.
364      * Else we won't reach this. 
365      */
367     /* Prepare all variables for smarty */
368     foreach($this->attributes as $s_attr){
369       /* Set value*/
370       $smarty->assign($s_attr,$this->$s_attr);
372       /* Set checkbox state*/
373       if(empty($this->$s_attr)){
374         $smarty->assign($s_attr."CHK","");
375       }else{
376         $smarty->assign($s_attr."CHK"," checked ");
377       }
379       /* Prepare ACL settings*/
380       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
381     }
383     foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
384       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
385     }
387     if($WriteOnly) {
388       $smarty->assign("gotoPrinterACL","r");
389     }else{
390       $smarty->assign("gotoPrinterACL","rw");
391     }
393     if(empty($this->useProfile)){
394       $smarty->assign("useProfileCHK","");
395       $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
396       $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
397       $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
398     }else{
399       $smarty->assign("useProfileCHK"," checked ");
400     }
403     $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
405     /* HANDLE Profile Settings here 
406      * Assign available Quota and resolution settings
407      * Get all available profile server
408      * Get cache checkbox
409      * Assign this all to Smarty 
410      */
412     if(empty($this->gotoProfileFlagL)){
413       $smarty->assign("gotoProfileFlagLCHK"," ");
414     }else{
415       $smarty->assign("gotoProfileFlagLCHK"," checked ");
416     }
418     if(empty($this->gotoProfileFlagC)){
419       $smarty->assign("gotoProfileFlagCCHK"," ");
420     }else{
421       $smarty->assign("gotoProfileFlagCCHK"," checked ");
422     }
425     $smarty->assign("gotoXResolutions"    , $this->gotoXResolutions);
426     $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
428     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
429     if(!is_array($this->gotoProfileServers)){
430       $this->gotoProfileServers =array();
431     }
432     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
434     /* Handle kiosk profiles 
435      * Read available from filesystem
436      * Open management if post is transmitted
437      */
439     /* Save */
440     if(isset($_POST['KioskClose'])){
441       $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
443       unset($this->dialog);
444       $this->dialog=NULL;
445       $this->is_dialog = false;
446     }
448     /* Reassign help class */
449     $_SESSION['current_class_for_help'] = get_class($this);
451     /* Open Management Dialog */
452     if(isset($_POST['KioskManagementDialog'])){
453       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
454       $this->dialog->parent= $this;
455       $this->dialog->acl = $this->acl;
456       $this->is_dialog = true;
457     }
458     $tmp = new kioskManagementDialog($this->config,$this->dn);
459     $list = $tmp->getKioskProfiles($this->newKioskProfiles);
460     $list['none']=_("None");
461     $list = array_reverse($list);
462     $smarty->assign("gotoKioskProfiles",$list);
463     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
465     /* Logonscript Management
466      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
467      * Perform add Delete edit Posts 
468      */
470     /* Dialog Save */
471     if(isset($_POST['LogonSave'])){
473       if(!$this->acl_is_writeable("gotoLogonScript")){
474         print_red(_("You are not allowed to write Logon scripts."));
475         unset($this->dialog);
476         $this->dialog=NULL;
477         $this->is_dialog=false;
478       }else{
479         $this->dialog->save_object();
480         if(count($this->dialog->check())!=0){
481           foreach($this->dialog->check() as $msg){
482             print_red($msg);
483           }
484         }else{
485           $tmp = $this->dialog->save();
486           unset($this->dialog);
487           $this->dialog=NULL;
488           $this->is_dialog=false;
489           $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
490         }
491       }
492     }
493     
495     /* Dialog Quit without saving */
496     if(isset($_POST['LogonCancel'])){
497       $this->is_dialog= false;
498       unset($this->dialog);
499       $this->dialog= NULL;
500     }
502     /* Check Edit Del New Posts for a selected LogonScript */ 
503     if($this->acl_is_writeable("gotoLogonScript") && 
504         (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
506       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
507        * In this case we create a new Logon Script.
508        */
509       if(isset($_POST['gotoLogonScriptNew'])){
510         $this->is_dialog = true;
511         $this->dialog = new logonManagementDialog($this->config,$this->dn);
512       }
514       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
515        * We only can delete if there is an entry selected.
516        */
517       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
518         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
519       }
521       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
522        * There must be an entry selected to perform edit request.
523        */
524       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
525         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
526         $this->is_dialog = true;
527         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
528       }
529     }
531     /* Append List to smarty*/
532     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
533     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
535     /* In this section server shares will be defined 
536      * A user can select one of the given shares and a mount point
537      *  and attach this combination to his setup.
538      */
540     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
541     if(!is_array($this->gotoShareSelections)){
542       print $this->gotoShareSelections;
543       $this->gotoShareSelections = array();
544     }
545     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
547     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
548      * This entry will be, a combination of mountPoint and sharedefinitions 
549      */
550     if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
551       /* We assign a share to this user, if we don't know where to mount the share */
552       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
553         print_red(_("You must specify a valid mount point."));
554       }elseif(!(
555             preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
556             preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
557             preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
558             preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
559             preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
560             preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
561             preg_match("/^%/",$_POST['gotoShareMountPoint'])
562             )
563           ){
564         print_red(_("You must specify a valid mount point.")); 
565       }else{
566         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
567         $s_mount = $_POST['gotoShareMountPoint'];
568         $s_user  = $_POST['ShareUser'];
569         /* Preparing the new assignment */ 
570         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
571         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
572         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
573         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
574       }
575     }  
577     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
578      * If there is no defined share selected, we will abort the deletion without any message 
579      */
580     $once = true;
581     if($this->acl_is_writeable("gotoShare")){
582       foreach($_POST as $name => $value){
583         if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
584           $once = false;  
585           $key  = preg_replace("/^gotoShareDel_/","",$name);
586           $key  = preg_replace("/_+[xy]$/","",$key);
587           $key  = base64_decode($key);
588           if(isset($this->gotoShares[$key])) {
589             unset($this->gotoShares[$key]);
590           }
592           /* Remove corresponding password entry, too. This is a workaround
593              to get rid of old-style entries. */
594           $key= preg_replace("/\|/", "|!", $key);
595           if(isset($this->gotoShares[$key])) {
596             unset($this->gotoShares[$key]);
597           }
598         }
599         if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
600           $once = false;
601           $key  = preg_replace("/^gotoShareResetPwd_/","",$name);
602           $key  = preg_replace("/_+[xy]$/","",$key);
603           $key  = base64_decode($key);
604           $this->gotoShares[$key]['PwdHash'] = "";
605           if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
606             unset($this->gotoShares[$key]);
607           }
608         }
609       }
610     }
611     $divlistShares = new divSelectBox("gotoShares");
612     $divlistShares->SetHeight(100);
613     $tmp = $this->printOutAssignedShares();
615     foreach($tmp as $key => $value){
616       $img = "";
618       /* Check if entry starts with an ! */
619       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
621         /* If we are currently editing groups environment, skip those ! entries */ 
622         if($this->is_group) continue;
624         /* Create pwd reset images */
625         if($this->gotoShares[$key]['PwdHash'] != ""){
626           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
627             title='"._("Reset password hash")."'>";
628         }
629         $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
630         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
631       }else{
633         /* Create pwd reset img && delete image */
634         if($this->gotoShares[$key]['PwdHash'] != ""){
635           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
636             title='"._("Reset password hash")."'>";
637           $img.= "&nbsp;";
638         }
639         $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."' 
640           title='"._("Delete share entry")."'>";
641         $field1 = array("string" => $value);
642         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
643       }
644       $divlistShares->AddEntry(array($field1,$field2));
645     }
646     $smarty->assign("divlistShares",$divlistShares->DrawList());
648     /* Hotplug devices will be handled here 
649      * There are 3 possible methods for this feature
650      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
651      * Delete will erase an entry, the entry must be selcted in the ListBox first
652      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
653      */
655     /* If there is a new entry wanted, open a new entry by initilising the dialog */
656     if(isset($_POST['gotoHotplugDeviceNew'])){
657       $this->dialog = new hotplugDialog($this->config,$this->dn);
658       $this->is_dialog = true;
659     }
661     /* We have to delete the selected hotplug from the list*/
662     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice'])) && $this->acl_is_writeable("gotoHotplugDevice")){
663       foreach($_POST['gotoHotplugDevice'] as $name){
664         unset($this->gotoHotplugDevices[$name]);
665       }
666     }
668     /* There are already defined hotplugs from other users we could use */
669     if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
670       $tmp  =array();
671       foreach($this->gotoHotplugDevices as $plugs){
672         $tmp[] = $plugs['name'];
673       }
674       $this->dialog = new hotplugDialog($this->config,$this->dn,true,$tmp);
675       $this->is_dialog = true;
676     }
678     /* Dialog Aborted */
679     if(isset($_POST['HotPlugCancel'])){
680       unset($this->dialog);
681       $this->dialog= NULL;
682       $this->is_dialog = false;
683     }
685     /* Dialod saved */
686     if(isset($_POST['HotPlugSave'])){
688       if(!$this->acl_is_writeable("gotoHotplug")){
689         unset($this->dialog);
690         $this->dialog= NULL;
691         $this->is_dialog = false;
692       }else{
694         $this->dialog->save_object();
695         if(count($this->dialog->check())!=0){
696           foreach($this->dialog->check() as $msg){
697             print_red($msg);
698           }
699         }else{
700           $this->dialog->save_object();
701           $a_tmp = $this->dialog->save();
703           if(is_array($a_tmp)){
704             foreach($a_tmp as $name => $hotplug){
705               $this->gotoHotplugDevices[$name]= $hotplug; 
706             }
707           }
708           unset($this->dialog);
709           $this->dialog= NULL;
710           $this->is_dialog = false;
711         }
712       }
713     }
714     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
715     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
717     /* Printer Assignment will managed below 
718      * A printer can be assigned in two different ways and two different types
719      * There are 2 types of users assigned to a printer : user and admin
720      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
721      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
722      */ 
724     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
725     if(isset($_POST['gotoPrinterAdd'])){
727       $this->is_dialog=true;
728       $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
729     }
731     if(isset($_POST['PrinterCancel'])){
732       $this->is_dialog=false;
733       unset($this->dialog);
734       $this->dialog=NULL;
735     }
737     if(isset($_POST['PrinterSave'])){
738       if(count($this->dialog->check())!=0){
739         $tmp = $this->dialog->check();
740         foreach($tmp as $msg){
741           print_red($msg);
742         } 
743       }else{
744         $this->dialog->save_object();
745         $tmp = $this->dialog->save();
746         $tmp2= $this->dialog->getPrinter(true);
748         foreach($tmp as $pname){
749         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn']);
750           if($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
751             $this->gotoPrinter[$pname]=$tmp2[$pname];
752             $this->gotoPrinter[$pname]['mode']="user";
753           }
754         }
756         $this->is_dialog=false;
757         unset($this->dialog);
758         $this->dialog   =NULL;
759       }
760     }
762     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
763       $printer = $_POST['gotoPrinterSel'];
764       foreach($printer as $pname){
766         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn']);
767         if($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->dn)){
768           unset($this->gotoPrinter[$pname]);
769         }
770       }
771     }
773     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
776       $printers = $_POST['gotoPrinterSel'];
778       foreach($printers as $printer){
779         if($this->gotoPrinter[$printer]['mode']=="user"){
780           $this->gotoPrinter[$printer]['mode']="admin";
781         }else{
782           $this->gotoPrinter[$printer]['mode']="user";
783         }
784       }
785     }
787     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
788       if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
789         $this->gosaDefaultPrinter= "";
790       } else {
791         $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
792       }
793     }
795     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
796     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
798     /* General behavior */
799     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
800       $this->dialog->save_object();
801       $disp =$this->dialog->execute();
803       $tmp = new kioskManagementDialog($this->config,$this->dn);
804       $list = $tmp->getKioskProfiles($this->newKioskProfiles);
805       $list['none']=_("None");
806       $list = array_reverse($list);
807       if(!isset($list[$this->gotoKioskProfile])){
808         print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
809         $this->gotoKioskProfile = 'none';
810       }
811       return($disp);
812     }
814     /* Als smarty vars are set. Get smarty template and generate output */
815     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
816     return($display);
817   }
819   function remove_from_parent()
820   {
821     /* only if it was an account*/
822     if (!$this->initially_was_account){
823       return;
824     }
826     /* include global link_info */
827     $ldap= $this->config->get_ldap_link();
829     /* Remove and write to LDAP */
830     plugin::remove_from_parent();
832     /* Don't save our template variables */
833     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
835     /* Skip all these attributes */
836     foreach($skip as $del){
837       unset($this->attrs[$del]);
838     }
840     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
842     $ldap->cd($this->dn);
843     $this->cleanup();
844     $ldap->modify ($this->attrs); 
846     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
848     /* Optionally execute a command after we're done */
849     $this->handle_post_events("remove");
850   }
853   /* Save data to object */
854   function save_object()
855   {
856     /* Get all Posted vars 
857      * Setup checkboxes 
858      */
860     if(isset($_POST['iamposted'])){
861       if(isset($_POST['useProfile'])){
862         $this->useProfile = true;
863       }else{
864         $this->useProfile = false;
865       }
866       if(isset($_POST['gotoProfileFlagC'])){
867         $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
868       }else{
869         $this->gotoProfileFlagC = false;
870       }
871       if(isset($_POST['gotoProfileFlagL'])){
872         $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
873       }else{
874         $this->gotoProfileFlagL = false;
875       }
877       $tmp= $this->gosaDefaultPrinter;
878       plugin::save_object();
879       foreach($this->attributes as $s_attr){
880         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
881         if(isset($_POST[$s_attr])){
882           $this->$s_attr = $_POST[$s_attr];
883         }else{
884           $this->$s_attr = false;
885         }
886       }
887       $this->gosaDefaultPrinter= $tmp;
888     }
889   }
892   /* Check supplied data */
893   function check()
894   {
895     /* Call common method to give check the hook */
896     $message= plugin::check();
898     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
899       $message[]=_("Please set a valid profile quota size.");
900     } 
901     if(!isset($this->attrs['objectClass'])){
902       $this->attrs['objectClass']=array();
903     } 
904     if(!$this->is_group){
905       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
906         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
907       }
908     }
909     return ($message);
910   }
913   /* Save to LDAP */
914   function save()
915   {
916     /* If group was renamed, all printer settings get lost
917      */ 
918     /* only save changed variables ....*/
919     if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
920     if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
921       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
922         $method="https://";
923       }else{
924         $method="http://";
925       }
927       $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
928       $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
929     }else{
930       $this->gotoKioskProfile= array();
931     }
933     plugin::save();
934     $ldap= $this->config->get_ldap_link();
936     $realyUsedAttrs= array();
938     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
939     /* Creating Kiosk Profiles */
940     foreach($this->newKioskProfiles as $file){
941       $contents = $file['contents'];
942       $fp = @fopen($path."/".$file['name'],"w");
943       if(!$fp){
944         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
945       }else{
946         fwrite($fp,$contents,strlen($contents));
947       }
948       @unlink($file['tmp_name']);
949     }
951     /* Save already used objectClasses */
952     $ocs        = $this->attrs['objectClass'];
953     unset($ocs['count']);
954     $this->attrs = array();
955     $this->attrs['objectClass']= $ocs;
956     foreach($this->objectclasses as $objc){
957       if(!in_array($objc,$this->attrs['objectClass'])){
958         $this->attrs['objectClass'][]=$objc;
959       }
960     }
962     /* 1. Search all printers that have our uid/cn as member 
963      * 2. Delete this uid/cn from every single entry and save it again.
964      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
965      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
966      */
967     $types = array( "gotoUserPrinter"       => "AddUser",
968         "gotoGroupPrinter"      => "AddGroup",
969         "gotoUserAdminPrinter"  => "AddAdminUser",
970         "gotoGroupAdminPrinter" => "AddAdminGroup");
972     if($this->is_group){
973       $s_suffix = "Group";
974       $useVar   = "cn";
975     }else{
976       $useVar   = "uid";
977       $s_suffix = "User";
978     }
980     /* Remove old entries */
981     $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
982     while($attr = $ldap->fetch()){
983       $printerObj = NULL;
984       $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
985       $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
986       $printerObj->by_object['printgeneric']->save();
987     }
989     $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
990     while($attr = $ldap->fetch()){
991       $printerObj = NULL;
992       $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
993       $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
994       $printerObj->by_object['printgeneric']->save();
995     }
997     foreach($this->gotoPrinter as $printer){
998       $printerObj = NULL;
999       $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
1001       if($printer['mode'] == "admin") {
1002         $attribute = "goto".$s_suffix."AdminPrinter";
1003       }else{
1004         $attribute = "goto".$s_suffix."Printer";
1005       }
1007       $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1008       $printerObj->by_object['printgeneric']->save();
1009     }
1011     /* Prepare HotPlug devices */
1012     $this->attrs['gotoHotplugDevice'] = array();
1013     foreach($this->gotoHotplugDevices as $name => $device){
1014       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'].
1015         "|".$device['produkt']."|".$device['vendor'];
1016     }
1018     /* Prepare LogonScripts */
1019     $this->attrs['gotoLogonScript'] = array();
1020     foreach($this->gotoLogonScripts as $name => $script){
1021       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1022         $script['LogonOverload'].$script['LogonLast']."|".
1023         $script['LogonPriority']."|".
1024         base64_encode($script['LogonData'])."|".
1025         $script['LogonDescription'];
1026     }
1028     /* Prepare Shares */
1029     $this->attrs['gotoShare']=array();
1030     foreach($this->gotoShares as $name => $share){
1031       $mntp= $share['mountPoint'];
1032       if (!preg_match('=^[a-z0-9+_/%-]+$=i', $mntp)){
1033         $mntp= base64_encode($mntp);
1034       }
1035       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1036     }
1039     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1040     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1042     foreach($saveThis as $tosave){
1043       if(!empty($this->$tosave)){
1044         $this->attrs[$tosave]=$this->$tosave;
1045       }else{
1046         $this->attrs[$tosave]=array();
1047       }
1048     }
1050     /* Prepare Flags */
1051     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1052     if(empty($this->attrs['gotoProfileFlags'][0])){
1053       $this->attrs['gotoProfileFlags']=array();
1054     }
1056     if($this->useProfile == false){
1057       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1058       $this->attrs['gotoProfileServer']= array(); 
1059     }
1061     $ldap->cat ($this->dn, array('dn'));
1062     if ($ldap->fetch()){
1063       $mode= "modify";
1064     } else {
1065       $mode= "add";
1066       $ldap->cd($this->config->current['BASE']);
1067       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1068     }
1070     $ldap->cd($this->dn);
1071     $this->cleanup();
1072     $ldap->$mode($this->attrs);
1073     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1074     $this->handle_post_events($mode);
1075   }
1077   /* Generate ListBox frindly output for the defined shares 
1078    * Possibly Add or remove an attribute here, 
1079    */
1080   function printOutAssignedShares()
1081   {
1082     $a_return = array();
1083     if(is_array($this->gotoShares)){
1084       foreach($this->gotoShares as $share){
1085         if(preg_match("/^!/",$share['server'])){
1086           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1087         }else{
1088           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1089         }
1090       }
1091       natcasesort($a_return);
1092     }
1093     return($a_return);
1094   }
1096   /* Generate ListBox frindly output for the definedhotplugs 
1097    * Possibly Add or remove an attribute here,
1098    */
1099   function printOutHotPlugDevices()
1100   {
1101     $a_return= array();
1102     if(is_array($this->gotoHotplugDevices)){
1103       foreach($this->gotoHotplugDevices as $key=>$device){
1104         $a_return[$key] = $device['name']." - ".$device['id'];
1105       }
1106     }
1107     return($a_return);
1108   }
1110   /* Generates ListBox frienly output of used printer devices 
1111    * Append ' - admin' if printer is used in admin mode
1112    */
1113   function printOutPrinterDevices()
1114   {
1115     $a_return = array();
1116     if(is_array($this->gotoPrinter)){
1117       foreach($this->gotoPrinter as $printer){
1118         if($printer['mode'] == "admin"){
1119           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1120         }else{
1121           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1122         }
1123         if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1124           $a_return[$printer['cn'][0]].=" - "._("Default printer");
1125         }
1126       }
1127     }
1128     return($a_return);
1129   }
1131   /* Generates ListBox frienly output of used logonscripts 
1132    */
1133   function printOutLogonScripts()
1134   {
1135     $a_return = array();
1136     if(is_array($this->gotoLogonScripts)){
1137       foreach($this->gotoLogonScripts as $script){
1138         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1139       }
1140     }
1141     return($a_return);
1142   }
1145   /* Return plugin informations for acl handling 
1146 #FIXME these ACLs should work for groups too */ 
1147   function plInfo()
1148   {
1149     return (array("plShortName"     => _("Environment"),
1150           "plDescription"   => _("Environment settings"),         // Description
1151           "plSelfModify"    => TRUE,                              
1152           "plDepends"       => array("user", "posixAccount"),     // This plugin depends on 
1153           "plPriority"      => 2,                                 // Position in tabs 
1154           "plSection"       => "personal",                        // This belongs to personal
1155           "plCategory"      => array("users", "groups"),          // Add to following categories 
1156           "plOptions"       => array("resolution_hook" => array("type" => "string",
1157               "description" => _("Command to extend the list of possible screen resolutions"))),
1159           "plProvidedAcls"  => array(
1161             "gotoProfileFlagL"    => _("Resolution changeable during session") ,
1162             "gotoProfileFlagC"    => _("Cache profile localy") ,
1164             "gotoProfileQuota"    => _("Profile quota") ,
1165             "gotoProfileServer"   => _("Profile server") ,
1167             "gotoXResolution"     => _("Resolution") ,
1168             "gotoKioskProfile"    => _("Kiosk profile") ,
1170             "gosaDefaultPrinter"  => _("Default printer") ,
1171             "gotoLogonScript"     => _("Logon script") ,
1172             "gotoHotplugDevice"   => _("Hotplug devices"),
1173             "gotoShare"           => _("Shares"))
1174             ));
1175   }
1178 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1179 ?>