Code

Created trunk inside of 2.6-lhm
[gosa.git] / trunk / gosa-plugins / dfs / addons / godfs / class_dfsManagment.inc
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";
10    
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;
22     
23   }
25   /* Execute is the function all plugins need. It fills the plugin with life and produces the output. */
26   function execute() {
27         
28     /* Normally you would react to user input here. */
29     plugin::execute();    
31     $action = "";
32     $s_action= "";
33     $options = "";
34     $regex = "";
35         
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       }
100     } 
101       
102     # save pressed
103     if (isset($_POST['edit_finish'])) {
104       $this->dfstab->last = $this->dfstab->current;
105       $this->dfstab->save_object(); 
106       #$disp = $this->by_object[''];
107       #var_dump($disp);
108     
109       $message = $this->dfstab->check();
110      
111       # any errors?
112       if (count($message) == 0) {
113         # write to ldap
114         $this->dfstab->save();
115       } else {
116         msg_dialog::displayChecks($message);
117       }
118     }
120     # cancel pressed
121     if (isset($_POST['edit_cancel'])) {
122       del_lock ($this->dn);
123       unset ($this->dfstab);
124       $this->dfstab = NULL;
125       $this->dn = "";
126     }
128     # delete pressed
129     if (isset($_POST['edit_delete'])) {
130       
131       # get the current values
132       $this->sambasharename = $_POST['sambaShareName'];
133       $this->sharedescription = $_POST['description'];
134       $this->fileserver = $_POST['fileserver'];
135       $this->share = $_POST['fileservershare'];
136       $this->loc = $_POST['location'];
137           
138       $base = get_base_from_people($this->ui->dn);
139       $ou = get_ou("DFS");
140       $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
142       $ldap = $this->config->get_ldap_link();
143       $ldap->cd($this->basedn);
144       $ldap->rmdir($this->basedn);
145       if (!$ldap->success()){
146               msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->basedn, LDAP_DEL, get_class()));
147       }
148       
149       del_lock ($this->dn);
150       unset ($this->dfstab);
151       $this->dfstab = NULL;
152       $this->dn = "";
153     }
155     # generate main page no tabs
157     $ldap = $this->config->get_ldap_link();
159     $ou = get_ou("DFS");
160     
161     $ldap->cd("$ou$base");
162     $ldap->search(("ou=*"), array("dn"));
163     
164     if ($ldap->count() == 0) {
165       $message[] = _("No DFS entries found");
166       msg_dialog::displayChecks($message);
167     } else {
168       $have_tree= false;
169       while ($dfs = $ldap->fetch()) {
170         if (preg_match("/^ou=DFS.*/", $dfs["dn"])) {
171           $dfs_root_node = new HTML_TreeNode(array('text' => "DFS", 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => false));
172           $have_tree= true;
173         } elseif ($have_tree) {
174           preg_match("/^ou=(.*),/U", $dfs["dn"], $reg);
175           $loc = $reg[1];
176           $node = $dfs_root_node->addItem(new HTML_TreeNode(array('text' => "$loc", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
177           
178           $sub_node_ldap = $this->config->get_ldap_link();
179           $sub_node_ldap->cd("ou=$loc, $ou$base");
180           $sub_node_ldap->search("(objectclass=sambaShare)", array("sambaShareName", "description", "documentLocation"));
181           
182           while ($dfs_loc = $sub_node_ldap->fetch()) {
183             $share_name = $dfs_loc["sambaShareName"][0];
184             $desc = $dfs_loc["description"][0];
185             $srv_loc = preg_replace("/msdfs:/", "", $dfs_loc["documentLocation"][0]);
186             #$srv_loc = preg_replace("/\\/", "\\\\", $srv_loc);
187             $link = "main.php\?plug=".$_GET['plug']."\&id=$loc\/$share_name\&act=edit_entry"; 
188             $share_node = &$node->addItem(new HTML_TreeNode(array('text' => "$share_name - $desc", 'link' => "$link", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
189             $srv_loc_node = &$share_node->addItem(new HTML_TreeNode(array('text' => "$srv_loc", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
190           }
191         }
192       }
193     }
195     $tree->addItem($dfs_root_node);
197     // Create the presentation class
198     $treeMenu = new HTML_TreeMenu_DHTML($tree, array('images' => 'images', 'defaultClass' => 'treeMenuDefault'));
199     $tree_html = $treeMenu->toHTML();
200     
201     if ($this->dfstab === NULL) {
203       if (($message = check_sizelimit()) != "") {
204         return ($message);
205       }
206   
207       $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
208          " <input type='image' class='center' src='images/lists/up.png' align='middle' title='"._("Go up one dfsshare")."' name='dfs_back' alt='"._("Up")."'>&nbsp;".
209          " <input type='image' class='center' src='images/lists/root.png' align='middle' title='"._("Go to dfs root")."' name='dfs_root' alt='"._("Root")."'>&nbsp;".
210          " <input class='center' type='image' src='plugins/dfs/images/dtree.png' align='middle' alt='"._("Create new dfsshare")."' name='dfs_new'>&nbsp;".
211          " <img class='center' src='images/lists/seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
212          _("Base")."&nbsp;<select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
213          " <input class='center' type='image' src='images/lists/submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
214          "'>&nbsp;</div>";
217       /* Use the smarty templating engine here... */
219       $smarty->assign('tree', $tree_html);
220       $smarty->assign('search_image', get_template_path('images/lists/search.png'));
221       $smarty->assign('infoimage', get_template_path('images/info.png'));
222       $smarty->assign('launchimage', get_template_path('images/launch.png'));
223       $smarty->assign('alphabet', generate_alphabet());
224       $smarty->assign('hint', print_sizelimit_warning());
225       $smarty->assign('apply', apply_filter());
226       $smarty->assign('dfshead', $listhead);
228       /* Let smarty fetch and process the page. Always seperate PHP and HTML as much as
229          you can. */
230       return ($smarty->fetch (get_template_path('contents.tpl', TRUE)));
231     }
233     /* TABS */
235     $display = $this->dfstab->execute();
236    
237     $display .= "<p>\n";
238     $display .= "  <table width=100\%>\n";
239     $display .= "    <tbody>\n";
240     $display .= "      <tr>\n";
241     $display .= "        <td style=\"text-align: right\">\n";
242     $display .= "          <input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
243     $display .= "          &nbsp;\n";
244     $display .= "          <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
245     $display .= "        </td>\n";
246     $display .= "      </tr>\n";
247     $display .= "    </tbody>\n";
248     $display .= "  </table>\n";
249     $display .= "</p>\n";
250     
251     return ($display);
253   }
255   function remove_lock() {
256     if (isset($this->dn)) {
257       del_lock ($this->dn);
258     }
259   }
262 ?>