Code

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