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