Code

d34c14f02aecbbbbb02b4a8a8c5356bcbc7e796e
[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     /* Reassign help class */
421     $_SESSION['current_class_for_help'] = get_class($this);
422  
423     /* Open Management Dialog */
424     if(isset($_POST['KioskManagementDialog'])){
425       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
426       $this->dialog->parent= $this;
427       $this->dialog->acl = $this->acl;
428       $this->is_dialog = true;
429     }
431     $smarty->assign("gotoKioskProfiles",$list);
432     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
434     /* Logonscript Management
435      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
436      * Perform add Delete edit Posts 
437      */
439     /* Dialog Save */
440     if(isset($_POST['LogonSave'])){
441       $this->dialog->save_object();
442       if(count($this->dialog->check())!=0){
443         foreach($this->dialog->check() as $msg){
444           print_red($msg);
445         }
446       }else{
447         $tmp = $this->dialog->save();
448         unset($this->dialog);
449         $this->dialog=NULL;
450         $this->is_dialog=false;
451         $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
452       }
453     }
454     
455     /* Dialog Quit without saving */
456     if(isset($_POST['LogonCancel'])){
457       $this->is_dialog= false;
458       unset($this->dialog);
459       $this->dialog= NULL;
460     }
461    
462     /* Check Edit Del New Posts for a selected LogonScript */ 
463     if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
465       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
466        * In this case we create a new Logon Script.
467        */
468       if(isset($_POST['gotoLogonScriptNew'])){
469         $this->is_dialog = true;
470         $this->dialog = new logonManagementDialog($this->config,$this->dn);
471       }
473       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
474        * We only can delete if there is an entry selected.
475        */
476       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
477         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
478       }
479       
480       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
481        * There must be an entry selected to perform edit request.
482        */
483       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
484         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
485         $this->is_dialog = true;
486         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
487       }
488     }
489      
490     /* Append List to smarty*/
491     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
492     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
494     /* In this section server shares will be defined 
495      * A user can select one of the given shares and a mount point
496      *  and attach this combination to his setup.
497      */
498     
499     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
500     if(!is_array($this->gotoShareSelections)){
501       print $this->gotoShareSelections;
502       $this->gotoShareSelections = array();
503     }
504     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
506     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
507      * This entry will be, a combination of mountPoint and sharedefinitions 
508      */
509     if(isset($_POST['gotoShareAdd'])){
510       /* We assign a share to this user, if we don't know where to mount the share */
511       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
512         print_red(_("You must specify a valid mount point."));
513       }elseif(!(
514         preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
515         preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
516         preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
517         preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
518         preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
519         preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
520         preg_match("/^%/",$_POST['gotoShareMountPoint'])
521         )
522       ){
523         print_red(_("You must specify a valid mount point.")); 
524       }else{
525         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
526         $s_mount = $_POST['gotoShareMountPoint'];
527         $s_user  = $_POST['ShareUser'];
528         /* Preparing the new assignment */ 
529         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
530         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
531         $this->gotoShares[$a_share['name']."|".$a_share['server']]['OtherStuff']="";
532         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
533       }
534     }  
536     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
537      * If there is no defined share selected, we will abort the deletion without any message 
538      */
539     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
540       unset($this->gotoShares[$_POST['gotoShare']]);
541     }
543     $smarty->assign("gotoShares",$this->printOutAssignedShares());
544     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
546     /* Hotplug devices will be handled here 
547      * There are 3 possible methods for this feature
548      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
549      * Delete will erase an entry, the entry must be selcted in the ListBox first
550      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
551      */
553     /* If there is a new entry wanted, open a new entry by initilising the dialog */
554     if(isset($_POST['gotoHotplugDeviceNew'])){
555       $this->dialog = new hotplugDialog($this->config,$this->dn);
556       $this->is_dialog = true;
557     }
559     /* We have to delete the selected hotplug from the list*/
560     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
561       unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
562     }
564     /* There are already defined hotplugs from other users we could use */
565     if(isset($_POST['gotoHotplugDeviceUse'])){
566       $this->dialog = new hotplugDialog($this->config,$this->dn,true);
567       $this->is_dialog = true;
568     }
570     /* Dialog Aborted */
571     if(isset($_POST['HotPlugCancel'])){
572       unset($this->dialog);
573       $this->dialog= NULL;
574       $this->is_dialog = false;
575     }
576  
577     /* Dialod saved */
578     if(isset($_POST['HotPlugSave'])){
579       $this->dialog->save_object();
580       if(count($this->dialog->check())!=0){
581         foreach($this->dialog->check() as $msg){
582           print_red($msg);
583         }
584       }else{
585         $this->dialog->save_object();
586         $a_tmp = $this->dialog->save();
587         if(is_array($a_tmp)){
588           $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp; 
589         }
590         unset($this->dialog);
591         $this->dialog= NULL;
592         $this->is_dialog = false;
593       }
594     }
595     
596     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
597     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
598   
599     /* Printer Assignment will managed below 
600      * A printer can be assigned in two different ways and two different types
601      * There are 2 types of users assigned to a printer : user and admin
602      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
603      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
604      */ 
605     
606     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
607     if(isset($_POST['gotoPrinterAdd'])){
608       $this->is_dialog=true;
609       $this->dialog = new selectPrinterDialog($this->config,$this->dn);
610     }
612     if(isset($_POST['PrinterCancel'])){
613         $this->is_dialog=false;
614         unset($this->dialog);
615         $this->dialog=NULL;
616     }
618     if(isset($_POST['PrinterSave'])){
619       if(count($this->dialog->check())!=0){
620         $tmp = $this->dialog->check();
621         foreach($tmp as $msg){
622           print_red($msg);
623         } 
624       }else{
625         $this->dialog->save_object();
626         $tmp = $this->dialog->save();
627         $tmp2= $this->dialog->getPrinter(true);
628         $this->gotoPrinter[$tmp]=$tmp2[$tmp];
629         $this->gotoPrinter[$tmp]['mode']="user";
630         $this->is_dialog=false;
631         unset($this->dialog);
632         $this->dialog   =NULL;
633       }
634     }
635   
636     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
637       $printer = $_POST['gotoPrinterSel'];
638       unset($this->gotoPrinter[$printer]);
639     }
641     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
642       $printer = $_POST['gotoPrinterSel'];
643       if($this->gotoPrinter[$printer]['mode']=="user"){
644         $this->gotoPrinter[$printer]['mode']="admin";
645       }else{
646         $this->gotoPrinter[$printer]['mode']="user";
647       }
648     }
650     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
651     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
652  
653     /* General behavior */
654     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
655       $this->dialog->save_object();
656       return ($this->dialog->execute());
657     }
658     if($this->acl != "#none#"){
659       $smarty->assign("useProfileACL","");
660     }else{
661       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
662       $smarty->assign("gotoProfileServerACL"," disabled ");
663       $smarty->assign("gotoProfileQuotaACL"," disabled ");
664     }
666     if(!$this->useProfile){
667       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
668       $smarty->assign("gotoProfileServerACL"," disabled ");
669       $smarty->assign("gotoProfileQuotaACL"," disabled ");
670     }
672     /* Als smarty vars are set. Get smarty template and generate output */
673     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
674     
675     return($display);
676   }
678   function remove_from_parent()
679   {
680     /* only if it was an account*/
681     if (!$this->initially_was_account){
682       return;
683     }
685     /* include global link_info */
686     $ldap= $this->config->get_ldap_link();
688     /* Remove and write to LDAP */
689     plugin::remove_from_parent();
691     /* Don't save our template variables */
692     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
694     /* Skip all these attributes */
695     foreach($skip as $del){
696       unset($this->attrs[$del]);
697     }
699     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
701     $ldap->cd($this->dn);
702     $this->cleanup();
703     $ldap->modify ($this->attrs); 
706     show_ldap_error($ldap->get_error());
708     /* Optionally execute a command after we're done */
709     $this->handle_post_events("remove");
710   }
713   /* Save data to object */
714   function save_object()
715   {
716     /* Get all Posted vars 
717      * Setup checkboxes 
718      */
719    
720     
721  
722     if(isset($_POST['iamposted'])){
723       if(isset($_POST['useProfile'])){
724         $this->useProfile = true;
725       }else{
726         $this->useProfile = false;
727       }
728       if(isset($_POST['gotoProfileFlag_C'])){
729         $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
730       }else{
731         $this->gotoProfileFlag_C = false;
732       }
733       if(isset($_POST['gotoProfileFlag_L'])){
734         $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
735       }else{
736         $this->gotoProfileFlag_L = false;
737       }
739       plugin::save_object();
740       foreach($this->attributes as $s_attr){
741         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
742         if(isset($_POST[$s_attr])){
743           $this->$s_attr = $_POST[$s_attr];
744         }else{
745           $this->$s_attr = false;
746         }
747       }
748     }
749   }
752   /* Check supplied data */
753   function check()
754   {
755     $message= array();
756   
757     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
758       $message[]=_("Please set a valid profile quota size.");
759     } 
760     if(!isset($this->attrs['objectClass'])){
761       $this->attrs['objectClass']=array();
762     } 
763     if(!$this->is_group){
764       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
765         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
766       }
767     }
768     return ($message);
769   }
772   /* Save to LDAP */
773   function save()
774   {
775     /* If group was renamed, all printer settings get lost
776      */ 
777     /* only save changed variables ....*/
778     if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
779     if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
780       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
781         $method="https://";
782       }else{
783         $method="http://";
784       }
786       $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
787       $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
788     }else{
789       $this->gotoKioskProfile= array();
790     }
791     
792     plugin::save();
793     $ldap= $this->config->get_ldap_link();
795     $realyUsedAttrs= array();
797     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
798     /* Creating Kiosk Profiles */
799     foreach($this->newKioskProfiles as $file){
800       $contents = $file['contents'];
801       $fp = @fopen($path."/".$file['name'],"w");
802       if(!$fp){
803         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
804       }else{
805         fwrite($fp,$contents,strlen($contents));
806       }
807       @unlink($file['tmp_name']);
808     }
809  
810     /* Save already used objectClasses */
811     $ocs        = $this->attrs['objectClass'];
812     unset($ocs['count']);
813     $this->attrs = array();
814     $this->attrs['objectClass']= $ocs;
815     foreach($this->objectclasses as $objc){
816       if(!in_array($objc,$this->attrs['objectClass'])){
817         $this->attrs['objectClass'][]=$objc;
818       }
819     }
822     /* Save usersettings to Printer */
824     if(chkacl($this->acl,"gotoPrinter")!=""){
825       $this->gotoPrinter = array();
826     }  
827     
828     if($this->is_group){
829       $s_suffix = "Group";
830     }else{
831       $s_suffix = "User";
832     }
833   
835     /* 1. Search all printers that have our uid/cn as member 
836      * 2. Delete this uid/cn from every single entry and save it again.
837      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
838      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
839      */
840     $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
841     while($attr = $ldap->fetch()){
843       /* Walk trough all printers and check if our user id used, if so remove it.
844        * Later we will insert our uid at the right place.
845        */
847       /* Remove normal entries (User)*/
848       if(isset($attr['goto'.$s_suffix.'Printer'])) {
849         foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
850           if($this->uid==$user){
851             unset($attr['goto'.$s_suffix.'Printer'][$key]);
852           }
853         }    
854       }
856       /* Remove administrational entries (Admin)*/
857       if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
858         foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
859           if($this->uid==$user){
860             unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
861           }
862         }    
863       }
865       /* Extract useable tags, to be able to save all changes 
866        */
867       $attrs_used = array();
868       foreach($attr as $key=>$val){
870         /* If index is numeric, skip it ...*/
871         if((!is_numeric($key))&&($key!="count")){
873           /* If entry contains 'count' remove it */
874           if(is_array($val)&&isset($val['count'])){
875             unset($val['count']);
876           }
877           $attrs_used[$key]=$val;
878         }
879       }
880       /* the result of cleaning the entry is 
881        *  to be able to directly save this again,
882        *  if all changes are made 
883        */
884       $attr= $attrs_used;
886 #fix : Id don't know why such an entry was set ... 
887       if(isset($attr['GOTOADMINPRINTER'])){
888         unset($attr['GOTOADMINPRINTER']);
889       }
891       /* Save changes */
892       $ldap->cd($attr['dn']);
893       unset($attr['dn']);
894 $ldap->modify ($attr); 
896       if($ldap->get_error()!="Success"){
897         print_red(_("Error while writing printer")." : ".$ldap->get_error());
898       }
899     }
901     /* All printers are cleaned, (our cn/uid removed) 
902      *  now we must add our uid / cn 
903      *  to the new configured printers.
904      */
905     foreach($this->gotoPrinter as $printer) {
906       $ldap->cd($printer['dn']);
907       $ldap->cat($printer['dn']);
908       $attrs= $ldap->fetch();
909       $attrs_used = array(); 
910       foreach($attrs as $key=>$val){
911         if((!is_numeric($key))&&($key!="count")){
912           if(is_array($val)&&isset($val['count'])){
913             unset($val['count']);
914           }
915           $attrs_used[$key]=$val;
916         }
917       }
918       /* $attrs contains all values 
919        * we need, to save the entry lateron 
920       */
921       $attrs= $attrs_used;
923       /* Depending on the type (User/Admin) 
924        *  switch these attributes, that makes it easier
925        */
926       if($printer['mode'] == "user"){
927         $attribute  = "goto".$s_suffix."Printer";
928         $attribute2 = "goto".$s_suffix."AdminPrinter";
929       }else{
930         $attribute  = "goto".$s_suffix."AdminPrinter";
931         $attribute2 = "goto".$s_suffix."Printer";
932       }
934       /* If this user is already assigned to $attribute2 
935        * delete user from $attribute2, to be albe to attach him to $attribute
936        * A user can't be admin and normal user for one printer
937        */
938       if(!isset($printer[$attribute2])){
939         $printer[$attribute2]=array();
940       }else{
941         if(in_array($this->uid,$printer[$attribute2])){ 
942           $tmp = array_flip($printer[$attribute2]);
943           unset($tmp[$this->uid]);
944           $attrs[$attribute2]=array_flip($tmp);
945         }
946         /* If Last entry removed, clear attribute*/
947         if(empty($attrs[$attribute2])){
948           $attrs[$attribute2]=array();
949         }
950       }
951     
952       /* Attach user to the $attribute, if he is'nt already attached
953        */
954       if(!isset($attrs[$attribute])){
955         $attrs[$attribute]=array($this->uid);
956       }else{
957         unset($attrs[$attribute]['count']);
958         if(!in_array($this->uid,$attrs[$attribute])){
959           $attrs[$attribute][]=$this->uid;
960         }
961       }
963       $ldap->cd($attrs['dn']);
964       unset($attrs['dn']);
965 $ldap->modify ($attrs); 
967       if($ldap->get_error()!="Success"){
968         print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
969       }
970     }
971   
972     /* Prepare HotPlug devices */
973     $this->attrs['gotoHotplugDevice'] = array();
974     foreach($this->gotoHotplugDevices as $name => $device){
975       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
976     }
978     /* Prepare LogonScripts */
979     $this->attrs['gotoLogonScript'] = array();
980     foreach($this->gotoLogonScripts as $name => $script){
981       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
982                                             $script['LogonOverload'].$script['LogonLast']."|".
983                                             $script['LogonPriority']."|".
984                                             base64_encode($script['LogonData'])."|".
985                                             $script['LogonDescription'];
986     }
988     /* Prepare Shares */
989     $this->attrs['gotoShare']=array();
990     foreach($this->gotoShares as $name => $share){
991       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint']."|".$share['OtherStuff']."|".$share['Username'];
992     }
995     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
996     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile");
997      
998     foreach($saveThis as $tosave){
999       if(!empty($this->$tosave)){
1000         $this->attrs[$tosave]=$this->$tosave;
1001       }else{
1002         $this->attrs[$tosave]=array();
1003       }
1004     }
1005  
1006     /* Prepare Flags */
1007     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
1008     if(empty($this->attrs['gotoProfileFlags'][0])){
1009       $this->attrs['gotoProfileFlags']=array();
1010       }
1012     if($this->useProfile == false){
1013       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1014       $this->attrs['gotoProfileServer']= array(); 
1015     }
1017     foreach($this->attributes as $s_attr){
1018       if(chkacl($this->acl,$s_attr)!="") {
1019         if(isset($this->attrs[$s_attr])){
1020           unset($this->attrs[$s_attr]);
1021         }
1022       }
1023     }
1025     $ldap->cat ($this->dn);
1026     if ($ldap->fetch()){
1027       $mode= "modify";
1028     } else {
1029       $mode= "add";
1030       $ldap->cd($this->config->current['BASE']);
1031       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1032     }
1034     $ldap->cd($this->dn);
1035     $this->cleanup();
1036     $ldap->$mode($this->attrs);
1037     if($ldap->get_error()!="Success"){
1038       print_red($ldap->get_error());
1039     }
1040     $this->handle_post_events($mode);
1041   }
1043 /* Generate ListBox frindly output for the defined shares 
1044  * Possibly Add or remove an attribute here, 
1045  */
1046   function printOutAssignedShares()
1047   {
1048     $a_return = array();
1049     if(is_array($this->gotoShares)){
1050       foreach($this->gotoShares as $share){
1051         if (!preg_match('/^!/', $share['server'])){
1052           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1053         }
1054       }
1055     }
1056     return($a_return);
1057   }
1059 /* Generate ListBox frindly output for the definedhotplugs 
1060  * Possibly Add or remove an attribute here,
1061  */
1062 function printOutHotPlugDevices()
1063   {
1064     $a_return= array();
1065     if(is_array($this->gotoHotplugDevices)){
1066       foreach($this->gotoHotplugDevices as $key=>$device){
1067         $a_return[$key] = $device['name']." - ".$device['id'];
1068       }
1069     }
1070     return($a_return);
1071   }
1073   /* Generates ListBox frienly output of used printer devices 
1074    * Append ' - admin' if printer is used in admin mode
1075    */
1076   function printOutPrinterDevices()
1077   {
1078     $a_return = array();
1079     if(is_array($this->gotoPrinter)){
1080       foreach($this->gotoPrinter as $printer){
1081         if($printer['mode'] == "admin"){
1082           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
1083         }else{
1084           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1085         }
1086       }
1087     }
1088     return($a_return);
1089   }
1091   /* Generates ListBox frienly output of used logonscripts 
1092    */
1093   function printOutLogonScripts()
1094   {
1095     $a_return = array();
1096     if(is_array($this->gotoLogonScripts)){
1097       foreach($this->gotoLogonScripts as $script){
1098         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1099       }
1100     }
1101     return($a_return);
1102   }
1108 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1109 ?>