Code

Removed several debug output
[gosa.git] / gosa-plugins / dfs / addons / godfs / class_dfsgeneric.inc
1 <?php
3   class dfsgeneric extends plugin {
4     /* CLI vars */
5     var $cli_summary      = "Manage terminal base objects";
6     var $cli_description  = "Some longer text\nfor help";
7     var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9     /* Needed values and lists */
10     var $base             = "";
11     var $cn               = "";
13     /* attribute list for save action */
14     var $attributes     = array();
15     var $objectclasses  = array();
17     function dfsgeneric(&$config, $dn) {
18       plugin::plugin($config, $dn);
19       $this->dn = $dn;
20       $this->orig_dn = $dn;
21     }
22  
23     function execute() {
24       /* Call parent execute */
25       plugin::execute();
26       
27       $smarty= get_smarty();
29       if (($this->dn == "new") || ($this->dn == "")) {
30         $smarty->assign("sambasharename", "");
31         $smarty->assign("sharedescription", "");
32         $smarty->assign("fileserver", "");
33         $smarty->assign("fileservershare", "");
34         $smarty->assign("location", "");
35         $smarty->assign("dfsdescription", "");
36       } else {
37         $ldap = $this->config->get_ldap_link();
39         $base = get_base_from_people($this->dn);
40         $ou = get_ou("DFS");
42         $tmp = preg_split('/\//', $this->dn, 2);
43         $this->loc = $tmp[0];
44         $this->sambasharename = $tmp[1];
46         $ldap->cd("$ou $base");
47         $ldap->search(("ou=$this->loc"), array("description"));
48         $dfs_desc = $ldap->fetch();
49         $this->dfsdescription = $dfs_desc['description'][0];
51         $ldap->cd("ou=$this->loc, $ou $base");
52         $ldap->search("(&(sambaShareName=$this->sambasharename)(objectclass=sambaShare))", array("description", "documentLocation"));
54         $details = $ldap->fetch();
55         $this->sharedescription = $details['description'][0];
56         $tmp = preg_split('/\\\\/', $details['documentLocation'][0], 2);
58         $this->fileserver = preg_replace("/msdfs:/", "", $tmp[0]);
59         $this->share = preg_replace("/\\\/", "", $tmp[1]);
60       
61         /* Fill array */
62         $smarty->assign("sambasharename", $this->sambasharename);
63         $smarty->assign("sharedescription", $this->sharedescription);
64         $smarty->assign("fileserver", $this->fileserver);
65         $smarty->assign("fileservershare", $this->share);
66         $smarty->assign("location", $this->loc);
67         $smarty->assign("dfsdescription", $this->dfsdescription);
68       }
70       /* Show main page */
71       return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
72     }
74     function check() 
75         {
76       plugin::check(); 
77       $message = array();
79       ## permission
80       #if (chkacl($this->acl, "create") != "") {
81       #  $message[] = _("You have no premissions to create a dfs share.");
82       #}
84       # existance
85       
86       $ldap = $this->config->get_ldap_link();
87       $base = get_base_from_people($this->ui->dn);
88       $ou = get_ou("DFS");
89       $dn_explode = explode("/", $this->dn);
90       $sub_ou = $dn_explode[0];
91       $sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
92       $dn = "sambaShareName=$sambaShareName,ou=$sub_ou,$ou$base";
93       $ldap->cat($dn);
94       $attrs = $ldap->fetch();
95       
96       if ($this->orig_dn == "new" && !($attrs == FALSE)) {
97         $message[] = _("Dfs share already exists.");
98       } elseif ($this->orig_dn != $this->dn && !($attrs == FALSE)) {
99         $message[] = _("Dfs share already exists.");
100       }
101       
102       if ($this->dn == "new" || $this->dn == "") {
103         $this->sambasharename = $_POST['sambaShareName'];
104         $this->sharedescription = $_POST['description'];
105         $this->fileserver = $_POST['fileserver'];
106         $this->share = $_POST['fileservershare'];
107         $this->loc = $_POST['location'];
108       }
109       
110       # required fields set?
111       if ($this->sambasharename == "") {
112         $message[] = _("Required Field \"Name of dfs Share\" is not set.");
113       }
114       if ($this->sharedescription == "") {
115         $message[] = _("Required Field \"Description\" is not set.");
116       }
117       if ($this->fileserver == "") {
118         $message[] = _("Required Field \"Fileserver\" is not set.");
119       }
120       if ($this->share == "") {
121         $message[] = _("Required Field \"Share on fileserver\" is not set.");
122       }
123       if ($this->loc == "") {
124         $message[] = _("Required Field \"Location\" is not set.");
125       }
127       return $message;
128     }
129     
130     function save() {
131       
132       plugin::save();
134       # get the current values
135       $this->sambasharename = $_POST['sambaShareName'];
136       $this->sharedescription = $_POST['description'];
137       $this->fileserver = $_POST['fileserver'];
138       $this->share = $_POST['fileservershare'];
139       $this->loc = $_POST['location'];
140           
141       # set the attribs
142       $this->attrs["sambaShareName"]   = "$this->sambasharename,ou=$this->loc,$ou$base";
143       $this->attrs["objectClass"][]    = "top";
144       $this->attrs["objectClass"][]    = "SambaShare";
145       $this->attrs["objectClass"][]    = "extensibleObject"; 
146       $this->attrs["sambaShareName"]   = $this->sambasharename;
147       $this->attrs["description"]      = $this->sharedescription;
148       $this->attrs["documentLocation"] = "msdfs:$this->fileserver\\\\$this->share";
150       $ldap = $this->config->get_ldap_link();
152       if ($this->dn == "new" || $this->dn == "") {
153         $base = get_base_from_people($this->ui->dn);
154         $ou = get_ou("DFS");
155         $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
156         $ldap->cd($this->basedn);
157         $ldap->add($this->attrs);
158       } else {
159         # try to find entry
160         $base = get_base_from_people($this->ui->dn);
161         $ou = get_ou("DFS");
162         #$dn_explode = explode("/", $this->sambasharename);
163         #$sub_ou = $dn_explode[0];
164         #$sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
165         $dn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
166         $ldap->cat($dn);
167         $attrs = $ldap->fetch();
168           
169         $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
170         $ldap->cd($this->basedn);
171         $nr = count($attrs);
172         
173         if (count($attrs)) {
174           # modify if found
175           $ldap->modify($this->attrs);
176         } else {
177           # add
178           $ldap->add($this->attrs);
179         }
180                                 show_ldap_error($ldap->get_error(), sprintf(_("Saving dfs/generic with dn '%s' failed."),$this->basedn));
181       }
182     }
184         function save_object() {
185                 plugin::save_object();
186                 $this->base = $_POST['base'];
187         }
189     function delete() {
190     
191       plugin::delete();
193       # get the current values
194       $this->sambasharename = $_POST['sambaShareName'];
195       $this->sharedescription = $_POST['description'];
196       $this->fileserver = $_POST['fileserver'];
197       $this->share = $_POST['fileservershare'];
198       $this->loc = $_POST['location'];
199           
200       $base = get_base_from_people($this->ui->dn);
201       $ou = get_ou("DFS");
202       $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
204       $ldap = $this->config->get_ldap_link();
205       $ldap->cd($this->basedn);
206       $ldap->rmdir($this->basedn);
207                         show_ldap_error($ldap->get_error(), sprintf(_("Removing dfs/generic with dn '%s' failed."),$this->basedn));
208     }
209       
210   }