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 Managment";
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['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 show_errors($message);
118 }
119 }
121 # cancel pressed
122 if (isset($_POST['edit_cancel'])) {
123 del_lock ($_SESSION['objectinfo']);
124 unset ($this->dfstab);
125 $this->dfstab = NULL;
126 $this->dn = "";
127 unset($_SESSION['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 show_ldap_error($ldap->get_error(), sprintf(_("Removing of DFS share with dn '%s' failed."),$this->dn));
149 del_lock ($_SESSION['objectinfo']);
150 unset ($this->dfstab);
151 $this->dfstab = NULL;
152 $this->dn = "";
153 unset($_SESSION['objectinfo']);
154 }
156 # generate main page no tabs
158 $ldap = $this->config->get_ldap_link();
160 $ou = get_ou("DFS");
162 $ldap->cd("$ou$base");
163 $ldap->search(("ou=*"), array("dn"));
165 if ($ldap->count() == 0) {
166 $message[] = _("No DFS entries found");
167 show_errors ($message);
168 } else {
169 $have_tree= false;
170 while ($dfs = $ldap->fetch()) {
171 if (preg_match("/^ou=DFS.*/", $dfs["dn"])) {
172 $dfs_root_node = new HTML_TreeNode(array('text' => "DFS", 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => false));
173 $have_tree= true;
174 } elseif ($have_tree) {
175 preg_match("/^ou=(.*),/U", $dfs["dn"], $reg);
176 $loc = $reg[1];
177 $node = $dfs_root_node->addItem(new HTML_TreeNode(array('text' => "$loc", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
179 $sub_node_ldap = $this->config->get_ldap_link();
180 $sub_node_ldap->cd("ou=$loc, $ou$base");
181 $sub_node_ldap->search("(objectclass=sambaShare)", array("sambaShareName", "description", "documentLocation"));
183 while ($dfs_loc = $sub_node_ldap->fetch()) {
184 $share_name = $dfs_loc["sambaShareName"][0];
185 $desc = $dfs_loc["description"][0];
186 $srv_loc = preg_replace("/msdfs:/", "", $dfs_loc["documentLocation"][0]);
187 #$srv_loc = preg_replace("/\\/", "\\\\", $srv_loc);
188 $link = "main.php\?plug=".$_GET['plug']."\&id=$loc\/$share_name\&act=edit_entry";
189 $share_node = &$node->addItem(new HTML_TreeNode(array('text' => "$share_name - $desc", 'link' => "$link", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
190 $srv_loc_node = &$share_node->addItem(new HTML_TreeNode(array('text' => "$srv_loc", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
191 }
192 }
193 }
194 }
196 $tree->addItem($dfs_root_node);
198 // Create the presentation class
199 $treeMenu = new HTML_TreeMenu_DHTML($tree, array('images' => 'images', 'defaultClass' => 'treeMenuDefault'));
200 $tree_html = $treeMenu->toHTML();
202 if ($this->dfstab === NULL) {
204 if (($message = check_sizelimit()) != "") {
205 return ($message);
206 }
208 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
209 " <input type='image' class='center' src='images/list_up.png' align='middle' title='"._("Go up one dfsshare")."' name='dfs_back' alt='"._("Up")."'> ".
210 " <input type='image' class='center' src='images/list_root.png' align='middle' title='"._("Go to dfs root")."' name='dfs_root' alt='"._("Root")."'> ".
211 " <input class='center' type='image' src='images/dtree.png' align='middle' alt='"._("Create new dfsshare")."' name='dfs_new'> ".
212 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
213 _("Base")." <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
214 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
215 "'> </div>";
218 /* Use the smarty templating engine here... */
220 $smarty->assign('tree', $tree_html);
221 $smarty->assign('search_image', get_template_path('images/search.png'));
222 $smarty->assign('infoimage', get_template_path('images/info.png'));
223 $smarty->assign('launchimage', get_template_path('images/launch.png'));
224 $smarty->assign('alphabet', generate_alphabet());
225 $smarty->assign('hint', print_sizelimit_warning());
226 $smarty->assign('apply', apply_filter());
227 $smarty->assign('dfshead', $listhead);
229 /* Let smarty fetch and process the page. Always seperate PHP and HTML as much as
230 you can. */
231 return ($smarty->fetch (get_template_path('contents.tpl', TRUE)));
232 }
234 /* TABS */
236 $display = $this->dfstab->execute();
238 $display .= "<p>\n";
239 $display .= " <table width=100\%>\n";
240 $display .= " <tbody>\n";
241 $display .= " <tr>\n";
242 $display .= " <td style=\"text-align: right\">\n";
243 $display .= " <input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
244 $display .= " \n";
245 $display .= " <input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
246 $display .= " </td>\n";
247 $display .= " </tr>\n";
248 $display .= " </tbody>\n";
249 $display .= " </table>\n";
250 $display .= "</p>\n";
252 return ($display);
254 }
256 function remove_lock() {
257 if (isset($this->dn)) {
258 del_lock ($this->dn);
259 }
260 }
262 }
263 ?>