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);
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 }
153 function set_acl_base($base)
154 {
155 plugin::set_acl_base($base);
156 if(is_object($this->netConfigDNS)){
157 $this->netConfigDNS->set_acl_base($base);
158 }
159 }
161 function set_acl_category($cat)
162 {
163 plugin::set_acl_category($cat);
164 if(is_object($this->netConfigDNS)){
165 $this->netConfigDNS->set_acl_category($cat);
166 }
167 }
169 /* Detect type of printer.
170 * Printer can be stand alone, belong to a workstation or belong to a terminal.
171 * We can detect the type printer type when comparing the tabs objects
172 */
173 function getTypeOfPrinter($UpdateAccountStatus = false)
174 {
175 /* Disable account as default
176 */
177 $this->is_account = $this->initially_was_account = false;
179 /* Detect type of printer via parent tabs.
180 */
182 $class = get_class($this->parent);
183 if(isset($this->parent->by_object['workgeneric'])){
185 /* Exclude templates
186 */
187 $this->cn = $this->parent->by_object['workgeneric']->cn;
188 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
189 $this->BelongsTo = "WorkstationTemplate";
190 }else{
191 $this->BelongsTo = "Workstation";
192 }
193 }elseif(isset($this->parent->by_object['termgeneric'])){
195 /* Exclude templates
196 */
197 $this->cn = $this->parent->by_object['termgeneric']->cn;
198 if($this->parent->by_object['termgeneric']->cn == "default"){
199 $this->BelongsTo = "TerminalTemplate";
200 }else{
201 $this->BelongsTo = "Terminal";
202 }
203 }elseif(isset($this->parent->by_name['printgeneric'])){
204 $this->BelongsTo = "Printer";
205 }
207 if($UpdateAccountStatus){
209 /* Set is_account / was account
210 */
211 if($this->dn == "new"){
212 $this->initially_was_account = false;
213 }
215 /* If is printer it must be a true account.
216 */
217 if($this->BelongsTo == "Printer"){
218 $this->is_account = true;
219 }
221 /* Update dn, to ensure storing as printer instead of WS / terminal
222 */
223 if($this->BelongsTo == "Terminal"){
224 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
225 }
227 if($this->BelongsTo == "Workstation"){
228 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
229 }
231 /* Detect if this is a valid printer account;
232 */
233 $ldap = $this->config->get_ldap_link();
234 $ldap->cat($this->dn, array('objectClass'));
236 if($ldap->count()){
237 $attrs = $ldap->fetch();
238 if(in_array("gotoPrinter",$attrs['objectClass'])){
239 $this->initially_was_account = true;
240 $this->is_account = true;
241 }else{
242 $this->is_account = false;
243 }
244 }
245 }
246 }
248 function execute()
249 {
250 /* Call parent execute */
251 plugin::execute();
253 /* If type of printer couldn't be detected (because of missing parent object in construction)
254 * hide this tab.
255 */
256 if($this->BelongsTo == "unknown"){
257 $display= $this->show_enable_header(_("Add printer extension"),
258 _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
259 return($display);
260 }
262 /* Templates can't have printer extensions
263 */
264 if($this->BelongsTo == "WorkstationTemplate"){
265 $display= $this->show_enable_header(_("Add printer extension"),
266 _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
267 return($display);
268 }
269 if($this->BelongsTo == "TerminalTemplate"){
270 $display= $this->show_enable_header(_("Add printer extension"),
271 _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
272 return($display);
273 }
275 /* Get cn from base object */
276 if($this->BelongsTo == "Workstation"){
277 $this->cn = $this->parent->by_object['workgeneric']->cn;
278 }
279 if($this->BelongsTo == "Terminal"){
280 $this->cn = $this->parent->by_object['termgeneric']->cn;
281 }
283 $smarty= get_smarty();
285 /* Assign acls */
286 $tmp = $this->plInfo();
287 foreach($tmp['plProvidedAcls'] as $name => $translation){
288 $smarty->assign($name."ACL", $this->getacl($name));
289 }
291 /* Create base acls */
292 $baseACL = $this->getacl("base");
293 if(!$this->acl_is_moveable()) {
294 $baseACL = preg_replace("/w/","",$baseACL);
295 }
296 $smarty->assign("baseACL", $baseACL);
299 $display="";
301 /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
302 if($this->BelongsTo == "Printer"){
303 $smarty->assign("StandAlone",true);
304 }else{
305 $smarty->assign("StandAlone",false);
306 }
308 /* Do we need to flip is_account state? */
309 if(isset($_POST['modify_state'])){
310 if($this->is_account && $this->acl_is_removeable()){
311 $this->is_account= FALSE;
312 }elseif(!$this->is_account && $this->acl_is_createable()){
313 $this->is_account= TRUE;
314 }
315 }
317 /* Do we represent a valid printer? */
318 if (!$this->is_account && $this->parent == NULL){
319 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
320 _("This 'dn' has no printer features.")."</b>";
321 return($display);
322 }
324 /* If this is a WS / Terminal depending printer, display account state button */
325 if($this->BelongsTo != "Printer"){
326 if((empty($this->cn)) && ($this->dn != "new")){
327 $display= $this->show_enable_header(_("Add printer extension"),
328 _("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);
329 $this->is_account= false;
330 return $display;
331 }
333 if (($this->is_account)){
334 if($this->BelongsTo=="Workstation"){
335 $display= $this->show_disable_header(_("Remove printer extension"),
336 _("This workstation has printer extension enabled.You can disable it by clicking below."));
337 }elseif($this->BelongsTo=="Terminal"){
338 $display= $this->show_disable_header(_("Remove printer extension"),
339 _("This terminal has printer extension enabled. You can disable it by clicking below."));
340 }
341 }else{
342 if($this->BelongsTo=="Workstation"){
343 $display= $this->show_disable_header(_("Add printer extension"),
344 _("This workstation has printer extension disabled. You can enable it by clicking below."));
345 }elseif($this->BelongsTo=="Terminal"){
346 $display= $this->show_enable_header(_("Add printer extension"),
347 _("This terminal has printer extension disabled. You can enable it by clicking below."));
348 }
349 return ($display);
350 }
351 }
353 /* Base select dialog */
354 $once = true;
355 foreach($_POST as $name => $value){
356 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_moveable()){
357 $once = false;
358 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
359 $this->dialog->setCurrentBase($this->base);
360 $this->baseSelection = true;
361 }
362 }
364 /* Dialog handling for base select dialog
365 * Check if base was selected, dialog aborted etc */
366 if(is_object($this->dialog)){
368 $this->dialog->save_object();
369 if($this->baseSelection){
370 if($this->dialog->isClosed()){
371 $this->dialog = false;
372 $this->baseSelection = false;
373 }elseif($this->dialog->isSelected()){
374 $this->base = $this->dialog->isSelected();
375 $this->dialog= false;
376 $this->baseSelection = false;
377 }else{
378 return($this->dialog->execute());
379 }
380 }
381 }
383 /* Fill templating stuff */
384 $smarty->assign("bases", $this->get_allowed_bases());
385 $smarty->assign("base_select", $this->base);
387 /* Assign attributes */
388 foreach ($this->attributes as $attr){
389 $smarty->assign("$attr", $this->$attr);
390 }
392 if(isset($_POST['AddUser'])){
393 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
394 }
395 if(isset($_POST['AddGroup'])){
396 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
397 }
398 if(isset($_POST['AddAdminUser'])){
399 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
400 }
401 if(isset($_POST['AddAdminGroup'])){
402 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
403 }
405 /* Display ppd configure/select dialog */
406 if(isset($_POST['EditDriver'])){
407 if($this->PPDdialogToSave){
408 $this->dialog = $this->PPDdialogToSave;
409 }else{
410 $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
411 }
412 }
414 /* remove ppd */
415 if(isset($_POST['RemoveDriver'])){
416 $this->gotoPrinterPPD = array();
417 $this->PPDdialogToSave = NULL;
418 }
420 /* Close ppd dialog */
421 if(isset($_POST['ClosePPD'])){
422 unset($this->dialog);
423 $this->dialog=NULL;
424 }
426 /* Save selected ppd */
427 if(isset($_POST['SavePPD'])){
428 $this->dialog->save_object();
429 if(count($this->dialog->check())){
430 foreach($this->dialog->check() as $msg){
431 print_red($msg);
432 }
433 }else{
434 $this->gotoPrinterPPD = array();
435 $this->gotoPrinterPPD = $this->dialog->save();
436 $this->PPDdialogToSave = $this->dialog;
437 unset($this->dialog);
438 $this->dialog=NULL;
439 }
440 }
442 /* Member management, delete user / group / admin ..*/
443 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
444 foreach($_POST['UserMember'] as $mem){
445 $this->DelMember('AddUser',$mem);
446 }
447 }
449 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
450 foreach($_POST['UserMember'] as $mem){
451 $this->DelMember('AddGroup',$mem);
452 }
453 }
455 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
456 foreach($_POST['AdminMember'] as $mem){
457 $this->DelMember('AddAdminUser',$mem);
458 }
459 }
461 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
462 foreach($_POST['AdminMember'] as $mem){
463 $this->DelMember('AddAdminGroup',$mem);
464 }
465 }
467 /* Abort user / group adding dialog */
468 if(isset($_POST['PrinterCancel'])){
469 unset($this->dialog);
470 $this->dialog= NULL;
471 }
473 /* Save selected users / groups */
474 if(isset($_POST['PrinterSave'])){
475 $this->dialog->save_object();
476 if(count($this->dialog->check())){
477 foreach($this->dialog->check() as $msg){
478 print_red($msg);
479 }
480 }else{
481 $data= $new = $this->dialog->save();
482 unset($data['type']);
483 foreach($data as $mem){
484 $this->AddMember($new['type'], $mem['dn']);
485 }
486 unset($this->dialog);
487 $this->dialog=NULL;
488 }
489 }
491 /* Display dialog, if there is currently one open*/
492 if($this->dialog != NULL){
493 $this->dialog->save_object();
494 $display = $this->dialog->execute();
495 return $display;
496 }
498 /* Parse selected ppd file */
499 require_once ("class_ppdManager.inc");
500 if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
502 $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
503 if(!preg_match("/\/$/",$path)){
504 $path = $path."/";
505 }
507 $ppdManager= new ppdManager($path);
508 if(!empty($this->gotoPrinterPPD)){
509 if((!file_exists($path.$this->gotoPrinterPPD))){
510 $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
511 }else{
512 $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
513 }
514 }else{
515 $smarty->assign("driverInfo", _("not defined"));
516 }
517 }else{
518 $smarty->assign("driverInfo",_("can't get ppd informations."));
519 }
521 /* Create user & admin user list */
522 $list=$this->generateList();
523 $userlist = array_merge($list['AddUser'],$list['AddGroup']);
524 $adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
526 asort($userlist);
527 asort($adminlist);
529 if($this->BelongsTo != "Printer"){
530 if($this->BelongsTo == "Terminal"){
531 $smarty->assign("desc" ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
532 }else{
533 $smarty->assign("desc" ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
534 }
535 $smarty->assign("cnACL" , $this->getacl("cn",true));
536 }else{
537 $smarty->assign("desc" ,"");
538 }
539 $smarty->assign("UserMember" ,$this->UserMember);
540 $smarty->assign("UserMembers" ,$userlist);
541 $smarty->assign("UserMemberKeys",array_flip($userlist));
543 $smarty->assign("AdminMember" ,$this->AdminMember);
544 $smarty->assign("AdminMembers" ,$adminlist);
545 $smarty->assign("AdminMemberKeys",array_flip($adminlist));
546 if($this->BelongsTo == "Printer"){
547 $smarty->assign("netconfig", $this->netConfigDNS->execute());
548 } else {
549 $smarty->assign("netconfig", "");
550 }
552 return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
553 }
555 function remove_from_parent()
556 {
557 /* Only remove if there was initially an account */
558 if($this->initially_was_account){
560 /* Update dn, to ensure storing as printer instead of WS / terminal
561 */
562 if($this->BelongsTo == "Terminal"){
563 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
564 }
566 if($this->BelongsTo == "Workstation"){
567 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
568 }
570 /* Check if this dn points to a printer, to avoid deleting something else */
571 $ldap= $this->config->get_ldap_link();
572 $ldap->cat($this->dn, array('dn',"objectClass"));
573 if(!$ldap->count()){
574 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
575 return;
576 }
578 /* Check if obejct is a printer */
579 $CheckPrinter = $ldap->fetch();
580 if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
581 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
582 return;
583 }
585 /* Remove account & dns extension */
586 $this->netConfigDNS->remove_from_parent();
587 $ldap->rmdir($this->dn);
588 show_ldap_error($ldap->get_error(), sprintf(_("Removing of system print/generic with dn '%s' failed."),$this->dn));
589 $this->handle_post_events("remove");
591 /* Delete references to object groups */
592 $ldap->cd ($this->config->current['BASE']);
593 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
594 while ($ldap->fetch()){
595 $og= new ogroup($this->config, $ldap->getDN());
596 unset($og->member[$this->dn]);
597 $og->save ();
598 }
599 }
600 }
603 /* Save data to object */
604 function save_object()
605 {
606 plugin::save_object();
608 if(is_object($this->netConfigDNS)){
609 $this->netConfigDNS->save_object();
610 }
612 /* Save base, since this is no LDAP attribute */
613 if((isset($_POST['base'])) && ($this->acl_is_moveable()) ) {
614 $this->set_acl_base('dummy,'.$_POST['base']);
615 if($this->acl_is_moveable()){
617 if(isset($this->config->idepartments[$_POST['base']])){
618 $this->base = $_POST['base'];
619 if ($_POST['base'] != $this->base){
620 $this->is_modified= TRUE;
621 }
622 }
623 }else{
625 print_red(sprintf(_("You are not allowed to move this object to '%s'."),LDAP::fix($_POST['base'])));
626 $this->set_acl_base('dummy,'.$this->base);
627 }
628 }
629 }
631 /* Check supplied data */
632 function check()
633 {
634 /* Call common method to give check the hook */
635 $message= plugin::check();
636 if ($this->BelongsTo == 'printer'){
637 $message= array_merge($message, $this->netConfigDNS->check());
638 }
640 /* Don't display check messages if this is a template object */
641 if(isset($this->parent->by_object['workgeneric'])){
642 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
643 return $message;
644 }
645 }elseif(isset($this->parent->by_object['termgeneric'])){
646 if($this->parent->by_object['termgeneric']->cn == "default"){
647 return $message;
648 }
649 }
651 $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
653 /* must: cn */
654 if(($this->BelongsTo == "Printer") && (empty($this->cn))){
655 $message[]= "The required field 'Printer name' is not set.";
656 }
658 /* Set new acl base */
659 if($this->dn == "new") {
660 $this->set_acl_base($this->base);
661 }
663 if($this->BelongsTo == "Printer"){
664 if ($this->orig_dn == "new" && !$this->acl_is_createable()){
665 $message[]= _("You have no permissions to create a group on this 'Base'.");
666 }
667 }
669 /* must: labeledURI */
670 if(empty($this->labeledURI)){
671 $message[]= "The required field 'Printer URL' is not set.";
672 }
674 /* Check if there is already an entry with this cn*/
675 if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
676 $ldap= $this->config->get_ldap_link();
677 $ldap->cd ($this->base);
678 $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
679 if ($ldap->count() != 0){
680 while ($attrs= $ldap->fetch()){
681 if ($attrs['dn'] != $this->orig_dn){
682 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
683 break;
684 }
685 }
686 }
687 }
689 return ($message);
690 }
693 /* Save to LDAP */
694 function save()
695 {
696 /* Update dn, to ensure storing as printer instead of WS / terminal
697 */
698 if($this->BelongsTo == "Terminal"){
699 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
700 }
702 if($this->BelongsTo == "Workstation"){
703 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
704 }
706 if(!$this->is_account) return;
707 if(isset($this->parent->by_object['workgeneric'])){
708 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
709 return;
710 }
711 }elseif(isset($this->parent->by_object['termgeneric'])){
712 if($this->parent->by_object['termgeneric']->cn == "default"){
713 return;
714 }
715 }
717 /* If type is still unknown, the initialisation of this printer failed, abort. */
718 if($this->BelongsTo == "unknown"){
719 return;
720 }
722 /* save ppd configuration */
723 if($this->PPDdialogToSave){
724 $this->PPDdialogToSave->save_ppd();
725 }
727 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
728 $method="https://";
729 }else{
730 $method="http://";
731 }
733 /* If no ppd is selected, remove this attribute */
734 if(!empty($this->gotoPrinterPPD)) {
735 $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
736 }else{
737 $this->gotoPrinterPPD = array();
738 }
740 $dn= $this->dn;
741 plugin::save();
742 $ldap= $this->config->get_ldap_link();
744 /* reduce objectClasses to minimun */
745 $this->attrs['objectClass']= $this->objectclasses;
747 /* Remove all empty values */
748 if ($this->orig_dn == 'new'){
749 $attrs= array();
750 foreach ($this->attrs as $key => $val){
751 if (is_array($val) && count($val) == 0){
752 continue;
753 }
754 $attrs[$key]= $val;
755 }
756 $this->attrs= $attrs;
757 }
759 /* Append printer user
760 */
761 $this->attrs['gotoUserPrinter']=array();
762 foreach($this->member['AddUser'] as $mem){
763 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
764 }
766 /* Append printer group
767 */
768 $this->attrs['gotoGroupPrinter'] = array();
769 foreach($this->member['AddGroup'] as $mem){
770 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
771 }
773 /* Append printer admin user
774 */
775 $this->attrs['gotoUserAdminPrinter'] = array();
776 foreach($this->member['AddAdminUser'] as $mem){
777 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
778 }
780 /* Append printer admin group
781 */
782 $this->attrs['gotoGroupAdminPrinter']= array();
783 foreach($this->member['AddAdminGroup'] as $mem){
784 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
785 }
787 if($this->orig_dn == 'new'){
788 foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
789 if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){
790 unset($this->attrs[$checkVar]);
791 }
792 }
793 }else{
794 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
795 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
796 }
797 }
799 /* Move object in necessary*/
800 if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){
801 $this->move($this->orig_dn, $this->dn);
802 }
804 /* Write back to ldap */
805 $ldap= $this->config->get_ldap_link();
806 $ldap->cat($this->dn);
807 if(!$ldap->count()){
808 $ldap->cd($this->config->current['BASE']);
809 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
810 $ldap->cd($this->dn);
811 $ldap->add($this->attrs);
812 $this->handle_post_events("add");
813 } else {
814 $ldap->cd($this->dn);
815 $this->cleanup();
816 $ldap->modify ($this->attrs);
817 $this->handle_post_events("modify");
818 }
819 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
821 if($this->BelongsTo == "Printer"){
822 $this->netConfigDNS->cn = $this->cn;
823 $this->netConfigDNS->dn = $this->dn;
824 $this->netConfigDNS->save($this->dn);
825 }
827 /* Optionally execute a command after we're done */
828 $this->postcreate();
830 /* This is a multi object. Handle tagging here... */
831 $this->handle_object_tagging();
832 }
834 function generateList(){
835 $a_return=array();
837 foreach($this->member as $type => $values){
838 $a_return[$type]=array();
839 foreach($values as $value){
840 if((preg_match("/Group/i",$type))){
841 if(!isset($value['description'])){
842 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
843 }else{
844 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
845 }
846 }else{
847 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
848 }
849 }
850 }
851 return($a_return);
852 }
854 /* Return plugin informations for acl handling
855 #FIXME FAIscript seams to ununsed within this class... */
856 function plInfo()
857 {
858 return (array(
859 "plShortName" => _("Generic"),
860 "plDescription" => _("Print generic"),
861 "plSelfModify" => FALSE,
862 "plDepends" => array(),
863 "plPriority" => 11,
864 "plSection" => array("administration"),
865 "plCategory" => array("printer" => array("description" => _("Printer"),
866 "objectClass" => "gotoPrinter"),"workstation","terminal"),
867 "plProvidedAcls"=> array(
868 "cn" => _("Name"),
869 "base" => _("Base") ,
870 "description" => _("Description"),
871 "l" => _("Location"),
872 "labeledURI" => _("LabeledURL"),
873 "gotoPrinterPPD" => _("Printer PPD"),
874 "gotoUserPrinter" => _("Permissions"))
875 ));
876 }
879 /* Delete member */
880 function DelMember($type,$id)
881 {
882 /* Check if there was a printer "dn" given, or the "cn" */
883 foreach($this->member[$type] as $key => $printer){
884 if($printer['dn'] == $id) {
885 $id = $key;
886 }
887 }
889 if(!$this->acl_is_writeable("gotoUserPrinter")){
890 print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
891 return(FALSE);
892 }
894 if(isset($this->member[$type][$id])){
895 unset($this->member[$type][$id]);
896 return(TRUE);
897 }
898 return(FALSE);
899 }
902 /* Add given obejct to members */
903 function AddMember($type,$dn)
904 {
905 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
906 if(!in_array_ics($type, $types)){
907 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
908 return(FALSE);
909 }
911 if(!$this->acl_is_writeable("gotoUserPrinter")){
912 print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
913 return(FALSE);
914 }
916 /* Get name of index attributes */
917 if(preg_match("/user/i",$type)){
918 $var = "uid";
919 }else{
920 $var = "cn";
921 }
923 $ldap = $this->config->get_ldap_link();
924 $ldap->cd($dn);
925 $ldap->cat($dn,array($var,"cn"));
926 if($ldap->count()){
928 $attrs = $ldap->fetch();
930 if(isset($attrs[$var][0])){
931 $name = $attrs[$var][0];
933 /* Check if this uid/cn is already assigned to any permission */
934 foreach($types as $ctype){
936 /* If we want to add a user, only check user/userAdmin members */
937 if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){
938 continue;
939 }
941 /* If we want to add a group, only check groups/adminGroups .. */
942 if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){
943 continue;
944 }
946 if(isset( $this->member[$ctype][$name])){
947 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
948 return(FALSE);
949 }
950 }
952 /* Everything is fine. So add the given object to members */
953 $this->member[$type][$attrs[$var][0]] = $attrs ;
954 }else{
955 print_a($attrs);
956 }
957 }else{
958 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
959 return(FALSE);
960 }
961 return(TRUE);
962 }
963 }
967 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
968 ?>