Code

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