6762c88ca328ddde77fd624313192de57fba1ac7
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 = "1024x768"; // The selected resolution eg: 1024x768
32 var $gotoXResolutions = array();// Contains all available resolutions for this account
33 var $gotoProfileFlag_L = ""; // Flag is set to L to enable runtime resolution change
34 var $gotoProfileQuota = ""; // User Quota Settings
36 /* Logon script section*/
37 var $gotoLogonScripts = array();// Contains all available Logon Scripts
38 var $gotoLogonScript = ""; // The selected Logon Script
40 /* Printer */
41 var $gotoPrinter = array();// All available Printer, with their configurations
42 var $gotoPrinterSel = ""; // The selected Printer
44 /* Share */
45 var $gotoShares = array();// Current Share Options
46 var $gotoShare = ""; // currently selected Share Option
47 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
48 var $gotoAvailableShares= array();// Available Shares for this account
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 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
154 }
155 }
157 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
158 $chr = $this->gotoProfileFlags[$i];
159 $name = "gotoProfileFlag_".$chr;
160 $this->$name=$chr;
161 }
163 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
164 $this->useProfile = true;
165 }else{
166 $this->useProfile = false;
167 }
169 /* Set to group environment if we editing a group */
170 if(!isset($this->parent)){
171 $this->is_group = true;
172 }
174 $this->gotoProfileServers= $config->getShareServerList() ;
175 $this->gotoShareSelections= $config->getShareList(true);
176 $this->gotoAvailableShares= $config->getShareList(false);
178 }
180 function execute()
181 {
182 /* Call parent execute */
183 plugin::execute();
185 /* Fill templating stuff */
186 $smarty= get_smarty();
187 $display= "";
189 /* Prepare all variables for smarty */
190 foreach($this->attributes as $s_attr){
191 /* Set value*/
192 $smarty->assign($s_attr,$this->$s_attr);
194 /* Set checkbox state*/
195 if(empty($this->$s_attr)){
196 $smarty->assign($s_attr."CHK","");
197 }else{
198 $smarty->assign($s_attr."CHK"," checked ");
199 }
201 /* Prepare ACL settings*/
202 if(chkacl($this->acl,$s_attr)=="") {
203 $smarty->assign($s_attr."ACL","");
204 }else{
205 $smarty->assign($s_attr."ACL"," disabled ");
206 }
208 }
210 /* Is accout enabled | are we editing from usermenu or admin menu
211 All these tab management is done here
212 */
214 /* Working from Usermenu an the Account is currently disbled
215 * this->parent : is only set if we are working in a list of tabs
216 * is_account : is only true if the needed objectClass is given
217 */
218 if((!isset($this->parent))&&(!$this->is_account)){
219 /* We are currently editing this tab from usermenu, but this account is not enabled */
220 $smarty->assign("is_account",$this->is_account);
221 /* Load template */
222 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
223 /* Avoid the "You are currently editing ...." message when you leave this tab */
224 $display .= back_to_main();
225 /* Display our message to the user */
226 return $display;
229 /* We are currently editing from group tabs, because
230 * $this->parent is set
231 * posixAccount is not set, so we are not in usertabs.
232 */
233 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
234 $smarty->assign("is_account","true");
235 $this->is_group = true;
236 $this->uid = $this->cn;
237 $this->attrs['uid'] = $this->cn;
239 /* Change state if needed */
240 if (isset($_POST['modify_state'])){
241 $this->is_account= !$this->is_account;
242 }
244 /* Group Dialog with enabled environment options */
245 if ($this->is_account){
246 $display= $this->show_header(_("Remove environment extension"),
247 _("Environment extension enabled. You can disable it by clicking below."));
248 } else {
250 /* Environment is disabled
251 If theres is no posixAccount enabled, you won't be able to enable
252 environment extensions
253 */
254 if((isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
255 // 4. There is a PosixAccount
256 $display= $this->show_header(_("Add environment extension"),
257 _("Environment extension disabled. You can enable it by clicking below."));
258 return $display;
259 }else{
260 // 4. There is no PosixAccount
261 $display= $this->show_header(_("Add environment extension"),
262 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
263 return $display;
264 }
265 }
266 }else{
267 /* Editing from Usermenu
268 * Tell smarty that this accoutn is enabled
269 */
270 $smarty->assign("is_account","true");
272 $this->is_group = false;
274 /* Do we need to flip is_account state? */
275 if (isset($_POST['modify_state'])){
276 $this->is_account= !$this->is_account;
277 }
279 if(isset($this->parent)){
280 // 3. Account enabled . Editing from adminmenu
281 if ($this->is_account){
282 $display= $this->show_header(_("Remove environment extension"),
283 _("Environment extension enabled. You can disable it by clicking below."));
284 } else {
285 if((isset($this->attrs['objectClass']))
286 &&((in_array("posixAccount",$this->attrs['objectClass'])))
287 ||($this->parent->by_object['posixAccount']->is_account==true)){
288 // 4. There is a PosixAccount
289 $display= $this->show_header(_("Add environment extension"),
290 _("Environment extension disabled. You can enable it by clicking below."));
291 return $display;
292 }else{
293 // 4. There is a PosixAccount
294 $display= $this->show_header(_("Add environment extension"),
295 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
296 return $display;
297 }
298 }
299 }
300 }
301 /* Account is Account : is_accounbt=true.
302 * Else we won't reach this.
303 */
305 /* Prepare all variables for smarty */
306 foreach($this->attributes as $s_attr){
307 /* Set value*/
308 $smarty->assign($s_attr,$this->$s_attr);
310 /* Set checkbox state*/
311 if(empty($this->$s_attr)){
312 $smarty->assign($s_attr."CHK","");
313 }else{
314 $smarty->assign($s_attr."CHK"," checked ");
315 }
317 /* Prepare ACL settings*/
318 if(chkacl($this->acl,$s_attr)=="") {
319 $smarty->assign($s_attr."ACL","");
320 }else{
321 $smarty->assign($s_attr."ACL"," disabled ");
322 }
324 }
326 foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
327 if(chkacl($this->acl,$s_attr)=="") {
328 $smarty->assign($s_attr."ACL","");
329 }else{
330 $smarty->assign($s_attr."ACL"," disabled ");
331 }
332 }
334 if(empty($this->useProfile)){
335 $smarty->assign("gotoProfileACL","disabled");
336 $smarty->assign("useProfileCHK","");
337 }else{
338 $smarty->assign("gotoProfileACL","");
339 $smarty->assign("useProfileCHK"," checked ");
340 }
343 $smarty->assign("useProfileACL","");
344 if($this->acl != "#none#"){
345 $smarty->assign("useProfileACL","");
346 }else{
347 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
348 $smarty->assign("useProfileACL","disabled");
349 $smarty->assign("gotoProfileServer"," disabled ");
350 }
352 /* HANDLE Profile Settings here
353 * Assign available Quota and resolution settings
354 * Get all available profile server
355 * Get cache checkbox
356 * Assign this all to Smarty
357 */
359 if(empty($this->gotoProfileFlag_L)){
360 $smarty->assign("gotoProfileFlag_LCHK"," ");
361 }else{
362 $smarty->assign("gotoProfileFlag_LCHK"," checked ");
363 }
365 if(empty($this->gotoProfileFlag_C)){
366 $smarty->assign("gotoProfileFlag_CCHK"," ");
367 }else{
368 $smarty->assign("gotoProfileFlag_CCHK"," checked ");
369 }
371 $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
373 $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
374 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
375 if(!is_array($this->gotoProfileServers)){
376 $this->gotoProfileServers =array();
377 }
378 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
380 /* Handle kiosk profiles
381 * Read available from filesystem
382 * Open management if post is transmitted
383 */
385 /* Save */
386 if(isset($_POST['KioskClose'])){
387 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
389 unset($this->dialog);
390 $this->dialog=NULL;
391 $this->is_dialog = false;
392 }
393 $tmp = new kioskManagementDialog($this->config,$this->dn);
394 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
396 $list['none']=_("None");
398 $list = array_reverse($list);
400 /* Reassign help class */
401 $_SESSION['current_class_for_help'] = get_class($this);
403 /* Open Management Dialog */
404 if(isset($_POST['KioskManagementDialog'])){
405 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
406 $this->dialog->parent= $this;
407 $this->is_dialog = true;
408 }
410 $smarty->assign("gotoKioskProfiles",$list);
411 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
413 /* Logonscript Management
414 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
415 * Perform add Delete edit Posts
416 */
418 /* Dialog Save */
419 if(isset($_POST['LogonSave'])){
420 $this->dialog->save_object();
421 if(count($this->dialog->check())!=0){
422 foreach($this->dialog->check() as $msg){
423 print_red($msg);
424 }
425 }else{
426 $tmp = $this->dialog->save();
427 unset($this->dialog);
428 $this->dialog=NULL;
429 $this->is_dialog=false;
430 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
431 }
432 }
434 /* Dialog Quit without saving */
435 if(isset($_POST['LogonCancel'])){
436 $this->is_dialog= false;
437 unset($this->dialog);
438 $this->dialog= NULL;
439 }
441 /* Check Edit Del New Posts for a selected LogonScript */
442 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
444 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
445 * In this case we create a new Logon Script.
446 */
447 if(isset($_POST['gotoLogonScriptNew'])){
448 $this->is_dialog = true;
449 $this->dialog = new logonManagementDialog($this->config,$this->dn);
450 }
452 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
453 * We only can delete if there is an entry selected.
454 */
455 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
456 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
457 }
459 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
460 * There must be an entry selected to perform edit request.
461 */
462 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
463 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
464 $this->is_dialog = true;
465 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
466 }
467 }
469 /* Append List to smarty*/
470 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
471 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
473 /* In this section server shares will be defined
474 * A user can select one of the given shares and a mount point
475 * and attach this combination to his setup.
476 */
478 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
479 if(!is_array($this->gotoShareSelections)){
480 print $this->gotoShareSelections;
481 $this->gotoShareSelections = array();
482 }
483 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
485 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
486 * This entry will be, a combination of mountPoint and sharedefinitions
487 */
488 if(isset($_POST['gotoShareAdd'])){
489 /* We assign a share to this user, if we don't know where to mount the share */
490 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
491 print_red(_("You must specify a valid mount point."));
492 }elseif($_POST['gotoShareMountPoint'][0] !="/" ){
493 print_red(_("You must specify a valid mount point."));
494 }else{
495 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
496 $s_mount = $_POST['gotoShareMountPoint'];
497 /* Preparing the new assignment */
498 $this->gotoShares[$a_share['name']]=$a_share;
499 $this->gotoShares[$a_share['name']]['OtherStuff']="";
500 $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
501 }
502 }
504 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
505 * If there is no defined share selected, we will abort the deletion without any message
506 */
507 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
508 unset($this->gotoShares[$_POST['gotoShare']]);
509 }
511 $smarty->assign("gotoShares",$this->printOutAssignedShares());
512 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
514 /* Hotplug devices will be handled here
515 * There are 3 possible methods for this feature
516 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
517 * Delete will erase an entry, the entry must be selcted in the ListBox first
518 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
519 */
521 /* If there is a new entry wanted, open a new entry by initilising the dialog */
522 if(isset($_POST['gotoHotplugDeviceNew'])){
523 $this->dialog = new hotplugDialog($this->config,$this->dn);
524 $this->is_dialog = true;
525 }
527 /* We have to delete the selected hotplug from the list*/
528 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
529 unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
530 }
532 /* There are already defined hotplugs from other users we could use */
533 if(isset($_POST['gotoHotplugDeviceUse'])){
534 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
535 $this->is_dialog = true;
536 }
538 /* Dialog Aborted */
539 if(isset($_POST['HotPlugCancel'])){
540 unset($this->dialog);
541 $this->dialog= NULL;
542 $this->is_dialog = false;
543 }
545 /* Dialod saved */
546 if(isset($_POST['HotPlugSave'])){
547 $this->dialog->save_object();
548 if(count($this->dialog->check())!=0){
549 foreach($this->dialog->check() as $msg){
550 print_red($msg);
551 }
552 }else{
553 $this->dialog->save_object();
554 $a_tmp = $this->dialog->save();
555 if(is_array($a_tmp)){
556 $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp;
557 }
558 unset($this->dialog);
559 $this->dialog= NULL;
560 $this->is_dialog = false;
561 }
562 }
564 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
565 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
567 /* Printer Assignment will managed below
568 * A printer can be assigned in two different ways and two different types
569 * There are 2 types of users assigned to a printer : user and admin
570 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
571 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
572 */
574 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
575 if(isset($_POST['gotoPrinterAdd'])){
576 $this->is_dialog=true;
577 $this->dialog = new selectPrinterDialog($this->config,$this->dn);
578 }
580 if(isset($_POST['PrinterCancel'])){
581 $this->is_dialog=false;
582 unset($this->dialog);
583 $this->dialog=NULL;
584 }
586 if(isset($_POST['PrinterSave'])){
587 if(count($this->dialog->check())!=0){
588 $tmp = $this->dialog->check();
589 foreach($tmp as $msg){
590 print_red($msg);
591 }
592 }else{
593 $this->dialog->save_object();
594 $tmp = $this->dialog->save();
595 $tmp2= $this->dialog->getPrinter(true);
596 $this->gotoPrinter[$tmp]=$tmp2[$tmp];
597 $this->gotoPrinter[$tmp]['mode']="user";
598 $this->is_dialog=false;
599 unset($this->dialog);
600 $this->dialog =NULL;
601 }
602 }
604 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
605 $printer = $_POST['gotoPrinterSel'];
606 unset($this->gotoPrinter[$printer]);
607 }
609 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
610 $printer = $_POST['gotoPrinterSel'];
611 if($this->gotoPrinter[$printer]['mode']=="user"){
612 $this->gotoPrinter[$printer]['mode']="admin";
613 }else{
614 $this->gotoPrinter[$printer]['mode']="user";
615 }
616 }
618 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
619 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
621 /* General behavior */
622 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
623 $this->dialog->save_object();
624 return ($this->dialog->execute());
625 }
626 if($this->acl != "#none#"){
627 $smarty->assign("useProfileACL","");
628 }else{
629 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
630 $smarty->assign("gotoProfileServerACL"," disabled ");
631 }
633 if(!$this->useProfile){
634 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
635 $smarty->assign("gotoProfileServerACL"," disabled ");
636 }
638 /* Als smarty vars are set. Get smarty template and generate output */
639 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
641 return($display);
642 }
644 function remove_from_parent()
645 {
646 /* only if it was an account*/
647 if (!$this->initially_was_account){
648 return;
649 }
651 /* include global link_info */
652 $ldap= $this->config->get_ldap_link();
654 /* Remove and write to LDAP */
655 plugin::remove_from_parent();
657 /* Don't save our template variables */
658 $skip = array("uid",
659 "gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
660 /* Skip all these attributes */
661 foreach($skip as $del){
662 unset($this->attrs[$del]);
663 }
665 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
667 $ldap->cd($this->dn);
668 $ldap->modify($this->attrs);
670 show_ldap_error($ldap->get_error());
672 /* Optionally execute a command after we're done */
673 $this->handle_post_events("remove");
674 }
677 /* Save data to object */
678 function save_object()
679 {
680 /* Get all Posted vars
681 * Setup checkboxes
682 */
686 if(isset($_POST['iamposted'])){
687 if(isset($_POST['useProfile'])){
688 $this->useProfile = true;
689 }else{
690 $this->useProfile = false;
691 }
692 if(isset($_POST['gotoProfileFlag_C'])){
693 $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
694 }else{
695 $this->gotoProfileFlag_C = false;
696 }
697 if(isset($_POST['gotoProfileFlag_L'])){
698 $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
699 }else{
700 $this->gotoProfileFlag_L = false;
701 }
703 plugin::save_object();
704 foreach($this->attributes as $s_attr){
705 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
706 if(isset($_POST[$s_attr])){
707 $this->$s_attr = $_POST[$s_attr];
708 }else{
709 $this->$s_attr = false;
710 }
711 }
712 }
713 }
716 /* Check supplied data */
717 function check()
718 {
719 $message= array();
721 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
722 $message[]=_("Please set a valid profile quota size.");
723 }
724 if(!isset($this->attrs['objectClass'])){
725 $this->attrs['objectClass']=array();
726 }
727 if(!$this->is_group){
728 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
729 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
730 }
731 }
732 return ($message);
733 }
736 /* Save to LDAP */
737 function save()
738 {
739 plugin::save();
740 $ldap= $this->config->get_ldap_link();
742 $realyUsedAttrs= array();
745 $path = search_config($this->config->data,"environment", "KIOSKPATH");
746 /* Creating Kiosk Profiles */
747 foreach($this->newKioskProfiles as $file){
748 $contents = $file['contents'];
749 $fp = @fopen($path."/".$file['name'],"w");
750 if(!$fp){
751 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
752 }else{
753 fwrite($fp,$contents,strlen($contents));
754 }
755 @unlink($file['tmp_name']);
756 }
758 /* Save already used objectClasses */
759 $ocs = $this->attrs['objectClass'];
760 unset($ocs['count']);
761 $this->attrs = array();
762 $this->attrs['objectClass']= $ocs;
763 foreach($this->objectclasses as $objc){
764 if(!in_array($objc,$this->attrs['objectClass'])){
765 $this->attrs['objectClass'][]=$objc;
766 }
767 }
770 /* Save usersettings to Printer */
772 if(chkacl($this->acl,"gotoPrinter")!=""){
773 $this->gotoPrinter = array();
774 }
776 if($this->is_group){
777 $s_suffix = "Group";
778 }else{
779 $s_suffix = "User";
780 }
783 /* 1. Search all printers that have our uid/cn as member
784 * 2. Delete this uid/cn from every single entry and save it again.
785 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
786 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
787 */
788 $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
789 while($attr = $ldap->fetch()){
791 /* Walk trough all printers and check if our user id used, if so remove it.
792 * Later we will insert our uid at the right place.
793 */
795 /* Remove normal entries (User)*/
796 if(isset($attr['goto'.$s_suffix.'Printer'])) {
797 foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
798 if($this->uid==$user){
799 unset($attr['goto'.$s_suffix.'Printer'][$key]);
800 }
801 }
802 }
804 /* Remove administrational entries (Admin)*/
805 if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
806 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
807 if($this->uid==$user){
808 unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
809 }
810 }
811 }
813 /* Extract useable tags, to be able to save all changes
814 */
815 $attrs_used = array();
816 foreach($attr as $key=>$val){
818 /* If index is numeric, skip it ...*/
819 if((!is_numeric($key))&&($key!="count")){
821 /* If entry contains 'count' remove it */
822 if(is_array($val)&&isset($val['count'])){
823 unset($val['count']);
824 }
825 $attrs_used[$key]=$val;
826 }
827 }
828 /* the result of cleaning the entry is
829 * to be able to directly save this again,
830 * if all changes are made
831 */
832 $attr= $attrs_used;
834 #fix : Id don't know why such an entry was set ...
835 if(isset($attr['GOTOADMINPRINTER'])){
836 unset($attr['GOTOADMINPRINTER']);
837 }
839 /* Save changes */
840 $ldap->cd($attr['dn']);
841 unset($attr['dn']);
842 $ldap->modify($attr);
843 if($ldap->get_error()!="Success"){
844 print_red(_("Error while writing printer")." : ".$ldap->get_error());
845 }
846 }
848 /* All printers are cleaned, (our cn/uid removed)
849 * now we must add our uid / cn
850 * to the new configured printers.
851 */
852 foreach($this->gotoPrinter as $printer) {
853 $ldap->cd($printer['dn']);
854 $ldap->cat($printer['dn']);
855 $attrs= $ldap->fetch();
856 $attrs_used = array();
857 foreach($attrs as $key=>$val){
858 if((!is_numeric($key))&&($key!="count")){
859 if(is_array($val)&&isset($val['count'])){
860 unset($val['count']);
861 }
862 $attrs_used[$key]=$val;
863 }
864 }
865 /* $attrs contains all values
866 * we need, to save the entry lateron
867 */
868 $attrs= $attrs_used;
870 /* Depending on the type (User/Admin)
871 * switch these attributes, that makes it easier
872 */
873 if($printer['mode'] == "user"){
874 $attribute = "goto".$s_suffix."Printer";
875 $attribute2 = "goto".$s_suffix."AdminPrinter";
876 }else{
877 $attribute = "goto".$s_suffix."AdminPrinter";
878 $attribute2 = "goto".$s_suffix."Printer";
879 }
881 /* If this user is already assigned to $attribute2
882 * delete user from $attribute2, to be albe to attach him to $attribute
883 * A user can't be admin and normal user for one printer
884 */
885 if(!isset($printer[$attribute2])){
886 $printer[$attribute2]=array();
887 }else{
888 if(in_array($this->uid,$printer[$attribute2])){
889 $tmp = array_flip($printer[$attribute2]);
890 unset($tmp[$this->uid]);
891 $attrs[$attribute2]=array_flip($tmp);
892 }
893 /* If Last entry removed, clear attribute*/
894 if(empty($attrs[$attribute2])){
895 $attrs[$attribute2]=array();
896 }
897 }
899 /* Attach user to the $attribute, if he is'nt already attached
900 */
901 if(!isset($attrs[$attribute])){
902 $attrs[$attribute]=array($this->uid);
903 }else{
904 unset($attrs[$attribute]['count']);
905 if(!in_array($this->uid,$attrs[$attribute])){
906 $attrs[$attribute][]=$this->uid;
907 }
908 }
910 $ldap->cd($attrs['dn']);
911 unset($attrs['dn']);
912 $ldap->modify($attrs);
913 if($ldap->get_error()!="Success"){
914 print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
915 }
916 }
918 /* Prepare HotPlug devices */
919 $this->attrs['gotoHotplugDevice'] = array();
920 foreach($this->gotoHotplugDevices as $name => $device){
921 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
922 }
924 /* Prepare LogonScripts */
925 $this->attrs['gotoLogonScript'] = array();
926 foreach($this->gotoLogonScripts as $name => $script){
927 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
928 $script['LogonOverload'].$script['LogonLast']."|".
929 $script['LogonPriority']."|".
930 base64_encode($script['LogonData'])."|".
931 $script['LogonDescription'];
932 }
934 /* Prepare Shares */
935 $this->attrs['gotoShare']=array();
936 foreach($this->gotoShares as $name => $share){
937 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint']."|".$share['OtherStuff'];
938 }
940 if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
941 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
942 $method="https://";
943 }else{
944 $method="http://";
945 }
947 $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
948 $this->attrs['gotoKioskProfile']= $str.$this->gotoKioskProfile;
949 }else{
950 $this->attrs['gotoKioskProfile']= array();
951 }
953 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer");
955 foreach($saveThis as $tosave){
956 if(!empty($this->$tosave)){
957 $this->attrs[$tosave]=$this->$tosave;
958 }else{
959 $this->attrs[$tosave]=array();
960 }
961 }
963 /* Prepare Flags */
964 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
965 if(empty($this->attrs['gotoProfileFlags'][0])){
966 $this->attrs['gotoProfileFlags']=array();
967 }
969 if($this->useProfile == false){
970 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
971 $this->attrs['gotoProfileServer']= array();
972 }
974 foreach($this->attributes as $s_attr){
975 if(chkacl($this->acl,$s_attr)!="") {
976 if(isset($this->attrs[$s_attr])){
977 unset($this->attrs[$s_attr]);
978 }
979 }
980 }
982 $ldap->cat ($this->dn);
983 if ($ldap->fetch()){
984 $mode= "modify";
985 } else {
986 $mode= "add";
987 $ldap->cd($this->config->current['BASE']);
988 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
989 }
991 $ldap->cd($this->dn);
992 $ldap->$mode($this->attrs);
993 if($ldap->get_error()!="Success"){
994 print_red($ldap->get_error());
995 }
996 $this->handle_post_events($mode);
997 }
999 /* Generate ListBox frindly output for the defined shares
1000 * Possibly Add or remove an attribute here,
1001 */
1002 function printOutAssignedShares()
1003 {
1004 $a_return = array();
1005 if(is_array($this->gotoShares)){
1006 foreach($this->gotoShares as $share){
1007 if (!preg_match('/^!/', $share['server'])){
1008 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint'];
1009 }
1010 }
1011 }
1012 return($a_return);
1013 }
1015 /* Generate ListBox frindly output for the definedhotplugs
1016 * Possibly Add or remove an attribute here,
1017 */
1018 function printOutHotPlugDevices()
1019 {
1020 $a_return= array();
1021 if(is_array($this->gotoHotplugDevices)){
1022 foreach($this->gotoHotplugDevices as $key=>$device){
1023 $a_return[$key] = $device['name']." - ".$device['id'];
1024 }
1025 }
1026 return($a_return);
1027 }
1029 /* Generates ListBox frienly output of used printer devices
1030 * Append ' - admin' if printer is used in admin mode
1031 */
1032 function printOutPrinterDevices()
1033 {
1034 $a_return = array();
1035 if(is_array($this->gotoPrinter)){
1036 foreach($this->gotoPrinter as $printer){
1037 if($printer['mode'] == "admin"){
1038 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
1039 }else{
1040 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1041 }
1042 }
1043 }
1044 return($a_return);
1045 }
1047 /* Generates ListBox frienly output of used logonscripts
1048 */
1049 function printOutLogonScripts()
1050 {
1051 $a_return = array();
1052 if(is_array($this->gotoLogonScripts)){
1053 foreach($this->gotoLogonScripts as $script){
1054 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1055 }
1056 }
1057 return($a_return);
1058 }
1059 }
1064 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1065 ?>