Code

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