1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_conference.inc";
22 class phoneConferenceManagment extends plugin
23 {
24 /* Definitions */
25 var $plHeadline = "Phone conferences";
26 var $plDescription = "Management";
28 /* CLI vars */
29 var $cli_summary = "Handling of LDAP subtrees";
30 var $cli_description = "Some longer text\nfor help";
31 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
33 /* attribute list for save action */
34 var $attributes = array();
35 var $objectclasses = array();
37 var $conferences = array();
38 var $conftab = false;
39 var $ui = NULL;
40 var $DivListConference = NULL;
42 /* Initialise Class */
43 function phoneConferenceManagment ($config, $ui)
44 {
45 $this->ui = $ui;
46 $this->dn = "";
47 $this->config = $config;
48 $this->DivListConference = new divListConference($this->config,$this);
49 }
52 /* Execute class and display something */
53 function execute()
54 {
55 /* Call parent execute */
56 plugin::execute();
58 /***************
59 Variable initialisation
60 ***************/
62 /* Reload departments */
63 $smarty = get_smarty();
64 $display = "";
65 $s_action = ""; // Will contain an action, like del or edit
66 $s_entry = ""; // The entry name for edit delete -...
69 /***************
70 Check posts
71 ***************/
73 foreach($_POST as $key => $post){
74 if(preg_match("/.*new.*/i",$key)){
75 $s_action = "new";
76 // Post for delete
77 }elseif(preg_match("/conf_del.*/",$key)){
78 $s_action = "del";
79 $s_entry = preg_replace("/conf_".$s_action."_/i","",$key);
80 $s_entry = preg_replace("/_.*$/","",$s_entry);
81 // Post for edit
82 }elseif(preg_match("/conf_edit_.*/",$key)){
83 $s_action="edit";
84 $s_entry = preg_replace("/conf_".$s_action."_/i","",$key);
85 $s_entry = preg_replace("/_.*$/","",$s_entry);
86 }
87 }
89 /* Edit Entry */
90 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
91 $s_action = "edit";
92 $s_entry = $_GET['id'];
93 }
96 /***************
97 Cancel dialogs
98 ***************/
100 /* Reset requested? */
101 if (isset($_POST['edit_cancel'])){
102 if (isset($this->conftab)){
103 del_lock ($this->conftab->dn);
104 unset ($this->conftab);
105 }
106 $this->conftab= NULL;
107 $this->lognames= array();;
108 $this->cn= "";
109 unset ($_SESSION['objectinfo']);
110 }
113 /***************
114 Delete
115 ***************/
117 /* Delete Entry if Posted action (s_action) == del
118 * The entry which will be deleted is defined in $s_entry
119 */
120 if ($s_action =="del"){
121 $this->dn= $this->conferences[$s_entry]['dn'];
123 /* Check locking */
124 if (($conf= get_lock($this->dn)) != ""){
125 $_SESSION['dn']= $this->dn;
126 return(gen_locked_message($conf, $this->dn));
127 } else {
128 add_lock ($this->dn, $this->ui->dn);
129 $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
130 $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
131 return ($display);
132 }
133 }
136 /***************
137 Delete confirmed
138 ***************/
140 /* If department deletion is accepted ...
141 * Finally delete department
142 */
143 $acl = $this->ui->get_permissions($this->dn,"gofon/conference");
144 if (isset($_POST['delete_department_confirm'])){
145 echo "What the hell is going on here ? Huh ?!!";
146 if(preg_match("/d/",$acl)){
147 $this->remove_from_parent();
148 gosa_log ("Department object'".$this->dn."' has been removed");
149 } else {
150 print_red (_("You have no permission to remove this department."));
151 }
152 }
155 /***************
156 Edit
157 ***************/
159 /* Edit Entry if Posted action (s_action) == edit
160 * The entry which will be edited is defined in $s_entry
161 */
162 if (($s_action=="edit") && (!isset($this->conftab->config))){
164 $this->dn= $this->conferences[$s_entry]['dn'];
166 if (($conf= get_lock($this->dn)) != ""){
167 return(gen_locked_message ($conf, $this->dn));
168 }
170 /* Lock the current entry, so everyone will get the above dialog */
171 add_lock ($this->dn, $this->ui->dn);
173 /* Register conftab to trigger edit dialog */
174 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofon");
175 $this->conftab->set_acl_base($this->dn);
176 $_SESSION['objectinfo']= $this->dn;
177 }
180 /***************
181 Create new
182 ***************/
184 /* Insert new entry*/
185 if($s_action == "new" ){
187 /* Set up the users ACL's for this 'dn' */
188 $this->dn= "new";
189 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofon");
190 $this->conftab->set_acl_base("cn=dummy,ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase);
191 unset($_SESSION['objectinfo']);
192 }
195 /***************
196 Save entry
197 ***************/
199 /* Edit finished, check and save changes */
200 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
201 /* Check tabs, will feed message array */
202 $this->conftab->last= $this->conftab->current;
203 $this->conftab->save_object();
204 $message= $this->conftab->check();
206 if (count($message) == 0){
207 if($this->conftab->save() == 1){
208 gosa_log ("goFonConference object '".$this->dn."' saving failed.");
209 return;
210 }
211 gosa_log ("goFonConference object '".$this->dn."' has been saved");
213 if (!isset($_POST['edit_apply'])){
214 if ($this->dn != "new"){
215 del_lock ($this->dn);
216 }
217 }
219 $this->conftab->save ();
220 del_lock ($this->conftab->dn);;
221 unset ($this->conftab);
222 $this->conftab= NULL;
223 unset ($_SESSION['objectinfo']);
224 } else {
225 show_errors($message);
226 }
227 }
230 /***************
231 Display dialogs
232 ***************/
234 /* if edit or new, show dialog */
235 if(($this->conftab) && (isset($this->conftab->config))){
236 $display= $this->conftab->execute();
238 /* Don't show buttons if tab dialog requests this */
239 if (!$this->conftab->by_object[$this->conftab->current]->dialog){
240 $display.= "<p style=\"text-align:right\">\n";
241 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
242 $display.= " \n";
243 if ($this->dn != "new"){
244 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
245 $display.= " \n";
246 }
247 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
248 $display.= "</p>";
249 }
250 return ($display);
251 }
254 /***************
255 display divlist
256 ***************/
258 /* Check if there is a snapshot dialog open */
259 $base = $this->DivListConference->selectedBase;
260 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
261 return($str);
262 }
264 /* Return rendered main page */
265 /* Display dialog with system list */
266 $this->DivListConference->parent = $this;
267 $this->DivListConference->execute();
269 /* Add departments if subsearch is disabled */
270 if(!$this->DivListConference->SubSearch){
271 $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5);
272 }
273 $this->reload();
274 $this->DivListConference->setEntries($this->conferences);
275 return($this->DivListConference->Draw());
276 }
279 /* Return departments, that will be included within snapshot detection */
280 function get_used_snapshot_bases()
281 {
282 return(array("ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase));
283 }
286 /* Reload entries for divlist.
287 * reload all conferences for the current base, with the given regex
288 */
289 function reload()
290 {
291 $Base = "ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;
292 $SubSearch = $this->DivListConference->SubSearch;
293 $Regex = $this->DivListConference->Regex;
294 $Flags = GL_SIZELIMIT ;
295 $Filter = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
296 $Attrs = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
298 if($SubSearch){
299 $Flags |= GL_SUBSEARCH;
300 }
302 $this->conferences= get_list($Filter, "gofon", $Base, $Attrs, $Flags);
303 }
305 function remove_from_parent()
306 {
307 /* Ehm what are we doinf here ? */
309 $cfg = new conference($this->config, $this->dn);
310 $cfg->set_acl_category("gofon");
311 $cfg->set_acl_base($this->dn);
313 $cfg->remove_from_parent();
314 $ldap= $this->config->get_ldap_link();
315 $ldap->cd ($this->dn);
316 $ldap->recursive_remove();
318 /* Optionally execute a command after we're done */
319 $this->postremove();
321 /* Delete references to object groups */
322 $ldap->cd ($this->config->current['BASE']);
323 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
324 while ($ldap->fetch()){
325 $og= new conftab($this->config, $ldap->getDN());
326 unset($og->member[$this->dn]);
327 $og->save ();
328 }
330 }
332 function save_object()
333 {
334 $this->DivListConference->save_object();
335 }
337 function remove_lock()
338 {
339 if (isset($this->dn)){
340 del_lock ($this->dn);
341 }
342 }
344 }
345 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
346 ?>