cd023e8504603777245df01a028b5f533e5f202f
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 = "";
18 /* Attribute definition
19 */
21 /* profile management */
22 var $useProfile = false; // Specifies if we want to use a Server
23 var $gotoProfileServer = ""; // Specifies the selected profile server
24 var $gotoProfileServers = array();// Specifies all available and selectable servers
25 var $gotoProfileFlags = ""; // Flags enabled ? only used to set ACL and save
26 var $gotoProfileFlag_C = ""; // Flag is set to C if we have the profile caching fucntion enabled
28 var $gotoXResolution = ""; // The selected resolution eg: 1024x768
29 var $gotoXResolutions = array();// Contains all available resolutions for this account
30 var $gotoProfileFlag_L = ""; // Flag is set to L to enable runtime resolution change
31 var $gotoProfileQuota = ""; // User Quota Settings
33 /* Logon script section*/
34 var $gotoLogonScripts = array();// Contains all available Logon Scripts
35 var $gotoLogonScript = ""; // The selected Logon Script
37 /* Printer */
38 var $gotoPrinters = array();// All available Printer
39 var $gotoPrinter = ""; // The selected Printer
41 /* Share */
42 var $gotoShares = array();// Currently Share Option
43 var $gotoShare = ""; // currently selected Share Option
44 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
45 var $gotoAvailableShares= array();// Available Shares for this account
47 /* Kiosk profile */
48 var $gotoKioskProfile = ""; // The selected Kiosk Profile
49 var $gotoKioskProfiles = array();// All available Kiosk profiles
51 /* Hotplug Devices */
52 var $gotoHotplugDevice = ""; // Selected hotplug
53 var $gotoHotplugDevices = array();// Already configured hotplug devices
56 /* general settings */
57 // Sets the attributes which will kept on page reload, which will be saved, ...
58 var $attributes = array("uid","useProfile","gotoProfileServer","gotoProfileServers","gotoProfileFlags","gotoProfileFlag_C",
59 "gotoXResolution","gotoXResolutions","gotoProfileFlag_L","gotoProfileQuota",
60 "gotoLogonScripts","gotoLogonScript",
61 "gotoPrinters","gotoPrinter",
62 "gotoShares","gotoShare","gotoShareSelections",
63 "gotoKioskProfile","gotoKioskProfiles",
64 "gotoHotplugDevice","gotoHotplugDevices");
65 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
67 function environment ($config, $dn= NULL)
68 {
69 plugin::plugin ($config, $dn);
71 /* Get all Printer assignments */
72 $ldap = $this->config->get_ldap_link();
73 $ldap->cd($this->config->current['BASE']);
74 $ldap->search("(&(objectClass=gotoPrinter)(gotoUserPrinter=".$this->uid."))",array("*"));
75 while($printer = $ldap->fetch()){
76 $this->gotoPrinters[$printer['cn'][0]]=$printer;
77 $this->gotoPrinters[$printer['cn'][0]]['mode']="user";
78 }
79 $ldap->search("(&(objectClass=gotoPrinter)(gotoAdminPrinter=".$this->uid."))",array("*"));
80 while($printer = $ldap->fetch()){
81 $this->gotoPrinters[$printer['cn'][0]]=$printer;
82 $this->gotoPrinters[$printer['cn'][0]]['mode']="admin";
83 }
85 /* prepare hotplugs */
86 if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
87 unset($this->attrs['gotoHotplugDevice']['count']);
88 foreach($this->attrs['gotoHotplugDevice'] as $device){
89 $tmp = $tmp2 = array();
90 $tmp = split("\|",$device);
91 $tmp2['name'] = $tmp[0];
92 $tmp2['description'] = $tmp[1];
93 $tmp2['id'] = $tmp[2];
94 $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
95 }
96 }
98 /* prepare LogonScripts */
99 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
100 unset($this->attrs['gotoLogonScript']['count']);
101 foreach($this->attrs['gotoLogonScript'] as $device){
102 $tmp = $tmp2 = array();
103 $tmp = split("\|",$device);
104 $tmp2['LogonName'] = $tmp[0];
105 $tmp2['LogonPriority'] = $tmp[2];
106 if(preg_match("/O/i",$tmp[1])){
107 $tmp2['LogonOverload'] = "O";
108 }else{
109 $tmp2['LogonOverload'] = "";
110 }
111 if(preg_match("/L/i",$tmp[1])){
112 $tmp2['LogonLast'] = "L";
113 }else{
114 $tmp2['LogonLast'] = "";
115 }
116 $tmp2['LogonData'] = base64_decode($tmp[3]);
117 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
118 }
119 }
121 /* Prepare Shares */
122 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
123 unset($this->attrs['gotoShare']['count']);
124 foreach($this->attrs['gotoShare'] as $share){
125 $tmp = $tmp2 = array();
126 $tmp = split("\|",$share);
127 $tmp2['name'] =$tmp[0];
128 $tmp2['mountPoint']=$tmp[1];
129 $this->gotoShares[$tmp[0]]=$tmp2;
130 }
131 }
133 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
134 $chr = $this->gotoProfileFlags[$i];
135 $name = "gotoProfileFlag_".$chr;
136 $this->$name=$chr;
137 }
139 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
140 $this->useProfile = true;
141 }else{
142 $this->useProfile = false;
143 }
145 }
147 function execute()
148 {
149 /* Fill templating stuff */
150 $smarty= get_smarty();
151 $display= "";
152 /* Is accout enabled | are we editing from usermenu or admin menu
153 All these tab management is done here
154 */
156 // 1. Account disabled . Editing from usermenu
157 if((!isset($this->parent))&&(!$this->is_account)){
158 /* We are currently editing this tab from usermenu, but this account is not enabled */
159 $smarty->assign("is_account",$this->is_account);
160 /* Load template */
161 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
162 /* Avoid the "You are currently editing ...." message when you leave this tab */
163 $display .= back_to_main();
164 /* Display our message to the user */
165 return $display;
167 // Account is enabled
168 }else{
169 /* Tell smarty that this accoutn is enabled */
170 $smarty->assign("is_account","true");
172 /* Do we need to flip is_account state? */
173 if (isset($_POST['modify_state'])){
174 $this->is_account= !$this->is_account;
175 }
176 if(!isset($this->parent)){
177 // 3. ? Account Enabled . Editing from usermenu
179 }else{
180 // 3. Account enabled . Editing from adminmenu
181 if ($this->is_account){
182 $display= $this->show_header(_("Remove environment extension"),
183 _("This server has environment extension enabled. You can disable it by clicking below."));
184 } else {
185 if((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)){
186 // 4. There is a PosixAccount
187 $display= $this->show_header(_("Add environment extension"),
188 _("This server has environment extension disabled. You can enable it by clicking below."));
189 return $display;
190 }else{
191 // 4. There is a PosixAccount
192 $display= $this->show_header(_("Add environment extension"),
193 _("This server has environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
194 return $display;
195 }
196 }
197 }
198 }
199 /* Account is Account : is_accounbt=true.
200 * Else we won't reach this.
201 */
203 /* Prepare all variables for smarty */
204 foreach($this->attributes as $s_attr){
205 /* Set value*/
206 $smarty->assign($s_attr,$this->$s_attr);
208 /* Set checkbox state*/
209 if(empty($this->$s_attr)){
210 $smarty->assign($s_attr."CHK","");
211 }else{
212 $smarty->assign($s_attr."CHK"," checked ");
213 }
215 /* Prepare ACL settings*/
216 if(chkacl($this->acl,$s_attr)=="") {
217 $smarty->assign($s_attr."ACL","");
218 }else{
219 $smarty->assign($s_attr."ACL"," disabled ");
220 }
222 }
224 if($this->acl != "#none#"){
225 $smarty->assign("useProfileACL","");
226 }else{
227 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
228 $smarty->assign("gotoProfileServer"," disabled ");
229 }
231 /* HANDLE Profile Settings here
232 * Assign available Quota and resolution settings
233 * Get all available profile server
234 * Get cache checkbox
235 * Assign this all to Smarty
236 */
238 if(empty($this->useProfile)){
239 $smarty->assign("gotoProfileACL","disabled");
240 $smarty->assign("useProfileCHK","");
241 }else{
242 $smarty->assign("gotoProfileACL","");
243 $smarty->assign("useProfileCHK"," checked ");
244 }
246 $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
247 $this->gotoProfileServers = array("none","none1");
249 $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
250 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
252 /* Handle kiosk profiles
253 * Read available from filesystem
254 * Open management if post is transmitted
255 */
256 $tmp = new kioskManagementDialog($this->config,$this->dn);
257 $list = $tmp->getKioskProfiles();
259 $smarty->assign("gotoKioskProfiles",$list);
260 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
262 /* Open Management Dialog */
263 if(isset($_POST['KioskManagementDialog'])){
264 $this->dialog = new kioskManagementDialog($this->config,$this->dn);
265 $this->is_dialog = true;
266 }
268 /* Save */
269 if(isset($_POST['KioskClose'])){
270 unset($this->dialog);
271 $this->dialog=NULL;
272 $this->is_dialog = false;
273 }
275 /* Logonscript Management
276 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
277 * Perform add Delete edit Posts
278 */
280 /* Dialog Save */
281 if(isset($_POST['LogonSave'])){
282 $this->dialog->save_object();
283 if(count($this->dialog->check())!=0){
284 foreach($this->dialog->check() as $msg){
285 print_red($msg);
286 }
287 }else{
288 $tmp = $this->dialog->save();
289 unset($this->dialog);
290 $this->dialog=NULL;
291 $this->is_dialog=false;
292 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
293 }
294 }
296 /* Dialog Quit without saving */
297 if(isset($_POST['LogonCancel'])){
298 $this->is_dialog= false;
299 unset($this->dialog);
300 $this->dialog= NULL;
301 }
303 /* Check Edit Del New Posts for a selected LogonScript */
304 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
306 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
307 * In this case we create a new Logon Script.
308 */
309 if(isset($_POST['gotoLogonScriptNew'])){
310 $this->is_dialog = true;
311 $this->dialog = new logonManagementDialog($this->config,$this->dn);
312 }
314 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
315 * We only can delete if there is an entry selected.
316 */
317 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
318 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
319 }
321 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
322 * There must be an entry selected to perform edit request.
323 */
324 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
325 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
326 $this->is_dialog = true;
327 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
328 }
329 }
331 /* Append List to smarty*/
332 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
333 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
335 /* In this section server shares will be defined
336 * A user can select one of the given shares and a mount point
337 * and attach this combination to his setup.
338 */
340 $this->gotoShareSelections = $this->getShareList(true);
341 $this->gotoAvailableShares = $this->getShareList(false);
343 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
344 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
346 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
347 * This entry will be, a combination of mountPoint and sharedefinitions
348 */
349 if(isset($_POST['gotoShareAdd'])){
350 /* We assign a share to this user, if we don't know where to mount the share */
351 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))){
352 print_red("You must specify a valid mount point.");
353 }else{
354 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
355 $s_mount = $_POST['gotoShareMountPoint'];
357 /* Preparing the new assignment */
358 $this->gotoShares[$a_share['name']]=$a_share;
359 $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
360 }
361 }
363 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
364 * If there is no defined share selected, we will abort the deletion without any message
365 */
366 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
367 unset($this->gotoShares[$_POST['gotoShare']]);
368 }
370 $smarty->assign("gotoShares",$this->printOutAssignedShares());
371 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
373 /* Hotplug devices will be handled here
374 * There are 3 possible methods for this feature
375 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
376 * Delete will erase an entry, the entry must be selcted in the ListBox first
377 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
378 */
380 /* If there is a new entry wanted, open a new entry by initilising the dialog */
381 if(isset($_POST['gotoHotplugDeviceNew'])){
382 $this->dialog = new hotplugDialog($this->config,$this->dn);
383 $this->is_dialog = true;
384 }
386 /* We have to delete the selected hotplug from the list*/
387 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
388 unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
389 }
391 /* There are already defined hotplugs from other users we could use */
392 if(isset($_POST['gotoHotplugDeviceUse'])){
393 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
394 $this->is_dialog = true;
395 }
397 /* Dialog Aborted */
398 if(isset($_POST['HotPlugCancel'])){
399 unset($this->dialog);
400 $this->dialog= NULL;
401 $this->is_dialog = false;
402 }
404 /* Dialod saved */
405 if(isset($_POST['HotPlugSave'])){
406 $this->dialog->save_object();
407 if(count($this->dialog->check())!=0){
408 foreach($this->dialog->check() as $msg){
409 print_red($msg);
410 }
411 }else{
412 $this->dialog->save_object();
413 $a_tmp = $this->dialog->save();
414 if(is_array($a_tmp)){
415 $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp;
416 }
417 unset($this->dialog);
418 $this->dialog= NULL;
419 $this->is_dialog = false;
420 }
421 }
423 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
424 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
426 /* Printer Assignment will managed below
427 * A printer can be assigned in two different ways and two different types
428 * There are 2 types of users assigned to a printer : user and admin
429 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
430 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
431 */
433 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
434 if(isset($_POST['gotoPrinterAdd'])){
435 $this->is_dialog=true;
436 $this->dialog = new selectPrinterDialog($this->config,$this->dn);
437 }
439 if(isset($_POST['PrinterCancel'])){
440 $this->is_dialog=false;
441 unset($this->dialog);
442 $this->dialog=NULL;
443 }
445 if(isset($_POST['PrinterSave'])){
446 if(count($this->dialog->check())!=0){
447 $tmp = $this->dialog->check();
448 foreach($tmp as $msg){
449 print_red($msg);
450 }
451 }else{
452 $this->dialog->save_object();
453 $tmp = $this->dialog->save();
454 $tmp2= $this->dialog->getPrinter(true);
455 $this->gotoPrinters[$tmp]=$tmp2[$tmp];
456 $this->gotoPrinters[$tmp]['mode']="user";
457 $this->is_dialog=false;
458 unset($this->dialog);
459 $this->dialog =NULL;
460 }
461 }
463 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
464 $printer = $_POST['gotoPrinter'];
465 unset($this->gotoPrinters[$printer]);
466 }
468 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
469 $printer = $_POST['gotoPrinter'];
470 if($this->gotoPrinters[$printer]['mode']=="user"){
471 $this->gotoPrinters[$printer]['mode']="admin";
472 }else{
473 $this->gotoPrinters[$printer]['mode']="user";
474 }
475 }
477 $smarty->assign("gotoPrinters",$this->printOutPrinterDevices());
478 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
480 /* General behavior */
481 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
482 $this->dialog->save_object();
483 return ($this->dialog->execute());
484 }
485 if($this->acl != "#none#"){
486 $smarty->assign("useProfileACL","");
487 }else{
488 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
489 $smarty->assign("gotoProfileServerACL"," disabled ");
490 }
492 if(!$this->useProfile){
493 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
494 $smarty->assign("gotoProfileServerACL"," disabled ");
495 }
497 /* Als smarty vars are set. Get smarty template and generate output */
498 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
500 return($display);
501 }
503 function remove_from_parent()
504 {
505 /* only if it was an account*/
506 if (!$this->initially_was_account){
507 return;
508 }
510 /* include global link_info */
511 $ldap= $this->config->get_ldap_link();
513 /* Remove and write to LDAP */
514 plugin::remove_from_parent();
516 /* Don't save our template variables */
517 $skip = array("useProfile","uid","gotoProfileServers","gotoProfileFlag_C","gotoXResolutions","gotoProfileFlag_L",
518 "gotoLogonScripts","gotoPrinters","gotoShares","gotoShareSelections","gotoKioskProfiles","gotoHotplugDevices",
519 "gotoPrinter");
520 /* Skip all these attributes */
521 foreach($skip as $del){
522 unset($this->attrs[$del]);
523 }
525 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
527 $ldap->cd($this->dn);
528 $ldap->modify($this->attrs);
530 show_ldap_error($ldap->get_error());
532 /* Optionally execute a command after we're done */
533 $this->handle_post_events("remove");
534 }
537 /* Save data to object */
538 function save_object()
539 {
540 /* Get all Posted vars
541 * Setup checkboxes
542 */
544 if(isset($_POST['iamposted'])){
545 plugin::save_object();
546 foreach($this->attributes as $s_attr){
547 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinters","gotoLogonScripts","uid"))) continue;
548 if(isset($_POST[$s_attr])){
549 $this->$s_attr = $_POST[$s_attr];
550 }else{
551 $this->$s_attr = false;
552 }
553 }
554 }
555 }
558 /* Check supplied data */
559 function check()
560 {
561 $message= array();
562 return ($message);
563 }
566 /* Save to LDAP */
567 function save()
568 {
569 plugin::save();
570 $ldap= $this->config->get_ldap_link();
572 $realyUsedAttrs= array();
574 /* Save already used objectClasses */
575 $ocs = $this->attrs['objectClass'];
576 unset($ocs['count']);
577 $this->attrs = array();
578 $this->attrs['objectClass']= $ocs;
579 foreach($this->objectclasses as $objc){
580 if(!in_array($objc,$this->attrs['objectClass'])){
581 $this->attrs['objectClass'][]=$objc;
582 }
583 }
586 /* Save usersettings to Printer */
588 if(chkacl($this->acl,"gotoPrinter")!=""){
589 $this->gotoPrinters = array();
590 }
592 if(count($this->gotoPrinters)==0){
593 $ldap->search("(&(objectClass=gotoPrinter)(|(gotoUserPrinter=".$this->uid.")(gotoAdminPrinter=".$this->uid.")))",array("*"));
594 while($attr = $ldap->fetch()){
596 foreach($attr['gotoUserPrinter'] as $key => $user){
597 if($this->uid==$user){
598 unset($attr['gotoUserPrinter'][$key]);
599 }
600 }
602 foreach($attr['gotoAdminPrinter'] as $key => $user){
603 if($this->uid==$user){
604 unset($attr['gotoAdminPrinter'][$key]);
605 }
606 }
608 $attrs_used = array();
609 foreach($attr as $key=>$val){
610 if((!is_numeric($key))&&($key!="count")){
611 if(is_array($val)&&isset($val['count'])){
612 unset($val['count']);
613 }
614 $attrs_used[$key]=$val;
615 }
616 }
617 $attr= $attrs_used;
618 $tmp =array();
619 foreach($attr['gotoAdminPrinter'] as $print){
620 $tmp[]=$print;
621 }
622 $attr['gotoAdminPrinter'] = $tmp;
624 $tmp =array();
625 foreach($attr['gotoUserPrinter'] as $print){
626 $tmp[]=$print;
627 }
628 $attr['gotoUserPrinter'] = $tmp;
630 $ldap->cd($attr['dn']);
631 unset($attr['dn']);
632 $ldap->modify($attr);
633 if($ldap->get_error()!="Success"){
634 print_red("Printer saving ".$ldap->get_error());
635 }
636 }
637 }
639 foreach($this->gotoPrinters as $printer) {
640 $ldap->cd($printer['dn']);
641 $ldap->cat($printer['dn']);
642 $attrs= $ldap->fetch();
643 $attrs_used = array();
644 foreach($attrs as $key=>$val){
645 if((!is_numeric($key))&&($key!="count")){
646 if(is_array($val)&&isset($val['count'])){
647 unset($val['count']);
648 }
649 $attrs_used[$key]=$val;
650 }
651 }
652 $attrs= $attrs_used;
654 /* Filter entries */
656 if($printer['mode'] == "user"){
657 $attribute = "gotoUserPrinter";
658 $attribute2 = "gotoAdminPrinter";
659 }else{
660 $attribute = "gotoAdminPrinter";
661 $attribute2 = "gotoUserPrinter";
662 }
664 /* If this user is already assigned to $attribute2
665 * delete user from $attribute2, to be albe to attach him to $attribute
666 * A user can't be admin and normal user for one printer
667 */
668 if(!isset($printer[$attribute2])){
669 $printer[$attribute2]=array();
670 }else{
671 if(in_array($this->uid,$printer[$attribute2])){
672 $tmp = array_flip($attrs[$attribute2]);
673 unset($tmp[$this->uid]);
674 $attrs[$attribute2]=array_flip($tmp);
675 }
676 /* If Last entry removed, clear attribute*/
677 if(empty($attrs[$attribute2])){
678 $attrs[$attribute2]=array();
679 }
680 }
682 /* Attach user to the $attribute, if he is'nt already attached
683 */
684 if(!isset($attrs[$attribute])){
685 $attrs[$attribute]=array($this->uid);
686 }else{
687 unset($attrs[$attribute]['count']);
688 if(!in_array($this->uid,$attrs[$attribute])){
689 $attrs[$attribute][]=$this->uid;
690 }
691 }
693 $tmp =array();
694 if(isset($attrs['gotoAdminPrinter'])){
695 foreach($attrs['gotoAdminPrinter'] as $print){
696 $tmp[]=$print;
697 }
698 }
699 $attrs['gotoAdminPrinter'] = $tmp;
701 $tmp =array();
702 if(isset($attrs['gotoUserPrinter'])){
703 foreach($attrs['gotoUserPrinter'] as $print){
704 $tmp[]=$print;
705 }
706 }
707 $attrs['gotoUserPrinter'] = $tmp;
709 $ldap->cd($attrs['dn']);
710 unset($attrs['dn']);
711 $ldap->modify($attrs);
712 if($ldap->get_error()!="Success"){
713 print_red("Printer saving ".$ldap->get_error());
714 }
715 }
717 if(isset($this->attrs['gotoPrinter'])){
718 unset($this->attrs['gotoPrinter']);
719 }
721 /* Prepare HotPlug devices */
722 $this->attrs['gotoHotplugDevice'] = array();
723 foreach($this->gotoHotplugDevices as $name => $device){
724 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
725 }
727 /* Prepare LogonScripts */
728 $this->attrs['gotoLogonScript'] = array();
729 foreach($this->gotoLogonScripts as $name => $script){
730 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
731 $script['LogonOverload'].$script['LogonLast']."|".
732 $script['LogonPriority']."|".
733 base64_encode($script['LogonData']);
734 }
736 /* Prepare Shares */
737 $this->attrs['gotoShare']=array();
738 foreach($this->gotoShares as $name => $share){
739 $this->attrs['gotoShare'][] = $share['name']."|".$share['mountPoint'];
740 }
742 if(!empty($this->gotoKioskProfile)){
743 $this->attrs['gotoKioskProfile']= $this->gotoKioskProfile;
744 }else{
745 $this->attrs['gotoKioskProfile']= array();
746 }
748 $saveThis = array("gotoKioskProfile","gotoProfileQuota","gotoXResolution","gotoProfileServer");
750 foreach($saveThis as $tosave){
751 if(!empty($this->$tosave)){
752 $this->attrs[$tosave]=$this->$tosave;
753 }else{
754 $this->attrs[$tosave]=array();
755 }
756 }
758 /* Prepare Flags */
759 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
760 if(empty($this->attrs['gotoProfileFlags'][0])){
761 $this->attrs['gotoProfileFlags']=array();
762 }
764 if($this->useProfile == false){
765 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
766 $this->attrs['gotoProfileServer']= array();
767 }
769 foreach($this->attributes as $s_attr){
770 if(chkacl($this->acl,$s_attr)!="") {
771 if(isset($this->attrs[$s_attr])){
772 unset($this->attrs[$s_attr]);
773 }
774 }
775 }
777 $ldap->cat ($this->dn);
778 if ($ldap->fetch()){
779 $mode= "modify";
780 } else {
781 $mode= "add";
782 $ldap->cd($this->config->current['BASE']);
783 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
784 }
786 $ldap->cd($this->dn);
787 $ldap->$mode($this->attrs);
788 if($ldap->get_error()!="Success"){
789 print_red($ldap->get_error());
790 }
791 $this->handle_post_events($mode);
792 }
794 /* This function returns all available Shares defined in this ldap
795 * There are two ways to call this function, if listboxEntry is true
796 * only name and path are attached to the array, in it is false, the whole
797 * entry will be parsed an atached to the result.
798 */
799 function getShareList($listboxEntry = false)
800 {
801 $ldap= $this->config->get_ldap_link();
802 $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry"));
803 $return= array();
804 while($entry = $ldap->fetch($a_res)){
805 $shareAttrs = split("\|",$entry['goExportEntry'][0]);
806 if($listboxEntry) {
807 $return[$shareAttrs[0]] = $shareAttrs[0]." - ".$shareAttrs[4];
808 }else{
809 $return[$shareAttrs[0]]['name'] = $shareAttrs[0];
810 $return[$shareAttrs[0]]['description'] = $shareAttrs[1];
811 $return[$shareAttrs[0]]['type'] = $shareAttrs[2];
812 $return[$shareAttrs[0]]['charset'] = $shareAttrs[3];
813 $return[$shareAttrs[0]]['path'] = $shareAttrs[4];
814 $return[$shareAttrs[0]]['option'] = $shareAttrs[5];
815 }
816 }
817 return($return);
818 }
821 /* Generate ListBox frindly output for the defined shares
822 * Possibly Add or remove an attribute here,
823 */
824 function printOutAssignedShares()
825 {
826 $a_return = array();
827 if(is_array($this->gotoShares)){
828 foreach($this->gotoShares as $share){
829 $a_return[$share['name']]= $share['name']." ".$share['mountPoint'];
830 }
831 }
832 return($a_return);
833 }
835 /* Generate ListBox frindly output for the definedhotplugs
836 * Possibly Add or remove an attribute here,
837 */
838 function printOutHotPlugDevices()
839 {
840 $a_return= array();
841 if(is_array($this->gotoHotplugDevices)){
842 foreach($this->gotoHotplugDevices as $key=>$device){
843 $a_return[$key] = $device['name']." - ".$device['id'];
844 }
845 }
846 return($a_return);
847 }
849 /* Generates ListBox frienly output of used printer devices
850 * Append ' - admin' if printer is used in admin mode
851 */
852 function printOutPrinterDevices()
853 {
854 $a_return = array();
855 if(is_array($this->gotoPrinters)){
856 foreach($this->gotoPrinters as $printer){
857 if($printer['mode'] == "admin"){
858 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
859 }else{
860 $a_return[$printer['cn'][0]]= $printer['cn'][0];
861 }
862 }
863 }
864 return($a_return);
865 }
867 /* Generates ListBox frienly output of used logonscripts
868 */
869 function printOutLogonScripts()
870 {
871 $a_return = array();
872 if(is_array($this->gotoLogonScripts)){
873 foreach($this->gotoLogonScripts as $script){
874 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
875 }
876 }
877 return($a_return);
878 }
879 }
884 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
885 ?>