Code

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