Code

6eab07bde2be7764d117a66b45feeefd886f1404
[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);
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     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>&nbsp;<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();
607     
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     if($this->BelongsTo == "Printer"){
659       if ($this->orig_dn == "new" && !$this->acl_is_createable()){
660         $message[]= _("You have no permissions to create a group on this 'Base'.");
661       }
662     }
663     
664     /* must: labeledURI */
665     if(empty($this->labeledURI)){
666       $message[]= "The required field 'Printer URL' is not set.";
667     }
668     
669     /* Check if there is already an entry with this cn*/
670     if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
671       $ldap= $this->config->get_ldap_link();
672       $ldap->cd ($this->base);
673       $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
674       if ($ldap->count() != 0){
675         while ($attrs= $ldap->fetch()){
676           if ($attrs['dn'] != $this->orig_dn){
677             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
678             break;
679           }
680         }
681       }
682     }
684     return ($message);
685   }
688   /* Save to LDAP */
689   function save()
690   {
691     /* Update dn, to ensure storing as printer instead of WS / terminal
692      */
693     if($this->BelongsTo == "Terminal"){
694       $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
695     }
697     if($this->BelongsTo == "Workstation"){
698       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
699     }
700     
701     if(!$this->is_account) return;
702     if(isset($this->parent->by_object['workgeneric'])){
703       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
704         return;
705       }
706     }elseif(isset($this->parent->by_object['termgeneric'])){
707       if($this->parent->by_object['termgeneric']->cn == "default"){
708         return;
709       }
710     }
712     /* If type is still unknown, the initialisation of this printer failed, abort. */
713     if($this->BelongsTo == "unknown"){
714       return;
715     }
717     /* save ppd configuration */
718     if($this->PPDdialogToSave){
719       $this->PPDdialogToSave->save_ppd();
720     }
722     if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
723       $method="https://";
724     }else{
725       $method="http://";
726     }
728     /* If no ppd is selected, remove this attribute */
729     if(!empty($this->gotoPrinterPPD)) {
730       $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
731     }else{
732       $this->gotoPrinterPPD = array();
733     }
735     $dn= $this->dn;
736     plugin::save();
737     $ldap= $this->config->get_ldap_link();
739     /* reduce objectClasses to minimun */
740     $this->attrs['objectClass']= $this->objectclasses;
742     /* Remove all empty values */
743     if ($this->orig_dn == 'new'){
744       $attrs= array();
745       foreach ($this->attrs as $key => $val){
746         if (is_array($val) && count($val) == 0){
747           continue;
748         }
749         $attrs[$key]= $val;
750       }
751       $this->attrs= $attrs;
752     }
754     /* Append printer user 
755      */
756     $this->attrs['gotoUserPrinter']=array();
757     foreach($this->member['AddUser'] as $mem){
758       $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
759     }
761     /* Append printer group 
762      */
763     $this->attrs['gotoGroupPrinter'] = array();
764     foreach($this->member['AddGroup'] as $mem){
765       $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
766     }
768     /* Append printer admin user 
769      */
770     $this->attrs['gotoUserAdminPrinter'] = array();
771     foreach($this->member['AddAdminUser'] as $mem){
772       $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
773     }
775     /* Append printer admin group 
776      */
777     $this->attrs['gotoGroupAdminPrinter']= array();
778     foreach($this->member['AddAdminGroup'] as $mem){
779       $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
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     }else{
789       if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
790         $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
791       }
792     }
794     /* Move object in necessary*/
795     if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){
796       $this->move($this->orig_dn, $this->dn);
797     }
799     /* Write back to ldap */
800     $ldap= $this->config->get_ldap_link();
801     $ldap->cat($this->dn);
802     if(!$ldap->count()){
803       $ldap->cd($this->config->current['BASE']);
804       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
805       $ldap->cd($this->dn);
806       $ldap->add($this->attrs);
807       $this->handle_post_events("add");
808     } else {
809       $ldap->cd($this->dn);
810       $this->cleanup();
811       $ldap->modify ($this->attrs); 
812       $this->handle_post_events("modify");
813     }
814     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
816     if($this->BelongsTo == "Printer"){
817       $this->netConfigDNS->cn = $this->cn;
818       $this->netConfigDNS->dn = $this->dn;
819       $this->netConfigDNS->save($this->dn);
820     }
822     /* Optionally execute a command after we're done */
823     $this->postcreate();
825     /* This is a multi object. Handle tagging here... */
826     $this->handle_object_tagging();
827   }
829   function generateList(){
830     $a_return=array();
832     foreach($this->member as $type => $values){
833       $a_return[$type]=array();
834       foreach($values as $value){
835         if((preg_match("/Group/i",$type))){
836           if(!isset($value['description'])){
837             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
838           }else{
839             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
840           }
841         }else{
842           $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
843         }
844       }
845     }
846     return($a_return);
847   }
849   /* Return plugin informations for acl handling
850       #FIXME FAIscript seams to ununsed within this class... */
851   function plInfo()
852   {
853     return (array(
854           "plShortName"   => _("Generic"),
855           "plDescription" => _("Print generic"),
856           "plSelfModify"  => FALSE,
857           "plDepends"     => array(),
858           "plPriority"    => 11,
859           "plSection"     => array("administration"),
860           "plCategory"    => array("printer" => array("description"  => _("Printer"),
861                                                     "objectClass"  => "gotoPrinter"),"workstation","terminal"),
862           "plProvidedAcls"=> array(
863             "cn"                => _("Name"),
864             "base"                => _("Base") ,         
865             "description"       => _("Description"), 
866             "l"                 => _("Location"), 
867             "labeledURI"        => _("LabeledURL"), 
868             "gotoPrinterPPD"    => _("Printer PPD"),
869             "gotoUserPrinter"   => _("Permissions")) 
870           ));
871   }
874   /* Delete member */
875   function DelMember($type,$id)
876   {
877     /* Check if there was a printer "dn" given, or the "cn" */
878     foreach($this->member[$type] as $key => $printer){
879       if($printer['dn'] == $id) {
880         $id = $key;
881       }
882     }
883   
884     if(!$this->acl_is_writeable("gotoUserPrinter")){
885       print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
886       return(FALSE);
887     }
888  
889     if(isset($this->member[$type][$id])){
890       unset($this->member[$type][$id]);
891       return(TRUE);
892     }
893     return(FALSE);
894   }
897   /* Add given obejct to members */
898   function AddMember($type,$dn)
899   {
900     $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
901     if(!in_array_ics($type, $types)){
902       print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
903       return(FALSE);
904     }
906     if(!$this->acl_is_writeable("gotoUserPrinter")){
907       print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
908       return(FALSE);
909     }
911     /* Get name of index attributes */
912     if(preg_match("/user/i",$type)){
913       $var = "uid";
914     }else{
915       $var = "cn";
916     }
918     $ldap = $this->config->get_ldap_link();
919     $ldap->cd($dn);
920     $ldap->cat($dn,array($var,"cn"));
921     if($ldap->count()){
923       $attrs = $ldap->fetch();
925       if(isset($attrs[$var][0])){
926         $name = $attrs[$var][0];
928         /* Check if this uid/cn is already assigned to any permission */
929         foreach($types as $ctype){
931           /* If we want to add a user, only check user/userAdmin members */
932           if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){
933             continue;
934           }
936           /* If we want to add a group, only check groups/adminGroups .. */
937           if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){
938             continue;
939           }
941           if(isset(  $this->member[$ctype][$name])){
942             print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
943             return(FALSE);
944           }
945         }
947         /* Everything is fine. So add the given object to members */
948         $this->member[$type][$attrs[$var][0]] = $attrs ;
949       }else{
950         print_a($attrs);
951       }
952     }else{
953       print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
954       return(FALSE);
955     }
956     return(TRUE);
957   }
962 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
963 ?>