Code

Further english text cleanup
[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     /* 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","gotoPrinterSel") 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       print $this->gotoShareSelections;
439       $this->gotoShareSelections = array();
440     }
441     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
443     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
444      * This entry will be, a combination of mountPoint and sharedefinitions 
445      */
446     if(isset($_POST['gotoShareAdd'])){
447       /* We assign a share to this user, if we don't know where to mount the share */
448       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
449         print_red(_("You must specify a valid mount point."));
450       }elseif($_POST['gotoShareMountPoint'][0] !="/" ){
451         print_red(_("You must specify a valid mount point.")); 
452       }else{
453         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
454         $s_mount = $_POST['gotoShareMountPoint'];
455         /* Preparing the new assignment */ 
456         $this->gotoShares[$a_share['name']]=$a_share;
457         $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
458       }
459     }  
461     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
462      * If there is no defined share selected, we will abort the deletion without any message 
463      */
464     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
465       unset($this->gotoShares[$_POST['gotoShare']]);
466     }
468     $smarty->assign("gotoShares",$this->printOutAssignedShares());
469     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
471     /* Hotplug devices will be handled here 
472      * There are 3 possible methods for this feature
473      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
474      * Delete will erase an entry, the entry must be selcted in the ListBox first
475      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
476      */
478     /* If there is a new entry wanted, open a new entry by initilising the dialog */
479     if(isset($_POST['gotoHotplugDeviceNew'])){
480       $this->dialog = new hotplugDialog($this->config,$this->dn);
481       $this->is_dialog = true;
482     }
484     /* We have to delete the selected hotplug from the list*/
485     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
486       unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
487     }
489     /* There are already defined hotplugs from other users we could use */
490     if(isset($_POST['gotoHotplugDeviceUse'])){
491       $this->dialog = new hotplugDialog($this->config,$this->dn,true);
492       $this->is_dialog = true;
493     }
495     /* Dialog Aborted */
496     if(isset($_POST['HotPlugCancel'])){
497       unset($this->dialog);
498       $this->dialog= NULL;
499       $this->is_dialog = false;
500     }
501  
502     /* Dialod saved */
503     if(isset($_POST['HotPlugSave'])){
504       $this->dialog->save_object();
505       if(count($this->dialog->check())!=0){
506         foreach($this->dialog->check() as $msg){
507           print_red($msg);
508         }
509       }else{
510         $this->dialog->save_object();
511         $a_tmp = $this->dialog->save();
512         if(is_array($a_tmp)){
513           $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp; 
514         }
515         unset($this->dialog);
516         $this->dialog= NULL;
517         $this->is_dialog = false;
518       }
519     }
520     
521     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
522     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
523   
524     /* Printer Assignment will managed below 
525      * A printer can be assigned in two different ways and two different types
526      * There are 2 types of users assigned to a printer : user and admin
527      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
528      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
529      */ 
530     
531     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
532     if(isset($_POST['gotoPrinterAdd'])){
533       $this->is_dialog=true;
534       $this->dialog = new selectPrinterDialog($this->config,$this->dn);
535     }
537     if(isset($_POST['PrinterCancel'])){
538         $this->is_dialog=false;
539         unset($this->dialog);
540         $this->dialog=NULL;
541     }
543     if(isset($_POST['PrinterSave'])){
544       if(count($this->dialog->check())!=0){
545         $tmp = $this->dialog->check();
546         foreach($tmp as $msg){
547           print_red($msg);
548         } 
549       }else{
550         $this->dialog->save_object();
551         $tmp = $this->dialog->save();
552         $tmp2= $this->dialog->getPrinter(true);
553         $this->gotoPrinter[$tmp]=$tmp2[$tmp];
554         $this->gotoPrinter[$tmp]['mode']="user";
555         $this->is_dialog=false;
556         unset($this->dialog);
557         $this->dialog   =NULL;
558       }
559     }
560   
561     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
562       $printer = $_POST['gotoPrinterSel'];
563       unset($this->gotoPrinter[$printer]);
564     }
566     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
567       $printer = $_POST['gotoPrinterSel'];
568       if($this->gotoPrinter[$printer]['mode']=="user"){
569         $this->gotoPrinter[$printer]['mode']="admin";
570       }else{
571         $this->gotoPrinter[$printer]['mode']="user";
572       }
573     }
575     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
576     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
577  
578     /* General behavior */
579     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
580       $this->dialog->save_object();
581       return ($this->dialog->execute());
582     }
583     if($this->acl != "#none#"){
584       $smarty->assign("useProfileACL","");
585     }else{
586       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
587       $smarty->assign("gotoProfileServerACL"," disabled ");
588     }
590     if(!$this->useProfile){
591       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
592       $smarty->assign("gotoProfileServerACL"," disabled ");
593     }
595     /* Als smarty vars are set. Get smarty template and generate output */
596     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
597     
598     return($display);
599   }
601   function remove_from_parent()
602   {
603     /* only if it was an account*/
604     if (!$this->initially_was_account){
605       return;
606     }
608     /* include global link_info */
609     $ldap= $this->config->get_ldap_link();
611     /* Remove and write to LDAP */
612     plugin::remove_from_parent();
614     /* Don't save our template variables */
615     $skip = array("uid",
616                   "gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
617     /* Skip all these attributes */
618     foreach($skip as $del){
619       unset($this->attrs[$del]);
620     }
622     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
624     $ldap->cd($this->dn);
625     $ldap->modify($this->attrs);
627     show_ldap_error($ldap->get_error());
629     /* Optionally execute a command after we're done */
630     $this->handle_post_events("remove");
631   }
634   /* Save data to object */
635   function save_object()
636   {
637     /* Get all Posted vars 
638      * Setup checkboxes 
639      */
640    
641     
642  
643     if(isset($_POST['iamposted'])){
644       if(isset($_POST['useProfile'])){
645         $this->useProfile = $_POST['useProfile'];
646       }else{
647         $this->useProfile = true;
648       }
649       if(isset($_POST['gotoProfileFlag_C'])){
650         $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
651       }else{
652         $this->gotoProfileFlag_C = false;
653       }
654       if(isset($_POST['gotoProfileFlag_L'])){
655         $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
656       }else{
657         $this->gotoProfileFlag_L = false;
658       }
660       plugin::save_object();
661       foreach($this->attributes as $s_attr){
662         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
663         if(isset($_POST[$s_attr])){
664           $this->$s_attr = $_POST[$s_attr];
665         }else{
666           $this->$s_attr = false;
667         }
668       }
669     }
670   }
673   /* Check supplied data */
674   function check()
675   {
676     $message= array();
677   
678     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
679       $message[]=_("Please set a valid profile quota size.");
680     } 
681     if(!isset($this->attrs['objectClass'])){
682       $this->attrs['objectClass']=array();
683     } 
684     if(!$this->is_group){
685       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
686         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
687       }
688     }
689     return ($message);
690   }
693   /* Save to LDAP */
694   function save()
695   {
696     plugin::save();
697     $ldap= $this->config->get_ldap_link();
699     $realyUsedAttrs= array();
702     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
703     /* Creating Kiosk Profiles */
704     foreach($this->newKioskProfiles as $file){
705       $contents = $file['contents'];
706       $fp = @fopen($path."/".$file['name'],"w");
707       if(!$fp){
708         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
709       }else{
710         fwrite($fp,$contents,strlen($contents));
711       }
712       @unlink($file['tmp_name']);
713     }
714  
715     /* Save already used objectClasses */
716     $ocs        = $this->attrs['objectClass'];
717     unset($ocs['count']);
718     $this->attrs = array();
719     $this->attrs['objectClass']= $ocs;
720     foreach($this->objectclasses as $objc){
721       if(!in_array($objc,$this->attrs['objectClass'])){
722         $this->attrs['objectClass'][]=$objc;
723       }
724     }
727     /* Save usersettings to Printer */
729     if(chkacl($this->acl,"gotoPrinter")!=""){
730       $this->gotoPrinter = array();
731     }  
732     
733     if($this->is_group){
734       $s_suffix = "Group";
735     }else{
736       $s_suffix = "User";
737     }
738   
740     /* 1. Search all printers that have our uid/cn as member 
741      * 2. Delete this uid/cn from every single entry and save it again.
742      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
743      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
744      */
745     $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
746     while($attr = $ldap->fetch()){
748       /* Walk trough all printers and check if our user id used, if so remove it.
749        * Later we will insert our uid at the right place.
750        */
752       /* Remove normal entries (User)*/
753       if(isset($attr['goto'.$s_suffix.'Printer'])) {
754         foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
755           if($this->uid==$user){
756             unset($attr['goto'.$s_suffix.'Printer'][$key]);
757           }
758         }    
759       }
761       /* Remove administrational entries (Admin)*/
762       if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
763         foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
764           if($this->uid==$user){
765             unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
766           }
767         }    
768       }
770       /* Extract useable tags, to be able to save all changes 
771        */
772       $attrs_used = array();
773       foreach($attr as $key=>$val){
775         /* If index is numeric, skip it ...*/
776         if((!is_numeric($key))&&($key!="count")){
778           /* If entry contains 'count' remove it */
779           if(is_array($val)&&isset($val['count'])){
780             unset($val['count']);
781           }
782           $attrs_used[$key]=$val;
783         }
784       }
785       /* the result of cleaning the entry is 
786        *  to be able to directly save this again,
787        *  if all changes are made 
788        */
789       $attr= $attrs_used;
791 #fix : Id don't know why such an entry was set ... 
792       if(isset($attr['GOTOADMINPRINTER'])){
793         unset($attr['GOTOADMINPRINTER']);
794       }
796       /* Save changes */
797       $ldap->cd($attr['dn']);
798       unset($attr['dn']);
799       $ldap->modify($attr);
800       if($ldap->get_error()!="Success"){
801         print_red(_("Error while writing printer")." : ".$ldap->get_error());
802       }
803     }
805     /* All printers are cleaned, (our cn/uid removed) 
806      *  now we must add our uid / cn 
807      *  to the new configured printers.
808      */
809     foreach($this->gotoPrinter as $printer) {
810       $ldap->cd($printer['dn']);
811       $ldap->cat($printer['dn']);
812       $attrs= $ldap->fetch();
813       $attrs_used = array(); 
814       foreach($attrs as $key=>$val){
815         if((!is_numeric($key))&&($key!="count")){
816           if(is_array($val)&&isset($val['count'])){
817             unset($val['count']);
818           }
819           $attrs_used[$key]=$val;
820         }
821       }
822       /* $attrs contains all values 
823        * we need, to save the entry lateron 
824       */
825       $attrs= $attrs_used;
827       /* Depending on the type (User/Admin) 
828        *  switch these attributes, that makes it easier
829        */
830       if($printer['mode'] == "user"){
831         $attribute  = "goto".$s_suffix."Printer";
832         $attribute2 = "goto".$s_suffix."AdminPrinter";
833       }else{
834         $attribute  = "goto".$s_suffix."AdminPrinter";
835         $attribute2 = "goto".$s_suffix."Printer";
836       }
838       /* If this user is already assigned to $attribute2 
839        * delete user from $attribute2, to be albe to attach him to $attribute
840        * A user can't be admin and normal user for one printer
841        */
842       if(!isset($printer[$attribute2])){
843         $printer[$attribute2]=array();
844       }else{
845         if(in_array($this->uid,$printer[$attribute2])){ 
846           $tmp = array_flip($printer[$attribute2]);
847           unset($tmp[$this->uid]);
848           $attrs[$attribute2]=array_flip($tmp);
849         }
850         /* If Last entry removed, clear attribute*/
851         if(empty($attrs[$attribute2])){
852           $attrs[$attribute2]=array();
853         }
854       }
855     
856       /* Attach user to the $attribute, if he is'nt already attached
857        */
858       if(!isset($attrs[$attribute])){
859         $attrs[$attribute]=array($this->uid);
860       }else{
861         unset($attrs[$attribute]['count']);
862         if(!in_array($this->uid,$attrs[$attribute])){
863           $attrs[$attribute][]=$this->uid;
864         }
865       }
867       $ldap->cd($attrs['dn']);
868       unset($attrs['dn']);
869       $ldap->modify($attrs);
870       if($ldap->get_error()!="Success"){
871         print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
872       }
873     }
874   
875     /* Prepare HotPlug devices */
876     $this->attrs['gotoHotplugDevice'] = array();
877     foreach($this->gotoHotplugDevices as $name => $device){
878       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
879     }
881     /* Prepare LogonScripts */
882     $this->attrs['gotoLogonScript'] = array();
883     foreach($this->gotoLogonScripts as $name => $script){
884       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
885                                             $script['LogonOverload'].$script['LogonLast']."|".
886                                             $script['LogonPriority']."|".
887                                             base64_encode($script['LogonData'])."|".
888                                             $script['LogonDescription'];
889     }
891     /* Prepare Shares */
892     $this->attrs['gotoShare']=array();
893     foreach($this->gotoShares as $name => $share){
894       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint'];
895     }
897     if(!empty($this->gotoKioskProfile)){
898       $this->attrs['gotoKioskProfile']= $this->gotoKioskProfile;
899     }else{
900       $this->attrs['gotoKioskProfile']= array();
901     }
903     $saveThis = array("gotoKioskProfile","gotoProfileQuota","gotoXResolution","gotoProfileServer");
904   
905     foreach($saveThis as $tosave){
906       if(!empty($this->$tosave)){
907         $this->attrs[$tosave]=$this->$tosave;
908       }else{
909         $this->attrs[$tosave]=array();
910       }
911     }
912  
913     /* Prepare Flags */
914     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
915     if(empty($this->attrs['gotoProfileFlags'][0])){
916       $this->attrs['gotoProfileFlags']=array();
917       }
919     if($this->useProfile == false){
920       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
921       $this->attrs['gotoProfileServer']= array(); 
922     }
924     foreach($this->attributes as $s_attr){
925       if(chkacl($this->acl,$s_attr)!="") {
926         if(isset($this->attrs[$s_attr])){
927           unset($this->attrs[$s_attr]);
928         }
929       }
930     }
932     $ldap->cat ($this->dn);
933     if ($ldap->fetch()){
934       $mode= "modify";
935     } else {
936       $mode= "add";
937       $ldap->cd($this->config->current['BASE']);
938       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
939     }
941     $ldap->cd($this->dn);
942     $ldap->$mode($this->attrs);
943     if($ldap->get_error()!="Success"){
944       print_red($ldap->get_error());
945     }
946     $this->handle_post_events($mode);
947   }
949 /* Generate ListBox frindly output for the defined shares 
950  * Possibly Add or remove an attribute here, 
951  */
952   function printOutAssignedShares()
953   {
954     $a_return = array();
955     if(is_array($this->gotoShares)){
956       foreach($this->gotoShares as $share){
957         $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint'];
958       }
959     }
960     return($a_return);
961   }
963 /* Generate ListBox frindly output for the definedhotplugs 
964  * Possibly Add or remove an attribute here,
965  */
966 function printOutHotPlugDevices()
967   {
968     $a_return= array();
969     if(is_array($this->gotoHotplugDevices)){
970       foreach($this->gotoHotplugDevices as $key=>$device){
971         $a_return[$key] = $device['name']." - ".$device['id'];
972       }
973     }
974     return($a_return);
975   }
977   /* Generates ListBox frienly output of used printer devices 
978    * Append ' - admin' if printer is used in admin mode
979    */
980   function printOutPrinterDevices()
981   {
982     $a_return = array();
983     if(is_array($this->gotoPrinter)){
984       foreach($this->gotoPrinter as $printer){
985         if($printer['mode'] == "admin"){
986           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
987         }else{
988           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
989         }
990       }
991     }
992     return($a_return);
993   }
995   /* Generates ListBox frienly output of used logonscripts 
996    */
997   function printOutLogonScripts()
998   {
999     $a_return = array();
1000     if(is_array($this->gotoLogonScripts)){
1001       foreach($this->gotoLogonScripts as $script){
1002         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1003       }
1004     }
1005     return($a_return);
1006   }
1012 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1013 ?>