Code

Fixed problem with empty attributes when creating a new printer extension
[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   function printgeneric ($config, $dn= NULL,$parent = NULL)
53   {
54     $this->config = $config;
55     $this->dn = $dn; 
56     
57     /* If parent was posted(the tabs object) we can detect the printer type. */
58     if($parent){
59       $this->parent = $parent;
60       $this->getTypeOfPrinter();
61     }else{
62       $this->BelongsTo = "unknown";
63       return;
64     }
66     /* Update dn, to ensure storing as printer instead of WS / terminal */
67     if($this->BelongsTo == "Terminal"){
68       $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
69     }
71     if($this->BelongsTo == "Workstation"){
72       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
73     }
75     $this->orig_dn = $this->dn;
77     /* Get printer settings, possibly dn has changed */
78     plugin::plugin ($config, $this->dn);
80     /* Get is_account initially_was_account status */
81     $this->getTypeOfPrinter(true);
83     /* set orig dn to new if object is new */
84     $ldap= $this->config->get_ldap_link();
85     $ldap->cat($this->dn, array('dn'));
86     if(!$ldap->count()){
87       $this->orig_dn = "new";
88     }
89     
90     /* create dns object */
91     $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
93     /* Set base */
94     if ($this->dn == "new"){
95       $ui= get_userinfo();
96       $this->base= dn2base($ui->dn);
97       $this->cn= "";
98     } else {
99     
100       /* Set base and check if the extracted base exists */
101       if(preg_match("/ou=incoming,/",$this->dn)){
102         $this->base= preg_replace("/ou=incoming,/","",dn2base($this->dn));
103       }else{
104         $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
105       }
107       if(!isset($this->config->idepartments[$this->base])){
108         print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),$_SESSION['CurrentMainBase']);
109         $this->base = $_SESSION['CurrentMainBase'];
110       }
111     }
113     /* Extract selected ppd */
114     if(isset($this->gotoPrinterPPD)){
115       $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
116     }
118     /* Prepare different member types */ 
119     foreach(array("AddUser"       =>"gotoUserPrinter",
120           "AddGroup"      =>"gotoGroupPrinter",
121           "AddAdminUser"  =>"gotoUserAdminPrinter",
122           "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){
124       /* $this->members contains all members */
125       $this->member[$type]=array();
127       if (isset($this->attrs[$attr]['count'])) {
128         unset($this->attrs[$attr]['count']);
129       }
131       if(isset($this->attrs[$attr])){
132         foreach($this->attrs[$attr] as $mem){
133           if(preg_match("/Group/",$type)){
134             $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
135             $entry = $ldap->fetch();
136             $this->member[$type][$entry['cn'][0]]=$entry;
137           }else{
138             $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
139             $entry = $ldap->fetch();
140             if(isset($entry['uid'])){
141               $this->member[$type][$entry['uid'][0]]=$entry;
142             }
143           }
144         }
145       }
146     }
147   }
150   /* Detect type of printer.
151    * Printer can be stand alone, belong to a workstation or belong to a terminal. 
152    * We can detect the type printer type when comparing the tabs objects
153    */
154   function getTypeOfPrinter($UpdateAccountStatus = false)
155   {
156     /* Disable account as default
157      */  
158     $this->is_account = $this->initially_was_account = false;
160     /* Detect type of printer via parent tabs.
161      */
162     if(isset($this->parent->by_object['workgeneric'])){
164       /* Exclude templates 
165        */
166       $this->cn = $this->parent->by_object['workgeneric']->cn;
167       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
168         $this->BelongsTo = "WorkstationTemplate";
169       }else{
170         $this->BelongsTo = "Workstation";
171       }
172     }elseif(isset($this->parent->by_object['termgeneric'])){
174       /* Exclude templates 
175        */
176       $this->cn = $this->parent->by_object['termgeneric']->cn;
177       if($this->parent->by_object['termgeneric']->cn == "default"){
178         $this->BelongsTo = "TerminalTemplate";  
179       }else{
180         $this->BelongsTo = "Terminal";
181       }
182     }elseif(isset($this->parent->by_name['printgeneric'])){
183       $this->BelongsTo  = "Printer";
184     }
186     if($UpdateAccountStatus){
188       /* Set is_account / was account 
189        */
190       if($this->dn == "new"){
191         $this->initially_was_account = false;
192       }
194       /* If is printer it must be a true account.
195        */
196       if($this->BelongsTo == "Printer"){
197         $this->is_account = true;
198       }
200       /* Update dn, to ensure storing as printer instead of WS / terminal
201        */
202       if($this->BelongsTo == "Terminal"){
203         $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
204       }
206       if($this->BelongsTo == "Workstation"){
207         $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
208       }
210       /* Detect if this is a valid printer account;
211        */
212       //FIXME: do we need to do this? we've already everything we need in $this->attrs...
213       $ldap = $this->config->get_ldap_link();
214       $ldap->cat($this->dn, array('objectClass'));
216       if($ldap->count()){
217         $attrs = $ldap->fetch();
218         if(in_array("gotoPrinter",$attrs['objectClass'])){
219           $this->initially_was_account = true;
220           $this->is_account             = true;
221         }else{
222           $this->is_account = false;
223         }
224       }
225     }
226   }
228   function execute()
229   {
230     /* Call parent execute */
231     plugin::execute();
233     /* If type of printer couldn't be detected (because of missing parent object in construction) 
234      * hide this tab.
235      */
236     if($this->BelongsTo == "unknown"){
237       $display= $this->show_enable_header(_("Add printer extension"),
238           _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
239       return($display);
240     }
242     /* Templates can't have printer extensions 
243      */
244     if($this->BelongsTo == "WorkstationTemplate"){
245       $display= $this->show_enable_header(_("Add printer extension"),
246           _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
247       return($display);
248     }
249     if($this->BelongsTo == "TerminalTemplate"){
250       $display= $this->show_enable_header(_("Add printer extension"),
251           _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
252       return($display);
253     }
255     /* Get cn from base object */
256     if($this->BelongsTo == "Workstation"){
257       $this->cn = $this->parent->by_object['workgeneric']->cn;
258     }
259     if($this->BelongsTo == "Terminal"){
260       $this->cn = $this->parent->by_object['termgeneric']->cn;
261     }
263     $smarty= get_smarty();
264     $display="";
266     /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
267     if($this->BelongsTo == "Printer"){    
268       $smarty->assign("StandAlone",true);
269     }else{
270       $smarty->assign("StandAlone",false);
271     }
273     /* Do we need to flip is_account state? */
274     if (isset($_POST['modify_state'])){
275       $this->is_modified = true;
276       $this->is_account= !$this->is_account;
277     }
279     /* Do we represent a valid printer? */
280     if (!$this->is_account && $this->parent == NULL){
281       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
282         _("This 'dn' has no printer features.")."</b>";
283       return($display);
284     }
286     /* If this is a WS / Terminal depending printer, display account state button */
287     if($this->BelongsTo != "Printer"){
288       if((empty($this->cn)) && ($this->dn != "new")){
289         $display= $this->show_enable_header(_("Add printer extension"),
290             _("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);
291         $this->is_account= false;
292         return $display;
293       }
295       if (($this->is_account)){
296         if($this->BelongsTo=="Workstation"){
297           $display= $this->show_disable_header(_("Remove printer extension"),
298               _("This workstation has printer extension enabled.You can disable it by clicking below."));
299         }elseif($this->BelongsTo=="Terminal"){
300           $display= $this->show_disable_header(_("Remove printer extension"),
301               _("This terminal has printer extension enabled. You can disable it by clicking below."));
302         }
303       }else{
304         if($this->BelongsTo=="Workstation"){
305           $display= $this->show_disable_header(_("Add printer extension"),
306               _("This workstation has printer extension disabled. You can enable it by clicking below."));
307         }elseif($this->BelongsTo=="Terminal"){
308           $display= $this->show_enable_header(_("Add printer extension"),
309               _("This terminal has printer extension disabled. You can enable it by clicking below."));
310         }  
311         return ($display);
312       }
313     }
315     /* Base select dialog */
316     $once = true;
317     foreach($_POST as $name => $value){
318       if(preg_match("/^chooseBase/",$name) && $once){
319         $once = false;
320         $this->dialog = new baseSelectDialog($this->config,$this);
321         $this->dialog->setCurrentBase($this->base);
322         $this->baseSelection = true;
323       }
324     }
326     /* Dialog handling for base select dialog
327      * Check if base was selected, dialog aborted etc */
328     if(is_object($this->dialog)){
330       $this->dialog->save_object();
331       if($this->baseSelection){
332         if($this->dialog->isClosed()){
333           $this->dialog = false;
334           $this->baseSelection = false;
335         }elseif($this->dialog->isSelected()){
336           $this->base = $this->dialog->isSelected();
337           $this->dialog= false;
338           $this->baseSelection = false;
339         }else{
340           return($this->dialog->execute());
341         }
342       }
343     }
345     /* Fill templating stuff */
346     $smarty->assign("bases", $this->config->idepartments);
347     $smarty->assign("base_select", $this->base);
349     /* Assign attributes */
350     foreach ($this->attributes as $attr){
351       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
352       $smarty->assign("$attr", $this->$attr);
353     }
355     $smarty->assign("baseACL", chkacl($this->acl,"base"));
357     if(isset($_POST['AddUser'])){
358       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
359     }
360     if(isset($_POST['AddGroup'])){
361       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
362     }
363     if(isset($_POST['AddAdminUser'])){
364       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
365     }
366     if(isset($_POST['AddAdminGroup'])){
367       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
368     }
370     /* Display ppd configure/select dialog      */
371     if(isset($_POST['EditDriver'])){
372       if($this->PPDdialogToSave){
373         $this->dialog = $this->PPDdialogToSave;
374       }else{
375         $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
376       }
377     }
379     /* remove ppd */
380     if(isset($_POST['RemoveDriver'])){
381       $this->gotoPrinterPPD = array();
382       $this->PPDdialogToSave = NULL;
383     }
385     /* Close ppd dialog */
386     if(isset($_POST['ClosePPD'])){
387       unset($this->dialog);
388       $this->dialog=NULL;
389     }
391     /* Save selected ppd */
392     if(isset($_POST['SavePPD'])){
393       $this->dialog->save_object();
394       if(count($this->dialog->check())){
395         foreach($this->dialog->check() as $msg){
396           print_red($msg);
397         }
398       }else{
399         $this->gotoPrinterPPD = array();
400         $this->gotoPrinterPPD = $this->dialog->save();
401         $this->PPDdialogToSave = $this->dialog;
402         unset($this->dialog);
403         $this->dialog=NULL;
404       }
405     }
407      /* Member management, delete user / group / admin ..*/
408     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
409       foreach($_POST['UserMember'] as $mem){
410         $this->DelMember('AddUser',$mem);
411       }
412     }
414     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
415       foreach($_POST['UserMember'] as $mem){
416         $this->DelMember('AddGroup',$mem);
417       }
418     }
420     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
421       foreach($_POST['AdminMember'] as $mem){
422         $this->DelMember('AddAdminUser',$mem);
423       }
424     }
426     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
427       foreach($_POST['AdminMember'] as $mem){
428         $this->DelMember('AddAdminGroup',$mem);
429       }
430     }
432     /* Abort user / group adding dialog */
433     if(isset($_POST['PrinterCancel'])){
434       unset($this->dialog);
435       $this->dialog= NULL;
436     }
438     /* Save selected users / groups */
439     if(isset($_POST['PrinterSave'])){
440       $this->dialog->save_object();
441       if(count($this->dialog->check())){
442         foreach($this->dialog->check() as $msg){
443           print_red($msg);
444         }
445       }else{
446         $data= $new = $this->dialog->save();
447         unset($data['type']);
448         foreach($data as $mem){
449           $this->AddMember($new['type'], $mem['dn']);
450         }
451         unset($this->dialog);
452         $this->dialog=NULL;
453       }
454     }
456     /* Display dialog, if there is currently one open*/
457     if($this->dialog != NULL){
458       $this->dialog->save_object();
459       $display = $this->dialog->execute();
460       return $display;
461     }
463     /* Parse selected ppd file */
464     require_once ("class_ppdManager.inc");
465     if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
467       $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
468       if(!preg_match("/\/$/",$path)){
469         $path = $path."/";
470       }
472       $ppdManager= new ppdManager($path);
473       if(!empty($this->gotoPrinterPPD)){
474         if((!file_exists($path.$this->gotoPrinterPPD))){
475           $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
476         }else{
477           $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
478         }
479       }else{
480         $smarty->assign("driverInfo", _("not defined"));
481       }
482     }else{
483       $smarty->assign("driverInfo",_("can't get ppd informations."));
484     }
486     /* Create user & admin user list */
487     $list=$this->generateList();
488     $userlist   = array_merge($list['AddUser'],$list['AddGroup']);
489     $adminlist  = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
491     asort($userlist);
492     asort($adminlist);
494     if($this->BelongsTo != "Printer"){
495       if($this->BelongsTo == "Terminal"){
496         $smarty->assign("desc"    ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
497       }else{
498         $smarty->assign("desc"    ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
499       }
500       $smarty->assign("cnACL"    ," disabled ");
501     }else{
502       $smarty->assign("desc"    ,"");
503     }
504     $smarty->assign("UserMember"    ,$this->UserMember);
505     $smarty->assign("UserMembers"   ,$userlist);
506     $smarty->assign("UserMemberKeys",array_flip($userlist));
508     $smarty->assign("AdminMember"    ,$this->AdminMember);
509     $smarty->assign("AdminMembers"   ,$adminlist);
510     $smarty->assign("AdminMemberKeys",array_flip($adminlist));
511     if($this->BelongsTo == "Printer"){
512       $smarty->assign("netconfig", $this->netConfigDNS->execute());
513     } else {
514       $smarty->assign("netconfig", "");
515     }
517     return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
518   }
520   function remove_from_parent()
521   {
522     /* Only remove if there was initially an account */
523     if($this->initially_was_account){
525       /* Update dn, to ensure storing as printer instead of WS / terminal
526        */
527       if($this->BelongsTo == "Terminal"){
528         $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
529       }
531       if($this->BelongsTo == "Workstation"){
532         $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
533       }
535       /* Check if this dn points to a printer, to avoid deleting something else */
536       $ldap= $this->config->get_ldap_link();
537       $ldap->cat($this->dn, array('dn',"objectClass"));
538       if(!$ldap->count()){
539         print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
540         return;
541       }
543       /* Check if obejct is a printer */
544       $CheckPrinter = $ldap->fetch();
545       if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
546         print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
547         return;
548       }
550       /* Remove account & dns extension */ 
551       $this->netConfigDNS->remove_from_parent();
552       $ldap->rmdir($this->dn);
553       show_ldap_error($ldap->get_error(), sprintf(_("Removing of system print/generic with dn '%s' failed."),$this->dn));
554       $this->handle_post_events("remove");
556       /* Delete references to object groups */
557       $ldap->cd ($this->config->current['BASE']);
558       $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
559       while ($ldap->fetch()){
560         $og= new ogroup($this->config, $ldap->getDN());
561         unset($og->member[$this->dn]);
562         $og->save ();
563       }
564     }
565   }
568   /* Save data to object */
569   function save_object()
570   {
571     plugin::save_object();
572     $this->netConfigDNS->save_object();
573     /* Save base, since this is no LDAP attribute */
574     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
575       $this->base= $_POST['base'];
576     }
577   }
579   /* Check supplied data */
580   function check()
581   {
582     /* Call common method to give check the hook */
583     $message= plugin::check();
584     if ($this->BelongsTo == 'printer'){
585       $message= array_merge($message, $this->netConfigDNS->check());
586     }
588     /* Don't display check messages if this is a template object */
589     if(isset($this->parent->by_object['workgeneric'])){
590       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
591         return $message;
592       }
593     }elseif(isset($this->parent->by_object['termgeneric'])){
594       if($this->parent->by_object['termgeneric']->cn == "default"){
595         return $message;
596       }
597     }
599     $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
601     /* must: cn */
602     if(($this->BelongsTo == "Printer") && (empty($this->cn))){
603       $message[]= "The required field 'Printer name' is not set.";
604     }
605     
606     /* must: labeledURI */
607     if(empty($this->labeledURI)){
608       $message[]= "The required field 'Printer URL' is not set.";
609     }
610     
611     /* Check if there is already an entry with this cn*/
612     if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
613       $ldap= $this->config->get_ldap_link();
614       $ldap->cd ($this->base);
615       $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
616       if ($ldap->count() != 0){
617         while ($attrs= $ldap->fetch()){
618           if ($attrs['dn'] != $this->orig_dn){
619             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
620             break;
621           }
622         }
623       }
624     }
626     return ($message);
627   }
630   /* Save to LDAP */
631   function save()
632   {
633     /* Update dn, to ensure storing as printer instead of WS / terminal
634      */
635     if($this->BelongsTo == "Terminal"){
636       $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
637     }
639     if($this->BelongsTo == "Workstation"){
640       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
641     }
642     
643     if(!$this->is_account) return;
644     if(isset($this->parent->by_object['workgeneric'])){
645       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
646         return;
647       }
648     }elseif(isset($this->parent->by_object['termgeneric'])){
649       if($this->parent->by_object['termgeneric']->cn == "default"){
650         return;
651       }
652     }
654     /* If type is still unknown, the initialisation of this printer failed, abort. */
655     if($this->BelongsTo == "unknown"){
656       return;
657     }
659     /* save ppd configuration */
660     if($this->PPDdialogToSave){
661       $this->PPDdialogToSave->save_ppd();
662     }
664     $dn= $this->dn;
665     plugin::save();
666     $ldap= $this->config->get_ldap_link();
668     /* reduce objectClasses to minimun */
669     $this->attrs['objectClass']= $this->objectclasses;
671     /* Remove all empty values */
672     if ($this->orig_dn == 'new'){
673       $attrs= array();
674       foreach ($this->attrs as $key => $val){
675         if (is_array($val) && count($val) == 0){
676           continue;
677         }
678         $attrs[$key]= $val;
679       }
680       $this->attrs= $attrs;
681     }
683     if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
684       $method="https://";
685     }else{
686       $method="http://";
687     }
688  
689     $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
691     /* Append printer user 
692      */
693     $this->attrs['gotoUserPrinter']=array();
694     foreach($this->member['AddUser'] as $mem){
695       $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
696     }
698     /* Append printer group 
699      */
700     $this->attrs['gotoGroupPrinter'] = array();
701     foreach($this->member['AddGroup'] as $mem){
702       $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
703     }
705     /* Append printer admin user 
706      */
707     $this->attrs['gotoUserAdminPrinter'] = array();
708     foreach($this->member['AddAdminUser'] as $mem){
709       $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
710     }
712     /* Append printer admin group 
713      */
714     $this->attrs['gotoGroupAdminPrinter']= array();
715     foreach($this->member['AddAdminGroup'] as $mem){
716       $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
717     }
719     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
720       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
721     }
723     if($this->orig_dn == 'new'){
724       foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
725         if(count($this->attrs[$checkVar])  == 0 || empty($this->attrs[$checkVar])){
726           unset($this->attrs[$checkVar]);
727         }
728       }
729     }
731     /* Write back to ldap */
732     $ldap= $this->config->get_ldap_link();
733     if ($this->orig_dn == 'new'){
734       $ldap->cd($this->config->current['BASE']);
735       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
736       $ldap->cd($this->dn);
737       $ldap->add($this->attrs);
738       $this->handle_post_events("add");
739     } else {
740       if ($this->orig_dn != $this->dn){
741         $this->move($this->orig_dn, $this->dn);
742       }
744       $ldap->cd($this->dn);
745       $this->cleanup();
746       $ldap->modify ($this->attrs); 
748       $this->handle_post_events("modify");
749     }
750     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
752     if($this->BelongsTo == "Printer"){
753       $this->netConfigDNS->cn = $this->cn;
754       $this->netConfigDNS->dn = $this->dn;
755       $this->netConfigDNS->save($this->dn);
756     }
758     /* Optionally execute a command after we're done */
759     $this->postcreate();
760   }
762   function generateList(){
763     $a_return=array();
764     foreach($this->member as $type => $values){
765       $a_return[$type]=array();
766       foreach($values as $value){
767         if((preg_match("/Group/i",$type))){
768           if(!isset($value['description'])){
769             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
770           }else{
771             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
772           }
773         }else{
774           $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
775         }
776       }
777     }
778     return($a_return);
779   }
781   /* Return plugin informations for acl handling
782       #FIXME FAIscript seams to ununsed within this class... */
783   function plInfo()
784   {
785     return (array(
786           "plShortName"   => _("Generic"),
787           "plDescription" => _("Print generic"),
788           "plSelfModify"  => FALSE,
789           "plDepends"     => array(),
790           "plPriority"    => 0,
791           "plSection"     => array("administration"),
792           "plCategory"    => array("printer" => array("description"  => _("Printer"),
793                                                     "objectClass"  => "gotoPrinter")),
794           "plProvidedAcls"=> array(
795             "cn"                => _("Name"), 
796             "description"       => _("Description"), 
797             "l"                 => _("Location"), 
798             "labeledURI"        => _("LabeledURL"), 
799             "gotoPrinterPPD"    => _("Printer PPD"),
800             "gotoUserPrinter"   => _("Permissions")) 
801           ));
802   }
805   /* Delete member */
806   function DelMember($type,$id)
807   {
808     /* Check if there was a printer "dn" given, or the "cn" */
809     foreach($this->member[$type] as $key => $printer){
810       if($printer['dn'] == $id) {
811         $id = key;
812       }
813     }
814     
815     if(!$this->acl_is_writeable($type)){
816       print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
817       return(FALSE);
818     }
819   
820     if(isset($this->member[$type][$id])){
821       unset($this->member[$type][$id]);
822       return(TRUE);
823     }
824     return(FALSE);
825   }
828   /* Add given obejct to members */
829   function AddMember($type,$dn)
830   {
831     $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
832     if(!in_array_ics($type, $types)){
833       print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
834       return(FALSE);
835     }
837     if(!$this->acl_is_writeable($type)){
838       print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
839       return(FALSE);
840     }
842     /* Get name of index attributes */
843     if(preg_match("/user/i",$type)){
844       $var = "uid";
845     }else{
846       $var = "cn";
847     }
849     $ldap = $this->config->get_ldap_link();
850     $ldap->cd($dn);
851     $ldap->cat($dn,array("cn","uid"));
852     if($ldap->count()){
854       $attrs = $ldap->fetch();
855       $name = $attrs[$var][0];
856   
857       /* Check if this uid/cn is already assigned to any permission */
858       foreach($types as $ctype){
859         if(isset(  $this->member[$ctype][$name])){
860           print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
861           return(FALSE);
862         }
863       }
865       /* Everything is fine. So add the given object to members */
866       $this->member[$type][$attrs[$var][0]] = $attrs ;
867     }else{
868       print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
869       return(FALSE);
870     }
871     return(TRUE);
872   }
877 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
878 ?>