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 = ""; // The selected Kiosk Profile
52 var $gotoKioskProfiles = array();// All available Kiosk profiles
53 VAR $newKioskProfiles = array();
55 /* Hotplug Devices */
56 var $gotoHotplugDevice = ""; // Selected hotplug
57 var $gotoHotplugDevices = array();// Already configured hotplug devices
60 /* general settings */
61 // Sets the attributes which will kept on page reload, which will be saved, ...
62 var $attributes = array("uid","gotoProfileServer","gotoProfileFlags",
63 "gotoXResolution","gotoProfileQuota",
64 "gotoLogonScripts","gotoLogonScript",
65 "gotoPrinter",
66 "gotoShares","gotoShare",
67 "gotoKioskProfile","gotoKioskProfiles",
68 "gotoHotplugDevices");
69 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
70 var $cn;
72 function environment ($config, $dn= NULL)
73 {
74 plugin::plugin ($config, $dn);
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 $smarty->assign("useProfileACL","");
335 if($this->acl != "#none#"){
336 $smarty->assign("useProfileACL","");
337 }else{
338 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
339 $smarty->assign("gotoProfileServer"," disabled ");
340 }
342 /* HANDLE Profile Settings here
343 * Assign available Quota and resolution settings
344 * Get all available profile server
345 * Get cache checkbox
346 * Assign this all to Smarty
347 */
349 if(empty($this->gotoProfileFlag_L)){
350 $smarty->assign("gotoProfileFlag_LCHK"," ");
351 }else{
352 $smarty->assign("gotoProfileFlag_LCHK"," checked ");
353 }
355 if(empty($this->gotoProfileFlag_C)){
356 $smarty->assign("gotoProfileFlag_CCHK"," ");
357 }else{
358 $smarty->assign("gotoProfileFlag_CCHK"," checked ");
359 }
361 if(empty($this->useProfile)){
362 $smarty->assign("gotoProfileACL","disabled");
363 $smarty->assign("useProfileCHK","");
364 }else{
365 $smarty->assign("gotoProfileACL","");
366 $smarty->assign("useProfileCHK"," checked ");
367 }
369 $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
371 $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
372 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
373 if(!is_array($this->gotoProfileServers)){
374 $this->gotoProfileServers =array();
375 }
376 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
378 /* Handle kiosk profiles
379 * Read available from filesystem
380 * Open management if post is transmitted
381 */
383 /* Save */
384 if(isset($_POST['KioskClose'])){
385 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
387 unset($this->dialog);
388 $this->dialog=NULL;
389 $this->is_dialog = false;
390 }
391 $tmp = new kioskManagementDialog($this->config,$this->dn);
392 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
394 /* Reassign help class */
395 $_SESSION['current_class_for_help'] = get_class($this);
397 /* Open Management Dialog */
398 if(isset($_POST['KioskManagementDialog'])){
399 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
400 $this->dialog->parent= $this;
401 $this->is_dialog = true;
402 }
404 $smarty->assign("gotoKioskProfiles",$list);
405 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
407 /* Logonscript Management
408 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
409 * Perform add Delete edit Posts
410 */
412 /* Dialog Save */
413 if(isset($_POST['LogonSave'])){
414 $this->dialog->save_object();
415 if(count($this->dialog->check())!=0){
416 foreach($this->dialog->check() as $msg){
417 print_red($msg);
418 }
419 }else{
420 $tmp = $this->dialog->save();
421 unset($this->dialog);
422 $this->dialog=NULL;
423 $this->is_dialog=false;
424 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
425 }
426 }
428 /* Dialog Quit without saving */
429 if(isset($_POST['LogonCancel'])){
430 $this->is_dialog= false;
431 unset($this->dialog);
432 $this->dialog= NULL;
433 }
435 /* Check Edit Del New Posts for a selected LogonScript */
436 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
438 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
439 * In this case we create a new Logon Script.
440 */
441 if(isset($_POST['gotoLogonScriptNew'])){
442 $this->is_dialog = true;
443 $this->dialog = new logonManagementDialog($this->config,$this->dn);
444 }
446 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
447 * We only can delete if there is an entry selected.
448 */
449 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
450 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
451 }
453 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
454 * There must be an entry selected to perform edit request.
455 */
456 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
457 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
458 $this->is_dialog = true;
459 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
460 }
461 }
463 /* Append List to smarty*/
464 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
465 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
467 /* In this section server shares will be defined
468 * A user can select one of the given shares and a mount point
469 * and attach this combination to his setup.
470 */
472 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
473 if(!is_array($this->gotoShareSelections)){
474 print $this->gotoShareSelections;
475 $this->gotoShareSelections = array();
476 }
477 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
479 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
480 * This entry will be, a combination of mountPoint and sharedefinitions
481 */
482 if(isset($_POST['gotoShareAdd'])){
483 /* We assign a share to this user, if we don't know where to mount the share */
484 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
485 print_red(_("You must specify a valid mount point."));
486 }elseif($_POST['gotoShareMountPoint'][0] !="/" ){
487 print_red(_("You must specify a valid mount point."));
488 }else{
489 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
490 $s_mount = $_POST['gotoShareMountPoint'];
491 /* Preparing the new assignment */
492 $this->gotoShares[$a_share['name']]=$a_share;
493 $this->gotoShares[$a_share['name']]['OtherStuff']="";
494 $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
495 }
496 }
498 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
499 * If there is no defined share selected, we will abort the deletion without any message
500 */
501 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
502 unset($this->gotoShares[$_POST['gotoShare']]);
503 }
505 $smarty->assign("gotoShares",$this->printOutAssignedShares());
506 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
508 /* Hotplug devices will be handled here
509 * There are 3 possible methods for this feature
510 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
511 * Delete will erase an entry, the entry must be selcted in the ListBox first
512 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
513 */
515 /* If there is a new entry wanted, open a new entry by initilising the dialog */
516 if(isset($_POST['gotoHotplugDeviceNew'])){
517 $this->dialog = new hotplugDialog($this->config,$this->dn);
518 $this->is_dialog = true;
519 }
521 /* We have to delete the selected hotplug from the list*/
522 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
523 unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
524 }
526 /* There are already defined hotplugs from other users we could use */
527 if(isset($_POST['gotoHotplugDeviceUse'])){
528 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
529 $this->is_dialog = true;
530 }
532 /* Dialog Aborted */
533 if(isset($_POST['HotPlugCancel'])){
534 unset($this->dialog);
535 $this->dialog= NULL;
536 $this->is_dialog = false;
537 }
539 /* Dialod saved */
540 if(isset($_POST['HotPlugSave'])){
541 $this->dialog->save_object();
542 if(count($this->dialog->check())!=0){
543 foreach($this->dialog->check() as $msg){
544 print_red($msg);
545 }
546 }else{
547 $this->dialog->save_object();
548 $a_tmp = $this->dialog->save();
549 if(is_array($a_tmp)){
550 $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp;
551 }
552 unset($this->dialog);
553 $this->dialog= NULL;
554 $this->is_dialog = false;
555 }
556 }
558 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
559 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
561 /* Printer Assignment will managed below
562 * A printer can be assigned in two different ways and two different types
563 * There are 2 types of users assigned to a printer : user and admin
564 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
565 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
566 */
568 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
569 if(isset($_POST['gotoPrinterAdd'])){
570 $this->is_dialog=true;
571 $this->dialog = new selectPrinterDialog($this->config,$this->dn);
572 }
574 if(isset($_POST['PrinterCancel'])){
575 $this->is_dialog=false;
576 unset($this->dialog);
577 $this->dialog=NULL;
578 }
580 if(isset($_POST['PrinterSave'])){
581 if(count($this->dialog->check())!=0){
582 $tmp = $this->dialog->check();
583 foreach($tmp as $msg){
584 print_red($msg);
585 }
586 }else{
587 $this->dialog->save_object();
588 $tmp = $this->dialog->save();
589 $tmp2= $this->dialog->getPrinter(true);
590 $this->gotoPrinter[$tmp]=$tmp2[$tmp];
591 $this->gotoPrinter[$tmp]['mode']="user";
592 $this->is_dialog=false;
593 unset($this->dialog);
594 $this->dialog =NULL;
595 }
596 }
598 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
599 $printer = $_POST['gotoPrinterSel'];
600 unset($this->gotoPrinter[$printer]);
601 }
603 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
604 $printer = $_POST['gotoPrinterSel'];
605 if($this->gotoPrinter[$printer]['mode']=="user"){
606 $this->gotoPrinter[$printer]['mode']="admin";
607 }else{
608 $this->gotoPrinter[$printer]['mode']="user";
609 }
610 }
612 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
613 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
615 /* General behavior */
616 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
617 $this->dialog->save_object();
618 return ($this->dialog->execute());
619 }
620 if($this->acl != "#none#"){
621 $smarty->assign("useProfileACL","");
622 }else{
623 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
624 $smarty->assign("gotoProfileServerACL"," disabled ");
625 }
627 if(!$this->useProfile){
628 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
629 $smarty->assign("gotoProfileServerACL"," disabled ");
630 }
632 /* Als smarty vars are set. Get smarty template and generate output */
633 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
635 return($display);
636 }
638 function remove_from_parent()
639 {
640 /* only if it was an account*/
641 if (!$this->initially_was_account){
642 return;
643 }
645 /* include global link_info */
646 $ldap= $this->config->get_ldap_link();
648 /* Remove and write to LDAP */
649 plugin::remove_from_parent();
651 /* Don't save our template variables */
652 $skip = array("uid",
653 "gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
654 /* Skip all these attributes */
655 foreach($skip as $del){
656 unset($this->attrs[$del]);
657 }
659 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
661 $ldap->cd($this->dn);
662 $ldap->modify($this->attrs);
664 show_ldap_error($ldap->get_error());
666 /* Optionally execute a command after we're done */
667 $this->handle_post_events("remove");
668 }
671 /* Save data to object */
672 function save_object()
673 {
674 /* Get all Posted vars
675 * Setup checkboxes
676 */
680 if(isset($_POST['iamposted'])){
681 if(isset($_POST['useProfile'])){
682 $this->useProfile = $_POST['useProfile'];
683 }else{
684 $this->useProfile = true;
685 }
686 if(isset($_POST['gotoProfileFlag_C'])){
687 $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
688 }else{
689 $this->gotoProfileFlag_C = false;
690 }
691 if(isset($_POST['gotoProfileFlag_L'])){
692 $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
693 }else{
694 $this->gotoProfileFlag_L = false;
695 }
697 plugin::save_object();
698 foreach($this->attributes as $s_attr){
699 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
700 if(isset($_POST[$s_attr])){
701 $this->$s_attr = $_POST[$s_attr];
702 }else{
703 $this->$s_attr = false;
704 }
705 }
706 }
707 }
710 /* Check supplied data */
711 function check()
712 {
713 $message= array();
715 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
716 $message[]=_("Please set a valid profile quota size.");
717 }
718 if(!isset($this->attrs['objectClass'])){
719 $this->attrs['objectClass']=array();
720 }
721 if(!$this->is_group){
722 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
723 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
724 }
725 }
726 return ($message);
727 }
730 /* Save to LDAP */
731 function save()
732 {
733 plugin::save();
734 $ldap= $this->config->get_ldap_link();
736 $realyUsedAttrs= array();
739 $path = search_config($this->config->data,"environment", "KIOSKPATH");
740 /* Creating Kiosk Profiles */
741 foreach($this->newKioskProfiles as $file){
742 $contents = $file['contents'];
743 $fp = @fopen($path."/".$file['name'],"w");
744 if(!$fp){
745 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
746 }else{
747 fwrite($fp,$contents,strlen($contents));
748 }
749 @unlink($file['tmp_name']);
750 }
752 /* Save already used objectClasses */
753 $ocs = $this->attrs['objectClass'];
754 unset($ocs['count']);
755 $this->attrs = array();
756 $this->attrs['objectClass']= $ocs;
757 foreach($this->objectclasses as $objc){
758 if(!in_array($objc,$this->attrs['objectClass'])){
759 $this->attrs['objectClass'][]=$objc;
760 }
761 }
764 /* Save usersettings to Printer */
766 if(chkacl($this->acl,"gotoPrinter")!=""){
767 $this->gotoPrinter = array();
768 }
770 if($this->is_group){
771 $s_suffix = "Group";
772 }else{
773 $s_suffix = "User";
774 }
777 /* 1. Search all printers that have our uid/cn as member
778 * 2. Delete this uid/cn from every single entry and save it again.
779 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
780 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
781 */
782 $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
783 while($attr = $ldap->fetch()){
785 /* Walk trough all printers and check if our user id used, if so remove it.
786 * Later we will insert our uid at the right place.
787 */
789 /* Remove normal entries (User)*/
790 if(isset($attr['goto'.$s_suffix.'Printer'])) {
791 foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
792 if($this->uid==$user){
793 unset($attr['goto'.$s_suffix.'Printer'][$key]);
794 }
795 }
796 }
798 /* Remove administrational entries (Admin)*/
799 if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
800 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
801 if($this->uid==$user){
802 unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
803 }
804 }
805 }
807 /* Extract useable tags, to be able to save all changes
808 */
809 $attrs_used = array();
810 foreach($attr as $key=>$val){
812 /* If index is numeric, skip it ...*/
813 if((!is_numeric($key))&&($key!="count")){
815 /* If entry contains 'count' remove it */
816 if(is_array($val)&&isset($val['count'])){
817 unset($val['count']);
818 }
819 $attrs_used[$key]=$val;
820 }
821 }
822 /* the result of cleaning the entry is
823 * to be able to directly save this again,
824 * if all changes are made
825 */
826 $attr= $attrs_used;
828 #fix : Id don't know why such an entry was set ...
829 if(isset($attr['GOTOADMINPRINTER'])){
830 unset($attr['GOTOADMINPRINTER']);
831 }
833 /* Save changes */
834 $ldap->cd($attr['dn']);
835 unset($attr['dn']);
836 $ldap->modify($attr);
837 if($ldap->get_error()!="Success"){
838 print_red(_("Error while writing printer")." : ".$ldap->get_error());
839 }
840 }
842 /* All printers are cleaned, (our cn/uid removed)
843 * now we must add our uid / cn
844 * to the new configured printers.
845 */
846 foreach($this->gotoPrinter as $printer) {
847 $ldap->cd($printer['dn']);
848 $ldap->cat($printer['dn']);
849 $attrs= $ldap->fetch();
850 $attrs_used = array();
851 foreach($attrs as $key=>$val){
852 if((!is_numeric($key))&&($key!="count")){
853 if(is_array($val)&&isset($val['count'])){
854 unset($val['count']);
855 }
856 $attrs_used[$key]=$val;
857 }
858 }
859 /* $attrs contains all values
860 * we need, to save the entry lateron
861 */
862 $attrs= $attrs_used;
864 /* Depending on the type (User/Admin)
865 * switch these attributes, that makes it easier
866 */
867 if($printer['mode'] == "user"){
868 $attribute = "goto".$s_suffix."Printer";
869 $attribute2 = "goto".$s_suffix."AdminPrinter";
870 }else{
871 $attribute = "goto".$s_suffix."AdminPrinter";
872 $attribute2 = "goto".$s_suffix."Printer";
873 }
875 /* If this user is already assigned to $attribute2
876 * delete user from $attribute2, to be albe to attach him to $attribute
877 * A user can't be admin and normal user for one printer
878 */
879 if(!isset($printer[$attribute2])){
880 $printer[$attribute2]=array();
881 }else{
882 if(in_array($this->uid,$printer[$attribute2])){
883 $tmp = array_flip($printer[$attribute2]);
884 unset($tmp[$this->uid]);
885 $attrs[$attribute2]=array_flip($tmp);
886 }
887 /* If Last entry removed, clear attribute*/
888 if(empty($attrs[$attribute2])){
889 $attrs[$attribute2]=array();
890 }
891 }
893 /* Attach user to the $attribute, if he is'nt already attached
894 */
895 if(!isset($attrs[$attribute])){
896 $attrs[$attribute]=array($this->uid);
897 }else{
898 unset($attrs[$attribute]['count']);
899 if(!in_array($this->uid,$attrs[$attribute])){
900 $attrs[$attribute][]=$this->uid;
901 }
902 }
904 $ldap->cd($attrs['dn']);
905 unset($attrs['dn']);
906 $ldap->modify($attrs);
907 if($ldap->get_error()!="Success"){
908 print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
909 }
910 }
912 /* Prepare HotPlug devices */
913 $this->attrs['gotoHotplugDevice'] = array();
914 foreach($this->gotoHotplugDevices as $name => $device){
915 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
916 }
918 /* Prepare LogonScripts */
919 $this->attrs['gotoLogonScript'] = array();
920 foreach($this->gotoLogonScripts as $name => $script){
921 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
922 $script['LogonOverload'].$script['LogonLast']."|".
923 $script['LogonPriority']."|".
924 base64_encode($script['LogonData'])."|".
925 $script['LogonDescription'];
926 }
928 /* Prepare Shares */
929 $this->attrs['gotoShare']=array();
930 foreach($this->gotoShares as $name => $share){
931 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint']."|".$share['OtherStuff'];
932 }
934 if(!empty($this->gotoKioskProfile)){
935 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
936 $method="https://";
937 }else{
938 $method="http://";
939 }
941 $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
942 $this->attrs['gotoKioskProfile']= $str.$this->gotoKioskProfile;
943 }else{
944 $this->attrs['gotoKioskProfile']= array();
945 }
947 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer");
949 foreach($saveThis as $tosave){
950 if(!empty($this->$tosave)){
951 $this->attrs[$tosave]=$this->$tosave;
952 }else{
953 $this->attrs[$tosave]=array();
954 }
955 }
957 /* Prepare Flags */
958 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
959 if(empty($this->attrs['gotoProfileFlags'][0])){
960 $this->attrs['gotoProfileFlags']=array();
961 }
963 if($this->useProfile == false){
964 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
965 $this->attrs['gotoProfileServer']= array();
966 }
968 foreach($this->attributes as $s_attr){
969 if(chkacl($this->acl,$s_attr)!="") {
970 if(isset($this->attrs[$s_attr])){
971 unset($this->attrs[$s_attr]);
972 }
973 }
974 }
976 $ldap->cat ($this->dn);
977 if ($ldap->fetch()){
978 $mode= "modify";
979 } else {
980 $mode= "add";
981 $ldap->cd($this->config->current['BASE']);
982 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
983 }
985 $ldap->cd($this->dn);
986 $ldap->$mode($this->attrs);
987 if($ldap->get_error()!="Success"){
988 print_red($ldap->get_error());
989 }
990 $this->handle_post_events($mode);
991 }
993 /* Generate ListBox frindly output for the defined shares
994 * Possibly Add or remove an attribute here,
995 */
996 function printOutAssignedShares()
997 {
998 $a_return = array();
999 if(is_array($this->gotoShares)){
1000 foreach($this->gotoShares as $share){
1001 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint'];
1002 }
1003 }
1004 return($a_return);
1005 }
1007 /* Generate ListBox frindly output for the definedhotplugs
1008 * Possibly Add or remove an attribute here,
1009 */
1010 function printOutHotPlugDevices()
1011 {
1012 $a_return= array();
1013 if(is_array($this->gotoHotplugDevices)){
1014 foreach($this->gotoHotplugDevices as $key=>$device){
1015 $a_return[$key] = $device['name']." - ".$device['id'];
1016 }
1017 }
1018 return($a_return);
1019 }
1021 /* Generates ListBox frienly output of used printer devices
1022 * Append ' - admin' if printer is used in admin mode
1023 */
1024 function printOutPrinterDevices()
1025 {
1026 $a_return = array();
1027 if(is_array($this->gotoPrinter)){
1028 foreach($this->gotoPrinter as $printer){
1029 if($printer['mode'] == "admin"){
1030 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
1031 }else{
1032 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1033 }
1034 }
1035 }
1036 return($a_return);
1037 }
1039 /* Generates ListBox frienly output of used logonscripts
1040 */
1041 function printOutLogonScripts()
1042 {
1043 $a_return = array();
1044 if(is_array($this->gotoLogonScripts)){
1045 foreach($this->gotoLogonScripts as $script){
1046 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1047 }
1048 }
1049 return($a_return);
1050 }
1051 }
1056 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1057 ?>