Code

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