Code

Updated queue handling for gotomasses.
[gosa.git] / plugins / 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         #var_dump($this->dn);
62         #echo "<BR>\n";
64         /* Fill array */
65         #$this->reload();
66         $smarty->assign("sambasharename", $this->sambasharename);
67         $smarty->assign("sharedescription", $this->sharedescription);
68         $smarty->assign("fileserver", $this->fileserver);
69         $smarty->assign("fileservershare", $this->share);
70         $smarty->assign("location", $this->loc);
71         $smarty->assign("dfsdescription", $this->dfsdescription);
72       }
74       /* Show main page */
75       return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
76       #, dirname(__FILE__))));
77     }
79     function check() 
80         {
81       plugin::check(); 
82       $message = array();
84       ## permission
85       #if (chkacl($this->acl, "create") != "") {
86       #  $message[] = _("You have no premissions to create a dfs share.");
87       #}
89       # existance
90       
91       $ldap = $this->config->get_ldap_link();
92       $base = get_base_from_people($this->ui->dn);
93       $ou = get_ou("DFS");
94       $dn_explode = explode("/", $this->dn);
95       $sub_ou = $dn_explode[0];
96       $sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
97       $dn = "sambaShareName=$sambaShareName,ou=$sub_ou,$ou$base";
98       $ldap->cat($dn);
99       $attrs = $ldap->fetch();
100       
101       if ($this->orig_dn == "new" && !($attrs == FALSE)) {
102         $message[] = _("Dfs share already exists.");
103       } elseif ($this->orig_dn != $this->dn && !($attrs == FALSE)) {
104         $message[] = _("Dfs share already exists.");
105       }
106       
107       if ($this->dn == "new" || $this->dn == "") {
108         $this->sambasharename = $_POST['sambaShareName'];
109         $this->sharedescription = $_POST['description'];
110         $this->fileserver = $_POST['fileserver'];
111         $this->share = $_POST['fileservershare'];
112         $this->loc = $_POST['location'];
113       }
114       
115       # required fields set?
116       if ($this->sambasharename == "") {
117         $message[] = _("Required Field \"Name of dfs Share\" is not set.");
118       }
119       if ($this->sharedescription == "") {
120         $message[] = _("Required Field \"Description\" is not set.");
121       }
122       if ($this->fileserver == "") {
123         $message[] = _("Required Field \"Fileserver\" is not set.");
124       }
125       if ($this->share == "") {
126         $message[] = _("Required Field \"Share on fileserver\" is not set.");
127       }
128       if ($this->loc == "") {
129         $message[] = _("Required Field \"Location\" is not set.");
130       }
132       return $message;
133     }
134     
135     function save() {
136       
137       plugin::save();
139       # get the current values
140       $this->sambasharename = $_POST['sambaShareName'];
141       $this->sharedescription = $_POST['description'];
142       $this->fileserver = $_POST['fileserver'];
143       $this->share = $_POST['fileservershare'];
144       $this->loc = $_POST['location'];
145           
146       # set the attribs
147       $this->attrs["sambaShareName"]   = "$this->sambasharename,ou=$this->loc,$ou$base";
148       $this->attrs["objectClass"][]    = "top";
149       $this->attrs["objectClass"][]    = "SambaShare";
150       $this->attrs["objectClass"][]    = "extensibleObject"; 
151       $this->attrs["sambaShareName"]   = $this->sambasharename;
152       $this->attrs["description"]      = $this->sharedescription;
153       $this->attrs["documentLocation"] = "msdfs:$this->fileserver\\\\$this->share";
155       $ldap = $this->config->get_ldap_link();
157       if ($this->dn == "new" || $this->dn == "") {
158         echo "new<br>\n";
159         $base = get_base_from_people($this->ui->dn);
160         $ou = get_ou("DFS");
161         $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
162         $ldap->cd($this->basedn);
163         $ldap->add($this->attrs);
164       } else {
165         # try to find entry
166         $base = get_base_from_people($this->ui->dn);
167         $ou = get_ou("DFS");
168         #$dn_explode = explode("/", $this->sambasharename);
169         #$sub_ou = $dn_explode[0];
170         #$sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
171         $dn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
172         $ldap->cat($dn);
173         $attrs = $ldap->fetch();
174           
175         $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
176         $ldap->cd($this->basedn);
177         $nr = count($attrs);
178         
179         if (count($attrs)) {
180           # modify if found
181           $ldap->modify($this->attrs);
182         } else {
183           # add
184           $ldap->add($this->attrs);
185         }
186                                 show_ldap_error($ldap->get_error(), sprintf(_("Saving dfs/generic with dn '%s' failed."),$this->basedn));
187       }
188     }
190     function save_object() {
191       #if (isset($_POST['base'])) {
192         plugin::save_object();
193         #echo "base = ".$_POST['base']."<br>\n";
194       #}
195       if (chkacl($this->acl, "create") == "") {
196         $this->base = $_POST['base'];
197       }
198     }
200     function delete() {
201     
202       plugin::delete();
204       # get the current values
205       $this->sambasharename = $_POST['sambaShareName'];
206       $this->sharedescription = $_POST['description'];
207       $this->fileserver = $_POST['fileserver'];
208       $this->share = $_POST['fileservershare'];
209       $this->loc = $_POST['location'];
210           
211       $base = get_base_from_people($this->ui->dn);
212       $ou = get_ou("DFS");
213       $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
214       echo "BASEDN: $this->basedn<br>\n";
216       $ldap = $this->config->get_ldap_link();
217       $ldap->cd($this->basedn);
218       $ldap->rmdir($this->basedn);
219                         show_ldap_error($ldap->get_error(), sprintf(_("Removing dfs/generic with dn '%s' failed."),$this->basedn));
220     }
221       
222   }