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