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";
27 /* attribute list for save action */
28 var $attributes = array();
29 var $objectclasses = array();
31 var $conferences = array();
32 var $conftab = false;
33 var $ui = NULL;
34 var $DivListConference = NULL;
36 var $CopyPasteHandler = NULL;
37 var $start_pasting_copied_objects = FALSE;
38 var $dns = array();
40 var $acl_module = array("gofonconference");
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);
50 /* Copy & Paste enabled ?*/
51 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
52 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
53 }
54 }
57 /* Execute class and display something */
58 function execute()
59 {
60 /* Call parent execute */
61 plugin::execute();
63 session::set('LOCK_VARS_TO_USE',array("/^menu_action/","/^id$/","/^act$/","/^conference_/","/^item_selected/","/^remove_multiple_conferences/"));
65 /***************
66 Variable initialisation
67 ***************/
69 /* Reload departments */
70 $smarty = get_smarty();
71 $display = "";
72 $s_action = ""; // Will contain an action, like del or edit
73 $s_entry = ""; // The entry name for edit delete -...
76 /***************
77 Check posts
78 ***************/
80 foreach($_POST as $key => $post){
81 if(preg_match("/^conference_new.*/i",$key)){
82 $s_action = "new";
83 // Post for delete
84 }elseif(preg_match("/^conference_del.*/",$key)){
85 $s_action = "del";
86 $s_entry = preg_replace("/^conference_del_/i","",$key);
87 $s_entry = preg_replace("/_.*$/","",$s_entry);
88 // Post for edit
89 }elseif(preg_match("/conference_edit_.*/",$key)){
90 $s_action="edit";
91 $s_entry = preg_replace("/conference_edit_/i","",$key);
92 $s_entry = preg_replace("/_.*$/","",$s_entry);
93 }elseif(preg_match("/^remove_multiple_conferences/",$key)){
94 $s_action="del_multiple";
95 }elseif(preg_match("/^editPaste.*/i",$key)){
96 $s_action="editPaste";
97 }elseif(preg_match("/^copy_.*/",$key)){
98 $s_action="copy";
99 $s_entry = preg_replace("/^copy_/i","",$key);
100 $s_entry = preg_replace("/_.$/","",$s_entry);
101 }elseif(preg_match("/^cut_.*/",$key)){
102 $s_action="cut";
103 $s_entry = preg_replace("/^cut_/i","",$key);
104 $s_entry = preg_replace("/_.$/","",$s_entry);
105 }elseif(preg_match("/^multiple_copy_objects/",$key)){
106 $s_action = "copy_multiple";
107 }elseif(preg_match("/^multiple_cut_objects/",$key)){
108 $s_action = "cut_multiple";
109 }
110 }
112 /* Edit Entry */
113 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
114 $s_action = "edit";
115 $s_entry = $_GET['id'];
116 }
118 /* handle C&P from layers menu */
119 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
120 $s_action = "copy_multiple";
121 }
122 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
123 $s_action = "cut_multiple";
124 }
125 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
126 $s_action = "editPaste";
127 }
129 /* Create options */
130 if(isset($_POST['menu_action']) && $_POST['menu_action'] == "conference_new"){
131 $s_action = "new";
132 }
134 /* handle remove from layers menu */
135 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
136 $s_action = "del_multiple";
137 }
140 /***************
141 Cancel dialogs
142 ***************/
144 /* Reset requested? */
145 if (isset($_POST['edit_cancel'])){
146 $this->remove_lock();
147 $this->conftab= NULL;
148 $this->lognames= array();;
149 $this->cn= "";
150 session::un_set('objectinfo');
151 }
154 /********************
155 Copy & Paste Handling ...
156 ********************/
158 /* Display the copy & paste dialog, if it is currently open */
159 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
160 if($ret){
161 return($ret);
162 }
165 /********************
166 Delete MULTIPLE entries requested, display confirm dialog
167 ********************/
169 if ($s_action=="del_multiple"){
170 $ids = $this->list_get_selected_items();
172 $this->dns = array();
173 if(count($ids)){
174 $disallowed = array();
175 foreach($ids as $id){
176 $dn = $this->conferences[$id]['dn'];
177 $acl = $this->ui->get_permissions($dn, "gofonconference/conference");
178 if(preg_match("/d/",$acl)){
179 $this->dns[$id] = $dn;
180 }else{
181 $disallowed[] = $dn;
182 }
183 }
185 if(count($disallowed)){
186 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
187 }
189 if(count($this->dns)){
191 /* Check locks */
192 if ($user= get_multiple_locks($this->dns)){
193 return(gen_locked_message($user,$this->dns));
194 }
196 /* Prepare entry list to be displayed */
197 $dns_names = array();
198 foreach($this->dns as $dn){
199 $dns_names[] = @LDAP::fix($dn);
200 }
202 /* Lock the current entry, so nobody will edit it during deletion */
203 add_lock ($this->dns, $this->ui->dn);
205 $smarty->assign("info", msgPool::deleteInfo($dns_names,_("conference")));
206 $smarty->assign("multiple", true);
207 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
208 }
209 }
210 }
213 /********************
214 Delete MULTIPLE entries confirmed
215 ********************/
217 /* Confirmation for deletion has been passed. Users should be deleted. */
218 if (isset($_POST['delete_multiple_conference_confirm'])){
220 /* Remove user by user and check acls before removeing them */
221 foreach($this->dns as $key => $dn){
222 $this->dn = $dn;
223 $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
224 if(preg_match("/d/",$acl)){
225 $this->remove_from_parent();
226 } else {
227 msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
228 }
229 }
231 /* Remove lock file after successfull deletion */
232 $this->remove_lock();
233 $this->dns = array();
234 }
237 /********************
238 Delete MULTIPLE entries Canceled
239 ********************/
241 /* Remove lock */
242 if(isset($_POST['delete_multiple_conference_cancel'])){
243 $this->remove_lock();
244 $this->dns =array();
245 }
248 /***************
249 Delete
250 ***************/
252 /* Delete Entry if Posted action (s_action) == del
253 * The entry which will be deleted is defined in $s_entry
254 */
255 if ($s_action =="del"){
257 $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference");
258 if(preg_match("/d/",$acl)){
259 $this->dn= $this->conferences[$s_entry]['dn'];
261 /* Check locking */
262 if (($conf= get_lock($this->dn)) != ""){
263 session::set('dn',$this->dn);
264 return(gen_locked_message($conf, $this->dn));
265 } else {
266 add_lock ($this->dn, $this->ui->dn);
267 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->dn),_("conference")));
268 $smarty->assign("multiple", false);
269 $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
270 return ($display);
271 }
272 }
273 }
276 /***************
277 Delete confirmed
278 ***************/
280 /* If department deletion is accepted ...
281 * Finally delete department
282 */
283 if (isset($_POST['delete_department_confirm'])){
284 $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
285 if(preg_match("/d/",$acl)){
286 $this->remove_from_parent();
287 } else {
288 msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
289 }
290 }
293 /***************
294 Edit
295 ***************/
297 /* Edit Entry if Posted action (s_action) == edit
298 * The entry which will be edited is defined in $s_entry
299 */
300 if (($s_action=="edit") && (!isset($this->conftab->config))){
302 $this->dn= $this->conferences[$s_entry]['dn'];
304 if (($conf= get_lock($this->dn)) != ""){
305 return(gen_locked_message ($conf, $this->dn));
306 }
308 /* Lock the current entry, so everyone will get the above dialog */
309 add_lock ($this->dn, $this->ui->dn);
311 /* Register conftab to trigger edit dialog */
312 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
313 $this->conftab->set_acl_base($this->dn);
314 session::set('objectinfo',$this->dn);
315 }
318 /***************
319 Create new
320 ***************/
322 /* Insert new entry*/
323 if($s_action == "new" ){
325 $dummy_dn = "cn=dummy,".get_ou('conferenceou').$this->DivListConference->selectedBase;
326 $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference");
327 if(preg_match("/c/",$acl)){
328 /* Set up the users ACL's for this 'dn' */
329 $this->dn= "new";
330 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
331 $this->conftab->set_acl_base($dummy_dn);
332 session::un_set('objectinfo');
333 }
334 }
337 /***************
338 Save entry
339 ***************/
341 /* Edit finished, check and save changes */
342 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
343 /* Check tabs, will feed message array */
344 $this->conftab->last= $this->conftab->current;
345 $this->conftab->save_object();
346 $message= $this->conftab->check();
348 if (count($message) == 0){
349 if($this->conftab->save() == 1){
350 gosa_log ("goFonConference object '".$this->dn."' saving failed.");
351 return;
352 }
353 gosa_log ("goFonConference object '".$this->dn."' has been saved");
355 if (!isset($_POST['edit_apply'])){
356 $this->remove_lock();
357 $this->conftab= NULL;
358 session::un_set('objectinfo');
359 }else{
361 /* Reinitialize tab */
362 if($this->conftab instanceof tabs){
363 $this->conftab->re_init();
364 }
365 }
367 } else {
368 msg_dialog::displayChecks($message);
369 }
370 }
373 /***************
374 Display dialogs
375 ***************/
377 /* if edit or new, show dialog */
378 if(($this->conftab) && (isset($this->conftab->config))){
379 $display= $this->conftab->execute();
381 /* Don't show buttons if tab dialog requests this */
382 if (!$this->conftab->by_object[$this->conftab->current]->dialog){
383 $display.= "<p style=\"text-align:right\">\n";
384 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
385 $display.= " \n";
386 if ($this->dn != "new"){
387 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
388 $display.= " \n";
389 }
390 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
391 $display.= "</p>";
392 }
393 return ($display);
394 }
397 /***************
398 display divlist
399 ***************/
401 /* Check if there is a snapshot dialog open */
402 $base = $this->DivListConference->selectedBase;
403 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
404 return($str);
405 }
407 /* Return rendered main page */
408 /* Display dialog with system list */
409 $this->DivListConference->parent = $this;
410 $this->DivListConference->execute();
412 /* Add departments if subsearch is disabled */
413 if(!$this->DivListConference->SubSearch){
414 $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5,1);
415 }
416 $this->reload();
417 $this->DivListConference->setEntries($this->conferences);
418 return($this->DivListConference->Draw());
419 }
422 /* Return departments, that will be included within snapshot detection */
423 function get_used_snapshot_bases()
424 {
425 return(array(get_ou('conferenceou').$this->DivListConference->selectedBase));
426 }
429 /* Reload entries for divlist.
430 * reload all conferences for the current base, with the given regex
431 */
432 function reload()
433 {
434 $Base = get_ou('conferenceou').$this->DivListConference->selectedBase;
435 $SubSearch = $this->DivListConference->SubSearch;
436 $Regex = $this->DivListConference->Regex;
437 $Flags = GL_SIZELIMIT ;
438 $Filter = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
439 $Attrs = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
441 if($SubSearch){
442 $Flags |= GL_SUBSEARCH;
443 }
445 $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
446 }
448 function remove_from_parent()
449 {
450 /* Ehm what are we doinf here ? */
452 $cfg = new conference($this->config, $this->dn);
453 $cfg->set_acl_category("gofonconference");
454 $cfg->set_acl_base($this->dn);
456 $cfg->remove_from_parent();
457 $ldap= $this->config->get_ldap_link();
458 $ldap->cd ($this->dn);
459 $ldap->recursive_remove();
461 /* Optionally execute a command after we're done */
462 $this->postremove();
464 /* Delete references to object groups */
465 $ldap->cd ($this->config->current['BASE']);
466 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
467 while ($ldap->fetch()){
468 $og= new conftab($this->config, $ldap->getDN());
469 unset($og->member[$this->dn]);
470 $og->save ();
471 }
473 }
476 function copyPasteHandling_from_queue($s_action,$s_entry)
477 {
478 /* Check if Copy & Paste is disabled */
479 if(!is_object($this->CopyPasteHandler)){
480 return("");
481 }
483 $ui = get_userinfo();
485 /* Add a single entry to queue */
486 if($s_action == "cut" || $s_action == "copy"){
488 /* Cleanup object queue */
489 $this->CopyPasteHandler->cleanup_queue();
490 $dn = $this->conferences[$s_entry]['dn'];
492 if($s_action == "copy" && $ui->is_copyable($dn,"gofonconference","conference")){
493 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference");
494 }
495 if($s_action == "cut" && $ui->is_cutable($dn,"gofonconference","conference")){
496 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference");
497 }
498 }
500 /* Add entries to queue */
501 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
503 /* Cleanup object queue */
504 $this->CopyPasteHandler->cleanup_queue();
506 /* Add new entries to CP queue */
507 foreach($this->list_get_selected_items() as $id){
508 $dn = $this->conferences[$id]['dn'];
510 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"gofonconference","conference")){
511 $this->CopyPasteHandler->add_to_queue($dn,"copy","conferencetabs","CONFERENCETABS","gofonconference");
512 }
513 if($s_action == "cut_multiple" && $ui->is_cutable($dn,"gofonconference","conference")){
514 $this->CopyPasteHandler->add_to_queue($dn,"cut","conferencetabs","CONFERENCETABS","gofonconference");
515 }
516 }
517 }
519 /* Start pasting entries */
520 if($s_action == "editPaste"){
521 $this->start_pasting_copied_objects = TRUE;
522 }
523 /* Return C&P dialog */
524 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
526 /* Get dialog */
527 $this->CopyPasteHandler->SetVar("base",$this->DivListConference->selectedBase);
528 $data = $this->CopyPasteHandler->execute();
530 /* Return dialog data */
531 if(!empty($data)){
532 return($data);
533 }
534 }
536 /* Automatically disable status for pasting */
537 if(!$this->CopyPasteHandler->entries_queued()){
538 $this->start_pasting_copied_objects = FALSE;
539 }
540 return("");
541 }
544 function save_object()
545 {
546 $this->DivListConference->save_object();
547 }
550 /*! \brief Remove entry locks if the plugin was aborted.
551 */
552 function remove_lock()
553 {
554 if($this->dn) del_lock($this->dn);
555 if(is_array($this->dns) && count($this->dns)) del_lock($this->dns);
556 if(isset($this->conftab) && isset($this->conftab->dn)){
557 del_lock ($this->conftab->dn);
558 }
559 }
562 function list_get_selected_items()
563 {
564 $ids = array();
565 foreach($_POST as $name => $value){
566 if(preg_match("/^item_selected_[0-9]*$/",$name)){
567 $id = preg_replace("/^item_selected_/","",$name);
568 $ids[$id] = $id;
569 }
570 }
571 return($ids);
572 }
575 }
576 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
577 ?>