Code

Added inherit && default fix for Terminal startup
[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   /* attribute list for save action */
43   var $attributes     = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress",
44                                 "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
45   var $objectclasses  = array("top", "gotoPrinter");
47     var $gotoUserAdminPrinter;
48   var $gotoGroupAdminPrinter ;
49   var $gotoGroupPrinter;
50   var $gotoUserPrinter ;
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             if($ldap->count()){
136               $entry = $ldap->fetch();
137               if(isset($entry['cn'])){
138                 $this->member[$type][$entry['cn'][0]]=$entry;
139               }
140             }
141           }else{
142             $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
143             if($ldap->count()){
144               $entry = $ldap->fetch();
145               if(isset($entry['uid'])){
146                 $this->member[$type][$entry['uid'][0]]=$entry;
147               }
148             }
149           }
150         }
151       }
152     }
153   }
156   /* Detect type of printer.
157    * Printer can be stand alone, belong to a workstation or belong to a terminal. 
158    * We can detect the type printer type when comparing the tabs objects
159    */
160   function getTypeOfPrinter($UpdateAccountStatus = false)
161   {
162     /* Disable account as default
163      */  
164     $this->is_account = $this->initially_was_account = false;
166     /* Detect type of printer via parent tabs.
167      */
168     if(isset($this->parent->by_object['workgeneric'])){
170       /* Exclude templates 
171        */
172       $this->cn = $this->parent->by_object['workgeneric']->cn;
173       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
174         $this->BelongsTo = "WorkstationTemplate";
175       }else{
176         $this->BelongsTo = "Workstation";
177       }
178     }elseif(isset($this->parent->by_object['termgeneric'])){
180       /* Exclude templates 
181        */
182       $this->cn = $this->parent->by_object['termgeneric']->cn;
183       if($this->parent->by_object['termgeneric']->cn == "default"){
184         $this->BelongsTo = "TerminalTemplate";  
185       }else{
186         $this->BelongsTo = "Terminal";
187       }
188     }elseif(isset($this->parent->by_name['printgeneric'])){
189       $this->BelongsTo  = "Printer";
190     }
192     if($UpdateAccountStatus){
194       /* Set is_account / was account 
195        */
196       if($this->dn == "new"){
197         $this->initially_was_account = false;
198       }
200       /* If is printer it must be a true account.
201        */
202       if($this->BelongsTo == "Printer"){
203         $this->is_account = true;
204       }
206       /* Update dn, to ensure storing as printer instead of WS / terminal
207        */
208       if($this->BelongsTo == "Terminal"){
209         $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
210       }
212       if($this->BelongsTo == "Workstation"){
213         $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
214       }
216       /* Detect if this is a valid printer account;
217        */
218       //FIXME: do we need to do this? we've already everything we need in $this->attrs...
219       $ldap = $this->config->get_ldap_link();
220       $ldap->cat($this->dn, array('objectClass'));
222       if($ldap->count()){
223         $attrs = $ldap->fetch();
224         if(in_array("gotoPrinter",$attrs['objectClass'])){
225           $this->initially_was_account = true;
226           $this->is_account             = true;
227         }else{
228           $this->is_account = false;
229         }
230       }
231     }
232   }
234   function execute()
235   {
236     /* Call parent execute */
237     plugin::execute();
239     /* If type of printer couldn't be detected (because of missing parent object in construction) 
240      * hide this tab.
241      */
242     if($this->BelongsTo == "unknown"){
243       $display= $this->show_header(_("Add printer extension"),
244           _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
245       return($display);
246     }
248     /* Templates can't have printer extensions 
249      */
250     if($this->BelongsTo == "WorkstationTemplate"){
251       $display= $this->show_header(_("Add printer extension"),
252           _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
253       return($display);
254     }
255     if($this->BelongsTo == "TerminalTemplate"){
256       $display= $this->show_header(_("Add printer extension"),
257           _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
258       return($display);
259     }
261     /* Get cn from base object */
262     if($this->BelongsTo == "Workstation"){
263       $this->cn = $this->parent->by_object['workgeneric']->cn;
264     }
265     if($this->BelongsTo == "Terminal"){
266       $this->cn = $this->parent->by_object['termgeneric']->cn;
267     }
269     $smarty= get_smarty();
270     $display="";
272     /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
273     if($this->BelongsTo == "Printer"){    
274       $smarty->assign("StandAlone",true);
275     }else{
276       $smarty->assign("StandAlone",false);
277     }
279     /* Do we need to flip is_account state? */
280     if (isset($_POST['modify_state'])){
281       $this->is_modified = true;
282       $this->is_account= !$this->is_account;
283     }
285     /* Do we represent a valid printer? */
286     if (!$this->is_account && $this->parent == NULL){
287       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
288         _("This 'dn' has no printer features.")."</b>";
289       return($display);
290     }
292     /* If this is a WS / Terminal depending printer, display account state button */
293     if($this->BelongsTo != "Printer"){
294       if((empty($this->cn)) && ($this->dn != "new")){
295         $display= $this->show_header(_("Add printer extension"),
296             _("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);
297         $this->is_account= false;
298         return $display;
299       }
301       if (($this->is_account)){
302         if($this->BelongsTo=="Workstation"){
303           $display= $this->show_header(_("Remove printer extension"),
304               _("This workstation has printer extension enabled.You can disable it by clicking below."));
305         }elseif($this->BelongsTo=="Terminal"){
306           $display= $this->show_header(_("Remove printer extension"),
307               _("This terminal has printer extension enabled. You can disable it by clicking below."));
308         }
309       }else{
310         if($this->BelongsTo=="Workstation"){
311           $display= $this->show_header(_("Add printer extension"),
312               _("This workstation has printer extension disabled. You can enable it by clicking below."));
313         }elseif($this->BelongsTo=="Terminal"){
314           $display= $this->show_header(_("Add printer extension"),
315               _("This terminal has printer extension disabled. You can enable it by clicking below."));
316         }  
317         return ($display);
318       }
319     }
321     /* Base select dialog */
322     $once = true;
323     foreach($_POST as $name => $value){
324       if(preg_match("/^chooseBase/",$name) && $once){
325         $once = false;
326         $this->dialog = new baseSelectDialog($this->config);
327         $this->dialog->setCurrentBase($this->base);
328         $this->baseSelection = true;
329       }
330     }
332     /* Dialog handling for base select dialog
333      * Check if base was selected, dialog aborted etc */
334     if(is_object($this->dialog)){
336       $this->dialog->save_object();
337       if($this->baseSelection){
338         if($this->dialog->isClosed()){
339           $this->dialog = false;
340           $this->baseSelection = false;
341         }elseif($this->dialog->isSelected()){
342           $this->base = $this->dialog->isSelected();
343           $this->dialog= false;
344           $this->baseSelection = false;
345         }else{
346           return($this->dialog->execute());
347         }
348       }
349     }
351     /* Fill templating stuff */
352     $smarty->assign("bases", $this->config->idepartments);
353     $smarty->assign("base_select", $this->base);
355     /* Assign attributes */
356     foreach ($this->attributes as $attr){
357       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
358       $smarty->assign("$attr", $this->$attr);
359     }
361     $smarty->assign("baseACL", chkacl($this->acl,"base"));
363     if(isset($_POST['AddUser'])){
364       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
365     }
366     if(isset($_POST['AddGroup'])){
367       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
368     }
369     if(isset($_POST['AddAdminUser'])){
370       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
371     }
372     if(isset($_POST['AddAdminGroup'])){
373       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
374     }
376     /* Display ppd configure/select dialog      */
377     if(isset($_POST['EditDriver'])){
378       if($this->PPDdialogToSave){
379         $this->dialog = $this->PPDdialogToSave;
380       }else{
381         $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
382       }
383     }
385     /* remove ppd */
386     if(isset($_POST['RemoveDriver'])){
387       $this->gotoPrinterPPD = array();
388       $this->PPDdialogToSave = NULL;
389     }
391     /* Close ppd dialog */
392     if(isset($_POST['ClosePPD'])){
393       unset($this->dialog);
394       $this->dialog=NULL;
395     }
397     /* Save selected ppd */
398     if(isset($_POST['SavePPD'])){
399       $this->dialog->save_object();
400       if(count($this->dialog->check())){
401         foreach($this->dialog->check() as $msg){
402           print_red($msg);
403         }
404       }else{
405         $this->gotoPrinterPPD = array();
406         $this->gotoPrinterPPD = $this->dialog->save();
407         $this->PPDdialogToSave = $this->dialog;
408         unset($this->dialog);
409         $this->dialog=NULL;
410       }
411     }
413     /* Member management, delete user / group / admin ..*/
414     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
415       foreach($_POST['UserMember'] as $mem){
416         $this->DelMember('AddUser',$mem);
417       }
418     }
420     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
421       foreach($_POST['UserMember'] as $mem){
422         $this->DelMember('AddGroup',$mem);
423       }
424     }
426     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
427       foreach($_POST['AdminMember'] as $mem){
428         $this->DelMember('AddAdminUser',$mem);
429       }
430     }
432     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
433       foreach($_POST['AdminMember'] as $mem){
434         $this->DelMember('AddAdminGroup',$mem);
435       }
436     }
438     /* Abort user / group adding dialog */
439     if(isset($_POST['PrinterCancel'])){
440       unset($this->dialog);
441       $this->dialog= NULL;
442     }
444     /* Save selected users / groups */
445     if(isset($_POST['PrinterSave'])){
446       $this->dialog->save_object();
447       if(count($this->dialog->check())){
448         foreach($this->dialog->check() as $msg){
449           print_red($msg);
450         }
451       }else{
452         $data= $new = $this->dialog->save();
453         unset($data['type']);
454         foreach($data as $mem){  
455           $this->AddMember($new['type'], $mem['dn']);    
456         }
457         unset($this->dialog);
458         $this->dialog=NULL; 
459       }
460     }
462     /* Display dialog, if there is currently one open*/
463     if($this->dialog != NULL){
464       $this->dialog->save_object();
465       $display = $this->dialog->execute();
466       return $display;
467     }
469     /* Parse selected ppd file */
470     require_once ("class_ppdManager.inc");
471     if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
473       $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
474       if(!preg_match("/\/$/",$path)){
475         $path = $path."/";
476       }
478       $ppdManager= new ppdManager($path);
479       if(!empty($this->gotoPrinterPPD)){
480         if((!file_exists($path.$this->gotoPrinterPPD))){
481           $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
482         }else{
483           $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
484         }
485       }else{
486         $smarty->assign("driverInfo", _("not defined"));
487       }
488     }else{
489       $smarty->assign("driverInfo",_("can't get ppd informations."));
490     }
492     /* Create user & admin user list */
493     $list=$this->generateList();
494     $userlist   = array_merge($list['AddUser'],$list['AddGroup']);
495     $adminlist  = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
497     asort($userlist);
498     asort($adminlist);
500     if($this->BelongsTo != "Printer"){
501       if($this->BelongsTo == "Terminal"){
502         $smarty->assign("desc"    ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
503       }else{
504         $smarty->assign("desc"    ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
505       }
506       $smarty->assign("cnACL"    ," disabled ");
507     }else{
508       $smarty->assign("desc"    ,"");
509     }
510     $smarty->assign("UserMember"    ,$this->UserMember);
511     $smarty->assign("UserMembers"   ,$userlist);
512     $smarty->assign("UserMemberKeys",array_flip($userlist));
514     $smarty->assign("AdminMember"    ,$this->AdminMember);
515     $smarty->assign("AdminMembers"   ,$adminlist);
516     $smarty->assign("AdminMemberKeys",array_flip($adminlist));
517     if($this->BelongsTo == "Printer"){
518       $smarty->assign("netconfig", $this->netConfigDNS->execute());
519     } else {
520       $smarty->assign("netconfig", "");
521     }
523     return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
524   }
526   function remove_from_parent()
527   {
528     /* Only remove if there was initially an account */
529     if($this->initially_was_account){
531       /* Update dn, to ensure storing as printer instead of WS / terminal
532        */
533       if($this->BelongsTo == "Terminal"){
534         $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
535       }
537       if($this->BelongsTo == "Workstation"){
538         $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
539       }
541       /* Check if this dn points to a printer, to avoid deleting something else */
542       $ldap= $this->config->get_ldap_link();
543       $ldap->cat($this->dn, array('dn',"objectClass"));
544       if(!$ldap->count()){
545         print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
546         return;
547       }
549       /* Check if obejct is a printer */
550       $CheckPrinter = $ldap->fetch();
551       if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
552         print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
553         return;
554       }
556       /* Remove account & dns extension */ 
557       $this->netConfigDNS->remove_from_parent();
558       $ldap->rmdir($this->dn);
559       show_ldap_error($ldap->get_error(), _("Removing printer failed"));
560       $this->handle_post_events("remove");
562       /* Delete references to object groups */
563       $ldap->cd ($this->config->current['BASE']);
564       $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
565       while ($ldap->fetch()){
566         $og= new ogroup($this->config, $ldap->getDN());
567         unset($og->member[$this->dn]);
568         $og->save ();
569       }
570     }
571   }
574   /* Save data to object */
575   function save_object()
576   {
577     plugin::save_object();
578     $this->netConfigDNS->save_object();
579     /* Save base, since this is no LDAP attribute */
580     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
581       $this->base= $_POST['base'];
582     }
583   }
585   /* Check supplied data */
586   function check()
587   {
588     /* Call common method to give check the hook */
589     $message= plugin::check();
590     if ($this->BelongsTo == 'printer'){
591       $message= array_merge($message, $this->netConfigDNS->check());
592     }
594     /* Don't display check messages if this is a template object */
595     if(isset($this->parent->by_object['workgeneric'])){
596       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
597         return $message;
598       }
599     }elseif(isset($this->parent->by_object['termgeneric'])){
600       if($this->parent->by_object['termgeneric']->cn == "default"){
601         return $message;
602       }
603     }
605     $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
607     /* must: cn */
608     if(($this->BelongsTo == "Printer") && (empty($this->cn))){
609       $message[]= "The required field 'Printer name' is not set.";
610     }
611     
612     /* must: labeledURI */
613     if(empty($this->labeledURI)){
614       $message[]= "The required field 'Printer URL' is not set.";
615     }
616     
617     /* Check if there is already an entry with this cn*/
618     if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
619       $ldap= $this->config->get_ldap_link();
620       $ldap->cd ($this->base);
621       $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
622       if ($ldap->count() != 0){
623         while ($attrs= $ldap->fetch()){
624           if ($attrs['dn'] != $this->orig_dn){
625             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
626             break;
627           }
628         }
629       }
630     }
632     return ($message);
633   }
636   /* Save to LDAP */
637   function save()
638   {
639     /* Update dn, to ensure storing as printer instead of WS / terminal
640      */
641     if($this->BelongsTo == "Terminal"){
642       $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
643     }
645     if($this->BelongsTo == "Workstation"){
646       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
647     }
648     
649     if(!$this->is_account) return;
650     if(isset($this->parent->by_object['workgeneric'])){
651       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
652         return;
653       }
654     }elseif(isset($this->parent->by_object['termgeneric'])){
655       if($this->parent->by_object['termgeneric']->cn == "default"){
656         return;
657       }
658     }
660     /* If type is still unknown, the initialisation of this printer failed, abort. */
661     if($this->BelongsTo == "unknown"){
662       return;
663     }
665     /* save ppd configuration */
666     if($this->PPDdialogToSave){
667       $this->PPDdialogToSave->save_ppd();
668     }
670     $dn= $this->dn;
671     plugin::save();
672     $ldap= $this->config->get_ldap_link();
674     /* reduce objectClasses to minimun */
675     $this->attrs['objectClass']= $this->objectclasses;
677     /* Remove all empty values */
678     if ($this->orig_dn == 'new'){
679       $attrs= array();
680       foreach ($this->attrs as $key => $val){
681         if (is_array($val) && count($val) == 0){
682           continue;
683         }
684         $attrs[$key]= $val;
685       }
686       $this->attrs= $attrs;
687     }
689     if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
690       $method="https://";
691     }else{
692       $method="http://";
693     }
694   
695     $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
697     /* Append printer user 
698      */
699     $this->attrs['gotoUserPrinter']=array();
700     foreach($this->member['AddUser'] as $mem){
701       $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
702     }
704     /* Append printer group 
705      */
706     $this->attrs['gotoGroupPrinter'] = array();
707     foreach($this->member['AddGroup'] as $mem){
708       $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
709     }
711     /* Append printer admin user 
712      */
713     $this->attrs['gotoUserAdminPrinter'] =array();
714     foreach($this->member['AddAdminUser'] as $mem){
715       $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
716     }
718     /* Append printer admin group 
719      */
720     $this->attrs['gotoGroupAdminPrinter'] = array();
721     foreach($this->member['AddAdminGroup'] as $mem){
722       $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
723     }
725     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
726       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
727     }
729     if($this->orig_dn == 'new'){
730       foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
731         if(count($this->attrs[$checkVar])  == 0 || empty($this->attrs[$checkVar])){
732           unset($this->attrs[$checkVar]);
733         }
734       }
735     }
737     /* Write back to ldap */
738     $ldap= $this->config->get_ldap_link();
739     if ($this->orig_dn == 'new'){
740       $ldap->cd($this->config->current['BASE']);
741       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
742       $ldap->cd($this->dn);
743       $ldap->add($this->attrs);
744       $this->handle_post_events("add");
745     } else {
746       if ($this->orig_dn != $this->dn){
747         $this->move($this->orig_dn, $this->dn);
748       }
750       $ldap->cd($this->dn);
751       $this->cleanup();
752       $ldap->modify ($this->attrs); 
754       $this->handle_post_events("modify");
755     }
756     show_ldap_error($ldap->get_error(), _("Saving printer failed"));
758     $this->netConfigDNS->cn = $this->cn;
759     $this->netConfigDNS->dn = $this->dn;
760     $this->netConfigDNS->save($this->dn);
762     /* Optionally execute a command after we're done */
763     $this->postcreate();
765     /* This is a multi object. Handle tagging here... */
766     $this->handle_object_tagging();
767   }
769   function generateList(){
770     $a_return=array();
771     foreach($this->member as $type => $values){
772       $a_return[$type]=array();
773       foreach($values as $value){
774         if((preg_match("/Group/i",$type))){
775           if(!isset($value['description'])){
776             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
777           }else{
778             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
779           }
780         }else{
781           $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
782         }
783       }
784     }
785     return($a_return);
786   }
788   /* Delete member */
789   function DelMember($type,$id)
790   {
791     if(isset($this->member[$type][$id])){
792       unset($this->member[$type][$id]);
793     }
794   }
796   /* Add given obejct to members */
797   function AddMember($type,$dn)
798   {
799     $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
800     if(!in_array_ics($type, $types)){
801       print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
802       return;
803     }
805     /* Get name of index attributes */
806     if(preg_match("/user/i",$type)){
807       $var = "uid";
808     }else{
809       $var = "cn";
810     }
812     $ldap = $this->config->get_ldap_link();
813     $ldap->cd($dn);
814     $ldap->cat($dn,array("cn","uid"));
815     if($ldap->count()){
817       $attrs = $ldap->fetch();
818       $name = $attrs[$var][0];
820       /* Check if this uid/cn is already assigned to any permission */
821       foreach($types as $ctype){
822         if(isset(  $this->member[$ctype][$name])){
823           print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
824           return;
825         }
826       }
828       /* Everything is fine. So add the given object to members */
829       $this->member[$type][$attrs[$var][0]] = $attrs ;
830     }else{
831       print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
832     }
833   }
836 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
837 ?>