Code

Removed show_ldap_error() calls
[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       $ldap = $this->config->get_ldap_link();
76       $base = get_base_from_people($this->ui->dn);
77       $ou = get_ou("DFS");
78       $dn_explode = explode("/", $this->dn);
79       $sub_ou = $dn_explode[0];
80       $sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
81       $dn = "sambaShareName=$sambaShareName,ou=$sub_ou,$ou$base";
82       $ldap->cat($dn);
83       $attrs = $ldap->fetch();
84       
85       if ($this->orig_dn == "new" && !($attrs == FALSE)) {
86                 $message[] = msgPool::duplicated("Dfs Share");
87       } elseif ($this->orig_dn != $this->dn && !($attrs == FALSE)) {
88                 $message[] = msgPool::duplicated("Dfs Share");
89       }
90       
91       if ($this->dn == "new" || $this->dn == "") {
92         $this->sambasharename = $_POST['sambaShareName'];
93         $this->sharedescription = $_POST['description'];
94         $this->fileserver = $_POST['fileserver'];
95         $this->share = $_POST['fileservershare'];
96         $this->loc = $_POST['location'];
97       }
98       
99       # required fields set?
100       if ($this->sambasharename == "") {
101                 $message[] = msgPool::required("Name");
102       }
103       if ($this->sharedescription == "") {
104                 $message[] = msgPool::required("Description");
105       }
106       if ($this->fileserver == "") {
107                 $message[] = msgPool::required("Fileserver");
108       }
109       if ($this->share == "") {
110                 $message[] = msgPool::required("Share");
111       }
112       if ($this->loc == "") {
113                 $message[] = msgPool::required("Location");
114       }
116       return $message;
117     }
118     
119     function save() {
120       
121       plugin::save();
123       # get the current values
124       $this->sambasharename = $_POST['sambaShareName'];
125       $this->sharedescription = $_POST['description'];
126       $this->fileserver = $_POST['fileserver'];
127       $this->share = $_POST['fileservershare'];
128       $this->loc = $_POST['location'];
129           
130       # set the attribs
131       $this->attrs["sambaShareName"]   = "$this->sambasharename,ou=$this->loc,$ou$base";
132       $this->attrs["objectClass"][]    = "top";
133       $this->attrs["objectClass"][]    = "SambaShare";
134       $this->attrs["objectClass"][]    = "extensibleObject"; 
135       $this->attrs["sambaShareName"]   = $this->sambasharename;
136       $this->attrs["description"]      = $this->sharedescription;
137       $this->attrs["documentLocation"] = "msdfs:$this->fileserver\\\\$this->share";
139       $ldap = $this->config->get_ldap_link();
141       if ($this->dn == "new" || $this->dn == "") {
142         $base = get_base_from_people($this->ui->dn);
143         $ou = get_ou("DFS");
144         $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
145         $ldap->cd($this->basedn);
146         $ldap->add($this->attrs);
147       } else {
148         # try to find entry
149         $base = get_base_from_people($this->ui->dn);
150         $ou = get_ou("DFS");
151         #$dn_explode = explode("/", $this->sambasharename);
152         #$sub_ou = $dn_explode[0];
153         #$sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
154         $dn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
155         $ldap->cat($dn);
156         $attrs = $ldap->fetch();
157           
158         $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
159         $ldap->cd($this->basedn);
160         $nr = count($attrs);
161         
162         if (count($attrs)) {
163           # modify if found
164           $ldap->modify($this->attrs);
165         } else {
166           # add
167           $ldap->add($this->attrs);
168         }
170         if (!$ldap->success()){
171                 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
172         }
173       }
174     }
176         function save_object() {
177                 plugin::save_object();
178                 $this->base = $_POST['base'];
179         }
181     function delete() {
182     
183       plugin::delete();
185       # get the current values
186       $this->sambasharename = $_POST['sambaShareName'];
187       $this->sharedescription = $_POST['description'];
188       $this->fileserver = $_POST['fileserver'];
189       $this->share = $_POST['fileservershare'];
190       $this->loc = $_POST['location'];
191           
192       $base = get_base_from_people($this->ui->dn);
193       $ou = get_ou("DFS");
194       $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
196       $ldap = $this->config->get_ldap_link();
197       $ldap->cd($this->basedn);
198       $ldap->rmdir($this->basedn);
199       if (!$ldap->success()){
200               msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->basedn, LDAP_DEL, get_class()));
201       }
202     }
203       
204   }