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