Code

2a3613535a401372b3271ed8a2d54ca34f0eec54
[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 $gotoProfileFlag_C  = "";     // Flag is set to C if we have the profile caching fucntion enabled 
30   
31   var $gotoXResolution    = "1024x768";     // The selected resolution eg: 1024x768
32   var $gotoXResolutions   = array();// Contains all available resolutions for this account
33   var $gotoProfileFlag_L  = "";     // 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
44   /* Share */
45   var $gotoShares         = array();// Current Share Options
46   var $gotoShare          = "";     // currently selected Share Option
47   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
48   var $gotoAvailableShares= array();// Available Shares for this account
49   
50   /* Kiosk profile */
51   var $gotoKioskProfile   = "none";     // The selected Kiosk Profile
52   var $gotoKioskProfiles  = array();// All available Kiosk profiles
53   VAR $newKioskProfiles   = array();
55   /* Hotplug Devices */
56   var $gotoHotplugDevice  = "";     // Selected hotplug
57   var $gotoHotplugDevices = array();// Already configured hotplug devices 
60   /* general settings */
61   // Sets the attributes which will kept on page reload, which will be saved, ...
62   var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags",
63                                     "gotoXResolution","gotoProfileQuota",
64                                     "gotoLogonScripts","gotoLogonScript",
65                                     "gotoPrinter",
66                                     "gotoShares","gotoShare",
67                                     "gotoKioskProfile","gotoKioskProfiles",
68                                     "gotoHotplugDevice");
69   var $objectclasses      = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here 
70   var $cn;
72   function environment ($config, $dn= NULL)
73   {
74     plugin::plugin ($config, $dn);
76    
77     /* Check : Are we currently editing a group or user dialog */
78     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
79       $suffix="Group";
80       $this->uid          = $this->attrs['cn'][0];
81       $this->attrs['uid'] = $this->attrs['cn'][0];
82     }else{
83       $suffix="User";
84     }
86     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
88     /* Get all Printer assignments */
89     $ldap = $this->config->get_ldap_link();
90     $ldap->cd($this->config->current['BASE']);
91     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
92     while($printer = $ldap->fetch()){
93       $this->gotoPrinter[$printer['cn'][0]]=$printer;
94       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
95     }
96     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
97     while($printer = $ldap->fetch()){
98       $this->gotoPrinter[$printer['cn'][0]]=$printer;
99       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
100     }
101   
102     /* prepare hotplugs */
103     if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
104       unset($this->attrs['gotoHotplugDevice']['count']);
105       foreach($this->attrs['gotoHotplugDevice'] as $device){
106         $tmp = $tmp2 = array();
107         $tmp = split("\|",$device);
108         $tmp2['name']        = $tmp[0]; 
109         $tmp2['description'] = $tmp[1]; 
110         $tmp2['id']          = $tmp[2]; 
111         $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
112       }
113     }
114     
115     /* prepare LogonScripts */
116     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
117       unset($this->attrs['gotoLogonScript']['count']);
118       foreach($this->attrs['gotoLogonScript'] as $device){
119         $tmp = $tmp2 = array();
120         $tmp = split("\|",$device);
121         $tmp2['LogonName']        = $tmp[0]; 
122         $tmp2['LogonPriority']    = $tmp[2]; 
123         if(preg_match("/O/i",$tmp[1])){
124           $tmp2['LogonOverload'] = "O";
125         }else{
126           $tmp2['LogonOverload'] = "";
127         }
128         if(preg_match("/L/i",$tmp[1])){
129           $tmp2['LogonLast'] = "L";
130         }else{
131           $tmp2['LogonLast'] = "";
132         }
133         $tmp2['LogonData']        = base64_decode($tmp[3]); 
134         $tmp2['LogonDescription'] = $tmp[4];
135         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
136       }
137     }
138     
139     /* Prepare Shares */
140     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
141       unset($this->attrs['gotoShare']['count']);
142       foreach($this->attrs['gotoShare'] as $share){
143         $tmp = $tmp2 = array();
144         $tmp = split("\|",$share);
145         $tmp2['server']      =$tmp[0];
146         $tmp2['name']        =$tmp[1];
147         $tmp2['mountPoint']  =$tmp[2];
148         if(isset($tmp[3])){
149           $tmp2['OtherStuff']  =$tmp[3];
150         }else{
151           $tmp2['OtherStuff']  ="";
152         }
153         if(isset($tmp[4])){
154           $tmp2['Username']  =$tmp[4];
155         }else{
156           $tmp2['Username']  ="";
157         }
158         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
159       }
160     }
162     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
163       $chr = $this->gotoProfileFlags[$i];
164       $name = "gotoProfileFlag_".$chr;
165       $this->$name=$chr;
166     }
168     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
169       $this->useProfile = true;
170     }else{
171       $this->useProfile = false;
172     }
174     /* Set to group environment if we editing a group */
175     if(!isset($this->parent)){
176       $this->is_group = true;
177     }
179     $this->gotoProfileServers= $config->getShareServerList() ;
180     $this->gotoShareSelections= $config->getShareList(true);
181     $this->gotoAvailableShares= $config->getShareList(false);  
183   }
185   function execute()
186   {
187         /* Call parent execute */
188         plugin::execute();
190   /* Fill templating stuff */
191   $smarty= get_smarty();
192   $display= "";
194   /* Prepare all variables for smarty */
195   foreach($this->attributes as $s_attr){
196     /* Set value*/
197     $smarty->assign($s_attr,$this->$s_attr);
199     /* Set checkbox state*/
200     if(empty($this->$s_attr)){
201       $smarty->assign($s_attr."CHK","");
202     }else{
203       $smarty->assign($s_attr."CHK"," checked ");
204     }
206     /* Prepare ACL settings*/
207     if(chkacl($this->acl,$s_attr)=="") {
208       $smarty->assign($s_attr."ACL","");
209     }else{
210       $smarty->assign($s_attr."ACL"," disabled ");
211     }
213   }
215   /* Is accout enabled | are we editing from usermenu or admin menu 
216      All these tab management is done here
217    */
219   /* Working from Usermenu an the Account is currently disbled
220      * this->parent :  is only set if we are working in a list of tabs
221      * is_account   :  is only true if the needed objectClass is given
222     */
223     if((!isset($this->parent))&&(!$this->is_account)){
224       /* We are currently editing this tab from usermenu, but this account is not enabled */
225       $smarty->assign("is_account",$this->is_account);
226       /* Load template */
227       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
228       /* Avoid the "You are currently editing ...." message when you leave this tab */
229       $display .= back_to_main(); 
230       /* Display our message to the user */
231       return $display;
232     
234     /* We are currently editing from group tabs, because 
235      * $this->parent is set
236      * posixAccount is not set, so we are not in usertabs.
237      */
238     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
239       $smarty->assign("is_account","true");
240       $this->is_group     = true;
241       $this->uid          = $this->cn;
242       $this->attrs['uid'] = $this->cn;
244       /* Change state if needed */
245       if (isset($_POST['modify_state'])){
246         $this->is_account= !$this->is_account;
247       }
249       /* Group Dialog with enabled environment options */
250       if ($this->is_account){
251         $display= $this->show_header(_("Remove environment extension"),
252             _("Environment extension enabled. You can disable it by clicking below."));
253       } else {
254   
255       /* Environment is disabled 
256          If theres is no posixAccount enabled, you won't be able to enable 
257          environment extensions
258        */
259         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
260           // 4. There is a PosixAccount
261           $display= $this->show_header(_("Add environment extension"),
262               _("Environment extension disabled. You can enable it by clicking below."));
263           return $display;
264         }else{
265           // 4. There is no PosixAccount
266           $display= $this->show_header(_("Add environment extension"),
267               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
268           return $display;
269         }
270       }
271     }else{
272       /* Editing from Usermenu 
273        *  Tell smarty that this accoutn is enabled 
274        */
275       $smarty->assign("is_account","true");
277       $this->is_group = false;
279       /* Do we need to flip is_account state? */
280       if (isset($_POST['modify_state'])){
281         $this->is_account= !$this->is_account;
282       }
284       if(isset($this->parent)){
286         // 3. Account enabled . Editing from adminmenu
287         if ($this->is_account){
288           $display= $this->show_header(_("Remove environment extension"),
289               _("Environment extension enabled. You can disable it by clicking below."));
290         } else {
292           if($this->parent->by_object['posixAccount']->is_account==true){
293             // 4. There is a PosixAccount
294             $display= $this->show_header(_("Add environment extension"),
295                 _("Environment extension disabled. You can enable it by clicking below."));
296             return $display;
297           }else{
298             // 4. There is a PosixAccount
299             $display= $this->show_header(_("Add environment extension"),
300                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
301             return $display;
302           }
303         }
304       }
305     }
306     /* Account is Account : is_accounbt=true.
307      * Else we won't reach this. 
308      */
309    
310     /* Prepare all variables for smarty */
311     foreach($this->attributes as $s_attr){
312       /* Set value*/
313       $smarty->assign($s_attr,$this->$s_attr);
314      
315       /* Set checkbox state*/
316       if(empty($this->$s_attr)){
317         $smarty->assign($s_attr."CHK","");
318       }else{
319         $smarty->assign($s_attr."CHK"," checked ");
320       }
321     
322       /* Prepare ACL settings*/
323       if(chkacl($this->acl,$s_attr)=="") {
324         $smarty->assign($s_attr."ACL","");
325       }else{
326         $smarty->assign($s_attr."ACL"," disabled ");
327       }
328  
329     }
331     foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
332       if(chkacl($this->acl,$s_attr)=="") {
333         $smarty->assign($s_attr."ACL","");
334       }else{
335         $smarty->assign($s_attr."ACL"," disabled ");
336       }
337     }
339     if(empty($this->useProfile)){
340       $smarty->assign("gotoProfileACL","disabled");
341       $smarty->assign("useProfileCHK","");
342     }else{
343       $smarty->assign("gotoProfileACL","");
344       $smarty->assign("useProfileCHK"," checked ");
345     }
347  
348     $smarty->assign("useProfileACL","");
349     if($this->acl != "#none#"){
350       $smarty->assign("useProfileACL","");
351       $smarty->assign("gotoProfileFlag_CACL"," ");
352       $smarty->assign("gotoProfileQuotaACL"," ");
353     }else{
354       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
355       $smarty->assign("useProfileACL","disabled");
356       $smarty->assign("gotoProfileServer"," disabled ");
357       $smarty->assign("gotoProfileQuotaACL"," disabled ");
358     }
360     /* HANDLE Profile Settings here 
361      * Assign available Quota and resolution settings
362      * Get all available profile server
363      * Get cache checkbox
364      * Assign this all to Smarty 
365      */
367     if(empty($this->gotoProfileFlag_L)){
368       $smarty->assign("gotoProfileFlag_LCHK"," ");
369     }else{
370       $smarty->assign("gotoProfileFlag_LCHK"," checked ");
371     }
373     if(empty($this->gotoProfileFlag_C)){
374       $smarty->assign("gotoProfileFlag_CCHK"," ");
375     }else{
376       $smarty->assign("gotoProfileFlag_CCHK"," checked ");
377     }
379     $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
381     $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
382     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
383     if(!is_array($this->gotoProfileServers)){
384       $this->gotoProfileServers =array();
385     }
386     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
388     /* Handle kiosk profiles 
389      * Read available from filesystem
390      * Open management if post is transmitted
391      */
393     /* Save */
394     if(isset($_POST['KioskClose'])){
395       $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
396   
397       unset($this->dialog);
398       $this->dialog=NULL;
399       $this->is_dialog = false;
400     }
401     $tmp = new kioskManagementDialog($this->config,$this->dn);
402     $list = $tmp->getKioskProfiles($this->newKioskProfiles);
404     $list['none']=_("None");
406     $list = array_reverse($list);
408     /* Reassign help class */
409     $_SESSION['current_class_for_help'] = get_class($this);
410  
411     /* Open Management Dialog */
412     if(isset($_POST['KioskManagementDialog'])){
413       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
414       $this->dialog->parent= $this;
415       $this->dialog->acl = $this->acl;
416       $this->is_dialog = true;
417     }
419     $smarty->assign("gotoKioskProfiles",$list);
420     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
422     /* Logonscript Management
423      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
424      * Perform add Delete edit Posts 
425      */
427     /* Dialog Save */
428     if(isset($_POST['LogonSave'])){
429       $this->dialog->save_object();
430       if(count($this->dialog->check())!=0){
431         foreach($this->dialog->check() as $msg){
432           print_red($msg);
433         }
434       }else{
435         $tmp = $this->dialog->save();
436         unset($this->dialog);
437         $this->dialog=NULL;
438         $this->is_dialog=false;
439         $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
440       }
441     }
442     
443     /* Dialog Quit without saving */
444     if(isset($_POST['LogonCancel'])){
445       $this->is_dialog= false;
446       unset($this->dialog);
447       $this->dialog= NULL;
448     }
449    
450     /* Check Edit Del New Posts for a selected LogonScript */ 
451     if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
453       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
454        * In this case we create a new Logon Script.
455        */
456       if(isset($_POST['gotoLogonScriptNew'])){
457         $this->is_dialog = true;
458         $this->dialog = new logonManagementDialog($this->config,$this->dn);
459       }
461       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
462        * We only can delete if there is an entry selected.
463        */
464       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
465         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
466       }
467       
468       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
469        * There must be an entry selected to perform edit request.
470        */
471       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
472         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
473         $this->is_dialog = true;
474         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
475       }
476     }
477      
478     /* Append List to smarty*/
479     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
480     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
482     /* In this section server shares will be defined 
483      * A user can select one of the given shares and a mount point
484      *  and attach this combination to his setup.
485      */
486     
487     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
488     if(!is_array($this->gotoShareSelections)){
489       print $this->gotoShareSelections;
490       $this->gotoShareSelections = array();
491     }
492     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
494     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
495      * This entry will be, a combination of mountPoint and sharedefinitions 
496      */
497     if(isset($_POST['gotoShareAdd'])){
498       /* We assign a share to this user, if we don't know where to mount the share */
499       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
500         print_red(_("You must specify a valid mount point."));
501       }elseif(!(
502         preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
503         preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
504         preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
505         preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
506         preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
507         preg_match("/^.USER/",$_POST['gotoShareMountPoint'])
508         )
509       ){
510         print_red(_("You must specify a valid mount point.")); 
511       }else{
512         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
513         $s_mount = $_POST['gotoShareMountPoint'];
514         $s_user  = $_POST['ShareUser'];
515         /* Preparing the new assignment */ 
516         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
517         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
518         $this->gotoShares[$a_share['name']."|".$a_share['server']]['OtherStuff']="";
519         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
520       }
521     }  
523     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
524      * If there is no defined share selected, we will abort the deletion without any message 
525      */
526     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
527       unset($this->gotoShares[$_POST['gotoShare']]);
528     }
530     $smarty->assign("gotoShares",$this->printOutAssignedShares());
531     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
533     /* Hotplug devices will be handled here 
534      * There are 3 possible methods for this feature
535      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
536      * Delete will erase an entry, the entry must be selcted in the ListBox first
537      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
538      */
540     /* If there is a new entry wanted, open a new entry by initilising the dialog */
541     if(isset($_POST['gotoHotplugDeviceNew'])){
542       $this->dialog = new hotplugDialog($this->config,$this->dn);
543       $this->is_dialog = true;
544     }
546     /* We have to delete the selected hotplug from the list*/
547     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
548       unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
549     }
551     /* There are already defined hotplugs from other users we could use */
552     if(isset($_POST['gotoHotplugDeviceUse'])){
553       $this->dialog = new hotplugDialog($this->config,$this->dn,true);
554       $this->is_dialog = true;
555     }
557     /* Dialog Aborted */
558     if(isset($_POST['HotPlugCancel'])){
559       unset($this->dialog);
560       $this->dialog= NULL;
561       $this->is_dialog = false;
562     }
563  
564     /* Dialod saved */
565     if(isset($_POST['HotPlugSave'])){
566       $this->dialog->save_object();
567       if(count($this->dialog->check())!=0){
568         foreach($this->dialog->check() as $msg){
569           print_red($msg);
570         }
571       }else{
572         $this->dialog->save_object();
573         $a_tmp = $this->dialog->save();
574         if(is_array($a_tmp)){
575           $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp; 
576         }
577         unset($this->dialog);
578         $this->dialog= NULL;
579         $this->is_dialog = false;
580       }
581     }
582     
583     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
584     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
585   
586     /* Printer Assignment will managed below 
587      * A printer can be assigned in two different ways and two different types
588      * There are 2 types of users assigned to a printer : user and admin
589      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
590      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
591      */ 
592     
593     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
594     if(isset($_POST['gotoPrinterAdd'])){
595       $this->is_dialog=true;
596       $this->dialog = new selectPrinterDialog($this->config,$this->dn);
597     }
599     if(isset($_POST['PrinterCancel'])){
600         $this->is_dialog=false;
601         unset($this->dialog);
602         $this->dialog=NULL;
603     }
605     if(isset($_POST['PrinterSave'])){
606       if(count($this->dialog->check())!=0){
607         $tmp = $this->dialog->check();
608         foreach($tmp as $msg){
609           print_red($msg);
610         } 
611       }else{
612         $this->dialog->save_object();
613         $tmp = $this->dialog->save();
614         $tmp2= $this->dialog->getPrinter(true);
615         $this->gotoPrinter[$tmp]=$tmp2[$tmp];
616         $this->gotoPrinter[$tmp]['mode']="user";
617         $this->is_dialog=false;
618         unset($this->dialog);
619         $this->dialog   =NULL;
620       }
621     }
622   
623     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
624       $printer = $_POST['gotoPrinterSel'];
625       unset($this->gotoPrinter[$printer]);
626     }
628     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
629       $printer = $_POST['gotoPrinterSel'];
630       if($this->gotoPrinter[$printer]['mode']=="user"){
631         $this->gotoPrinter[$printer]['mode']="admin";
632       }else{
633         $this->gotoPrinter[$printer]['mode']="user";
634       }
635     }
637     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
638     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
639  
640     /* General behavior */
641     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
642       $this->dialog->save_object();
643       return ($this->dialog->execute());
644     }
645     if($this->acl != "#none#"){
646       $smarty->assign("useProfileACL","");
647     }else{
648       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
649       $smarty->assign("gotoProfileServerACL"," disabled ");
650       $smarty->assign("gotoProfileQuotaACL"," disabled ");
651     }
653     if(!$this->useProfile){
654       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
655       $smarty->assign("gotoProfileServerACL"," disabled ");
656       $smarty->assign("gotoProfileQuotaACL"," disabled ");
657     }
659     /* Als smarty vars are set. Get smarty template and generate output */
660     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
661     
662     return($display);
663   }
665   function remove_from_parent()
666   {
667     /* only if it was an account*/
668     if (!$this->initially_was_account){
669       return;
670     }
672     /* include global link_info */
673     $ldap= $this->config->get_ldap_link();
675     /* Remove and write to LDAP */
676     plugin::remove_from_parent();
678     /* Don't save our template variables */
679     $skip = array("uid",
680                   "gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
681     /* Skip all these attributes */
682     foreach($skip as $del){
683       unset($this->attrs[$del]);
684     }
686     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
688     $ldap->cd($this->dn);
689     $ldap->modify($this->attrs);
691     show_ldap_error($ldap->get_error());
693     /* Optionally execute a command after we're done */
694     $this->handle_post_events("remove");
695   }
698   /* Save data to object */
699   function save_object()
700   {
701     /* Get all Posted vars 
702      * Setup checkboxes 
703      */
704    
705     
706  
707     if(isset($_POST['iamposted'])){
708       if(isset($_POST['useProfile'])){
709         $this->useProfile = true;
710       }else{
711         $this->useProfile = false;
712       }
713       if(isset($_POST['gotoProfileFlag_C'])){
714         $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
715       }else{
716         $this->gotoProfileFlag_C = false;
717       }
718       if(isset($_POST['gotoProfileFlag_L'])){
719         $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
720       }else{
721         $this->gotoProfileFlag_L = false;
722       }
724       plugin::save_object();
725       foreach($this->attributes as $s_attr){
726         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
727         if(isset($_POST[$s_attr])){
728           $this->$s_attr = $_POST[$s_attr];
729         }else{
730           $this->$s_attr = false;
731         }
732       }
733     }
734   }
737   /* Check supplied data */
738   function check()
739   {
740     $message= array();
741   
742     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
743       $message[]=_("Please set a valid profile quota size.");
744     } 
745     if(!isset($this->attrs['objectClass'])){
746       $this->attrs['objectClass']=array();
747     } 
748     if(!$this->is_group){
749       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
750         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
751       }
752     }
753     return ($message);
754   }
757   /* Save to LDAP */
758   function save()
759   {
760     plugin::save();
761     $ldap= $this->config->get_ldap_link();
763     $realyUsedAttrs= array();
766     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
767     /* Creating Kiosk Profiles */
768     foreach($this->newKioskProfiles as $file){
769       $contents = $file['contents'];
770       $fp = @fopen($path."/".$file['name'],"w");
771       if(!$fp){
772         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
773       }else{
774         fwrite($fp,$contents,strlen($contents));
775       }
776       @unlink($file['tmp_name']);
777     }
778  
779     /* Save already used objectClasses */
780     $ocs        = $this->attrs['objectClass'];
781     unset($ocs['count']);
782     $this->attrs = array();
783     $this->attrs['objectClass']= $ocs;
784     foreach($this->objectclasses as $objc){
785       if(!in_array($objc,$this->attrs['objectClass'])){
786         $this->attrs['objectClass'][]=$objc;
787       }
788     }
791     /* Save usersettings to Printer */
793     if(chkacl($this->acl,"gotoPrinter")!=""){
794       $this->gotoPrinter = array();
795     }  
796     
797     if($this->is_group){
798       $s_suffix = "Group";
799     }else{
800       $s_suffix = "User";
801     }
802   
804     /* 1. Search all printers that have our uid/cn as member 
805      * 2. Delete this uid/cn from every single entry and save it again.
806      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
807      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
808      */
809     $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
810     while($attr = $ldap->fetch()){
812       /* Walk trough all printers and check if our user id used, if so remove it.
813        * Later we will insert our uid at the right place.
814        */
816       /* Remove normal entries (User)*/
817       if(isset($attr['goto'.$s_suffix.'Printer'])) {
818         foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
819           if($this->uid==$user){
820             unset($attr['goto'.$s_suffix.'Printer'][$key]);
821           }
822         }    
823       }
825       /* Remove administrational entries (Admin)*/
826       if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
827         foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
828           if($this->uid==$user){
829             unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
830           }
831         }    
832       }
834       /* Extract useable tags, to be able to save all changes 
835        */
836       $attrs_used = array();
837       foreach($attr as $key=>$val){
839         /* If index is numeric, skip it ...*/
840         if((!is_numeric($key))&&($key!="count")){
842           /* If entry contains 'count' remove it */
843           if(is_array($val)&&isset($val['count'])){
844             unset($val['count']);
845           }
846           $attrs_used[$key]=$val;
847         }
848       }
849       /* the result of cleaning the entry is 
850        *  to be able to directly save this again,
851        *  if all changes are made 
852        */
853       $attr= $attrs_used;
855 #fix : Id don't know why such an entry was set ... 
856       if(isset($attr['GOTOADMINPRINTER'])){
857         unset($attr['GOTOADMINPRINTER']);
858       }
860       /* Save changes */
861       $ldap->cd($attr['dn']);
862       unset($attr['dn']);
863       $ldap->modify($attr);
864       if($ldap->get_error()!="Success"){
865         print_red(_("Error while writing printer")." : ".$ldap->get_error());
866       }
867     }
869     /* All printers are cleaned, (our cn/uid removed) 
870      *  now we must add our uid / cn 
871      *  to the new configured printers.
872      */
873     foreach($this->gotoPrinter as $printer) {
874       $ldap->cd($printer['dn']);
875       $ldap->cat($printer['dn']);
876       $attrs= $ldap->fetch();
877       $attrs_used = array(); 
878       foreach($attrs as $key=>$val){
879         if((!is_numeric($key))&&($key!="count")){
880           if(is_array($val)&&isset($val['count'])){
881             unset($val['count']);
882           }
883           $attrs_used[$key]=$val;
884         }
885       }
886       /* $attrs contains all values 
887        * we need, to save the entry lateron 
888       */
889       $attrs= $attrs_used;
891       /* Depending on the type (User/Admin) 
892        *  switch these attributes, that makes it easier
893        */
894       if($printer['mode'] == "user"){
895         $attribute  = "goto".$s_suffix."Printer";
896         $attribute2 = "goto".$s_suffix."AdminPrinter";
897       }else{
898         $attribute  = "goto".$s_suffix."AdminPrinter";
899         $attribute2 = "goto".$s_suffix."Printer";
900       }
902       /* If this user is already assigned to $attribute2 
903        * delete user from $attribute2, to be albe to attach him to $attribute
904        * A user can't be admin and normal user for one printer
905        */
906       if(!isset($printer[$attribute2])){
907         $printer[$attribute2]=array();
908       }else{
909         if(in_array($this->uid,$printer[$attribute2])){ 
910           $tmp = array_flip($printer[$attribute2]);
911           unset($tmp[$this->uid]);
912           $attrs[$attribute2]=array_flip($tmp);
913         }
914         /* If Last entry removed, clear attribute*/
915         if(empty($attrs[$attribute2])){
916           $attrs[$attribute2]=array();
917         }
918       }
919     
920       /* Attach user to the $attribute, if he is'nt already attached
921        */
922       if(!isset($attrs[$attribute])){
923         $attrs[$attribute]=array($this->uid);
924       }else{
925         unset($attrs[$attribute]['count']);
926         if(!in_array($this->uid,$attrs[$attribute])){
927           $attrs[$attribute][]=$this->uid;
928         }
929       }
931       $ldap->cd($attrs['dn']);
932       unset($attrs['dn']);
933       $ldap->modify($attrs);
934       if($ldap->get_error()!="Success"){
935         print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
936       }
937     }
938   
939     /* Prepare HotPlug devices */
940     $this->attrs['gotoHotplugDevice'] = array();
941     foreach($this->gotoHotplugDevices as $name => $device){
942       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
943     }
945     /* Prepare LogonScripts */
946     $this->attrs['gotoLogonScript'] = array();
947     foreach($this->gotoLogonScripts as $name => $script){
948       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
949                                             $script['LogonOverload'].$script['LogonLast']."|".
950                                             $script['LogonPriority']."|".
951                                             base64_encode($script['LogonData'])."|".
952                                             $script['LogonDescription'];
953     }
955     /* Prepare Shares */
956     $this->attrs['gotoShare']=array();
957     foreach($this->gotoShares as $name => $share){
958       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint']."|".$share['OtherStuff']."|".$share['Username'];
959     }
961     if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
962       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
963         $method="https://";
964       }else{
965         $method="http://";
966       }
968       $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
969       $this->attrs['gotoKioskProfile']= $str.$this->gotoKioskProfile;
970     }else{
971       $this->attrs['gotoKioskProfile']= array();
972     }
974     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer");
975   
976     foreach($saveThis as $tosave){
977       if(!empty($this->$tosave)){
978         $this->attrs[$tosave]=$this->$tosave;
979       }else{
980         $this->attrs[$tosave]=array();
981       }
982     }
983  
984     /* Prepare Flags */
985     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
986     if(empty($this->attrs['gotoProfileFlags'][0])){
987       $this->attrs['gotoProfileFlags']=array();
988       }
990     if($this->useProfile == false){
991       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
992       $this->attrs['gotoProfileServer']= array(); 
993     }
995     foreach($this->attributes as $s_attr){
996       if(chkacl($this->acl,$s_attr)!="") {
997         if(isset($this->attrs[$s_attr])){
998           unset($this->attrs[$s_attr]);
999         }
1000       }
1001     }
1003     $ldap->cat ($this->dn);
1004     if ($ldap->fetch()){
1005       $mode= "modify";
1006     } else {
1007       $mode= "add";
1008       $ldap->cd($this->config->current['BASE']);
1009       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1010     }
1012     $ldap->cd($this->dn);
1013     $ldap->$mode($this->attrs);
1014     if($ldap->get_error()!="Success"){
1015       print_red($ldap->get_error());
1016     }
1017     $this->handle_post_events($mode);
1018   }
1020 /* Generate ListBox frindly output for the defined shares 
1021  * Possibly Add or remove an attribute here, 
1022  */
1023   function printOutAssignedShares()
1024   {
1025     $a_return = array();
1026     if(is_array($this->gotoShares)){
1027       foreach($this->gotoShares as $share){
1028         if (!preg_match('/^!/', $share['server'])){
1029           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1030         }
1031       }
1032     }
1033     return($a_return);
1034   }
1036 /* Generate ListBox frindly output for the definedhotplugs 
1037  * Possibly Add or remove an attribute here,
1038  */
1039 function printOutHotPlugDevices()
1040   {
1041     $a_return= array();
1042     if(is_array($this->gotoHotplugDevices)){
1043       foreach($this->gotoHotplugDevices as $key=>$device){
1044         $a_return[$key] = $device['name']." - ".$device['id'];
1045       }
1046     }
1047     return($a_return);
1048   }
1050   /* Generates ListBox frienly output of used printer devices 
1051    * Append ' - admin' if printer is used in admin mode
1052    */
1053   function printOutPrinterDevices()
1054   {
1055     $a_return = array();
1056     if(is_array($this->gotoPrinter)){
1057       foreach($this->gotoPrinter as $printer){
1058         if($printer['mode'] == "admin"){
1059           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
1060         }else{
1061           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1062         }
1063       }
1064     }
1065     return($a_return);
1066   }
1068   /* Generates ListBox frienly output of used logonscripts 
1069    */
1070   function printOutLogonScripts()
1071   {
1072     $a_return = array();
1073     if(is_array($this->gotoLogonScripts)){
1074       foreach($this->gotoLogonScripts as $script){
1075         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1076       }
1077     }
1078     return($a_return);
1079   }
1085 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1086 ?>