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 /* Initialise Class */
41 function phoneConferenceManagment (&$config, $ui)
42 {
43 $this->ui = $ui;
44 $this->dn = "";
45 $this->config = $config;
46 $this->DivListConference = new divListConference($this->config,$this);
48 /* Copy & Paste enabled ?*/
49 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
50 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
51 }
52 }
55 /* Execute class and display something */
56 function execute()
57 {
58 /* Call parent execute */
59 plugin::execute();
61 session::set('LOCK_VARS_TO_USE',array("/^menu_action/","/^id$/","/^act$/","/^conference_/","/^item_selected/","/^remove_multiple_conferences/"));
63 /***************
64 Variable initialisation
65 ***************/
67 /* Reload departments */
68 $smarty = get_smarty();
69 $display = "";
70 $s_action = ""; // Will contain an action, like del or edit
71 $s_entry = ""; // The entry name for edit delete -...
74 /***************
75 Check posts
76 ***************/
78 foreach($_POST as $key => $post){
79 if(preg_match("/^conference_new.*/i",$key)){
80 $s_action = "new";
81 // Post for delete
82 }elseif(preg_match("/^conference_del.*/",$key)){
83 $s_action = "del";
84 $s_entry = preg_replace("/^conference_del_/i","",$key);
85 $s_entry = preg_replace("/_.*$/","",$s_entry);
86 // Post for edit
87 }elseif(preg_match("/conference_edit_.*/",$key)){
88 $s_action="edit";
89 $s_entry = preg_replace("/conference_edit_/i","",$key);
90 $s_entry = preg_replace("/_.*$/","",$s_entry);
91 }elseif(preg_match("/^remove_multiple_conferences/",$key)){
92 $s_action="del_multiple";
93 }elseif(preg_match("/^editPaste.*/i",$key)){
94 $s_action="editPaste";
95 }elseif(preg_match("/^copy_.*/",$key)){
96 $s_action="copy";
97 $s_entry = preg_replace("/^copy_/i","",$key);
98 $s_entry = preg_replace("/_.$/","",$s_entry);
99 }elseif(preg_match("/^cut_.*/",$key)){
100 $s_action="cut";
101 $s_entry = preg_replace("/^cut_/i","",$key);
102 $s_entry = preg_replace("/_.$/","",$s_entry);
103 }elseif(preg_match("/^multiple_copy_objects/",$key)){
104 $s_action = "copy_multiple";
105 }elseif(preg_match("/^multiple_cut_objects/",$key)){
106 $s_action = "cut_multiple";
107 }
108 }
110 /* Edit Entry */
111 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
112 $s_action = "edit";
113 $s_entry = $_GET['id'];
114 }
116 /* handle C&P from layers menu */
117 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
118 $s_action = "copy_multiple";
119 }
120 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
121 $s_action = "cut_multiple";
122 }
123 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
124 $s_action = "editPaste";
125 }
127 /* Create options */
128 if(isset($_POST['menu_action']) && $_POST['menu_action'] == "conference_new"){
129 $s_action = "new";
130 }
132 /* handle remove from layers menu */
133 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
134 $s_action = "del_multiple";
135 }
138 /***************
139 Cancel dialogs
140 ***************/
142 /* Reset requested? */
143 if (isset($_POST['edit_cancel'])){
144 $this->remove_lock();
145 $this->conftab= NULL;
146 $this->lognames= array();;
147 $this->cn= "";
148 session::un_set('objectinfo');
149 }
152 /********************
153 Copy & Paste Handling ...
154 ********************/
156 /* Display the copy & paste dialog, if it is currently open */
157 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
158 if($ret){
159 return($ret);
160 }
163 /********************
164 Delete MULTIPLE entries requested, display confirm dialog
165 ********************/
167 if ($s_action=="del_multiple"){
168 $ids = $this->list_get_selected_items();
170 $this->dns = array();
171 if(count($ids)){
172 $disallowed = array();
173 foreach($ids as $id){
174 $dn = $this->conferences[$id]['dn'];
175 $acl = $this->ui->get_permissions($dn, "gofonconference/conference");
176 if(preg_match("/d/",$acl)){
177 $this->dns[$id] = $dn;
178 }else{
179 $disallowed[] = $dn;
180 }
181 }
183 if(count($disallowed)){
184 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
185 }
187 if(count($this->dns)){
189 /* Check locks */
190 if ($user= get_multiple_locks($this->dns)){
191 return(gen_locked_message($user,$this->dns));
192 }
194 /* Prepare entry list to be displayed */
195 $dns_names = array();
196 foreach($this->dns as $dn){
197 $dns_names[] = @LDAP::fix($dn);
198 }
200 /* Lock the current entry, so nobody will edit it during deletion */
201 add_lock ($this->dns, $this->ui->dn);
203 $smarty->assign("info", msgPool::deleteInfo($dns_names,_("conference")));
204 $smarty->assign("multiple", true);
205 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
206 }
207 }
208 }
211 /********************
212 Delete MULTIPLE entries confirmed
213 ********************/
215 /* Confirmation for deletion has been passed. Users should be deleted. */
216 if (isset($_POST['delete_multiple_conference_confirm'])){
218 /* Remove user by user and check acls before removeing them */
219 foreach($this->dns as $key => $dn){
220 $this->dn = $dn;
221 $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
222 if(preg_match("/d/",$acl)){
223 $this->remove_from_parent();
224 } else {
225 msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
226 }
227 }
229 /* Remove lock file after successfull deletion */
230 $this->remove_lock();
231 $this->dns = array();
232 }
235 /********************
236 Delete MULTIPLE entries Canceled
237 ********************/
239 /* Remove lock */
240 if(isset($_POST['delete_multiple_conference_cancel'])){
241 $this->remove_lock();
242 $this->dns =array();
243 }
246 /***************
247 Delete
248 ***************/
250 /* Delete Entry if Posted action (s_action) == del
251 * The entry which will be deleted is defined in $s_entry
252 */
253 if ($s_action =="del"){
255 $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference");
256 if(preg_match("/d/",$acl)){
257 $this->dn= $this->conferences[$s_entry]['dn'];
259 /* Check locking */
260 if (($conf= get_lock($this->dn)) != ""){
261 session::set('dn',$this->dn);
262 return(gen_locked_message($conf, $this->dn));
263 } else {
264 add_lock ($this->dn, $this->ui->dn);
265 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->dn),_("conference")));
266 $smarty->assign("multiple", false);
267 $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
268 return ($display);
269 }
270 }
271 }
274 /***************
275 Delete confirmed
276 ***************/
278 /* If department deletion is accepted ...
279 * Finally delete department
280 */
281 if (isset($_POST['delete_department_confirm'])){
282 $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference");
283 if(preg_match("/d/",$acl)){
284 $this->remove_from_parent();
285 } else {
286 msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
287 }
288 }
291 /***************
292 Edit
293 ***************/
295 /* Edit Entry if Posted action (s_action) == edit
296 * The entry which will be edited is defined in $s_entry
297 */
298 if (($s_action=="edit") && (!isset($this->conftab->config))){
300 $this->dn= $this->conferences[$s_entry]['dn'];
302 if (($conf= get_lock($this->dn)) != ""){
303 return(gen_locked_message ($conf, $this->dn));
304 }
306 /* Lock the current entry, so everyone will get the above dialog */
307 add_lock ($this->dn, $this->ui->dn);
309 /* Register conftab to trigger edit dialog */
310 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
311 $this->conftab->set_acl_base($this->dn);
312 session::set('objectinfo',$this->dn);
313 }
316 /***************
317 Create new
318 ***************/
320 /* Insert new entry*/
321 if($s_action == "new" ){
323 $dummy_dn = "cn=dummy,".get_ou('conferenceou').$this->DivListConference->selectedBase;
324 $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference");
325 if(preg_match("/c/",$acl)){
326 /* Set up the users ACL's for this 'dn' */
327 $this->dn= "new";
328 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference");
329 $this->conftab->set_acl_base($dummy_dn);
330 session::un_set('objectinfo');
331 }
332 }
335 /***************
336 Save entry
337 ***************/
339 /* Edit finished, check and save changes */
340 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
341 /* Check tabs, will feed message array */
342 $this->conftab->last= $this->conftab->current;
343 $this->conftab->save_object();
344 $message= $this->conftab->check();
346 if (count($message) == 0){
347 if($this->conftab->save() == 1){
348 gosa_log ("goFonConference object '".$this->dn."' saving failed.");
349 return;
350 }
351 gosa_log ("goFonConference object '".$this->dn."' has been saved");
353 if (!isset($_POST['edit_apply'])){
354 $this->remove_lock();
355 $this->conftab= NULL;
356 session::un_set('objectinfo');
357 }else{
359 /* Reinitialize tab */
360 if($this->conftab instanceof tabs){
361 $this->conftab->re_init();
362 }
363 }
365 } else {
366 msg_dialog::displayChecks($message);
367 }
368 }
371 /***************
372 Display dialogs
373 ***************/
375 /* if edit or new, show dialog */
376 if(($this->conftab) && (isset($this->conftab->config))){
377 $display= $this->conftab->execute();
379 /* Don't show buttons if tab dialog requests this */
380 if (!$this->conftab->by_object[$this->conftab->current]->dialog){
381 $display.= "<p style=\"text-align:right\">\n";
382 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
383 $display.= " \n";
384 if ($this->dn != "new"){
385 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
386 $display.= " \n";
387 }
388 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
389 $display.= "</p>";
390 }
391 return ($display);
392 }
395 /***************
396 display divlist
397 ***************/
399 /* Check if there is a snapshot dialog open */
400 $base = $this->DivListConference->selectedBase;
401 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
402 return($str);
403 }
405 /* Return rendered main page */
406 /* Display dialog with system list */
407 $this->DivListConference->parent = $this;
408 $this->DivListConference->execute();
410 /* Add departments if subsearch is disabled */
411 if(!$this->DivListConference->SubSearch){
412 $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5,1);
413 }
414 $this->reload();
415 $this->DivListConference->setEntries($this->conferences);
416 return($this->DivListConference->Draw());
417 }
420 /* Return departments, that will be included within snapshot detection */
421 function get_used_snapshot_bases()
422 {
423 return(array(get_ou('conferenceou').$this->DivListConference->selectedBase));
424 }
427 /* Reload entries for divlist.
428 * reload all conferences for the current base, with the given regex
429 */
430 function reload()
431 {
432 $Base = get_ou('conferenceou').$this->DivListConference->selectedBase;
433 $SubSearch = $this->DivListConference->SubSearch;
434 $Regex = $this->DivListConference->Regex;
435 $Flags = GL_SIZELIMIT ;
436 $Filter = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
437 $Attrs = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
439 if($SubSearch){
440 $Flags |= GL_SUBSEARCH;
441 }
443 $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags);
444 }
446 function remove_from_parent()
447 {
448 /* Ehm what are we doinf here ? */
450 $cfg = new conference($this->config, $this->dn);
451 $cfg->set_acl_category("gofonconference");
452 $cfg->set_acl_base($this->dn);
454 $cfg->remove_from_parent();
455 $ldap= $this->config->get_ldap_link();
456 $ldap->cd ($this->dn);
457 $ldap->recursive_remove();
459 /* Optionally execute a command after we're done */
460 $this->postremove();
462 /* Delete references to object groups */
463 $ldap->cd ($this->config->current['BASE']);
464 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
465 while ($ldap->fetch()){
466 $og= new conftab($this->config, $ldap->getDN());
467 unset($og->member[$this->dn]);
468 $og->save ();
469 }
471 }
474 function copyPasteHandling_from_queue($s_action,$s_entry)
475 {
476 /* Check if Copy & Paste is disabled */
477 if(!is_object($this->CopyPasteHandler)){
478 return("");
479 }
481 $ui = get_userinfo();
483 /* Add a single entry to queue */
484 if($s_action == "cut" || $s_action == "copy"){
486 /* Cleanup object queue */
487 $this->CopyPasteHandler->cleanup_queue();
488 $dn = $this->conferences[$s_entry]['dn'];
490 if($s_action == "copy" && preg_match("/r/",$ui->has_complete_category_acls($dn,"gofonconference"))){
491 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference");
492 }
493 if($s_action == "cut" && preg_match("/(r.*d|d.*r)/",$ui->has_complete_category_acls($dn,"gofonconference"))){
494 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference");
495 }
496 }
498 /* Add entries to queue */
499 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
501 /* Cleanup object queue */
502 $this->CopyPasteHandler->cleanup_queue();
504 /* Add new entries to CP queue */
505 foreach($this->list_get_selected_items() as $id){
506 $dn = $this->conferences[$id]['dn'];
508 if($s_action == "copy_multiple" && preg_match("/r/",$ui->has_complete_category_acls($dn,"gofonconference"))){
509 $this->CopyPasteHandler->add_to_queue($dn,"copy","conferencetabs","CONFERENCETABS","gofonconference");
510 }
511 if($s_action == "cut_multiple" && preg_match("/(r.*d|d.*r)/",$ui->has_complete_category_acls($dn,"gofonconference"))){
512 $this->CopyPasteHandler->add_to_queue($dn,"cut","conferencetabs","CONFERENCETABS","gofonconference");
513 }
514 }
515 }
517 /* Start pasting entries */
518 if($s_action == "editPaste"){
519 $this->start_pasting_copied_objects = TRUE;
520 }
521 /* Return C&P dialog */
522 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
524 /* Get dialog */
525 $data = $this->CopyPasteHandler->execute();
526 $this->CopyPasteHandler->SetVar("base",$this->DivListConference->selectedBase);
528 /* Return dialog data */
529 if(!empty($data)){
530 return($data);
531 }
532 }
534 /* Automatically disable status for pasting */
535 if(!$this->CopyPasteHandler->entries_queued()){
536 $this->start_pasting_copied_objects = FALSE;
537 }
538 return("");
539 }
542 function save_object()
543 {
544 $this->DivListConference->save_object();
545 }
548 /*! \brief Remove entry locks if the plugin was aborted.
549 */
550 function remove_lock()
551 {
552 if($this->dn) del_lock($this->dn);
553 if(is_array($this->dns) && count($this->dns)) del_lock($this->dns);
554 if(isset($this->conftab) && isset($this->conftab->dn)){
555 del_lock ($this->conftab->dn);
556 }
557 }
560 function list_get_selected_items()
561 {
562 $ids = array();
563 foreach($_POST as $name => $value){
564 if(preg_match("/^item_selected_[0-9]*$/",$name)){
565 $id = preg_replace("/^item_selected_/","",$name);
566 $ids[$id] = $id;
567 }
568 }
569 return($ids);
570 }
573 }
574 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
575 ?>