1 <?php
3 class printgeneric extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary = "Manage terminal base 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 /* Generic terminal attributes */
11 var $interfaces = array();
12 var $ignore_account = FALSE;
14 /* Needed values and lists */
15 var $base = "";
16 var $cn = "";
17 var $l = "";
18 var $description = "";
19 var $labeledURI = "";
20 var $gotoPrinterPPD = "";
21 var $orig_dn = "";
23 var $UserMember ="";
24 var $UserMembers =array();
25 var $UserMemberKeys =array();
27 var $AdminMember ="";
28 var $AdminMembers =array();
29 var $AdminMemberKeys =array();
31 var $PPDdialogToSave = NULL;
32 var $BelongsTo = "unknown"; // Specifies if this is a standalone printer, or belongs to a terminal / WS
34 var $member =array();
35 var $strings = "";
36 var $dialog =NULL;
38 var $netConfigDNS;
39 var $baseSelection = false;
40 var $macAddress = "";
42 var $gotoUserAdminPrinter;
43 var $gotoGroupAdminPrinter ;
44 var $gotoGroupPrinter;
45 var $gotoUserPrinter ;
47 /* attribute list for save action */
48 var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress",
49 "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
50 var $objectclasses = array("top", "gotoPrinter");
52 var $parent;
54 function printgeneric ($config, $dn,$parent_init,$parent)
55 {
56 $this->config = $config;
57 $this->dn = $dn;
59 /* If parent was posted(the tabs object) we can detect the printer type. */
60 if($parent){
61 $this->parent = $parent;
62 $this->getTypeOfPrinter();
63 }else{
64 $this->BelongsTo = "unknown";
65 return;
66 }
68 /* Update dn, to ensure storing as printer instead of WS / terminal */
69 if($this->BelongsTo == "Terminal"){
70 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
71 }
73 if($this->BelongsTo == "Workstation"){
74 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
75 }
77 $this->orig_dn = $this->dn;
79 /* Get printer settings, possibly dn has changed */
80 plugin::plugin ($config, $this->dn,$parent_init);
82 /* Get is_account initially_was_account status */
83 $this->getTypeOfPrinter(true);
85 /* set orig dn to new if object is new */
86 $ldap= $this->config->get_ldap_link();
87 $ldap->cat($this->dn, array('dn'));
88 if(!$ldap->count()){
89 $this->orig_dn = "new";
90 }
92 /* create dns object */
93 $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
95 /* Set base */
96 if ($this->dn == "new"){
97 $ui= get_userinfo();
98 $this->base= dn2base($ui->dn);
99 $this->cn= "";
100 } else {
102 /* Set base and check if the extracted base exists */
103 if(preg_match("/ou=incoming,/",$this->dn)){
104 $this->base= preg_replace("/ou=incoming,/","",dn2base($this->dn));
105 }else{
106 $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
107 }
109 if(!isset($this->config->idepartments[$this->base])){
110 print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),$_SESSION['CurrentMainBase']);
111 $this->base = $_SESSION['CurrentMainBase'];
112 }
113 }
115 /* Extract selected ppd */
116 if(isset($this->gotoPrinterPPD)){
117 $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
118 }
120 /* Prepare different member types */
121 foreach(array("AddUser" =>"gotoUserPrinter",
122 "AddGroup" =>"gotoGroupPrinter",
123 "AddAdminUser" =>"gotoUserAdminPrinter",
124 "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){
126 /* $this->members contains all members */
127 $this->member[$type]=array();
129 if (isset($this->attrs[$attr]['count'])) {
130 unset($this->attrs[$attr]['count']);
131 }
133 if(isset($this->attrs[$attr])){
134 foreach($this->attrs[$attr] as $mem){
135 if(preg_match("/Group/",$type)){
136 $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
137 if($ldap->count()){
138 $entry = $ldap->fetch();
139 $this->member[$type][$entry['cn'][0]]=$entry;
140 }
141 }else{
142 $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
143 if($ldap->count()){
144 $entry = $ldap->fetch();
145 $this->member[$type][$entry['uid'][0]]=$entry;
146 }
147 }
148 }
149 }
150 }
151 }
154 /* Detect type of printer.
155 * Printer can be stand alone, belong to a workstation or belong to a terminal.
156 * We can detect the type printer type when comparing the tabs objects
157 */
158 function getTypeOfPrinter($UpdateAccountStatus = false)
159 {
160 /* Disable account as default
161 */
162 $this->is_account = $this->initially_was_account = false;
164 /* Detect type of printer via parent tabs.
165 */
167 $class = get_class($this->parent);
168 if(isset($this->parent->by_object['workgeneric'])){
170 /* Exclude templates
171 */
172 $this->cn = $this->parent->by_object['workgeneric']->cn;
173 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
174 $this->BelongsTo = "WorkstationTemplate";
175 }else{
176 $this->BelongsTo = "Workstation";
177 }
178 }elseif(isset($this->parent->by_object['termgeneric'])){
180 /* Exclude templates
181 */
182 $this->cn = $this->parent->by_object['termgeneric']->cn;
183 if($this->parent->by_object['termgeneric']->cn == "default"){
184 $this->BelongsTo = "TerminalTemplate";
185 }else{
186 $this->BelongsTo = "Terminal";
187 }
188 }elseif(isset($this->parent->by_name['printgeneric'])){
189 $this->BelongsTo = "Printer";
190 }
192 if($UpdateAccountStatus){
194 /* Set is_account / was account
195 */
196 if($this->dn == "new"){
197 $this->initially_was_account = false;
198 }
200 /* If is printer it must be a true account.
201 */
202 if($this->BelongsTo == "Printer"){
203 $this->is_account = true;
204 }
206 /* Update dn, to ensure storing as printer instead of WS / terminal
207 */
208 if($this->BelongsTo == "Terminal"){
209 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
210 }
212 if($this->BelongsTo == "Workstation"){
213 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
214 }
216 /* Detect if this is a valid printer account;
217 */
218 $ldap = $this->config->get_ldap_link();
219 $ldap->cat($this->dn, array('objectClass'));
221 if($ldap->count()){
222 $attrs = $ldap->fetch();
223 if(in_array("gotoPrinter",$attrs['objectClass'])){
224 $this->initially_was_account = true;
225 $this->is_account = true;
226 }else{
227 $this->is_account = false;
228 }
229 }
230 }
231 }
233 function execute()
234 {
235 /* Call parent execute */
236 plugin::execute();
238 /* If type of printer couldn't be detected (because of missing parent object in construction)
239 * hide this tab.
240 */
241 if($this->BelongsTo == "unknown"){
242 $display= $this->show_enable_header(_("Add printer extension"),
243 _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
244 return($display);
245 }
247 /* Templates can't have printer extensions
248 */
249 if($this->BelongsTo == "WorkstationTemplate"){
250 $display= $this->show_enable_header(_("Add printer extension"),
251 _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
252 return($display);
253 }
254 if($this->BelongsTo == "TerminalTemplate"){
255 $display= $this->show_enable_header(_("Add printer extension"),
256 _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
257 return($display);
258 }
260 /* Get cn from base object */
261 if($this->BelongsTo == "Workstation"){
262 $this->cn = $this->parent->by_object['workgeneric']->cn;
263 }
264 if($this->BelongsTo == "Terminal"){
265 $this->cn = $this->parent->by_object['termgeneric']->cn;
266 }
268 $smarty= get_smarty();
270 /* Assign acls */
271 $tmp = $this->plInfo();
272 foreach($tmp['plProvidedAcls'] as $name => $translation){
273 $smarty->assign($name."ACL", $this->getacl($name));
274 }
276 /* Create base acls */
277 $baseACL = $this->getacl("base");
278 if(!$this->acl_is_moveable()) {
279 $baseACL = preg_replace("/w/","",$baseACL);
280 }
281 $smarty->assign("baseACL", $baseACL);
284 $display="";
286 /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
287 if($this->BelongsTo == "Printer"){
288 $smarty->assign("StandAlone",true);
289 }else{
290 $smarty->assign("StandAlone",false);
291 }
293 /* Do we need to flip is_account state? */
294 if(isset($_POST['modify_state'])){
295 if($this->is_account && $this->acl_is_removeable()){
296 $this->is_account= FALSE;
297 }elseif(!$this->is_account && $this->acl_is_createable()){
298 $this->is_account= TRUE;
299 }
300 }
302 /* Do we represent a valid printer? */
303 if (!$this->is_account && $this->parent == NULL){
304 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
305 _("This 'dn' has no printer features.")."</b>";
306 return($display);
307 }
309 /* If this is a WS / Terminal depending printer, display account state button */
310 if($this->BelongsTo != "Printer"){
311 if((empty($this->cn)) && ($this->dn != "new")){
312 $display= $this->show_enable_header(_("Add printer extension"),
313 _("This object has printer extension disabled. You can't enable it while 'cn' is not present in entry. Possibly you are currently creating a new terminal template"),TRUE,TRUE);
314 $this->is_account= false;
315 return $display;
316 }
318 if (($this->is_account)){
319 if($this->BelongsTo=="Workstation"){
320 $display= $this->show_disable_header(_("Remove printer extension"),
321 _("This workstation has printer extension enabled.You can disable it by clicking below."));
322 }elseif($this->BelongsTo=="Terminal"){
323 $display= $this->show_disable_header(_("Remove printer extension"),
324 _("This terminal has printer extension enabled. You can disable it by clicking below."));
325 }
326 }else{
327 if($this->BelongsTo=="Workstation"){
328 $display= $this->show_disable_header(_("Add printer extension"),
329 _("This workstation has printer extension disabled. You can enable it by clicking below."));
330 }elseif($this->BelongsTo=="Terminal"){
331 $display= $this->show_enable_header(_("Add printer extension"),
332 _("This terminal has printer extension disabled. You can enable it by clicking below."));
333 }
334 return ($display);
335 }
336 }
338 /* Base select dialog */
339 $once = true;
340 foreach($_POST as $name => $value){
341 if(preg_match("/^chooseBase/",$name) && $once){
342 $once = false;
343 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
344 $this->dialog->setCurrentBase($this->base);
345 $this->baseSelection = true;
346 }
347 }
349 /* Dialog handling for base select dialog
350 * Check if base was selected, dialog aborted etc */
351 if(is_object($this->dialog)){
353 $this->dialog->save_object();
354 if($this->baseSelection){
355 if($this->dialog->isClosed()){
356 $this->dialog = false;
357 $this->baseSelection = false;
358 }elseif($this->dialog->isSelected()){
359 $this->base = $this->dialog->isSelected();
360 $this->dialog= false;
361 $this->baseSelection = false;
362 }else{
363 return($this->dialog->execute());
364 }
365 }
366 }
368 /* Fill templating stuff */
369 $smarty->assign("bases", $this->get_allowed_bases());
370 $smarty->assign("base_select", $this->base);
372 /* Assign attributes */
373 foreach ($this->attributes as $attr){
374 $smarty->assign("$attr", $this->$attr);
375 }
377 if(isset($_POST['AddUser'])){
378 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
379 }
380 if(isset($_POST['AddGroup'])){
381 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
382 }
383 if(isset($_POST['AddAdminUser'])){
384 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
385 }
386 if(isset($_POST['AddAdminGroup'])){
387 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
388 }
390 /* Display ppd configure/select dialog */
391 if(isset($_POST['EditDriver'])){
392 if($this->PPDdialogToSave){
393 $this->dialog = $this->PPDdialogToSave;
394 }else{
395 $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
396 }
397 }
399 /* remove ppd */
400 if(isset($_POST['RemoveDriver'])){
401 $this->gotoPrinterPPD = array();
402 $this->PPDdialogToSave = NULL;
403 }
405 /* Close ppd dialog */
406 if(isset($_POST['ClosePPD'])){
407 unset($this->dialog);
408 $this->dialog=NULL;
409 }
411 /* Save selected ppd */
412 if(isset($_POST['SavePPD'])){
413 $this->dialog->save_object();
414 if(count($this->dialog->check())){
415 foreach($this->dialog->check() as $msg){
416 print_red($msg);
417 }
418 }else{
419 $this->gotoPrinterPPD = array();
420 $this->gotoPrinterPPD = $this->dialog->save();
421 $this->PPDdialogToSave = $this->dialog;
422 unset($this->dialog);
423 $this->dialog=NULL;
424 }
425 }
427 /* Member management, delete user / group / admin ..*/
428 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
429 foreach($_POST['UserMember'] as $mem){
430 $this->DelMember('AddUser',$mem);
431 }
432 }
434 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
435 foreach($_POST['UserMember'] as $mem){
436 $this->DelMember('AddGroup',$mem);
437 }
438 }
440 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
441 foreach($_POST['AdminMember'] as $mem){
442 $this->DelMember('AddAdminUser',$mem);
443 }
444 }
446 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
447 foreach($_POST['AdminMember'] as $mem){
448 $this->DelMember('AddAdminGroup',$mem);
449 }
450 }
452 /* Abort user / group adding dialog */
453 if(isset($_POST['PrinterCancel'])){
454 unset($this->dialog);
455 $this->dialog= NULL;
456 }
458 /* Save selected users / groups */
459 if(isset($_POST['PrinterSave'])){
460 $this->dialog->save_object();
461 if(count($this->dialog->check())){
462 foreach($this->dialog->check() as $msg){
463 print_red($msg);
464 }
465 }else{
466 $data= $new = $this->dialog->save();
467 unset($data['type']);
468 foreach($data as $mem){
469 $this->AddMember($new['type'], $mem['dn']);
470 }
471 unset($this->dialog);
472 $this->dialog=NULL;
473 }
474 }
476 /* Display dialog, if there is currently one open*/
477 if($this->dialog != NULL){
478 $this->dialog->save_object();
479 $display = $this->dialog->execute();
480 return $display;
481 }
483 /* Parse selected ppd file */
484 require_once ("class_ppdManager.inc");
485 if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
487 $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
488 if(!preg_match("/\/$/",$path)){
489 $path = $path."/";
490 }
492 $ppdManager= new ppdManager($path);
493 if(!empty($this->gotoPrinterPPD)){
494 if((!file_exists($path.$this->gotoPrinterPPD))){
495 $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
496 }else{
497 $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
498 }
499 }else{
500 $smarty->assign("driverInfo", _("not defined"));
501 }
502 }else{
503 $smarty->assign("driverInfo",_("can't get ppd informations."));
504 }
506 /* Create user & admin user list */
507 $list=$this->generateList();
508 $userlist = array_merge($list['AddUser'],$list['AddGroup']);
509 $adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
511 asort($userlist);
512 asort($adminlist);
514 if($this->BelongsTo != "Printer"){
515 if($this->BelongsTo == "Terminal"){
516 $smarty->assign("desc" ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
517 }else{
518 $smarty->assign("desc" ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
519 }
520 $smarty->assign("cnACL" , $this->getacl("cn",true));
521 }else{
522 $smarty->assign("desc" ,"");
523 }
524 $smarty->assign("UserMember" ,$this->UserMember);
525 $smarty->assign("UserMembers" ,$userlist);
526 $smarty->assign("UserMemberKeys",array_flip($userlist));
528 $smarty->assign("AdminMember" ,$this->AdminMember);
529 $smarty->assign("AdminMembers" ,$adminlist);
530 $smarty->assign("AdminMemberKeys",array_flip($adminlist));
531 if($this->BelongsTo == "Printer"){
532 $smarty->assign("netconfig", $this->netConfigDNS->execute());
533 } else {
534 $smarty->assign("netconfig", "");
535 }
537 return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
538 }
540 function remove_from_parent()
541 {
542 /* Only remove if there was initially an account */
543 if($this->initially_was_account){
545 /* Update dn, to ensure storing as printer instead of WS / terminal
546 */
547 if($this->BelongsTo == "Terminal"){
548 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
549 }
551 if($this->BelongsTo == "Workstation"){
552 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
553 }
555 /* Check if this dn points to a printer, to avoid deleting something else */
556 $ldap= $this->config->get_ldap_link();
557 $ldap->cat($this->dn, array('dn',"objectClass"));
558 if(!$ldap->count()){
559 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
560 return;
561 }
563 /* Check if obejct is a printer */
564 $CheckPrinter = $ldap->fetch();
565 if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
566 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
567 return;
568 }
570 /* Remove account & dns extension */
571 $this->netConfigDNS->remove_from_parent();
572 $ldap->rmdir($this->dn);
573 show_ldap_error($ldap->get_error(), sprintf(_("Removing of system print/generic with dn '%s' failed."),$this->dn));
574 $this->handle_post_events("remove");
576 /* Delete references to object groups */
577 $ldap->cd ($this->config->current['BASE']);
578 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
579 while ($ldap->fetch()){
580 $og= new ogroup($this->config, $ldap->getDN());
581 unset($og->member[$this->dn]);
582 $og->save ();
583 }
584 }
585 }
588 /* Save data to object */
589 function save_object()
590 {
591 plugin::save_object();
593 if(is_object($this->netConfigDNS)){
594 $this->netConfigDNS->save_object();
595 }
597 /* Save base, since this is no LDAP attribute */
598 if((isset($_POST['base'])) && ($this->acl_is_moveable()) ) {
599 $this->set_acl_base('dummy,'.$_POST['base']);
600 if($this->acl_is_moveable()){
602 if(isset($this->config->idepartments[$_POST['base']])){
603 $this->base = $_POST['base'];
604 if ($_POST['base'] != $this->base){
605 $this->is_modified= TRUE;
606 }
607 }
608 }else{
610 print_red(sprintf(_("You are not allowed to move this object to '%s'."),LDAP::fix($_POST['base'])));
611 $this->set_acl_base('dummy,'.$this->base);
612 }
613 }
614 }
616 /* Check supplied data */
617 function check()
618 {
619 /* Call common method to give check the hook */
620 $message= plugin::check();
621 if ($this->BelongsTo == 'printer'){
622 $message= array_merge($message, $this->netConfigDNS->check());
623 }
625 /* Don't display check messages if this is a template object */
626 if(isset($this->parent->by_object['workgeneric'])){
627 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
628 return $message;
629 }
630 }elseif(isset($this->parent->by_object['termgeneric'])){
631 if($this->parent->by_object['termgeneric']->cn == "default"){
632 return $message;
633 }
634 }
636 $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
638 /* must: cn */
639 if(($this->BelongsTo == "Printer") && (empty($this->cn))){
640 $message[]= "The required field 'Printer name' is not set.";
641 }
643 if($this->BelongsTo == "Printer"){
644 if ($this->orig_dn == "new" && !$this->acl_is_createable()){
645 $message[]= _("You have no permissions to create a group on this 'Base'.");
646 }
647 }
649 /* must: labeledURI */
650 if(empty($this->labeledURI)){
651 $message[]= "The required field 'Printer URL' is not set.";
652 }
654 /* Check if there is already an entry with this cn*/
655 if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
656 $ldap= $this->config->get_ldap_link();
657 $ldap->cd ($this->base);
658 $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
659 if ($ldap->count() != 0){
660 while ($attrs= $ldap->fetch()){
661 if ($attrs['dn'] != $this->orig_dn){
662 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
663 break;
664 }
665 }
666 }
667 }
669 return ($message);
670 }
673 /* Save to LDAP */
674 function save()
675 {
676 /* Update dn, to ensure storing as printer instead of WS / terminal
677 */
678 if($this->BelongsTo == "Terminal"){
679 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
680 }
682 if($this->BelongsTo == "Workstation"){
683 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
684 }
686 if(!$this->is_account) return;
687 if(isset($this->parent->by_object['workgeneric'])){
688 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
689 return;
690 }
691 }elseif(isset($this->parent->by_object['termgeneric'])){
692 if($this->parent->by_object['termgeneric']->cn == "default"){
693 return;
694 }
695 }
697 /* If type is still unknown, the initialisation of this printer failed, abort. */
698 if($this->BelongsTo == "unknown"){
699 return;
700 }
702 /* save ppd configuration */
703 if($this->PPDdialogToSave){
704 $this->PPDdialogToSave->save_ppd();
705 }
707 $dn= $this->dn;
708 plugin::save();
709 $ldap= $this->config->get_ldap_link();
711 /* reduce objectClasses to minimun */
712 $this->attrs['objectClass']= $this->objectclasses;
714 /* Remove all empty values */
715 if ($this->orig_dn == 'new'){
716 $attrs= array();
717 foreach ($this->attrs as $key => $val){
718 if (is_array($val) && count($val) == 0){
719 continue;
720 }
721 $attrs[$key]= $val;
722 }
723 $this->attrs= $attrs;
724 }
726 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
727 $method="https://";
728 }else{
729 $method="http://";
730 }
732 /* If no ppd is selected, remove this attribute */
733 if(!empty($this->gotoPrinterPPD)) {
734 $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
735 }else{
736 $this->attrs['gotoPrinterPPD'] = array();
737 }
739 /* Append printer user
740 */
741 $this->attrs['gotoUserPrinter']=array();
742 foreach($this->member['AddUser'] as $mem){
743 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
744 }
746 /* Append printer group
747 */
748 $this->attrs['gotoGroupPrinter'] = array();
749 foreach($this->member['AddGroup'] as $mem){
750 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
751 }
753 /* Append printer admin user
754 */
755 $this->attrs['gotoUserAdminPrinter'] = array();
756 foreach($this->member['AddAdminUser'] as $mem){
757 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
758 }
760 /* Append printer admin group
761 */
762 $this->attrs['gotoGroupAdminPrinter']= array();
763 foreach($this->member['AddAdminGroup'] as $mem){
764 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
765 }
767 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
768 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
769 }
771 if($this->orig_dn == 'new'){
772 foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
773 if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){
774 unset($this->attrs[$checkVar]);
775 }
776 }
777 }
779 /* Move object in necessary*/
780 if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){
781 $this->move($this->orig_dn, $this->dn);
782 }
784 /* Write back to ldap */
785 $ldap= $this->config->get_ldap_link();
786 $ldap->cat($this->dn);
787 if(!$ldap->count()){
788 $ldap->cd($this->config->current['BASE']);
789 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
790 $ldap->cd($this->dn);
791 $ldap->add($this->attrs);
792 $this->handle_post_events("add");
793 } else {
794 $ldap->cd($this->dn);
795 $this->cleanup();
796 $ldap->modify ($this->attrs);
797 $this->handle_post_events("modify");
798 }
799 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
801 if($this->BelongsTo == "Printer"){
802 $this->netConfigDNS->cn = $this->cn;
803 $this->netConfigDNS->dn = $this->dn;
804 $this->netConfigDNS->save($this->dn);
805 }
807 /* Optionally execute a command after we're done */
808 $this->postcreate();
810 /* This is a multi object. Handle tagging here... */
811 $this->handle_object_tagging();
812 }
814 function generateList(){
815 $a_return=array();
816 foreach($this->member as $type => $values){
817 $a_return[$type]=array();
818 foreach($values as $value){
819 if((preg_match("/Group/i",$type))){
820 if(!isset($value['description'])){
821 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
822 }else{
823 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
824 }
825 }else{
826 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
827 }
828 }
829 }
830 return($a_return);
831 }
833 /* Return plugin informations for acl handling
834 #FIXME FAIscript seams to ununsed within this class... */
835 function plInfo()
836 {
837 return (array(
838 "plShortName" => _("Generic"),
839 "plDescription" => _("Print generic"),
840 "plSelfModify" => FALSE,
841 "plDepends" => array(),
842 "plPriority" => 0,
843 "plSection" => array("administration"),
844 "plCategory" => array("printer" => array("description" => _("Printer"),
845 "objectClass" => "gotoPrinter"),"workstation"),
846 "plProvidedAcls"=> array(
847 "cn" => _("Name"),
848 "base" => _("Base") ,
849 "description" => _("Description"),
850 "l" => _("Location"),
851 "labeledURI" => _("LabeledURL"),
852 "gotoPrinterPPD" => _("Printer PPD"),
853 "gotoUserPrinter" => _("Permissions"))
854 ));
855 }
858 /* Delete member */
859 function DelMember($type,$id)
860 {
861 /* Check if there was a printer "dn" given, or the "cn" */
862 foreach($this->member[$type] as $key => $printer){
863 if($printer['dn'] == $id) {
864 $id = $key;
865 }
866 }
868 if(!$this->acl_is_writeable("gotoUserPrinter")){
869 print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
870 return(FALSE);
871 }
873 if(isset($this->member[$type][$id])){
874 unset($this->member[$type][$id]);
875 return(TRUE);
876 }
877 return(FALSE);
878 }
881 /* Add given obejct to members */
882 function AddMember($type,$dn)
883 {
884 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
885 if(!in_array_ics($type, $types)){
886 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
887 return(FALSE);
888 }
890 if(!$this->acl_is_writeable("gotoUserPrinter")){
891 print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
892 return(FALSE);
893 }
895 /* Get name of index attributes */
896 if(preg_match("/user/i",$type)){
897 $var = "uid";
898 }else{
899 $var = "cn";
900 }
902 $ldap = $this->config->get_ldap_link();
903 $ldap->cd($dn);
904 $ldap->cat($dn,array($var));
905 if($ldap->count()){
907 $attrs = $ldap->fetch();
909 if(isset($attrs[$var][0])){
910 $name = $attrs[$var][0];
912 /* Check if this uid/cn is already assigned to any permission */
913 foreach($types as $ctype){
915 /* If we want to add a user, only check user/userAdmin members */
916 if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){
917 continue;
918 }
920 /* If we want to add a group, only check groups/adminGroups .. */
921 if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){
922 continue;
923 }
925 if(isset( $this->member[$ctype][$name])){
926 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
927 return(FALSE);
928 }
929 }
931 /* Everything is fine. So add the given object to members */
932 $this->member[$type][$attrs[$var][0]] = $attrs ;
933 }else{
934 print_a($attrs);
935 }
936 }else{
937 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
938 return(FALSE);
939 }
940 return(TRUE);
941 }
942 }
946 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
947 ?>