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"){
122 $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference");
123 if(preg_match("/d/",$acl)){
124 $this->dn= $this->conferences[$s_entry]['dn'];
126 /* Check locking */
127 if (($conf= get_lock($this->dn)) != ""){
128 $_SESSION['dn']= $this->dn;
129 return(gen_locked_message($conf, $this->dn));
130 } else {
131 add_lock ($this->dn, $this->ui->dn);
132 $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
133 $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
134 return ($display);
135 }
136 }
137 }
140 /***************
141 Delete confirmed
142 ***************/
144 /* If department deletion is accepted ...
145 * Finally delete department
146 */
147 if (isset($_POST['delete_department_confirm'])){
148 $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
149 if(preg_match("/d/",$acl)){
150 $this->remove_from_parent();
151 gosa_log ("Department object'".$this->dn."' has been removed");
152 } else {
153 print_red (_("You have no permission to remove this department."));
154 }
155 }
158 /***************
159 Edit
160 ***************/
162 /* Edit Entry if Posted action (s_action) == edit
163 * The entry which will be edited is defined in $s_entry
164 */
165 if (($s_action=="edit") && (!isset($this->conftab->config))){
167 $this->dn= $this->conferences[$s_entry]['dn'];
169 if (($conf= get_lock($this->dn)) != ""){
170 return(gen_locked_message ($conf, $this->dn));
171 }
173 /* Lock the current entry, so everyone will get the above dialog */
174 add_lock ($this->dn, $this->ui->dn);
176 /* Register conftab to trigger edit dialog */
177 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
178 $this->conftab->set_acl_base($this->dn);
179 $_SESSION['objectinfo']= $this->dn;
180 }
183 /***************
184 Create new
185 ***************/
187 /* Insert new entry*/
188 if($s_action == "new" ){
190 $dummy_dn = "cn=dummy,ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;
191 $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference");
192 if(preg_match("/c/",$acl)){
193 /* Set up the users ACL's for this 'dn' */
194 $this->dn= "new";
195 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
196 $this->conftab->set_acl_base($dummy_dn);
197 unset($_SESSION['objectinfo']);
198 }
199 }
202 /***************
203 Save entry
204 ***************/
206 /* Edit finished, check and save changes */
207 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
208 /* Check tabs, will feed message array */
209 $this->conftab->last= $this->conftab->current;
210 $this->conftab->save_object();
211 $message= $this->conftab->check();
213 if (count($message) == 0){
214 if($this->conftab->save() == 1){
215 gosa_log ("goFonConference object '".$this->dn."' saving failed.");
216 return;
217 }
218 gosa_log ("goFonConference object '".$this->dn."' has been saved");
220 if (!isset($_POST['edit_apply'])){
221 if ($this->dn != "new"){
222 del_lock ($this->dn);
223 }
224 }
226 $this->conftab->save ();
227 del_lock ($this->conftab->dn);;
228 unset ($this->conftab);
229 $this->conftab= NULL;
230 unset ($_SESSION['objectinfo']);
231 } else {
232 show_errors($message);
233 }
234 }
237 /***************
238 Display dialogs
239 ***************/
241 /* if edit or new, show dialog */
242 if(($this->conftab) && (isset($this->conftab->config))){
243 $display= $this->conftab->execute();
245 /* Don't show buttons if tab dialog requests this */
246 if (!$this->conftab->by_object[$this->conftab->current]->dialog){
247 $display.= "<p style=\"text-align:right\">\n";
248 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
249 $display.= " \n";
250 if ($this->dn != "new"){
251 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
252 $display.= " \n";
253 }
254 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
255 $display.= "</p>";
256 }
257 return ($display);
258 }
261 /***************
262 display divlist
263 ***************/
265 /* Check if there is a snapshot dialog open */
266 $base = $this->DivListConference->selectedBase;
267 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
268 return($str);
269 }
271 /* Return rendered main page */
272 /* Display dialog with system list */
273 $this->DivListConference->parent = $this;
274 $this->DivListConference->execute();
276 /* Add departments if subsearch is disabled */
277 if(!$this->DivListConference->SubSearch){
278 $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5);
279 }
280 $this->reload();
281 $this->DivListConference->setEntries($this->conferences);
282 return($this->DivListConference->Draw());
283 }
286 /* Return departments, that will be included within snapshot detection */
287 function get_used_snapshot_bases()
288 {
289 return(array("ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase));
290 }
293 /* Reload entries for divlist.
294 * reload all conferences for the current base, with the given regex
295 */
296 function reload()
297 {
298 $Base = "ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;
299 $SubSearch = $this->DivListConference->SubSearch;
300 $Regex = $this->DivListConference->Regex;
301 $Flags = GL_SIZELIMIT ;
302 $Filter = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
303 $Attrs = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
305 if($SubSearch){
306 $Flags |= GL_SUBSEARCH;
307 }
309 $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
310 }
312 function remove_from_parent()
313 {
314 /* Ehm what are we doinf here ? */
316 $cfg = new conference($this->config, $this->dn);
317 $cfg->set_acl_category("gofonconference");
318 $cfg->set_acl_base($this->dn);
320 $cfg->remove_from_parent();
321 $ldap= $this->config->get_ldap_link();
322 $ldap->cd ($this->dn);
323 $ldap->recursive_remove();
325 /* Optionally execute a command after we're done */
326 $this->postremove();
328 /* Delete references to object groups */
329 $ldap->cd ($this->config->current['BASE']);
330 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
331 while ($ldap->fetch()){
332 $og= new conftab($this->config, $ldap->getDN());
333 unset($og->member[$this->dn]);
334 $og->save ();
335 }
337 }
339 function save_object()
340 {
341 $this->DivListConference->save_object();
342 }
344 function remove_lock()
345 {
346 if (isset($this->dn)){
347 del_lock ($this->dn);
348 }
349 }
351 }
352 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
353 ?>