Code

Removed non ldap attributes from attributes array
[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","gotoProfileServer","gotoProfileFlags",
63                                     "gotoXResolution","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->gotoProfileFlag_L)){
317       $smarty->assign("gotoProfileFlag_LCHK"," ");
318     }else{
319       $smarty->assign("gotoProfileFlag_LCHK"," checked ");
320     }
322     if(empty($this->gotoProfileFlag_C)){
323       $smarty->assign("gotoProfileFlag_CCHK"," ");
324     }else{
325       $smarty->assign("gotoProfileFlag_CCHK"," checked ");
326     }
328     if(empty($this->useProfile)){
329       $smarty->assign("gotoProfileACL","disabled"); 
330       $smarty->assign("useProfileCHK",""); 
331     }else{
332       $smarty->assign("gotoProfileACL",""); 
333       $smarty->assign("useProfileCHK"," checked "); 
334     }
336     $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
338     $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
339     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
340     if(!is_array($this->gotoProfileServers)){
341       $this->gotoProfileServers =array();
342     }
343     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
345     /* Handle kiosk profiles 
346      * Read available from filesystem
347      * Open management if post is transmitted
348      */
350     /* Open Management Dialog */
351     if(isset($_POST['KioskManagementDialog'])){
352       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
353       $this->dialog->parent= $this;
354       $this->is_dialog = true;
355     }
357     /* Save */
358     if(isset($_POST['KioskClose'])){
359       $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
360   
361       unset($this->dialog);
362       $this->dialog=NULL;
363       $this->is_dialog = false;
364     }
365     $tmp = new kioskManagementDialog($this->config,$this->dn);
366     $list = $tmp->getKioskProfiles($this->newKioskProfiles);
368     $smarty->assign("gotoKioskProfiles",$list);
369     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
371     /* Logonscript Management
372      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
373      * Perform add Delete edit Posts 
374      */
376     /* Dialog Save */
377     if(isset($_POST['LogonSave'])){
378       $this->dialog->save_object();
379       if(count($this->dialog->check())!=0){
380         foreach($this->dialog->check() as $msg){
381           print_red($msg);
382         }
383       }else{
384         $tmp = $this->dialog->save();
385         unset($this->dialog);
386         $this->dialog=NULL;
387         $this->is_dialog=false;
388         $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
389       }
390     }
391     
392     /* Dialog Quit without saving */
393     if(isset($_POST['LogonCancel'])){
394       $this->is_dialog= false;
395       unset($this->dialog);
396       $this->dialog= NULL;
397     }
398    
399     /* Check Edit Del New Posts for a selected LogonScript */ 
400     if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
402       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
403        * In this case we create a new Logon Script.
404        */
405       if(isset($_POST['gotoLogonScriptNew'])){
406         $this->is_dialog = true;
407         $this->dialog = new logonManagementDialog($this->config,$this->dn);
408       }
410       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
411        * We only can delete if there is an entry selected.
412        */
413       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
414         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
415       }
416       
417       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
418        * There must be an entry selected to perform edit request.
419        */
420       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
421         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
422         $this->is_dialog = true;
423         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
424       }
425     }
426      
427     /* Append List to smarty*/
428     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
429     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
431     /* In this section server shares will be defined 
432      * A user can select one of the given shares and a mount point
433      *  and attach this combination to his setup.
434      */
435     
436     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
437     if(!is_array($this->gotoShareSelections)){
438       $this->gotoShareSelections = array();
439     }
440     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
442     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
443      * This entry will be, a combination of mountPoint and sharedefinitions 
444      */
445     if(isset($_POST['gotoShareAdd'])){
446       /* We assign a share to this user, if we don't know where to mount the share */
447       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
448         print_red(_("You must specify a valid mount point."));
449       }else{
450         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
451         $s_mount = $_POST['gotoShareMountPoint'];
452         /* Preparing the new assignment */ 
453         $this->gotoShares[$a_share['name']]=$a_share;
454         $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
455       }
456     }  
458     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
459      * If there is no defined share selected, we will abort the deletion without any message 
460      */
461     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
462       unset($this->gotoShares[$_POST['gotoShare']]);
463     }
465     $smarty->assign("gotoShares",$this->printOutAssignedShares());
466     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
468     /* Hotplug devices will be handled here 
469      * There are 3 possible methods for this feature
470      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
471      * Delete will erase an entry, the entry must be selcted in the ListBox first
472      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
473      */
475     /* If there is a new entry wanted, open a new entry by initilising the dialog */
476     if(isset($_POST['gotoHotplugDeviceNew'])){
477       $this->dialog = new hotplugDialog($this->config,$this->dn);
478       $this->is_dialog = true;
479     }
481     /* We have to delete the selected hotplug from the list*/
482     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
483       unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
484     }
486     /* There are already defined hotplugs from other users we could use */
487     if(isset($_POST['gotoHotplugDeviceUse'])){
488       $this->dialog = new hotplugDialog($this->config,$this->dn,true);
489       $this->is_dialog = true;
490     }
492     /* Dialog Aborted */
493     if(isset($_POST['HotPlugCancel'])){
494       unset($this->dialog);
495       $this->dialog= NULL;
496       $this->is_dialog = false;
497     }
498  
499     /* Dialod saved */
500     if(isset($_POST['HotPlugSave'])){
501       $this->dialog->save_object();
502       if(count($this->dialog->check())!=0){
503         foreach($this->dialog->check() as $msg){
504           print_red($msg);
505         }
506       }else{
507         $this->dialog->save_object();
508         $a_tmp = $this->dialog->save();
509         if(is_array($a_tmp)){
510           $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp; 
511         }
512         unset($this->dialog);
513         $this->dialog= NULL;
514         $this->is_dialog = false;
515       }
516     }
517     
518     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
519     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
520   
521     /* Printer Assignment will managed below 
522      * A printer can be assigned in two different ways and two different types
523      * There are 2 types of users assigned to a printer : user and admin
524      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
525      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
526      */ 
527     
528     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
529     if(isset($_POST['gotoPrinterAdd'])){
530       $this->is_dialog=true;
531       $this->dialog = new selectPrinterDialog($this->config,$this->dn);
532     }
534     if(isset($_POST['PrinterCancel'])){
535         $this->is_dialog=false;
536         unset($this->dialog);
537         $this->dialog=NULL;
538     }
540     if(isset($_POST['PrinterSave'])){
541       if(count($this->dialog->check())!=0){
542         $tmp = $this->dialog->check();
543         foreach($tmp as $msg){
544           print_red($msg);
545         } 
546       }else{
547         $this->dialog->save_object();
548         $tmp = $this->dialog->save();
549         $tmp2= $this->dialog->getPrinter(true);
550         $this->gotoPrinters[$tmp]=$tmp2[$tmp];
551         $this->gotoPrinters[$tmp]['mode']="user";
552         $this->is_dialog=false;
553         unset($this->dialog);
554         $this->dialog   =NULL;
555       }
556     }
557   
558     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
559       $printer = $_POST['gotoPrinter'];
560       unset($this->gotoPrinters[$printer]);
561     }
563     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
564       $printer = $_POST['gotoPrinter'];
565       if($this->gotoPrinters[$printer]['mode']=="user"){
566         $this->gotoPrinters[$printer]['mode']="admin";
567       }else{
568         $this->gotoPrinters[$printer]['mode']="user";
569       }
570     }
572     $smarty->assign("gotoPrinters",$this->printOutPrinterDevices());
573     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
574  
575     /* General behavior */
576     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
577       $this->dialog->save_object();
578       return ($this->dialog->execute());
579     }
580     if($this->acl != "#none#"){
581       $smarty->assign("useProfileACL","");
582     }else{
583       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
584       $smarty->assign("gotoProfileServerACL"," disabled ");
585     }
587     if(!$this->useProfile){
588       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
589       $smarty->assign("gotoProfileServerACL"," disabled ");
590     }
592     /* Als smarty vars are set. Get smarty template and generate output */
593     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
594     
595     return($display);
596   }
598   function remove_from_parent()
599   {
600     /* only if it was an account*/
601     if (!$this->initially_was_account){
602       return;
603     }
605     /* include global link_info */
606     $ldap= $this->config->get_ldap_link();
608     /* Remove and write to LDAP */
609     plugin::remove_from_parent();
611     /* Don't save our template variables */
612     $skip = array("uid",
613                   "gotoLogonScripts","gotoPrinters","gotoShares","gotoKioskProfiles","gotoHotplugDevices",
614                   "gotoPrinter");
615     /* Skip all these attributes */
616     foreach($skip as $del){
617       unset($this->attrs[$del]);
618     }
620     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
622     $ldap->cd($this->dn);
623     $ldap->modify($this->attrs);
625     show_ldap_error($ldap->get_error());
627     /* Optionally execute a command after we're done */
628     $this->handle_post_events("remove");
629   }
632   /* Save data to object */
633   function save_object()
634   {
635     /* Get all Posted vars 
636      * Setup checkboxes 
637      */
638    
639     
640  
641     if(isset($_POST['iamposted'])){
642       if(isset($_POST['useProfile'])){
643         $this->useProfile = $_POST['useProfile'];
644       }else{
645         $this->useProfile = true;
646       }
647       if(isset($_POST['gotoProfileFlag_C'])){
648         $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
649       }else{
650         $this->gotoProfileFlag_C = false;
651       }
652       if(isset($_POST['gotoProfileFlag_L'])){
653         $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
654       }else{
655         $this->gotoProfileFlag_L = false;
656       }
658       plugin::save_object();
659       foreach($this->attributes as $s_attr){
660         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinters","gotoLogonScripts","uid"))) continue;
661         if(isset($_POST[$s_attr])){
662           $this->$s_attr = $_POST[$s_attr];
663         }else{
664           $this->$s_attr = false;
665         }
666       }
667     }
668   }
671   /* Check supplied data */
672   function check()
673   {
674     $message= array();
675   
676     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
677       $message[]=_("Please set a valid profile quota size.");
678     } 
679     if(!isset($this->attrs['objectClass'])){
680       $this->attrs['objectClass']=array();
681     } 
682     if(!$this->is_group){
683       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
684         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
685       }
686     }
687     return ($message);
688   }
691   /* Save to LDAP */
692   function save()
693   {
694     plugin::save();
695     $ldap= $this->config->get_ldap_link();
697     $realyUsedAttrs= array();
700     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
701     /* Creating Kiosk Profiles */
702     foreach($this->newKioskProfiles as $file){
703       $contents = $file['contents'];
704       $fp = @fopen($path."/".$file['name'],"w");
705       if(!$fp){
706         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
707       }else{
708         fwrite($fp,$contents,strlen($contents));
709       }
710       @unlink($file['tmp_name']);
711     }
712  
713     /* Save already used objectClasses */
714     $ocs        = $this->attrs['objectClass'];
715     unset($ocs['count']);
716     $this->attrs = array();
717     $this->attrs['objectClass']= $ocs;
718     foreach($this->objectclasses as $objc){
719       if(!in_array($objc,$this->attrs['objectClass'])){
720         $this->attrs['objectClass'][]=$objc;
721       }
722     }
725     /* Save usersettings to Printer */
727     if(chkacl($this->acl,"gotoPrinter")!=""){
728       $this->gotoPrinters = array();
729     }  
730     
731     if($this->is_group){
732       $s_suffix = "Group";
733     }else{
734       $s_suffix = "User";
735     }
736   
739     /* Deleted printer settings wasn't deleted from ldap ... 
740      */
741     //if(count($this->gotoPrinters)==0){
742     if(1==1){
743       $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
744       while($attr = $ldap->fetch()){
745         if(isset($attr['goto'.$s_suffix.'Printer'])) {
746           foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
747             if($this->uid==$user){
748               unset($attr['goto'.$s_suffix.'Printer'][$key]);
749             }
750           }    
751         }
753         if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
754           foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
755             if($this->uid==$user){
756               unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
757             }
758           }    
759         }
761         $attrs_used = array();
762         foreach($attr as $key=>$val){
763           if((!is_numeric($key))&&($key!="count")){
764             if(is_array($val)&&isset($val['count'])){
765               unset($val['count']);
766             }
767             $attrs_used[$key]=$val;
768           }
769         }
770         $attr= $attrs_used;
771         $tmp =array();
772         
773         if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
774           foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $print){
775             $tmp[]=$print;
776           }
777         }
778         $attr['goto'.$s_suffix.'AdminPrinter'] = $tmp;
780         $tmp =array();
781     
782         if(isset($attr['goto'.$s_suffix.'Printer'])){
783           foreach($attr['goto'.$s_suffix.'Printer'] as $print){
784             $tmp[]=$print;
785           }
786         }
787         $attr['goto'.$s_suffix.'Printer'] = $tmp;
789         if(isset($attr['GOTOADMINPRINTER'])){
790           unset($attr['GOTOADMINPRINTER']);
791         }
793         $ldap->cd($attr['dn']);
794         unset($attr['dn']);
795         $ldap->modify($attr);
796         if($ldap->get_error()!="Success"){
797           print_red(_("Error while writing printer")." : ".$ldap->get_error());
798         }
799       }
800     }    
802     foreach($this->gotoPrinters as $printer) {
803       $ldap->cd($printer['dn']);
804       $ldap->cat($printer['dn']);
805       $attrs= $ldap->fetch();
806       $attrs_used = array(); 
807       foreach($attrs as $key=>$val){
808         if((!is_numeric($key))&&($key!="count")){
809           if(is_array($val)&&isset($val['count'])){
810             unset($val['count']);
811           }
812           $attrs_used[$key]=$val;
813         }
814       }
816       $attrs= $attrs_used;
818       /* Filter entries */
819  
820       if($printer['mode'] == "user"){
821         $attribute  = "goto".$s_suffix."Printer";
822         $attribute2 = "goto".$s_suffix."AdminPrinter";
823       }else{
824         $attribute  = "goto".$s_suffix."AdminPrinter";
825         $attribute2 = "goto".$s_suffix."Printer";
826       }
828       /* If this user is already assigned to $attribute2 
829        * delete user from $attribute2, to be albe to attach him to $attribute
830        * A user can't be admin and normal user for one printer
831        */
832       if(!isset($printer[$attribute2])){
833         $printer[$attribute2]=array();
834       }else{
835         if(in_array($this->uid,$printer[$attribute2])){ 
836           $tmp = array_flip($attrs[$attribute2]);
837           unset($tmp[$this->uid]);
838           $attrs[$attribute2]=array_flip($tmp);
839         }
840         /* If Last entry removed, clear attribute*/
841         if(empty($attrs[$attribute2])){
842           $attrs[$attribute2]=array();
843         }
844       }
845     
846       /* Attach user to the $attribute, if he is'nt already attached
847        */
848       if(!isset($attrs[$attribute])){
849         $attrs[$attribute]=array($this->uid);
850       }else{
851         unset($attrs[$attribute]['count']);
852         if(!in_array($this->uid,$attrs[$attribute])){
853           $attrs[$attribute][]=$this->uid;
854         }
855       }
857       $tmp =array();
858       if(isset($attrs['goto'.$s_suffix.'AdminPrinter'])){
859         foreach($attrs['goto'.$s_suffix.'AdminPrinter'] as $print){
860           $tmp[]=$print;
861         }
862       }
863       $attrs['goto'.$s_suffix.'AdminPrinter'] = $tmp;
865       $tmp =array();
866       if(isset($attrs['goto'.$s_suffix.'Printer'])){
867         foreach($attrs['goto'.$s_suffix.'Printer'] as $print){
868           $tmp[]=$print;
869         }
870       }
871       $attrs['goto'.$s_suffix.'Printer'] = $tmp;
873       $ldap->cd($attrs['dn']);
874       unset($attrs['dn']);
875       $ldap->modify($attrs);
876       if($ldap->get_error()!="Success"){
877         print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
878       }
879     }
880   
881     /* Prepare HotPlug devices */
882     $this->attrs['gotoHotplugDevice'] = array();
883     foreach($this->gotoHotplugDevices as $name => $device){
884       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
885     }
887     /* Prepare LogonScripts */
888     $this->attrs['gotoLogonScript'] = array();
889     foreach($this->gotoLogonScripts as $name => $script){
890       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
891                                             $script['LogonOverload'].$script['LogonLast']."|".
892                                             $script['LogonPriority']."|".
893                                             base64_encode($script['LogonData'])."|".
894                                             $script['LogonDescription'];
895     }
897     /* Prepare Shares */
898     $this->attrs['gotoShare']=array();
899     foreach($this->gotoShares as $name => $share){
900       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint'];
901     }
903     if(!empty($this->gotoKioskProfile)){
904       $this->attrs['gotoKioskProfile']= $this->gotoKioskProfile;
905     }else{
906       $this->attrs['gotoKioskProfile']= array();
907     }
909     $saveThis = array("gotoKioskProfile","gotoProfileQuota","gotoXResolution","gotoProfileServer");
910   
911     foreach($saveThis as $tosave){
912       if(!empty($this->$tosave)){
913         $this->attrs[$tosave]=$this->$tosave;
914       }else{
915         $this->attrs[$tosave]=array();
916       }
917     }
918  
919     /* Prepare Flags */
920     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
921     if(empty($this->attrs['gotoProfileFlags'][0])){
922       $this->attrs['gotoProfileFlags']=array();
923       }
925     if($this->useProfile == false){
926       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
927       $this->attrs['gotoProfileServer']= array(); 
928     }
930     foreach($this->attributes as $s_attr){
931       if(chkacl($this->acl,$s_attr)!="") {
932         if(isset($this->attrs[$s_attr])){
933           unset($this->attrs[$s_attr]);
934         }
935       }
936     }
938     $ldap->cat ($this->dn);
939     if ($ldap->fetch()){
940       $mode= "modify";
941     } else {
942       $mode= "add";
943       $ldap->cd($this->config->current['BASE']);
944       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
945     }
947     $ldap->cd($this->dn);
948     $ldap->$mode($this->attrs);
949     if($ldap->get_error()!="Success"){
950       print_red($ldap->get_error());
951     }
952     $this->handle_post_events($mode);
953   }
955 /* Generate ListBox frindly output for the defined shares 
956  * Possibly Add or remove an attribute here, 
957  */
958   function printOutAssignedShares()
959   {
960     $a_return = array();
961     if(is_array($this->gotoShares)){
962       foreach($this->gotoShares as $share){
963         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
964       }
965     }
966     return($a_return);
967   }
969 /* Generate ListBox frindly output for the definedhotplugs 
970  * Possibly Add or remove an attribute here,
971  */
972 function printOutHotPlugDevices()
973   {
974     $a_return= array();
975     if(is_array($this->gotoHotplugDevices)){
976       foreach($this->gotoHotplugDevices as $key=>$device){
977         $a_return[$key] = $device['name']." - ".$device['id'];
978       }
979     }
980     return($a_return);
981   }
983   /* Generates ListBox frienly output of used printer devices 
984    * Append ' - admin' if printer is used in admin mode
985    */
986   function printOutPrinterDevices()
987   {
988     $a_return = array();
989     if(is_array($this->gotoPrinters)){
990       foreach($this->gotoPrinters as $printer){
991         if($printer['mode'] == "admin"){
992           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
993         }else{
994           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
995         }
996       }
997     }
998     return($a_return);
999   }
1001   /* Generates ListBox frienly output of used logonscripts 
1002    */
1003   function printOutLogonScripts()
1004   {
1005     $a_return = array();
1006     if(is_array($this->gotoLogonScripts)){
1007       foreach($this->gotoLogonScripts as $script){
1008         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1009       }
1010     }
1011     return($a_return);
1012   }
1018 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1019 ?>