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 conference extends plugin
22 {
23 /* department attributes */
24 var $cn = "";
25 var $description = "";
26 var $base = "";
27 var $old_base = "";
28 var $ou = "";
29 var $goFonPIN = "";
30 var $old_cn = "";
32 var $goFonConferenceOption = "";
33 var $goFonConferenceOption_P = ""; // Set PIN
34 var $goFonConferenceOption_r = ""; // record Conference
35 var $goFonConferenceOption_M = ""; // Play Music opn hold
36 var $goFonConferenceOption_s = ""; // activate menu
37 var $goFonConferenceOption_i = ""; // announce new and leaving user
38 var $goFonConferenceOption_c = ""; // Count User
39 var $goFonConferenceOption_D = ""; // Conference Type, no PIN/PIN
41 var $goFonConferenceOwner = "";
42 var $goFonHomeServer = "0"; // Home server of the conference
43 var $init_HomeServer = "0"; // Initial home server of the conference
44 var $goFonHomeServers = array(); // All available home servers
46 var $goFonConferenceOptionFormat = "";
47 var $goFonConferenceOptionLifetime = "";
48 var $telephoneNumber = "";
50 var $old_tele_number = false;
51 var $old_dn;
53 /* Headpage attributes */
54 var $last_dep_sorting= "invalid";
55 var $departments= array();
56 var $view_logged = FALSE;
57 var $dialog ;
59 /* attribute list for save action */
60 var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r","goFonHomeServer",
61 "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c","goFonHomeServer",
62 "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber","goFonConferenceOwner");
64 var $language = "de";
65 var $languages = array();
67 var $objectclasses= array("top", "goFonConference");
69 function conference (&$config, $dn, $plugin= NULL)
70 {
71 plugin::plugin($config, $dn, $plugin);
72 $this->is_account = TRUE;
73 $this->ui = get_userinfo();
74 $this->orig_dn = $dn;
76 $this->languages= get_languages(TRUE,TRUE);
79 /* Check server configurations
80 * Load all server configuration in $this->goFonHomeServers if available
81 * and use first server as default if necessary.
82 */
83 $a_SETUP= array();
84 $config = session::get('config');
85 if(isset($config->data['SERVERS']['FON']) && is_callable("mysql_connect")) {
87 /* Set available server */
88 $this->goFonHomeServers = $config->data['SERVERS']['FON'];
90 /* Set default server */
91 if($this->dn == "new"){
92 $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
93 }
95 /* Remember inital home server, to be able to remove old entries */
96 $this->init_HomeServer = $this->goFonHomeServer;
98 /* get config */
99 if(!isset($this->goFonHomeServers[$this->goFonHomeServer])){
100 msg_dialog::display(_("Obsolete entry"), sprintf(_("The current home server is not available anymore. It will be moved to '%s' if you save this entry!"), preg_replace("/,/",", ",$this->goFonHomeServers[0]['DN'])), ERROR_DIALOG);
102 $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
103 $this->init_HomeServer = $this->goFonHomeServers[0]['DN'];
104 }
105 $cur_cfg = $this->goFonHomeServers[$this->goFonHomeServer];
106 }
108 /* Set base */
109 if ($this->dn == "new"){
110 $ui= get_userinfo();
111 if(session::is_set('CurrentMainBase')){
112 $this->base = session::get('CurrentMainBase');
113 }else{
114 $this->base= dn2base($ui->dn);
115 }
116 } else {
118 /* Get base */
119 $this->base = preg_replace ("/^[^,]+,".normalizePreg(get_ou('conferenceou'))."/i","",$this->dn);;
120 }
122 $this->goFonConferenceOwner=$this->ui->dn;
124 /* Parse Options ...
125 * Parameter|Lifetime|number
126 */
127 if($this->dn!="new"){
128 $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
130 for($i = 0 ; $i < strlen($tmp1[0]);$i++){
131 $varname = "goFonConferenceOption_".$tmp1[0][$i];
132 if($tmp1[0][$i]=="d"){
133 $this->goFonConferenceOption_D = $tmp1[0][$i];
134 }else{
135 $this->$varname = $tmp1[0][$i];
136 }
137 }
139 $this->goFonConferenceOptionLifetime = $tmp1[1];
140 if(isset($tmp1[2]) && isset($this->languages[$tmp1[2]])){
141 $this->language = $tmp1[2];
142 }
144 $this->old_tele_number = $this->telephoneNumber;
145 }
146 $this->old_dn = $this->dn;
147 $this->old_cn = $this->cn;
148 $this->old_base = $this->base;
149 }
152 function execute()
153 {
154 /* Call parent execute */
155 plugin::execute();
157 /* Log last action */
158 if($this->is_account && !$this->view_logged){
159 $this->view_logged = TRUE;
160 new log("view","gofonconference/".get_class($this),$this->dn);
161 }
163 $smarty= get_smarty();
165 $smarty->assign("bases" ,$this->config->idepartments);
166 $smarty->assign("base" ,$this->base);
168 $once = true;
169 foreach($_POST as $name => $value){
170 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){
171 $once = false;
172 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
173 $this->dialog->setCurrentBase($this->base);
174 }
175 }
177 /* Dialog handling */
178 if(is_object($this->dialog)){
179 /* Must be called before save_object */
180 $this->dialog->save_object();
182 if($this->dialog->isClosed()){
183 $this->dialog = false;
184 }elseif($this->dialog->isSelected()){
185 $tmp = $this->get_allowed_bases();
186 if(isset($tmp[$this->dialog->isSelected()])){
187 $this->base = $this->dialog->isSelected();
188 }
189 $this->dialog= false;
190 }else{
191 return($this->dialog->execute());
192 }
193 }
195 foreach ($this->attributes as $val){
196 $smarty->assign("$val", $this->$val);
197 if(!$this->$val){
198 $smarty->assign($val."CHK", "");
199 }else{
200 $smarty->assign($val."CHK", " checked ");
201 }
202 }
204 /* Create array with goFonHomeServer */
205 $tmp = array();
206 foreach($this->goFonHomeServers as $dn => $val){
207 if(!is_numeric($dn)){
208 $tmp[$dn] = $val['SERVER'];
209 }
210 }
211 $smarty->assign("language",$this->language);
212 $smarty->assign("languages",$this->languages);
213 $smarty->assign("goFonHomeServers",$tmp);
214 $smarty->assign("goFonConferenceOptions", array("D"=>"Conference ","d"=>"Conference without PIN"));
215 $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
216 $smarty->assign("goFonConferenceOption", $this->goFonConferenceOption_D);
218 $tmp = $this->plInfo();
219 foreach($tmp['plProvidedAcls'] as $name => $translation){
220 $smarty->assign($name."ACL",$this->getacl($name));
221 }
223 if($this->acl_is_writeable("base")){
224 $smarty->assign("baseSelect",true);
225 }else{
226 $smarty->assign("baseSelect",false);
227 }
229 $smarty->assign("bases" ,$this->get_allowed_bases());
230 $smarty->assign("base_select" ,$this->base);
233 if(session::get('js')==1){
234 if($this->goFonConferenceOption_P != "P"){
235 $smarty->assign("goFonPINACL", $this->getacl("goFonPIN",TRUE));
236 $smarty->assign("goFonPIN","");
237 }
238 if($this->goFonConferenceOption_r != "r"){
239 $smarty->assign("goFonConferenceOptionFormatACL", $this->getacl("goFonConferenceOptionr",TRUE));
240 }
241 }
242 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
243 }
246 function remove_from_parent()
247 {
248 /* Check if 'old' home server is available in gosa FON server configuration
249 * Try to remove this entry from database and display errors.
250 */
251 if(isset($this->goFonHomeServers[$this->goFonHomeServer])){
252 $str = $this->SQL_remove_me(true);
253 if($str){
254 msg_dialog::display(_("Error"), $str, ERROR_DIALOG);
255 return false;
256 }
257 }else{
258 msg_dialog::display(_("Error"), sprintf(_("Cannot delete entry from server '%s' because it seems to be removed!"), preg_replace("/,/",", ",$this->goFonHomeServer)), ERROR_DIALOG);
259 return false;
260 }
262 /* Remove ldap entry */
263 $ldap= $this->config->get_ldap_link();
264 $ldap->cd ($this->dn);
265 $ldap->recursive_remove();
267 new log("remove","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
269 /* Optionally execute a command after we're done */
270 $this->handle_post_events('remove');
271 }
274 /* Save data to object */
275 function save_object()
276 {
277 if(isset($_POST['phoneConferenceGeneric'])){
279 /* Get selected language */
280 if(isset($_POST['language']) && isset($this->languages[get_post('language')])){
281 $this->language = get_post('language');
282 }
284 /* Create a base backup and reset the
285 base directly after calling plugin::save_object();
286 Base will be set seperatly a few lines below */
287 $base_tmp = $this->base;
288 plugin::save_object();
289 $this->base = $base_tmp;
291 /* Save base, since this is no LDAP attribute */
292 $tmp = $this->get_allowed_bases();
293 if(isset($_POST['base'])){
294 if(isset($tmp[$_POST['base']])){
295 $this->base= $_POST['base'];
296 }
297 }
298 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
299 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
301 /* Acl can't contain _ so we remove it here. */
302 $acl_name = preg_replace("/_/","",$attrs);
304 if($this->acl_is_writeable($acl_name)){
306 if(isset($_POST[$attrs])){
307 $this->$attrs = $_POST[$attrs];
308 }else{
309 $this->$attrs = false;
310 }
311 }
312 }
313 }
314 }
317 function check_database_accessibility()
318 {
319 /* Check if mysql extension is available */
320 if(!is_callable("mysql_pconnect")){
321 return(sprintf(_("Missing %s PHP extension!"), "mysql"));
322 }
324 /********************
325 * Check currently selected home server
326 ********************/
328 $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer];
329 $r_current = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
330 if(!$r_current){
331 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current));
333 return(sprintf(_("Cannot connect to %s database on server '%s'!"), "GOfon", $cfg_Current['SERVER']));
334 }
335 $db_current = @mysql_select_db($cfg_Current['DB'],$r_current);
336 if(!$db_current){
337 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current));
338 mysql_close($r_current);
339 return(sprintf(_("Cannot select %s database on server '%s'!"), "GOfon", $cfg_Current['SERVER']));
340 }
342 /********************
343 * Check init home server
344 ********************/
346 if($this->goFonHomeServers != $this->init_HomeServer){
347 $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
348 $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
349 if(!$r_init){
350 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
351 return(sprintf(_("Cannot connect to %s database on server '%s'!"), "GOfon", $cfg_Init['SERVER']));
352 }
353 $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
354 if(!$db_init){
355 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
356 mysql_close($r_init);
357 return(sprintf(_("Cannot select %s database on server '%s'!"), "GOfon", $cfg_Init['SERVER']));
358 }
359 }
360 }
362 /* Check values */
363 function check()
364 {
365 /* Call common method to give check the hook */
366 $message= plugin::check();
368 if($this->is_number_used()){
369 $message[] = $this->is_number_used();
370 }
372 /* Check if previously selected server is still available */
373 if($this->initially_was_account && !isset($this->goFonHomeServers[$this->goFonHomeServer])){
374 $message[]= sprintf(_("The previously selected asterisk home server '%s' is no longer available!"),preg_replace("/,/",", ",$this->goFonHomeServer));
375 return($message);
376 }
378 if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
379 $message[]= _("PIN is not set!");
380 }
382 if(empty($this->cn)){
383 $message[] =_("Name is not set!");
384 }
386 if(!is_numeric($this->telephoneNumber)){
387 $message[] =_("Number is not valid!");
388 }
390 if(!((is_numeric($this->goFonConferenceOptionLifetime))||(empty($this->goFonConferenceOptionLifetime)))){
391 $message[] =_("Lifetime is not valid!");
392 }
394 /* Check if add could be successful */
395 $str = $this->SQL_add_me(false);
396 if(!empty($str)){
397 $message[] = $str;
398 }
400 if($this->old_cn != $this->cn || $this->base != $this->old_base){
401 $ldap = $this->config->get_ldap_link();
402 $ldap->cd(get_ou('conferenceou').$this->base);
403 $ldap->search("(&(objectClass=goFonConference)(cn=".$this->cn."))",array("cn"));
404 if($ldap->count()){
405 $message[] =_("Name is already in use!");
406 }
407 }
408 return $message;
409 }
412 function SQL_add_me($save)
413 {
414 /* Check if there is at least on server configuration */
415 if(!count($this->goFonHomeServers)){
416 return( _("There is currently no asterisk server defined!"));
417 }
419 /********************
420 * Get configuration and try to connect
421 ********************/
423 /* Check if databases are reachable, returns an error string if anything fails */
424 $error_str = $this->check_database_accessibility();
425 if($error_str){
426 return($error_str);
427 }
429 /* Remove old entries, returns an error string if anything fails */
430 $error_str = $this->SQL_remove_me($save);
431 if($error_str){
432 return($error_str);
433 }
435 /* Connect to current database to be able to add new entries */
436 $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer] ;
437 $res_cur = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
438 $db_cur = @mysql_select_db($cfg_Current['DB'],$res_cur);
440 /********************
441 * Remove entries that could cause trouble
442 ********************/
444 /* If the current home server is different to the initial home server,
445 * there may be already some entries with the given telephoneNumber and/or cn.
446 * We must remove those entries to avoid duplicate use of the same extension name.
447 */
448 if($this->goFonHomeServer != $this->init_HomeServer){
449 $query = "SELECT id FROM ".$cfg_Current['EXT_TABLE']." WHERE exten='".$this->telephoneNumber."' OR exten='".$this->cn."';";
450 $res = @mysql_query($query,$res_cur);
451 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
452 if(!$res){
453 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($res_cur));
454 return(sprintf(_("Cannot query %s database on server '%s'!"), "GOfon", $cfg_Current['SERVER']));
455 }
456 if($save && mysql_affected_rows($res_cur)) {
457 $SQL = "DELETE FROM ".$cfg_Current['EXT_TABLE']."
458 WHERE (exten='".$this->telephoneNumber."')
459 OR (exten='".$this->cn."')";
461 /* Query and ensure that everything went fine */
462 $res = @mysql_query($SQL,$res_cur);
463 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query");
464 if(!$res){
465 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($res_cur));
466 return(sprintf(_("Cannot query %s database on server '%s'!"), "GOfon", $cfg_Current['SERVER']));
467 }
468 }
469 }
471 /********************
472 * Add new conference entry
473 ********************/
474 if((!empty($this->telephoneNumber))&&($save==true)){
476 /* Create string out of conference Flags */
477 $parameter ="";
478 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
479 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
480 $parameter .= $this->$attrs;
481 }
483 $i=1;
484 $EXT=array();
485 $context="GOsa";
486 // Set Language to German
487 $EXT[$i]['exten'] =$this->telephoneNumber;
488 $EXT[$i]['context'] = $context;
489 $EXT[$i]['priority']= $i;
490 $EXT[$i]['app'] ="SetLanguage";
491 $EXT[$i]['appdata'] =$this->language;
492 $i++;
494 if($this->goFonConferenceOption_r == "r"){
496 // Recordingformat for conference
497 $EXT[$i]['exten'] =$this->telephoneNumber;
498 $EXT[$i]['context'] =$context;
499 $EXT[$i]['priority']= $i;
500 $EXT[$i]['app'] ="Setvar";
501 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
502 $i++;
504 }
506 // Answer Call
507 $EXT[$i]['exten'] =$this->telephoneNumber;
508 $EXT[$i]['context'] =$context;
509 $EXT[$i]['priority']=$i;
510 $EXT[$i]['app'] ="answer";
511 $EXT[$i]['appdata'] ="";
512 $i++;
514 // Start Conference
515 $EXT[$i]['exten'] =$this->telephoneNumber;
516 $EXT[$i]['context'] =$context;
517 $EXT[$i]['priority']=$i;
518 $EXT[$i]['app'] ="MeetMe";
520 if(empty($this->goFonPIN)) {
521 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
522 }else{
523 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
524 }
525 $i++;
527 // Start Conference
528 $EXT[$i]['exten'] =$this->cn;
529 $EXT[$i]['context'] =$context;
530 $EXT[$i]['priority']=1;
531 $EXT[$i]['app'] ="Goto";
532 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
533 $SQL=array();
535 foreach($EXT as $keytop => $valtop){
536 $s_keys = "";
537 $s_values = "";
538 foreach($valtop as $key=>$val){
539 $s_keys .="`".$key."`,";
540 $s_values .="'".$val."',";
541 }
542 $s_keys =preg_replace("/\,$/","",$s_keys);
543 $s_values =preg_replace("/\,$/","",$s_values);
544 $SQL[]="INSERT INTO ".$cfg_Current['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
545 }
546 foreach($SQL as $sqlsyn){
547 mysql_query($sqlsyn,$res_cur);
548 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$sqlsyn, "Database query");
549 }
550 }
552 @mysql_close($res_cur);
553 }
556 /* Remove initial entry from database
557 * This function checks if there is an entry in the
558 * initial home server that uses this->old_cn or $this->old_tele_number
559 * and removes this entries.
560 * This function is called from save and remove_from parent.
561 *
562 * The parameter '$save' is false if we just
563 * want to check if a remove is possible.
564 * And true if we realy want to remove the entries.
565 */
566 function SQL_remove_me($save)
567 {
568 /* check database access */
569 $str = $this->check_database_accessibility();
570 if($str){
571 return($str);
572 }
574 /* Connect to old database */
575 $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
576 $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
577 $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
579 /* Check if there is an old entry */
580 $query = "SELECT id FROM ".$cfg_Init['EXT_TABLE']." WHERE exten='".$this->old_tele_number."' OR exten='".$this->old_cn."';";
581 $res = @mysql_query($query,$r_init);
582 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
583 if(!$res){
584 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
585 return(sprintf(_("Cannot query %s database on server '%s'!"), "GOfon", $cfg_Init['SERVER']));
586 }
588 /* There are entries using this cn and/or phone number */
589 if($save && mysql_affected_rows($r_init)) {
590 $SQL = "DELETE FROM ".$cfg_Init['EXT_TABLE']."
591 WHERE (exten='".$this->old_tele_number."')
592 OR (exten='".$this->old_cn."')";
594 /* Query and ensure that everything went fine */
595 $res = @mysql_query($SQL,$r_init);
596 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query");
597 if(!$res){
598 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
599 return(sprintf(_("Cannot query %s database on server '%s'!"), "GOfon", $cfg_Init['SERVER']));
600 }
602 }//ENDE old num availiable ...
603 @mysql_close($r_init);
604 return(false);
605 }
609 /* This function checks if the given phonenumbers are available or already in use*/
610 function is_number_used()
611 {
612 $ldap= $this->config->get_ldap_link();
613 $ldap->cd($this->config->current['BASE']);
614 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
615 while($attrs = $ldap->fetch()) {
616 unset($attrs['telephoneNumber']['count']);
617 foreach($attrs['telephoneNumber'] as $tele){
618 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
619 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
620 $numbers[$tele]=$attrs;
621 }
622 }
624 $num = $this->telephoneNumber;
625 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){
626 if(isset($numbers[$num]['uid'][0])){
627 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['uid'][0]);
628 }else{
629 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['cn'][0]);
630 }
631 }
632 }
635 /* Save to LDAP */
636 function save()
637 {
639 if((!isset($this->attrs['goFonPIN']))){
640 $pin_use = false;
641 }else{
642 $pin_use = true;
643 }
645 /* Unset PIN if this is a conference without PIN */
646 if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
647 $this->goFonPIN = "";
648 }
650 plugin::save();
652 if(empty($this->old_tele_number)){
653 $this->old_tele_number= $this->telephoneNumber;
654 }
656 $this->SQL_add_me(true);
658 if(empty($this->goFonConferenceOption_P)){
659 if($pin_use){
660 $this->attrs['goFonPIN']=array();
661 }else{
662 unset($this->attrs['goFonPIN']);
663 }
664 }
665 $this->attrs['goFonConferenceOption']="";
666 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
667 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
668 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
669 unset($this->attrs[$attrs]);
670 }
672 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
673 $this->attrs['goFonConferenceOption'].="|".$this->language;
674 unset($this->attrs['goFonConferenceOptionLifetime']);
676 /* Write back to ldap */
678 unset($this->attrs['base']);
680 $ldap= $this->config->get_ldap_link();
681 $ldap->cd($this->config->current['BASE']);
682 $ldap->cat($this->dn, array('dn'));
684 if ($ldap->count()){
685 $ldap->cd($this->dn);
686 $this->cleanup();
687 $ldap->modify ($this->attrs);
688 $this->handle_post_events('modify');
689 } else {
690 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
691 $ldap->cd($this->dn);
692 $ldap->add($this->attrs);
693 $this->handle_post_events('add');
694 }
696 /* Log last action */
697 if($this->initially_was_account){
698 new log("modify","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
699 }else{
700 new log("create","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
701 }
703 if (!$ldap->success()){
704 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
705 }
707 /* Optionally execute a command after we're done */
708 $this->postcreate();
709 }
712 function getCopyDialog()
713 {
714 $smarty = get_smarty();
715 $smarty->assign("cn" ,$this->cn);
716 $smarty->assign("telephoneNumber" ,$this->telephoneNumber);
717 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
718 $ret = array();
719 $ret['string'] = $str;
720 $ret['status'] = "";
721 return($ret);
722 }
725 function saveCopyDialog()
726 {
727 if(isset($_POST['cn'])){
728 $this->cn = $_POST['cn'];
729 }
730 if(isset($_POST['telephoneNumber'])){
731 $this->telephoneNumber = $_POST['telephoneNumber'];
732 }
733 }
735 function PrepareForCopyPaste($source)
736 {
737 plugin::PrepareForCopyPaste($source) ;
739 $source_o = new conference($this->config,$source['dn']);
741 foreach($this->attributes as $attr){
742 $this->$attr = $source_o->$attr;
743 }
744 }
747 /* Return plugin informations for acl handling */
748 static function plInfo()
749 {
750 return (array(
751 "plShortName" => _("Conference"),
752 "plDescription" => _("Phone conference management"),
753 "plSelfModify" => TRUE,
754 "plDepends" => array(),
755 "plPriority" => 0,
756 "plSection" => array("addons" => _("Addons")),
757 "plCategory" => array("gofonconference" => array("description" => _("GOfon conference"),
758 "objectClass" => "gofonConference")),
760 "plProvidedAcls" => array(
761 "cn" => _("Name"),
762 "base" => _("Base"),
763 "description" => _("Description"),
764 "goFonPIN" => _("Conference PIN"),
766 "goFonHomeServer" => _("Home server"),
767 "goFonConferenceOptionP" => _("Preset PIN"),
768 "goFonConferenceOptionr" => _("Record conference"),
769 "goFonConferenceOptionM" => _("Play music on hold"),
770 "goFonConferenceOptions" => _("Activate menu"),
771 "goFonConferenceOptioni" => _("Announce user activity"),
772 "goFonConferenceOptionc" => _("Count user"),
773 "goFonConferenceOptionD" => _("Conference type"),
775 "goFonConferenceOptionFormat" => _("Format"),
776 "goFonConferenceOptionLifetime" => _("Lifetime"),
777 "telephoneNumber" => _("Telephone number"),
778 "goFonConferenceOwner" => _("Owner"))
779 ));
780 }
783 }
785 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
786 ?>