Code

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