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 $gotoPrinters = array();// All available Printer
42 var $gotoPrinter = ""; // The selected Printer
44 /* Share */
45 var $gotoShares = array();// Currently Share Option
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","useProfile","gotoProfileServer","gotoProfileServers","gotoProfileFlags","gotoProfileFlag_C",
63 "gotoXResolution","gotoXResolutions","gotoProfileFlag_L","gotoProfileQuota",
64 "gotoLogonScripts","gotoLogonScript",
65 "gotoPrinters","gotoPrinter",
66 "gotoShares","gotoShare","gotoShareSelections",
67 "gotoKioskProfile","gotoKioskProfiles",
68 "gotoHotplugDevice","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);
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->gotoPrinters[$printer['cn'][0]]=$printer;
92 $this->gotoPrinters[$printer['cn'][0]]['mode']="user";
93 }
94 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
95 while($printer = $ldap->fetch()){
96 $this->gotoPrinters[$printer['cn'][0]]=$printer;
97 $this->gotoPrinters[$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 /* Fill templating stuff */
176 $smarty= get_smarty();
177 $display= "";
178 /* Is accout enabled | are we editing from usermenu or admin menu
179 All these tab management is done here
180 */
182 /* Working from Usermenu an the Account is currently disbled
183 * this->parent : is only set if we are working in a list of tabs
184 * is_account : is only true if the needed objectClass is given
185 */
186 if((!isset($this->parent))&&(!$this->is_account)){
187 /* We are currently editing this tab from usermenu, but this account is not enabled */
188 $smarty->assign("is_account",$this->is_account);
189 /* Load template */
190 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
191 /* Avoid the "You are currently editing ...." message when you leave this tab */
192 $display .= back_to_main();
193 /* Display our message to the user */
194 return $display;
197 /* We are currently editing from group tabs, because
198 * $this->parent is set
199 * posixAccount is not set, so we are not in usertabs.
200 */
201 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
202 $smarty->assign("is_account","true");
203 $this->is_group = true;
204 $this->uid = $this->cn;
205 $this->attrs['uid'] = $this->cn;
207 /* Change state if needed */
208 if (isset($_POST['modify_state'])){
209 $this->is_account= !$this->is_account;
210 }
212 /* Group Dialog with enabled environment options */
213 if ($this->is_account){
214 $display= $this->show_header(_("Remove environment extension"),
215 _("Environment extension enabled. You can disable it by clicking below."));
216 } else {
218 /* Environment is disabled
219 If theres is no posixAccount enabled, you won't be able to enable
220 environment extensions
221 */
222 if((isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
223 // 4. There is a PosixAccount
224 $display= $this->show_header(_("Add environment extension"),
225 _("Environment extension disabled. You can enable it by clicking below."));
226 return $display;
227 }else{
228 // 4. There is no PosixAccount
229 $display= $this->show_header(_("Add environment extension"),
230 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
231 return $display;
232 }
233 }
234 }else{
235 /* Editing from Usermenu
236 * Tell smarty that this accoutn is enabled
237 */
238 $smarty->assign("is_account","true");
240 /* Do we need to flip is_account state? */
241 if (isset($_POST['modify_state'])){
242 $this->is_account= !$this->is_account;
243 }
245 if(isset($this->parent)){
246 // 3. Account enabled . Editing from adminmenu
247 if ($this->is_account){
248 $display= $this->show_header(_("Remove environment extension"),
249 _("Environment extension enabled. You can disable it by clicking below."));
250 } else {
251 if((isset($this->attrs['objectClass']))
252 &&((in_array("posixAccount",$this->attrs['objectClass'])))
253 ||($this->parent->by_object['posixAccount']->is_account==true)){
254 // 4. There is a PosixAccount
255 $display= $this->show_header(_("Add environment extension"),
256 _("Environment extension disabled. You can enable it by clicking below."));
257 return $display;
258 }else{
259 // 4. There is a PosixAccount
260 $display= $this->show_header(_("Add environment extension"),
261 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
262 return $display;
263 }
264 }
265 }
266 }
267 /* Account is Account : is_accounbt=true.
268 * Else we won't reach this.
269 */
271 /* Prepare all variables for smarty */
272 foreach($this->attributes as $s_attr){
273 /* Set value*/
274 $smarty->assign($s_attr,$this->$s_attr);
276 /* Set checkbox state*/
277 if(empty($this->$s_attr)){
278 $smarty->assign($s_attr."CHK","");
279 }else{
280 $smarty->assign($s_attr."CHK"," checked ");
281 }
283 /* Prepare ACL settings*/
284 if(chkacl($this->acl,$s_attr)=="") {
285 $smarty->assign($s_attr."ACL","");
286 }else{
287 $smarty->assign($s_attr."ACL"," disabled ");
288 }
290 }
292 if($this->acl != "#none#"){
293 $smarty->assign("useProfileACL","");
294 }else{
295 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
296 $smarty->assign("gotoProfileServer"," disabled ");
297 }
299 /* HANDLE Profile Settings here
300 * Assign available Quota and resolution settings
301 * Get all available profile server
302 * Get cache checkbox
303 * Assign this all to Smarty
304 */
306 if(empty($this->useProfile)){
307 $smarty->assign("gotoProfileACL","disabled");
308 $smarty->assign("useProfileCHK","");
309 }else{
310 $smarty->assign("gotoProfileACL","");
311 $smarty->assign("useProfileCHK"," checked ");
312 }
314 $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
316 $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
317 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
318 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
320 /* Handle kiosk profiles
321 * Read available from filesystem
322 * Open management if post is transmitted
323 */
325 /* Open Management Dialog */
326 if(isset($_POST['KioskManagementDialog'])){
327 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
328 $this->dialog->parent= $this;
329 $this->is_dialog = true;
330 }
332 /* Save */
333 if(isset($_POST['KioskClose'])){
334 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
336 unset($this->dialog);
337 $this->dialog=NULL;
338 $this->is_dialog = false;
339 }
340 $tmp = new kioskManagementDialog($this->config,$this->dn);
341 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
343 $smarty->assign("gotoKioskProfiles",$list);
344 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
346 /* Logonscript Management
347 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
348 * Perform add Delete edit Posts
349 */
351 /* Dialog Save */
352 if(isset($_POST['LogonSave'])){
353 $this->dialog->save_object();
354 if(count($this->dialog->check())!=0){
355 foreach($this->dialog->check() as $msg){
356 print_red($msg);
357 }
358 }else{
359 $tmp = $this->dialog->save();
360 unset($this->dialog);
361 $this->dialog=NULL;
362 $this->is_dialog=false;
363 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
364 }
365 }
367 /* Dialog Quit without saving */
368 if(isset($_POST['LogonCancel'])){
369 $this->is_dialog= false;
370 unset($this->dialog);
371 $this->dialog= NULL;
372 }
374 /* Check Edit Del New Posts for a selected LogonScript */
375 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
377 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
378 * In this case we create a new Logon Script.
379 */
380 if(isset($_POST['gotoLogonScriptNew'])){
381 $this->is_dialog = true;
382 $this->dialog = new logonManagementDialog($this->config,$this->dn);
383 }
385 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
386 * We only can delete if there is an entry selected.
387 */
388 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
389 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
390 }
392 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
393 * There must be an entry selected to perform edit request.
394 */
395 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
396 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
397 $this->is_dialog = true;
398 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
399 }
400 }
402 /* Append List to smarty*/
403 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
404 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
406 /* In this section server shares will be defined
407 * A user can select one of the given shares and a mount point
408 * and attach this combination to his setup.
409 */
411 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
412 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
414 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
415 * This entry will be, a combination of mountPoint and sharedefinitions
416 */
417 if(isset($_POST['gotoShareAdd'])){
418 /* We assign a share to this user, if we don't know where to mount the share */
419 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
420 print_red(_("You must specify a valid mount point."));
421 }else{
422 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
423 $s_mount = $_POST['gotoShareMountPoint'];
424 /* Preparing the new assignment */
425 $this->gotoShares[$a_share['name']]=$a_share;
426 $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
427 }
428 }
430 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
431 * If there is no defined share selected, we will abort the deletion without any message
432 */
433 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
434 unset($this->gotoShares[$_POST['gotoShare']]);
435 }
437 $smarty->assign("gotoShares",$this->printOutAssignedShares());
438 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
440 /* Hotplug devices will be handled here
441 * There are 3 possible methods for this feature
442 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
443 * Delete will erase an entry, the entry must be selcted in the ListBox first
444 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
445 */
447 /* If there is a new entry wanted, open a new entry by initilising the dialog */
448 if(isset($_POST['gotoHotplugDeviceNew'])){
449 $this->dialog = new hotplugDialog($this->config,$this->dn);
450 $this->is_dialog = true;
451 }
453 /* We have to delete the selected hotplug from the list*/
454 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
455 unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
456 }
458 /* There are already defined hotplugs from other users we could use */
459 if(isset($_POST['gotoHotplugDeviceUse'])){
460 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
461 $this->is_dialog = true;
462 }
464 /* Dialog Aborted */
465 if(isset($_POST['HotPlugCancel'])){
466 unset($this->dialog);
467 $this->dialog= NULL;
468 $this->is_dialog = false;
469 }
471 /* Dialod saved */
472 if(isset($_POST['HotPlugSave'])){
473 $this->dialog->save_object();
474 if(count($this->dialog->check())!=0){
475 foreach($this->dialog->check() as $msg){
476 print_red($msg);
477 }
478 }else{
479 $this->dialog->save_object();
480 $a_tmp = $this->dialog->save();
481 if(is_array($a_tmp)){
482 $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp;
483 }
484 unset($this->dialog);
485 $this->dialog= NULL;
486 $this->is_dialog = false;
487 }
488 }
490 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
491 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
493 /* Printer Assignment will managed below
494 * A printer can be assigned in two different ways and two different types
495 * There are 2 types of users assigned to a printer : user and admin
496 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
497 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
498 */
500 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
501 if(isset($_POST['gotoPrinterAdd'])){
502 $this->is_dialog=true;
503 $this->dialog = new selectPrinterDialog($this->config,$this->dn);
504 }
506 if(isset($_POST['PrinterCancel'])){
507 $this->is_dialog=false;
508 unset($this->dialog);
509 $this->dialog=NULL;
510 }
512 if(isset($_POST['PrinterSave'])){
513 if(count($this->dialog->check())!=0){
514 $tmp = $this->dialog->check();
515 foreach($tmp as $msg){
516 print_red($msg);
517 }
518 }else{
519 $this->dialog->save_object();
520 $tmp = $this->dialog->save();
521 $tmp2= $this->dialog->getPrinter(true);
522 $this->gotoPrinters[$tmp]=$tmp2[$tmp];
523 $this->gotoPrinters[$tmp]['mode']="user";
524 $this->is_dialog=false;
525 unset($this->dialog);
526 $this->dialog =NULL;
527 }
528 }
530 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
531 $printer = $_POST['gotoPrinter'];
532 unset($this->gotoPrinters[$printer]);
533 }
535 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
536 $printer = $_POST['gotoPrinter'];
537 if($this->gotoPrinters[$printer]['mode']=="user"){
538 $this->gotoPrinters[$printer]['mode']="admin";
539 }else{
540 $this->gotoPrinters[$printer]['mode']="user";
541 }
542 }
544 $smarty->assign("gotoPrinters",$this->printOutPrinterDevices());
545 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
547 /* General behavior */
548 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
549 $this->dialog->save_object();
550 return ($this->dialog->execute());
551 }
552 if($this->acl != "#none#"){
553 $smarty->assign("useProfileACL","");
554 }else{
555 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
556 $smarty->assign("gotoProfileServerACL"," disabled ");
557 }
559 if(!$this->useProfile){
560 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
561 $smarty->assign("gotoProfileServerACL"," disabled ");
562 }
564 /* Als smarty vars are set. Get smarty template and generate output */
565 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
567 return($display);
568 }
570 function remove_from_parent()
571 {
572 /* only if it was an account*/
573 if (!$this->initially_was_account){
574 return;
575 }
577 /* include global link_info */
578 $ldap= $this->config->get_ldap_link();
580 /* Remove and write to LDAP */
581 plugin::remove_from_parent();
583 /* Don't save our template variables */
584 $skip = array("useProfile","uid","gotoProfileServers","gotoProfileFlag_C","gotoXResolutions","gotoProfileFlag_L",
585 "gotoLogonScripts","gotoPrinters","gotoShares","gotoShareSelections","gotoKioskProfiles","gotoHotplugDevices",
586 "gotoPrinter");
587 /* Skip all these attributes */
588 foreach($skip as $del){
589 unset($this->attrs[$del]);
590 }
592 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
594 $ldap->cd($this->dn);
595 $ldap->modify($this->attrs);
597 show_ldap_error($ldap->get_error());
599 /* Optionally execute a command after we're done */
600 $this->handle_post_events("remove");
601 }
604 /* Save data to object */
605 function save_object()
606 {
607 /* Get all Posted vars
608 * Setup checkboxes
609 */
611 if(isset($_POST['iamposted'])){
612 plugin::save_object();
613 foreach($this->attributes as $s_attr){
614 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinters","gotoLogonScripts","uid"))) continue;
615 if(isset($_POST[$s_attr])){
616 $this->$s_attr = $_POST[$s_attr];
617 }else{
618 $this->$s_attr = false;
619 }
620 }
621 }
622 }
625 /* Check supplied data */
626 function check()
627 {
628 $message= array();
630 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
631 $message[]=_("Please set a valid profile quota size.");
632 }
633 if(!isset($this->attrs['objectClass'])){
634 $this->attrs['objectClass']=array();
635 }
636 if(!$this->is_group){
637 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
638 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
639 }
640 }
641 return ($message);
642 }
645 /* Save to LDAP */
646 function save()
647 {
648 plugin::save();
649 $ldap= $this->config->get_ldap_link();
651 $realyUsedAttrs= array();
654 $path = search_config($this->config->data,"environment", "KIOSKPATH");
655 /* Creating Kiosk Profiles */
656 foreach($this->newKioskProfiles as $file){
657 $contents = $file['contents'];
658 $fp = @fopen($path."/".$file['name'],"w");
659 if(!$fp){
660 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
661 }else{
662 fwrite($fp,$contents,strlen($contents));
663 }
664 @unlink($file['tmp_name']);
665 }
667 /* Save already used objectClasses */
668 $ocs = $this->attrs['objectClass'];
669 unset($ocs['count']);
670 $this->attrs = array();
671 $this->attrs['objectClass']= $ocs;
672 foreach($this->objectclasses as $objc){
673 if(!in_array($objc,$this->attrs['objectClass'])){
674 $this->attrs['objectClass'][]=$objc;
675 }
676 }
679 /* Save usersettings to Printer */
681 if(chkacl($this->acl,"gotoPrinter")!=""){
682 $this->gotoPrinters = array();
683 }
685 if($this->is_group){
686 $s_suffix = "Group";
687 }else{
688 $s_suffix = "User";
689 }
692 if(count($this->gotoPrinters)==0){
693 $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
694 while($attr = $ldap->fetch()){
696 foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
697 if($this->uid==$user){
698 unset($attr['goto'.$s_suffix.'Printer'][$key]);
699 }
700 }
702 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
703 if($this->uid==$user){
704 unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
705 }
706 }
708 $attrs_used = array();
709 foreach($attr as $key=>$val){
710 if((!is_numeric($key))&&($key!="count")){
711 if(is_array($val)&&isset($val['count'])){
712 unset($val['count']);
713 }
714 $attrs_used[$key]=$val;
715 }
716 }
717 $attr= $attrs_used;
718 $tmp =array();
719 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $print){
720 $tmp[]=$print;
721 }
722 $attr['goto'.$s_suffix.'AdminPrinter'] = $tmp;
724 $tmp =array();
725 foreach($attr['goto'.$s_suffix.'Printer'] as $print){
726 $tmp[]=$print;
727 }
728 $attr['goto'.$s_suffix.'Printer'] = $tmp;
730 $ldap->cd($attr['dn']);
731 unset($attr['dn']);
732 $ldap->modify($attr);
733 if($ldap->get_error()!="Success"){
734 print_red(_("Error while writing printer")." : ".$ldap->get_error());
735 }
736 }
737 }
739 foreach($this->gotoPrinters as $printer) {
740 $ldap->cd($printer['dn']);
741 $ldap->cat($printer['dn']);
742 $attrs= $ldap->fetch();
743 $attrs_used = array();
744 foreach($attrs as $key=>$val){
745 if((!is_numeric($key))&&($key!="count")){
746 if(is_array($val)&&isset($val['count'])){
747 unset($val['count']);
748 }
749 $attrs_used[$key]=$val;
750 }
751 }
752 $attrs= $attrs_used;
754 /* Filter entries */
756 if($printer['mode'] == "user"){
757 $attribute = "goto".$s_suffix."Printer";
758 $attribute2 = "goto".$s_suffix."AdminPrinter";
759 }else{
760 $attribute = "goto".$s_suffix."AdminPrinter";
761 $attribute2 = "goto".$s_suffix."UserPrinter";
762 }
764 /* If this user is already assigned to $attribute2
765 * delete user from $attribute2, to be albe to attach him to $attribute
766 * A user can't be admin and normal user for one printer
767 */
768 if(!isset($printer[$attribute2])){
769 $printer[$attribute2]=array();
770 }else{
771 if(in_array($this->uid,$printer[$attribute2])){
772 $tmp = array_flip($attrs[$attribute2]);
773 unset($tmp[$this->uid]);
774 $attrs[$attribute2]=array_flip($tmp);
775 }
776 /* If Last entry removed, clear attribute*/
777 if(empty($attrs[$attribute2])){
778 $attrs[$attribute2]=array();
779 }
780 }
782 /* Attach user to the $attribute, if he is'nt already attached
783 */
784 if(!isset($attrs[$attribute])){
785 $attrs[$attribute]=array($this->uid);
786 }else{
787 unset($attrs[$attribute]['count']);
788 if(!in_array($this->uid,$attrs[$attribute])){
789 $attrs[$attribute][]=$this->uid;
790 }
791 }
793 $tmp =array();
794 if(isset($attrs['goto'.$s_suffix.'AdminPrinter'])){
795 foreach($attrs['goto'.$s_suffix.'AdminPrinter'] as $print){
796 $tmp[]=$print;
797 }
798 }
799 $attrs['goto'.$s_suffix.'AdminPrinter'] = $tmp;
801 $tmp =array();
802 if(isset($attrs['goto'.$s_suffix.'Printer'])){
803 foreach($attrs['goto'.$s_suffix.'Printer'] as $print){
804 $tmp[]=$print;
805 }
806 }
807 $attrs['goto'.$s_suffix.'Printer'] = $tmp;
809 $ldap->cd($attrs['dn']);
810 unset($attrs['dn']);
811 $ldap->modify($attrs);
812 if($ldap->get_error()!="Success"){
813 print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
814 }
815 }
817 if(isset($this->attrs['gotoPrinter'])){
818 unset($this->attrs['gotoPrinter']);
819 }
821 /* Prepare HotPlug devices */
822 $this->attrs['gotoHotplugDevice'] = array();
823 foreach($this->gotoHotplugDevices as $name => $device){
824 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
825 }
827 /* Prepare LogonScripts */
828 $this->attrs['gotoLogonScript'] = array();
829 foreach($this->gotoLogonScripts as $name => $script){
830 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
831 $script['LogonOverload'].$script['LogonLast']."|".
832 $script['LogonPriority']."|".
833 base64_encode($script['LogonData'])."|".
834 $script['LogonDescription'];
835 }
837 /* Prepare Shares */
838 $this->attrs['gotoShare']=array();
839 foreach($this->gotoShares as $name => $share){
840 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint'];
841 }
843 if(!empty($this->gotoKioskProfile)){
844 $this->attrs['gotoKioskProfile']= $this->gotoKioskProfile;
845 }else{
846 $this->attrs['gotoKioskProfile']= array();
847 }
849 $saveThis = array("gotoKioskProfile","gotoProfileQuota","gotoXResolution","gotoProfileServer");
851 foreach($saveThis as $tosave){
852 if(!empty($this->$tosave)){
853 $this->attrs[$tosave]=$this->$tosave;
854 }else{
855 $this->attrs[$tosave]=array();
856 }
857 }
859 /* Prepare Flags */
860 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
861 if(empty($this->attrs['gotoProfileFlags'][0])){
862 $this->attrs['gotoProfileFlags']=array();
863 }
865 if($this->useProfile == false){
866 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
867 $this->attrs['gotoProfileServer']= array();
868 }
870 foreach($this->attributes as $s_attr){
871 if(chkacl($this->acl,$s_attr)!="") {
872 if(isset($this->attrs[$s_attr])){
873 unset($this->attrs[$s_attr]);
874 }
875 }
876 }
878 $ldap->cat ($this->dn);
879 if ($ldap->fetch()){
880 $mode= "modify";
881 } else {
882 $mode= "add";
883 $ldap->cd($this->config->current['BASE']);
884 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
885 }
887 $ldap->cd($this->dn);
888 $ldap->$mode($this->attrs);
889 if($ldap->get_error()!="Success"){
890 print_red($ldap->get_error());
891 }
892 $this->handle_post_events($mode);
893 }
895 /* Generate ListBox frindly output for the defined shares
896 * Possibly Add or remove an attribute here,
897 */
898 function printOutAssignedShares()
899 {
900 $a_return = array();
901 if(is_array($this->gotoShares)){
902 foreach($this->gotoShares as $share){
903 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
904 }
905 }
906 return($a_return);
907 }
909 /* Generate ListBox frindly output for the definedhotplugs
910 * Possibly Add or remove an attribute here,
911 */
912 function printOutHotPlugDevices()
913 {
914 $a_return= array();
915 if(is_array($this->gotoHotplugDevices)){
916 foreach($this->gotoHotplugDevices as $key=>$device){
917 $a_return[$key] = $device['name']." - ".$device['id'];
918 }
919 }
920 return($a_return);
921 }
923 /* Generates ListBox frienly output of used printer devices
924 * Append ' - admin' if printer is used in admin mode
925 */
926 function printOutPrinterDevices()
927 {
928 $a_return = array();
929 if(is_array($this->gotoPrinters)){
930 foreach($this->gotoPrinters as $printer){
931 if($printer['mode'] == "admin"){
932 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
933 }else{
934 $a_return[$printer['cn'][0]]= $printer['cn'][0];
935 }
936 }
937 }
938 return($a_return);
939 }
941 /* Generates ListBox frienly output of used logonscripts
942 */
943 function printOutLogonScripts()
944 {
945 $a_return = array();
946 if(is_array($this->gotoLogonScripts)){
947 foreach($this->gotoLogonScripts as $script){
948 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
949 }
950 }
951 return($a_return);
952 }
953 }
958 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
959 ?>