Code

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