Code

Kolab template ready
[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();
13   /* Needed values and lists */
14   var $base= "";
15   var $cn= "";
16   var $macAddress= "";
17   var $ipHostNumber= "";
18   var $l= "";
19   var $description= "";
20   var $labeledURI= "";
21   var $gotoPrinterPPD= "";
22   var $orig_dn= "";
24   /* attribute list for save action */
25   var $attributes= array("cn", "description", "l", "labeledURI", "gotoPrinterPPD",
26                          "macAddress", "ipHostNumber");
27   var $objectclasses= array("top", "gotoPrinter");
29   function printgeneric ($config, $dn= NULL)
30   {
31     plugin::plugin ($config, $dn);
33     /* Set base */
34     if ($this->dn == "new"){
35       $ui= get_userinfo();
36       $this->base= dn2base($ui->dn);
37       $this->cn= "";
38     } else {
39       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
40     }
42     /* Save dn for later references */
43     $this->orig_dn= $this->dn;
44   }
46   function execute()
47   {
48     /* Do we need to flip is_account state? */
49     if (isset($_POST['modify_state'])){
50       $this->is_account= !$this->is_account;
51     }
53     /* Do we represent a valid printer? */
54     if (!$this->is_account && $this->parent == NULL){
55       $display= "<img src=\"images/stop.png\" align=center>&nbsp;<b>".
56         _("This 'dn' has no printer features.")."</b>";
57       return($display);
58     }
60     /* Fill templating stuff */
61     $smarty= get_smarty();
62     $smarty->assign("bases", $this->config->idepartments);
64     /* Assign attributes */
65     foreach ($this->attributes as $attr){
66       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
67       $smarty->assign("$attr", $this->$attr);
68     }
69     $smarty->assign("base_select", $this->base);
71     /* Show main page */
72     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
73     return($smarty->fetch (get_template_path('printer.tpl', TRUE)));
74   }
76   function remove_from_parent()
77   {
78     $ldap= $this->config->get_ldap_link();
79     $ldap->rmdir($this->dn);
80     show_ldap_error($ldap->get_error());
81     $this->handle_post_events("remove");
83     /* Delete references to object groups */
84     $ldap->cd ($this->config->current['BASE']);
85     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
86     while ($ldap->fetch()){
87       $og= new ogroup($this->config, $ldap->getDN());
88       unset($og->member[$this->dn]);
89       $og->save ();
90     }
92   }
95   /* Save data to object */
96   function save_object()
97   {
98     plugin::save_object();
100     /* Save base, since this is no LDAP attribute */
101     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
102       $this->base= $_POST['base'];
103     }
104   }
107   /* Check supplied data */
108   function check()
109   {
110     $message= array();
111     $this->dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
113     /* must: cn */
114     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
115       $message[]= "The required field 'Printer name' is not set.";
116     }
118     $ui= get_userinfo();
119     $acl= get_permissions ($this->dn, $ui->subtreeACL);
120     $acl= get_module_permission($acl, "printer", $this->dn);
121     if (chkacl($acl, "create") != ""){
122       $message[]= _("You have no permissions to create a printer on this 'Base'.");
123     }
125     if ($this->orig_dn != $this->dn){
126       $ldap= $this->config->get_ldap_link();
127       $ldap->cd ($this->base);
128       $ldap->search ("(cn=".$this->cn.")", array("cn"));
129       if ($ldap->count() != 0){
130         while ($attrs= $ldap->fetch()){
131           if ($attrs['dn'] != $this->orig_dn){
132             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
133             break;
134           }
135         }
136       }
137     }
139     return ($message);
140   }
143   /* Save to LDAP */
144   function save()
145   {
146     plugin::save();
148     /* Remove all empty values */
149     if ($this->orig_dn == 'new'){
150       $attrs= array();
151       foreach ($this->attrs as $key => $val){
152         if (is_array($val) && count($val) == 0){
153           continue;
154         }
155         $attrs[$key]= $val;
156       }
157       $this->attrs= $attrs;
158     }
160     /* Write back to ldap */
161     $ldap= $this->config->get_ldap_link();
162     if ($this->orig_dn == 'new'){
163       $ldap->cd($this->config->current['BASE']);
164       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
165       $ldap->cd($this->dn);
166       $ldap->add($this->attrs);
167       $this->handle_post_events("add");
168     } else {
169       if ($this->orig_dn != $this->dn){
170         $this->move($this->orig_dn, $this->dn);
171       }
173       $ldap->cd($this->dn);
174       $ldap->modify($this->attrs);
175       $this->handle_post_events("modify");
176     }
177     show_ldap_error($ldap->get_error());
179     /* Optionally execute a command after we're done */
180     $this->postcreate();
181   }
185 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
186 ?>