Code

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