a4f13c28e81329b56bf5c94a5f375c85b79e5817
1 <?php
3 /* Create a class (name must be unique inside GOsa) which extends plugin. The plugin base
4 class contains all methods that are used by GOsa and it provides the mechanism to load data
5 from LDAP to local variables and prepare the save to ldap routine for you. */
6 class dfsManagment extends plugin {
7 /* Definitions */
8 var $plHeadline = "DFS Management";
9 var $plDescription = "This does something";
11 /* These contain attributes to be loaded. We're not doing an LDAP plugin currently, so we don't
12 care... */
13 var $attributes = array();
14 var $objectclasses = array();
15 var $dfstab = NULL;
17 /* The constructor just saves a copy of the config. You may add what ever you need. */
18 function dfsManagment (&$config, &$ui) {
19 /* save config for later use */
20 $this->config = &$config;
21 $this->ui = &$ui;
23 }
25 /* Execute is the function all plugins need. It fills the plugin with life and produces the output. */
26 function execute() {
28 /* Normally you would react to user input here. */
29 plugin::execute();
31 $action = "";
32 $s_action= "";
33 $options = "";
34 $regex = "";
36 $icon = 'folder.gif';
37 $expandedIcon = 'folder-expanded.gif';
38 $base = get_base_from_people($this->ui->dn);
39 $smarty= get_smarty();
41 foreach ($_POST as $key => $val) {
42 # delete
43 if (preg_match("/dfs_del.*/", $key)) {
44 $s_action = "del";
45 $s_entry = preg_replace("/dfs_".$s_action."_/i", "", $key);
46 $s_entry = preg_replace("/_.*$/", "", $s_entry);
47 $s_entry = base64_decode($s_entry);
48 # edit
49 } elseif (preg_match("/dfs_edit.*/", $key)) {
50 $s_action = "edit";
51 $s_entry = preg_replace("/dfs_".$s_action."_/i", "", $key);
52 $s_entry = preg_replace("/_.*$/", "", $s_entry);
53 $s_entry = base64_decode($s_entry);
54 # new
55 } elseif (preg_match("/dfs_new.*/", $key)) {
56 $s_action = "new";
57 # back
58 } elseif (preg_match("/dfs_back.*/", $key)) {
59 $s_action = "back";
60 # home
61 } elseif (preg_match("/dfs_home.*/", $key)) {
62 $s_action = "home";
63 # root
64 } elseif (preg_match("/dfs_root.*/", $key)) {
65 $s_action = "root";
66 }
67 }
69 $tree = new HTML_TreeMenu();
71 if ((isset($_GET['act'])) && ($_GET['act'] == "edit_entry")) {
72 $s_action = "edit";
73 $dfs_share = $_GET['id'];
74 }
76 # new
77 if ($s_action == "new") {
78 $this->dn = "new";
79 $this->dfstab = new dfstabs($this->config, $this->config->data['TABS']['DFSTABS'], $this->dn);
80 }
82 # edit
83 if (($_SERVER['REQUEST_METHOD'] == "POST") || ($_SERVER['REQUEST_METHOD'] == "GET")) {
84 if ($s_action == "edit") {
86 $this->dn = $dfs_share;
88 if (($user = get_lock($this->dn)) != "") {
89 return (gen_locked_message ($user, $this->dn));
90 } else {
91 add_lock ($this->dn, $this->ui->dn);
92 }
94 $this->acl = get_permissions($this->dn, $this->ui->subtreeACL);
96 $this->dfstab = new dfstabs($this->config, $this->config->data['TABS']['DFSTABS'], $this->dn);
97 $this->dfstab->set_acl($this->acl);
98 $this->dfstab->save_object();
99 session::set('objectinfo',$this->dn);
100 }
101 }
103 # save pressed
104 if (isset($_POST['edit_finish'])) {
105 $this->dfstab->last = $this->dfstab->current;
106 $this->dfstab->save_object();
107 #$disp = $this->by_object[''];
108 #var_dump($disp);
110 $message = $this->dfstab->check();
112 # any errors?
113 if (count($message) == 0) {
114 # write to ldap
115 $this->dfstab->save();
116 } else {
117 msg_dialog::displayChecks($message);
118 }
119 }
121 # cancel pressed
122 if (isset($_POST['edit_cancel'])) {
123 del_lock (session::get('objectinfo'));
124 unset ($this->dfstab);
125 $this->dfstab = NULL;
126 $this->dn = "";
127 session::un_set('objectinfo');
128 }
130 # delete pressed
131 if (isset($_POST['edit_delete'])) {
133 # get the current values
134 $this->sambasharename = $_POST['sambaShareName'];
135 $this->sharedescription = $_POST['description'];
136 $this->fileserver = $_POST['fileserver'];
137 $this->share = $_POST['fileservershare'];
138 $this->loc = $_POST['location'];
140 $base = get_base_from_people($this->ui->dn);
141 $ou = get_ou("DFS");
142 $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
144 $ldap = $this->config->get_ldap_link();
145 $ldap->cd($this->basedn);
146 $ldap->rmdir($this->basedn);
147 if (!$ldap->success()){
148 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->basedn, LDAP_DEL, get_class()));
149 }
151 del_lock (session::get('objectinfo'));
152 unset ($this->dfstab);
153 $this->dfstab = NULL;
154 $this->dn = "";
155 session::un_set('objectinfo');
156 }
158 # generate main page no tabs
160 $ldap = $this->config->get_ldap_link();
162 $ou = get_ou("DFS");
164 $ldap->cd("$ou$base");
165 $ldap->search(("ou=*"), array("dn"));
167 if ($ldap->count() == 0) {
168 $message[] = _("No DFS entries found");
169 msg_dialog::displayChecks($message);
170 } else {
171 $have_tree= false;
172 while ($dfs = $ldap->fetch()) {
173 if (preg_match("/^ou=DFS.*/", $dfs["dn"])) {
174 $dfs_root_node = new HTML_TreeNode(array('text' => "DFS", 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => false));
175 $have_tree= true;
176 } elseif ($have_tree) {
177 preg_match("/^ou=(.*),/U", $dfs["dn"], $reg);
178 $loc = $reg[1];
179 $node = $dfs_root_node->addItem(new HTML_TreeNode(array('text' => "$loc", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
181 $sub_node_ldap = $this->config->get_ldap_link();
182 $sub_node_ldap->cd("ou=$loc, $ou$base");
183 $sub_node_ldap->search("(objectclass=sambaShare)", array("sambaShareName", "description", "documentLocation"));
185 while ($dfs_loc = $sub_node_ldap->fetch()) {
186 $share_name = $dfs_loc["sambaShareName"][0];
187 $desc = $dfs_loc["description"][0];
188 $srv_loc = preg_replace("/msdfs:/", "", $dfs_loc["documentLocation"][0]);
189 #$srv_loc = preg_replace("/\\/", "\\\\", $srv_loc);
190 $link = "main.php\?plug=".$_GET['plug']."\&id=$loc\/$share_name\&act=edit_entry";
191 $share_node = &$node->addItem(new HTML_TreeNode(array('text' => "$share_name - $desc", 'link' => "$link", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
192 $srv_loc_node = &$share_node->addItem(new HTML_TreeNode(array('text' => "$srv_loc", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
193 }
194 }
195 }
196 }
198 $tree->addItem($dfs_root_node);
200 // Create the presentation class
201 $treeMenu = new HTML_TreeMenu_DHTML($tree, array('images' => 'images', 'defaultClass' => 'treeMenuDefault'));
202 $tree_html = $treeMenu->toHTML();
204 if ($this->dfstab === NULL) {
206 if (($message = check_sizelimit()) != "") {
207 return ($message);
208 }
210 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
211 " <input type='image' class='center' src='images/list_up.png' align='middle' title='"._("Go up one dfsshare")."' name='dfs_back' alt='"._("Up")."'> ".
212 " <input type='image' class='center' src='images/list_root.png' align='middle' title='"._("Go to dfs root")."' name='dfs_root' alt='"._("Root")."'> ".
213 " <input class='center' type='image' src='images/dtree.png' align='middle' alt='"._("Create new dfsshare")."' name='dfs_new'> ".
214 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
215 _("Base")." <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
216 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
217 "'> </div>";
220 /* Use the smarty templating engine here... */
222 $smarty->assign('tree', $tree_html);
223 $smarty->assign('search_image', get_template_path('images/search.png'));
224 $smarty->assign('infoimage', get_template_path('images/info.png'));
225 $smarty->assign('launchimage', get_template_path('images/launch.png'));
226 $smarty->assign('alphabet', generate_alphabet());
227 $smarty->assign('hint', print_sizelimit_warning());
228 $smarty->assign('apply', apply_filter());
229 $smarty->assign('dfshead', $listhead);
231 /* Let smarty fetch and process the page. Always seperate PHP and HTML as much as
232 you can. */
233 return ($smarty->fetch (get_template_path('contents.tpl', TRUE)));
234 }
236 /* TABS */
238 $display = $this->dfstab->execute();
240 $display .= "<p>\n";
241 $display .= " <table width=100\%>\n";
242 $display .= " <tbody>\n";
243 $display .= " <tr>\n";
244 $display .= " <td style=\"text-align: right\">\n";
245 $display .= " <input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
246 $display .= " \n";
247 $display .= " <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
248 $display .= " </td>\n";
249 $display .= " </tr>\n";
250 $display .= " </tbody>\n";
251 $display .= " </table>\n";
252 $display .= "</p>\n";
254 return ($display);
256 }
258 function remove_lock() {
259 if (isset($this->dn)) {
260 del_lock ($this->dn);
261 }
262 }
264 }
265 ?>