Code

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