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 */
21 class phoneConferenceManagment extends plugin
22 {
23 /* Definitions */
24 var $plHeadline = "Phone conferences";
25 var $plDescription = "Management";
26 var $plIcon = "plugins/gofon/images/conference.png";
28 /* attribute list for save action */
29 var $attributes = array();
30 var $objectclasses = array();
32 var $conferences = array();
33 var $conftab = false;
34 var $ui = NULL;
35 var $DivListConference = NULL;
37 var $CopyPasteHandler = NULL;
38 var $start_pasting_copied_objects = FALSE;
39 var $dns = array();
41 var $acl_module = array("gofonconference");
43 /* Initialise Class */
44 function phoneConferenceManagment (&$config, $ui)
45 {
46 $this->ui = $ui;
47 $this->dn = "";
48 $this->config = $config;
49 $this->DivListConference = new divListConference($this->config,$this);
51 /* Copy & Paste enabled ?*/
52 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
53 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
54 }
55 }
58 /* Execute class and display something */
59 function execute()
60 {
61 /* Call parent execute */
62 plugin::execute();
64 session::set('LOCK_VARS_TO_USE',array("/^menu_action/","/^id$/","/^act$/","/^conference_/","/^item_selected/","/^remove_multiple_conferences/"));
66 /***************
67 Variable initialisation
68 ***************/
70 /* Reload departments */
71 $smarty = get_smarty();
72 $display = "";
73 $s_action = ""; // Will contain an action, like del or edit
74 $s_entry = ""; // The entry name for edit delete -...
77 /***************
78 Check posts
79 ***************/
81 foreach($_POST as $key => $post){
82 if(preg_match("/^conference_new.*/i",$key)){
83 $s_action = "new";
84 // Post for delete
85 }elseif(preg_match("/^conference_del.*/",$key)){
86 $s_action = "del";
87 $s_entry = preg_replace("/^conference_del_/i","",$key);
88 $s_entry = preg_replace("/_.*$/","",$s_entry);
89 // Post for edit
90 }elseif(preg_match("/conference_edit_.*/",$key)){
91 $s_action="edit";
92 $s_entry = preg_replace("/conference_edit_/i","",$key);
93 $s_entry = preg_replace("/_.*$/","",$s_entry);
94 }elseif(preg_match("/^remove_multiple_conferences/",$key)){
95 $s_action="del_multiple";
96 }elseif(preg_match("/^editPaste.*/i",$key)){
97 $s_action="editPaste";
98 }elseif(preg_match("/^copy_.*/",$key)){
99 $s_action="copy";
100 $s_entry = preg_replace("/^copy_/i","",$key);
101 $s_entry = preg_replace("/_.$/","",$s_entry);
102 }elseif(preg_match("/^cut_.*/",$key)){
103 $s_action="cut";
104 $s_entry = preg_replace("/^cut_/i","",$key);
105 $s_entry = preg_replace("/_.$/","",$s_entry);
106 }elseif(preg_match("/^multiple_copy_objects/",$key)){
107 $s_action = "copy_multiple";
108 }elseif(preg_match("/^multiple_cut_objects/",$key)){
109 $s_action = "cut_multiple";
110 }
111 }
113 /* Edit Entry */
114 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
115 $s_action = "edit";
116 $s_entry = $_GET['id'];
117 }
119 /* handle C&P from layers menu */
120 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
121 $s_action = "copy_multiple";
122 }
123 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
124 $s_action = "cut_multiple";
125 }
126 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
127 $s_action = "editPaste";
128 }
130 /* Create options */
131 if(isset($_POST['menu_action']) && $_POST['menu_action'] == "conference_new"){
132 $s_action = "new";
133 }
135 /* handle remove from layers menu */
136 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
137 $s_action = "del_multiple";
138 }
141 /***************
142 Cancel dialogs
143 ***************/
145 /* Reset requested? */
146 if (isset($_POST['edit_cancel'])){
147 $this->remove_lock();
148 $this->conftab= NULL;
149 $this->lognames= array();;
150 $this->cn= "";
151 session::un_set('objectinfo');
152 }
155 /********************
156 Copy & Paste Handling ...
157 ********************/
159 /* Display the copy & paste dialog, if it is currently open */
160 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
161 if($ret){
162 return($ret);
163 }
166 /********************
167 Delete MULTIPLE entries requested, display confirm dialog
168 ********************/
170 if ($s_action=="del_multiple"){
171 $ids = $this->list_get_selected_items();
173 $this->dns = array();
174 if(count($ids)){
175 $disallowed = array();
176 foreach($ids as $id){
177 $dn = $this->conferences[$id]['dn'];
178 $acl = $this->ui->get_permissions($dn, "gofonconference/conference");
179 if(preg_match("/d/",$acl)){
180 $this->dns[$id] = $dn;
181 }else{
182 $disallowed[] = $dn;
183 }
184 }
186 if(count($disallowed)){
187 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
188 }
190 if(count($this->dns)){
192 /* Check locks */
193 if ($user= get_multiple_locks($this->dns)){
194 return(gen_locked_message($user,$this->dns));
195 }
197 /* Prepare entry list to be displayed */
198 $dns_names = array();
199 foreach($this->dns as $dn){
200 $dns_names[] = @LDAP::fix($dn);
201 }
203 /* Lock the current entry, so nobody will edit it during deletion */
204 add_lock ($this->dns, $this->ui->dn);
206 $smarty->assign("info", msgPool::deleteInfo($dns_names,_("conference")));
207 $smarty->assign("multiple", true);
208 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
209 }
210 }
211 }
214 /********************
215 Delete MULTIPLE entries confirmed
216 ********************/
218 /* Confirmation for deletion has been passed. Users should be deleted. */
219 if (isset($_POST['delete_multiple_conference_confirm'])){
221 /* Remove user by user and check acls before removeing them */
222 foreach($this->dns as $key => $dn){
223 $this->dn = $dn;
224 $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
225 if(preg_match("/d/",$acl)){
226 $this->remove_from_parent();
227 } else {
228 msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
229 }
230 }
232 /* Remove lock file after successfull deletion */
233 $this->remove_lock();
234 $this->dns = array();
235 }
238 /********************
239 Delete MULTIPLE entries Canceled
240 ********************/
242 /* Remove lock */
243 if(isset($_POST['delete_multiple_conference_cancel'])){
244 $this->remove_lock();
245 $this->dns =array();
246 }
249 /***************
250 Delete
251 ***************/
253 /* Delete Entry if Posted action (s_action) == del
254 * The entry which will be deleted is defined in $s_entry
255 */
256 if ($s_action =="del"){
258 $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference");
259 if(preg_match("/d/",$acl)){
260 $this->dn= $this->conferences[$s_entry]['dn'];
262 /* Check locking */
263 if (($conf= get_lock($this->dn)) != ""){
264 session::set('dn',$this->dn);
265 return(gen_locked_message($conf, $this->dn));
266 } else {
267 add_lock ($this->dn, $this->ui->dn);
268 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->dn),_("conference")));
269 $smarty->assign("multiple", false);
270 $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
271 return ($display);
272 }
273 }
274 }
277 /***************
278 Delete confirmed
279 ***************/
281 /* If department deletion is accepted ...
282 * Finally delete department
283 */
284 if (isset($_POST['delete_department_confirm'])){
285 $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
286 if(preg_match("/d/",$acl)){
287 $this->remove_from_parent();
288 } else {
289 msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
290 }
291 }
294 /***************
295 Edit
296 ***************/
298 /* Edit Entry if Posted action (s_action) == edit
299 * The entry which will be edited is defined in $s_entry
300 */
301 if (($s_action=="edit") && (!isset($this->conftab->config))){
303 $this->dn= $this->conferences[$s_entry]['dn'];
305 if (($conf= get_lock($this->dn)) != ""){
306 return(gen_locked_message ($conf, $this->dn));
307 }
309 /* Lock the current entry, so everyone will get the above dialog */
310 add_lock ($this->dn, $this->ui->dn);
312 /* Register conftab to trigger edit dialog */
313 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
314 $this->conftab->set_acl_base($this->dn);
315 session::set('objectinfo',$this->dn);
316 }
319 /***************
320 Create new
321 ***************/
323 /* Insert new entry*/
324 if($s_action == "new" ){
326 $dummy_dn = "cn=dummy,".get_ou('conferenceou').$this->DivListConference->selectedBase;
327 $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference");
328 if(preg_match("/c/",$acl)){
329 /* Set up the users ACL's for this 'dn' */
330 $this->dn= "new";
331 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
332 $this->conftab->set_acl_base($dummy_dn);
333 session::un_set('objectinfo');
334 }
335 }
338 /***************
339 Save entry
340 ***************/
342 /* Edit finished, check and save changes */
343 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
344 /* Check tabs, will feed message array */
345 $this->conftab->last= $this->conftab->current;
346 $this->conftab->save_object();
347 $message= $this->conftab->check();
349 if (count($message) == 0){
350 if($this->conftab->save() == 1){
351 gosa_log ("goFonConference object '".$this->dn."' saving failed.");
352 return;
353 }
354 gosa_log ("goFonConference object '".$this->dn."' has been saved");
356 if (!isset($_POST['edit_apply'])){
357 $this->remove_lock();
358 $this->conftab= NULL;
359 session::un_set('objectinfo');
360 }else{
362 /* Reinitialize tab */
363 if($this->conftab instanceof tabs){
364 $this->conftab->re_init();
365 }
366 }
368 } else {
369 msg_dialog::displayChecks($message);
370 }
371 }
374 /***************
375 Display dialogs
376 ***************/
378 /* if edit or new, show dialog */
379 if(($this->conftab) && (isset($this->conftab->config))){
380 $display= $this->conftab->execute();
382 /* Don't show buttons if tab dialog requests this */
383 if (!$this->conftab->by_object[$this->conftab->current]->dialog){
384 $display.= "<p style=\"text-align:right\">\n";
385 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
386 $display.= " \n";
387 if ($this->dn != "new"){
388 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
389 $display.= " \n";
390 }
391 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
392 $display.= "</p>";
393 }
394 return ($display);
395 }
398 /***************
399 display divlist
400 ***************/
402 /* Check if there is a snapshot dialog open */
403 $base = $this->DivListConference->selectedBase;
404 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
405 return($str);
406 }
408 /* Return rendered main page */
409 /* Display dialog with system list */
410 $this->DivListConference->parent = $this;
411 $this->DivListConference->execute();
413 /* Add departments if subsearch is disabled */
414 if(!$this->DivListConference->SubSearch){
415 $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5,1);
416 }
417 $this->reload();
418 $this->DivListConference->setEntries($this->conferences);
419 return($this->DivListConference->Draw());
420 }
423 /* Return departments, that will be included within snapshot detection */
424 function get_used_snapshot_bases()
425 {
426 return(array(get_ou('conferenceou').$this->DivListConference->selectedBase));
427 }
430 /* Reload entries for divlist.
431 * reload all conferences for the current base, with the given regex
432 */
433 function reload()
434 {
435 $Base = get_ou('conferenceou').$this->DivListConference->selectedBase;
436 $SubSearch = $this->DivListConference->SubSearch;
437 $Regex = $this->DivListConference->Regex;
438 $Flags = GL_SIZELIMIT ;
439 $Filter = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
440 $Attrs = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
442 if($SubSearch){
443 $Flags |= GL_SUBSEARCH;
444 }
446 $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
447 }
449 function remove_from_parent()
450 {
451 /* Ehm what are we doinf here ? */
453 $cfg = new conference($this->config, $this->dn);
454 $cfg->set_acl_category("gofonconference");
455 $cfg->set_acl_base($this->dn);
457 $cfg->remove_from_parent();
458 $ldap= $this->config->get_ldap_link();
459 $ldap->cd ($this->dn);
460 $ldap->recursive_remove();
462 /* Optionally execute a command after we're done */
463 $this->postremove();
465 /* Delete references to object groups */
466 $ldap->cd ($this->config->current['BASE']);
467 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
468 while ($ldap->fetch()){
469 $og= new conftab($this->config, $ldap->getDN());
470 unset($og->member[$this->dn]);
471 $og->save ();
472 }
474 }
477 function copyPasteHandling_from_queue($s_action,$s_entry)
478 {
479 /* Check if Copy & Paste is disabled */
480 if(!is_object($this->CopyPasteHandler)){
481 return("");
482 }
484 $ui = get_userinfo();
486 /* Add a single entry to queue */
487 if($s_action == "cut" || $s_action == "copy"){
489 /* Cleanup object queue */
490 $this->CopyPasteHandler->cleanup_queue();
491 $dn = $this->conferences[$s_entry]['dn'];
493 if($s_action == "copy" && $ui->is_copyable($dn,"gofonconference","conference")){
494 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference");
495 }
496 if($s_action == "cut" && $ui->is_cutable($dn,"gofonconference","conference")){
497 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference");
498 }
499 }
501 /* Add entries to queue */
502 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
504 /* Cleanup object queue */
505 $this->CopyPasteHandler->cleanup_queue();
507 /* Add new entries to CP queue */
508 foreach($this->list_get_selected_items() as $id){
509 $dn = $this->conferences[$id]['dn'];
511 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"gofonconference","conference")){
512 $this->CopyPasteHandler->add_to_queue($dn,"copy","conferencetabs","CONFERENCETABS","gofonconference");
513 }
514 if($s_action == "cut_multiple" && $ui->is_cutable($dn,"gofonconference","conference")){
515 $this->CopyPasteHandler->add_to_queue($dn,"cut","conferencetabs","CONFERENCETABS","gofonconference");
516 }
517 }
518 }
520 /* Start pasting entries */
521 if($s_action == "editPaste"){
522 $this->start_pasting_copied_objects = TRUE;
523 }
524 /* Return C&P dialog */
525 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
527 /* Get dialog */
528 $this->CopyPasteHandler->SetVar("base",$this->DivListConference->selectedBase);
529 $data = $this->CopyPasteHandler->execute();
531 /* Return dialog data */
532 if(!empty($data)){
533 return($data);
534 }
535 }
537 /* Automatically disable status for pasting */
538 if(!$this->CopyPasteHandler->entries_queued()){
539 $this->start_pasting_copied_objects = FALSE;
540 }
541 return("");
542 }
545 function save_object()
546 {
547 $this->DivListConference->save_object();
548 }
551 /*! \brief Remove entry locks if the plugin was aborted.
552 */
553 function remove_lock()
554 {
555 if($this->dn) del_lock($this->dn);
556 if(is_array($this->dns) && count($this->dns)) del_lock($this->dns);
557 if(isset($this->conftab) && isset($this->conftab->dn)){
558 del_lock ($this->conftab->dn);
559 }
560 }
563 function list_get_selected_items()
564 {
565 $ids = array();
566 foreach($_POST as $name => $value){
567 if(preg_match("/^item_selected_[0-9]*$/",$name)){
568 $id = preg_replace("/^item_selected_/","",$name);
569 $ids[$id] = $id;
570 }
571 }
572 return($ids);
573 }
576 }
577 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
578 ?>