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 = "1024x768"; // 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
50 VAR $newKioskProfiles = array();
52 /* Hotplug Devices */
53 var $gotoHotplugDevice = ""; // Selected hotplug
54 var $gotoHotplugDevices = array();// Already configured hotplug devices
57 /* general settings */
58 // Sets the attributes which will kept on page reload, which will be saved, ...
59 var $attributes = array("uid","useProfile","gotoProfileServer","gotoProfileServers","gotoProfileFlags","gotoProfileFlag_C",
60 "gotoXResolution","gotoXResolutions","gotoProfileFlag_L","gotoProfileQuota",
61 "gotoLogonScripts","gotoLogonScript",
62 "gotoPrinters","gotoPrinter",
63 "gotoShares","gotoShare","gotoShareSelections",
64 "gotoKioskProfile","gotoKioskProfiles",
65 "gotoHotplugDevice","gotoHotplugDevices");
66 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
68 function environment ($config, $dn= NULL)
69 {
70 plugin::plugin ($config, $dn);
72 /* Get all Printer assignments */
73 $ldap = $this->config->get_ldap_link();
74 $ldap->cd($this->config->current['BASE']);
75 $ldap->search("(&(objectClass=gotoPrinter)(gotoUserPrinter=".$this->uid."))",array("*"));
76 while($printer = $ldap->fetch()){
77 $this->gotoPrinters[$printer['cn'][0]]=$printer;
78 $this->gotoPrinters[$printer['cn'][0]]['mode']="user";
79 }
80 $ldap->search("(&(objectClass=gotoPrinter)(gotoAdminPrinter=".$this->uid."))",array("*"));
81 while($printer = $ldap->fetch()){
82 $this->gotoPrinters[$printer['cn'][0]]=$printer;
83 $this->gotoPrinters[$printer['cn'][0]]['mode']="admin";
84 }
86 /* prepare hotplugs */
87 if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
88 unset($this->attrs['gotoHotplugDevice']['count']);
89 foreach($this->attrs['gotoHotplugDevice'] as $device){
90 $tmp = $tmp2 = array();
91 $tmp = split("\|",$device);
92 $tmp2['name'] = $tmp[0];
93 $tmp2['description'] = $tmp[1];
94 $tmp2['id'] = $tmp[2];
95 $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
96 }
97 }
99 /* prepare LogonScripts */
100 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
101 unset($this->attrs['gotoLogonScript']['count']);
102 foreach($this->attrs['gotoLogonScript'] as $device){
103 $tmp = $tmp2 = array();
104 $tmp = split("\|",$device);
105 $tmp2['LogonName'] = $tmp[0];
106 $tmp2['LogonPriority'] = $tmp[2];
107 if(preg_match("/O/i",$tmp[1])){
108 $tmp2['LogonOverload'] = "O";
109 }else{
110 $tmp2['LogonOverload'] = "";
111 }
112 if(preg_match("/L/i",$tmp[1])){
113 $tmp2['LogonLast'] = "L";
114 }else{
115 $tmp2['LogonLast'] = "";
116 }
117 $tmp2['LogonData'] = base64_decode($tmp[3]);
118 $tmp2['LogonDescription'] = $tmp[4];
119 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
120 }
121 }
123 /* Prepare Shares */
124 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
125 unset($this->attrs['gotoShare']['count']);
126 foreach($this->attrs['gotoShare'] as $share){
127 $tmp = $tmp2 = array();
128 $tmp = split("\|",$share);
129 $tmp2['name'] =$tmp[0];
130 $tmp2['mountPoint']=$tmp[1];
131 $this->gotoShares[$tmp[0]]=$tmp2;
132 }
133 }
135 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
136 $chr = $this->gotoProfileFlags[$i];
137 $name = "gotoProfileFlag_".$chr;
138 $this->$name=$chr;
139 }
141 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
142 $this->useProfile = true;
143 }else{
144 $this->useProfile = false;
145 }
147 }
149 function execute()
150 {
151 /* Fill templating stuff */
152 $smarty= get_smarty();
153 $display= "";
154 /* Is accout enabled | are we editing from usermenu or admin menu
155 All these tab management is done here
156 */
158 // 1. Account disabled . Editing from usermenu
159 if((!isset($this->parent))&&(!$this->is_account)){
160 /* We are currently editing this tab from usermenu, but this account is not enabled */
161 $smarty->assign("is_account",$this->is_account);
162 /* Load template */
163 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
164 /* Avoid the "You are currently editing ...." message when you leave this tab */
165 $display .= back_to_main();
166 /* Display our message to the user */
167 return $display;
169 // Account is enabled
170 }else{
171 /* Tell smarty that this accoutn is enabled */
172 $smarty->assign("is_account","true");
174 /* Do we need to flip is_account state? */
175 if (isset($_POST['modify_state'])){
176 $this->is_account= !$this->is_account;
177 }
178 if(!isset($this->parent)){
179 // 3. ? Account Enabled . Editing from usermenu
181 }else{
182 // 3. Account enabled . Editing from adminmenu
183 if ($this->is_account){
184 $display= $this->show_header(_("Remove environment extension"),
185 _("This server has environment extension enabled. You can disable it by clicking below."));
186 } else {
187 if((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)){
188 // 4. There is a PosixAccount
189 $display= $this->show_header(_("Add environment extension"),
190 _("This server has environment extension disabled. You can enable it by clicking below."));
191 return $display;
192 }else{
193 // 4. There is a PosixAccount
194 $display= $this->show_header(_("Add environment extension"),
195 _("This server has environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
196 return $display;
197 }
198 }
199 }
200 }
201 /* Account is Account : is_accounbt=true.
202 * Else we won't reach this.
203 */
205 /* Prepare all variables for smarty */
206 foreach($this->attributes as $s_attr){
207 /* Set value*/
208 $smarty->assign($s_attr,$this->$s_attr);
210 /* Set checkbox state*/
211 if(empty($this->$s_attr)){
212 $smarty->assign($s_attr."CHK","");
213 }else{
214 $smarty->assign($s_attr."CHK"," checked ");
215 }
217 /* Prepare ACL settings*/
218 if(chkacl($this->acl,$s_attr)=="") {
219 $smarty->assign($s_attr."ACL","");
220 }else{
221 $smarty->assign($s_attr."ACL"," disabled ");
222 }
224 }
226 if($this->acl != "#none#"){
227 $smarty->assign("useProfileACL","");
228 }else{
229 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
230 $smarty->assign("gotoProfileServer"," disabled ");
231 }
233 /* HANDLE Profile Settings here
234 * Assign available Quota and resolution settings
235 * Get all available profile server
236 * Get cache checkbox
237 * Assign this all to Smarty
238 */
240 if(empty($this->useProfile)){
241 $smarty->assign("gotoProfileACL","disabled");
242 $smarty->assign("useProfileCHK","");
243 }else{
244 $smarty->assign("gotoProfileACL","");
245 $smarty->assign("useProfileCHK"," checked ");
246 }
248 $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
249 $this->gotoProfileServers =$this->getShareServerList() ;
251 $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
252 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
253 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
255 /* Handle kiosk profiles
256 * Read available from filesystem
257 * Open management if post is transmitted
258 */
260 /* Open Management Dialog */
261 if(isset($_POST['KioskManagementDialog'])){
262 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
263 $this->is_dialog = true;
264 }
266 /* Save */
267 if(isset($_POST['KioskClose'])){
268 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
270 unset($this->dialog);
271 $this->dialog=NULL;
272 $this->is_dialog = false;
273 }
274 $tmp = new kioskManagementDialog($this->config,$this->dn);
275 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
277 $smarty->assign("gotoKioskProfiles",$list);
278 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
280 /* Logonscript Management
281 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
282 * Perform add Delete edit Posts
283 */
285 /* Dialog Save */
286 if(isset($_POST['LogonSave'])){
287 $this->dialog->save_object();
288 if(count($this->dialog->check())!=0){
289 foreach($this->dialog->check() as $msg){
290 print_red($msg);
291 }
292 }else{
293 $tmp = $this->dialog->save();
294 unset($this->dialog);
295 $this->dialog=NULL;
296 $this->is_dialog=false;
297 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
298 }
299 }
301 /* Dialog Quit without saving */
302 if(isset($_POST['LogonCancel'])){
303 $this->is_dialog= false;
304 unset($this->dialog);
305 $this->dialog= NULL;
306 }
308 /* Check Edit Del New Posts for a selected LogonScript */
309 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
311 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
312 * In this case we create a new Logon Script.
313 */
314 if(isset($_POST['gotoLogonScriptNew'])){
315 $this->is_dialog = true;
316 $this->dialog = new logonManagementDialog($this->config,$this->dn);
317 }
319 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
320 * We only can delete if there is an entry selected.
321 */
322 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
323 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
324 }
326 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
327 * There must be an entry selected to perform edit request.
328 */
329 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
330 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
331 $this->is_dialog = true;
332 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
333 }
334 }
336 /* Append List to smarty*/
337 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
338 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
340 /* In this section server shares will be defined
341 * A user can select one of the given shares and a mount point
342 * and attach this combination to his setup.
343 */
345 $this->gotoShareSelections = $this->getShareList(true);
346 $this->gotoAvailableShares = $this->getShareList(false);
348 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
349 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
351 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
352 * This entry will be, a combination of mountPoint and sharedefinitions
353 */
354 if(isset($_POST['gotoShareAdd'])){
355 /* We assign a share to this user, if we don't know where to mount the share */
356 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))){
357 print_red("You must specify a valid mount point.");
358 }else{
359 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
360 $s_mount = $_POST['gotoShareMountPoint'];
362 /* Preparing the new assignment */
363 $this->gotoShares[$a_share['name']]=$a_share;
364 $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
365 }
366 }
368 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
369 * If there is no defined share selected, we will abort the deletion without any message
370 */
371 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
372 unset($this->gotoShares[$_POST['gotoShare']]);
373 }
375 $smarty->assign("gotoShares",$this->printOutAssignedShares());
376 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
378 /* Hotplug devices will be handled here
379 * There are 3 possible methods for this feature
380 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
381 * Delete will erase an entry, the entry must be selcted in the ListBox first
382 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
383 */
385 /* If there is a new entry wanted, open a new entry by initilising the dialog */
386 if(isset($_POST['gotoHotplugDeviceNew'])){
387 $this->dialog = new hotplugDialog($this->config,$this->dn);
388 $this->is_dialog = true;
389 }
391 /* We have to delete the selected hotplug from the list*/
392 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
393 unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
394 }
396 /* There are already defined hotplugs from other users we could use */
397 if(isset($_POST['gotoHotplugDeviceUse'])){
398 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
399 $this->is_dialog = true;
400 }
402 /* Dialog Aborted */
403 if(isset($_POST['HotPlugCancel'])){
404 unset($this->dialog);
405 $this->dialog= NULL;
406 $this->is_dialog = false;
407 }
409 /* Dialod saved */
410 if(isset($_POST['HotPlugSave'])){
411 $this->dialog->save_object();
412 if(count($this->dialog->check())!=0){
413 foreach($this->dialog->check() as $msg){
414 print_red($msg);
415 }
416 }else{
417 $this->dialog->save_object();
418 $a_tmp = $this->dialog->save();
419 if(is_array($a_tmp)){
420 $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp;
421 }
422 unset($this->dialog);
423 $this->dialog= NULL;
424 $this->is_dialog = false;
425 }
426 }
428 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
429 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
431 /* Printer Assignment will managed below
432 * A printer can be assigned in two different ways and two different types
433 * There are 2 types of users assigned to a printer : user and admin
434 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
435 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
436 */
438 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
439 if(isset($_POST['gotoPrinterAdd'])){
440 $this->is_dialog=true;
441 $this->dialog = new selectPrinterDialog($this->config,$this->dn);
442 }
444 if(isset($_POST['PrinterCancel'])){
445 $this->is_dialog=false;
446 unset($this->dialog);
447 $this->dialog=NULL;
448 }
450 if(isset($_POST['PrinterSave'])){
451 if(count($this->dialog->check())!=0){
452 $tmp = $this->dialog->check();
453 foreach($tmp as $msg){
454 print_red($msg);
455 }
456 }else{
457 $this->dialog->save_object();
458 $tmp = $this->dialog->save();
459 $tmp2= $this->dialog->getPrinter(true);
460 $this->gotoPrinters[$tmp]=$tmp2[$tmp];
461 $this->gotoPrinters[$tmp]['mode']="user";
462 $this->is_dialog=false;
463 unset($this->dialog);
464 $this->dialog =NULL;
465 }
466 }
468 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
469 $printer = $_POST['gotoPrinter'];
470 unset($this->gotoPrinters[$printer]);
471 }
473 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
474 $printer = $_POST['gotoPrinter'];
475 if($this->gotoPrinters[$printer]['mode']=="user"){
476 $this->gotoPrinters[$printer]['mode']="admin";
477 }else{
478 $this->gotoPrinters[$printer]['mode']="user";
479 }
480 }
482 $smarty->assign("gotoPrinters",$this->printOutPrinterDevices());
483 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
485 /* General behavior */
486 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
487 $this->dialog->save_object();
488 return ($this->dialog->execute());
489 }
490 if($this->acl != "#none#"){
491 $smarty->assign("useProfileACL","");
492 }else{
493 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
494 $smarty->assign("gotoProfileServerACL"," disabled ");
495 }
497 if(!$this->useProfile){
498 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
499 $smarty->assign("gotoProfileServerACL"," disabled ");
500 }
502 /* Als smarty vars are set. Get smarty template and generate output */
503 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
505 return($display);
506 }
508 function remove_from_parent()
509 {
510 /* only if it was an account*/
511 if (!$this->initially_was_account){
512 return;
513 }
515 /* include global link_info */
516 $ldap= $this->config->get_ldap_link();
518 /* Remove and write to LDAP */
519 plugin::remove_from_parent();
521 /* Don't save our template variables */
522 $skip = array("useProfile","uid","gotoProfileServers","gotoProfileFlag_C","gotoXResolutions","gotoProfileFlag_L",
523 "gotoLogonScripts","gotoPrinters","gotoShares","gotoShareSelections","gotoKioskProfiles","gotoHotplugDevices",
524 "gotoPrinter");
525 /* Skip all these attributes */
526 foreach($skip as $del){
527 unset($this->attrs[$del]);
528 }
530 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
532 $ldap->cd($this->dn);
533 $ldap->modify($this->attrs);
535 show_ldap_error($ldap->get_error());
537 /* Optionally execute a command after we're done */
538 $this->handle_post_events("remove");
539 }
542 /* Save data to object */
543 function save_object()
544 {
545 /* Get all Posted vars
546 * Setup checkboxes
547 */
549 if(isset($_POST['iamposted'])){
550 plugin::save_object();
551 foreach($this->attributes as $s_attr){
552 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinters","gotoLogonScripts","uid"))) continue;
553 if(isset($_POST[$s_attr])){
554 $this->$s_attr = $_POST[$s_attr];
555 }else{
556 $this->$s_attr = false;
557 }
558 }
559 }
560 }
563 /* Check supplied data */
564 function check()
565 {
566 $message= array();
568 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
569 $message[]=_("Please set a valid profile quota size.");
570 }
572 if(!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true))){
573 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
574 }
576 return ($message);
577 }
580 /* Save to LDAP */
581 function save()
582 {
583 plugin::save();
584 $ldap= $this->config->get_ldap_link();
586 $realyUsedAttrs= array();
589 $path = search_config($this->config->data['MENU'],"environment", "KIOSKPATH");
590 /* Creating Kiosk Profiles */
591 foreach($this->newKioskProfiles as $file){
592 $contents = $file['contents'];
593 $fp = @fopen($path."/".$file['name'],"w");
594 if(!$fp){
595 print_red("Can't save new kiosk profiles, possibly permission denied for folder :",$path);
596 }else{
597 fwrite($fp,$contents,strlen($contents));
598 }
599 @unlink($file['tmp_name']);
600 }
607 /* Save already used objectClasses */
608 $ocs = $this->attrs['objectClass'];
609 unset($ocs['count']);
610 $this->attrs = array();
611 $this->attrs['objectClass']= $ocs;
612 foreach($this->objectclasses as $objc){
613 if(!in_array($objc,$this->attrs['objectClass'])){
614 $this->attrs['objectClass'][]=$objc;
615 }
616 }
619 /* Save usersettings to Printer */
621 if(chkacl($this->acl,"gotoPrinter")!=""){
622 $this->gotoPrinters = array();
623 }
625 if(count($this->gotoPrinters)==0){
626 $ldap->search("(&(objectClass=gotoPrinter)(|(gotoUserPrinter=".$this->uid.")(gotoAdminPrinter=".$this->uid.")))",array("*"));
627 while($attr = $ldap->fetch()){
629 foreach($attr['gotoUserPrinter'] as $key => $user){
630 if($this->uid==$user){
631 unset($attr['gotoUserPrinter'][$key]);
632 }
633 }
635 foreach($attr['gotoAdminPrinter'] as $key => $user){
636 if($this->uid==$user){
637 unset($attr['gotoAdminPrinter'][$key]);
638 }
639 }
641 $attrs_used = array();
642 foreach($attr as $key=>$val){
643 if((!is_numeric($key))&&($key!="count")){
644 if(is_array($val)&&isset($val['count'])){
645 unset($val['count']);
646 }
647 $attrs_used[$key]=$val;
648 }
649 }
650 $attr= $attrs_used;
651 $tmp =array();
652 foreach($attr['gotoAdminPrinter'] as $print){
653 $tmp[]=$print;
654 }
655 $attr['gotoAdminPrinter'] = $tmp;
657 $tmp =array();
658 foreach($attr['gotoUserPrinter'] as $print){
659 $tmp[]=$print;
660 }
661 $attr['gotoUserPrinter'] = $tmp;
663 $ldap->cd($attr['dn']);
664 unset($attr['dn']);
665 $ldap->modify($attr);
666 if($ldap->get_error()!="Success"){
667 print_red("Printer saving ".$ldap->get_error());
668 }
669 }
670 }
672 foreach($this->gotoPrinters as $printer) {
673 $ldap->cd($printer['dn']);
674 $ldap->cat($printer['dn']);
675 $attrs= $ldap->fetch();
676 $attrs_used = array();
677 foreach($attrs as $key=>$val){
678 if((!is_numeric($key))&&($key!="count")){
679 if(is_array($val)&&isset($val['count'])){
680 unset($val['count']);
681 }
682 $attrs_used[$key]=$val;
683 }
684 }
685 $attrs= $attrs_used;
687 /* Filter entries */
689 if($printer['mode'] == "user"){
690 $attribute = "gotoUserPrinter";
691 $attribute2 = "gotoAdminPrinter";
692 }else{
693 $attribute = "gotoAdminPrinter";
694 $attribute2 = "gotoUserPrinter";
695 }
697 /* If this user is already assigned to $attribute2
698 * delete user from $attribute2, to be albe to attach him to $attribute
699 * A user can't be admin and normal user for one printer
700 */
701 if(!isset($printer[$attribute2])){
702 $printer[$attribute2]=array();
703 }else{
704 if(in_array($this->uid,$printer[$attribute2])){
705 $tmp = array_flip($attrs[$attribute2]);
706 unset($tmp[$this->uid]);
707 $attrs[$attribute2]=array_flip($tmp);
708 }
709 /* If Last entry removed, clear attribute*/
710 if(empty($attrs[$attribute2])){
711 $attrs[$attribute2]=array();
712 }
713 }
715 /* Attach user to the $attribute, if he is'nt already attached
716 */
717 if(!isset($attrs[$attribute])){
718 $attrs[$attribute]=array($this->uid);
719 }else{
720 unset($attrs[$attribute]['count']);
721 if(!in_array($this->uid,$attrs[$attribute])){
722 $attrs[$attribute][]=$this->uid;
723 }
724 }
726 $tmp =array();
727 if(isset($attrs['gotoAdminPrinter'])){
728 foreach($attrs['gotoAdminPrinter'] as $print){
729 $tmp[]=$print;
730 }
731 }
732 $attrs['gotoAdminPrinter'] = $tmp;
734 $tmp =array();
735 if(isset($attrs['gotoUserPrinter'])){
736 foreach($attrs['gotoUserPrinter'] as $print){
737 $tmp[]=$print;
738 }
739 }
740 $attrs['gotoUserPrinter'] = $tmp;
742 $ldap->cd($attrs['dn']);
743 unset($attrs['dn']);
744 $ldap->modify($attrs);
745 if($ldap->get_error()!="Success"){
746 print_red("Printer saving ".$ldap->get_error());
747 }
748 }
750 if(isset($this->attrs['gotoPrinter'])){
751 unset($this->attrs['gotoPrinter']);
752 }
754 /* Prepare HotPlug devices */
755 $this->attrs['gotoHotplugDevice'] = array();
756 foreach($this->gotoHotplugDevices as $name => $device){
757 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
758 }
760 /* Prepare LogonScripts */
761 $this->attrs['gotoLogonScript'] = array();
762 foreach($this->gotoLogonScripts as $name => $script){
763 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
764 $script['LogonOverload'].$script['LogonLast']."|".
765 $script['LogonPriority']."|".
766 base64_encode($script['LogonData'])."|".
767 $script['LogonDescription'];
768 }
770 /* Prepare Shares */
771 $this->attrs['gotoShare']=array();
772 foreach($this->gotoShares as $name => $share){
773 $this->attrs['gotoShare'][] = $share['name']."|".$share['mountPoint'];
774 }
776 if(!empty($this->gotoKioskProfile)){
777 $this->attrs['gotoKioskProfile']= $this->gotoKioskProfile;
778 }else{
779 $this->attrs['gotoKioskProfile']= array();
780 }
782 $saveThis = array("gotoKioskProfile","gotoProfileQuota","gotoXResolution","gotoProfileServer");
784 foreach($saveThis as $tosave){
785 if(!empty($this->$tosave)){
786 $this->attrs[$tosave]=$this->$tosave;
787 }else{
788 $this->attrs[$tosave]=array();
789 }
790 }
792 /* Prepare Flags */
793 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
794 if(empty($this->attrs['gotoProfileFlags'][0])){
795 $this->attrs['gotoProfileFlags']=array();
796 }
798 if($this->useProfile == false){
799 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
800 $this->attrs['gotoProfileServer']= array();
801 }
803 foreach($this->attributes as $s_attr){
804 if(chkacl($this->acl,$s_attr)!="") {
805 if(isset($this->attrs[$s_attr])){
806 unset($this->attrs[$s_attr]);
807 }
808 }
809 }
811 $ldap->cat ($this->dn);
812 if ($ldap->fetch()){
813 $mode= "modify";
814 } else {
815 $mode= "add";
816 $ldap->cd($this->config->current['BASE']);
817 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
818 }
820 $ldap->cd($this->dn);
821 $ldap->$mode($this->attrs);
822 if($ldap->get_error()!="Success"){
823 print_red($ldap->get_error());
824 }
825 $this->handle_post_events($mode);
826 }
828 /* This function returns all available Shares defined in this ldap
829 * There are two ways to call this function, if listboxEntry is true
830 * only name and path are attached to the array, in it is false, the whole
831 * entry will be parsed an atached to the result.
832 */
833 function getShareList($listboxEntry = false)
834 {
835 $ldap= $this->config->get_ldap_link();
836 $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry"));
837 $return= array();
838 while($entry = $ldap->fetch($a_res)){
839 unset($entry['goExportEntry']['count']);
840 foreach($entry['goExportEntry'] as $export){
841 $shareAttrs = split("\|",$export);
842 if($listboxEntry) {
843 $return[$shareAttrs[0]] = $shareAttrs[0]." - ".$shareAttrs[4];
844 }else{
845 $return[$shareAttrs[0]]['name'] = $shareAttrs[0];
846 $return[$shareAttrs[0]]['description'] = $shareAttrs[1];
847 $return[$shareAttrs[0]]['type'] = $shareAttrs[2];
848 $return[$shareAttrs[0]]['charset'] = $shareAttrs[3];
849 $return[$shareAttrs[0]]['path'] = $shareAttrs[4];
850 $return[$shareAttrs[0]]['option'] = $shareAttrs[5];
851 }
852 }
853 }
854 return($return);
855 }
858 /* This function returns all available ShareServer
859 */
860 function getShareServerList()
861 {
862 $ldap= $this->config->get_ldap_link();
863 $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry","cn"));
864 $return= array();
865 while($entry = $ldap->fetch($a_res)){
866 $return[$entry['cn'][0]] = $entry['cn'][0];
867 }
868 return($return);
869 }
871 /* Generate ListBox frindly output for the defined shares
872 * Possibly Add or remove an attribute here,
873 */
874 function printOutAssignedShares()
875 {
876 $a_return = array();
877 if(is_array($this->gotoShares)){
878 foreach($this->gotoShares as $share){
879 $a_return[$share['name']]= $share['name']." ".$share['mountPoint'];
880 }
881 }
882 return($a_return);
883 }
885 /* Generate ListBox frindly output for the definedhotplugs
886 * Possibly Add or remove an attribute here,
887 */
888 function printOutHotPlugDevices()
889 {
890 $a_return= array();
891 if(is_array($this->gotoHotplugDevices)){
892 foreach($this->gotoHotplugDevices as $key=>$device){
893 $a_return[$key] = $device['name']." - ".$device['id'];
894 }
895 }
896 return($a_return);
897 }
899 /* Generates ListBox frienly output of used printer devices
900 * Append ' - admin' if printer is used in admin mode
901 */
902 function printOutPrinterDevices()
903 {
904 $a_return = array();
905 if(is_array($this->gotoPrinters)){
906 foreach($this->gotoPrinters as $printer){
907 if($printer['mode'] == "admin"){
908 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
909 }else{
910 $a_return[$printer['cn'][0]]= $printer['cn'][0];
911 }
912 }
913 }
914 return($a_return);
915 }
917 /* Generates ListBox frienly output of used logonscripts
918 */
919 function printOutLogonScripts()
920 {
921 $a_return = array();
922 if(is_array($this->gotoLogonScripts)){
923 foreach($this->gotoLogonScripts as $script){
924 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
925 }
926 }
927 return($a_return);
928 }
929 }
934 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
935 ?>