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