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