c816cc23489838c5fefd84be915953b839b7db4f
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> <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 /* Show main page */
73 $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
74 return($smarty->fetch (get_template_path('printer.tpl', TRUE)));
75 }
77 function remove_from_parent()
78 {
79 $ldap= $this->config->get_ldap_link();
80 $ldap->rmdir($this->dn);
81 show_ldap_error($ldap->get_error());
82 $this->handle_post_events("remove");
84 /* Delete references to object groups */
85 $ldap->cd ($this->config->current['BASE']);
86 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
87 while ($ldap->fetch()){
88 $og= new ogroup($this->config, $ldap->getDN());
89 unset($og->member[$this->dn]);
90 $og->save ();
91 }
93 }
96 /* Save data to object */
97 function save_object()
98 {
99 plugin::save_object();
101 /* Save base, since this is no LDAP attribute */
102 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
103 $this->base= $_POST['base'];
104 }
105 }
108 /* Check supplied data */
109 function check()
110 {
111 $message= array();
112 $this->dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
114 /* must: cn */
115 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
116 $message[]= "The required field 'Printer name' is not set.";
117 }
119 $ui= get_userinfo();
120 $acl= get_permissions ($this->dn, $ui->subtreeACL);
121 $acl= get_module_permission($acl, "printer", $this->dn);
122 if (chkacl($acl, "create") != ""){
123 $message[]= _("You have no permissions to create a printer on this 'Base'.");
124 }
126 if ($this->orig_dn != $this->dn){
127 $ldap= $this->config->get_ldap_link();
128 $ldap->cd ($this->base);
129 $ldap->search ("(cn=".$this->cn.")", array("cn"));
130 if ($ldap->count() != 0){
131 while ($attrs= $ldap->fetch()){
132 if ($attrs['dn'] != $this->orig_dn){
133 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
134 break;
135 }
136 }
137 }
138 }
140 return ($message);
141 }
144 /* Save to LDAP */
145 function save()
146 {
147 plugin::save();
149 /* Remove all empty values */
150 if ($this->orig_dn == 'new'){
151 $attrs= array();
152 foreach ($this->attrs as $key => $val){
153 if (is_array($val) && count($val) == 0){
154 continue;
155 }
156 $attrs[$key]= $val;
157 }
158 $this->attrs= $attrs;
159 }
161 /* Write back to ldap */
162 $ldap= $this->config->get_ldap_link();
163 if ($this->orig_dn == 'new'){
164 $ldap->cd($this->config->current['BASE']);
165 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
166 $ldap->cd($this->dn);
167 $ldap->add($this->attrs);
168 $this->handle_post_events("add");
169 } else {
170 if ($this->orig_dn != $this->dn){
171 $this->move($this->orig_dn, $this->dn);
172 }
174 $ldap->cd($this->dn);
175 $ldap->modify($this->attrs);
176 $this->handle_post_events("modify");
177 }
178 show_ldap_error($ldap->get_error());
180 /* Optionally execute a command after we're done */
181 $this->postcreate();
182 }
184 }
186 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
187 ?>