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(msgPool::missingext("php-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));
332 return(msgPool::dbconnect("GOfon",@mysql_error($r_current), $cfg_Current['SERVER']));
333 }
334 $db_current = @mysql_select_db($cfg_Current['DB'],$r_current);
335 if(!$db_current){
336 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current));
337 mysql_close($r_current);
338 return(msgPool::dbselect("GOfon",@mysql_error($r_current), $cfg_Current['DB']));
339 }
341 /********************
342 * Check init home server
343 ********************/
345 if($this->goFonHomeServers != $this->init_HomeServer){
346 $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
347 $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
348 if(!$r_init){
349 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
350 return(msgPool::dbconnect("GOfon",@mysql_error($r_current), $cfg_Init['SERVER']));
351 }
352 $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
353 if(!$db_init){
354 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
355 mysql_close($r_init);
356 return(msgPool::dbselect("GOfon",@mysql_error($r_current), $cfg_Init['DB']));
357 }
358 }
359 }
361 /* Check values */
362 function check()
363 {
364 /* Call common method to give check the hook */
365 $message= plugin::check();
367 if($this->is_number_used()){
368 $message[] = $this->is_number_used();
369 }
371 /* Check if previously selected server is still available */
372 if($this->initially_was_account && !isset($this->goFonHomeServers[$this->goFonHomeServer])){
373 $message[]= sprintf(_("The previously selected asterisk home server '%s' is no longer available!"),preg_replace("/,/",", ",$this->goFonHomeServer));
374 return($message);
375 }
377 if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
378 $message[]= msgPool::required(_("PIN"));
379 }
381 if(empty($this->cn)){
382 $message[] = msgPool::required(_("Name"));
383 }
385 if(!is_numeric($this->telephoneNumber)){
386 $message[] = msgPool::invalid(_("Number"),$this->telephoneNumber,"/[0-9]/");
387 }
389 if(!((is_numeric($this->goFonConferenceOptionLifetime))||(empty($this->goFonConferenceOptionLifetime)))){
390 $message[] = msgPool::invalid(_("Lifetime"),$this->goFonConferenceOptionLifetime,"/[0-9]/");
391 }
393 /* Check if add could be successful */
394 $str = $this->SQL_add_me(false);
395 if(!empty($str)){
396 $message[] = $str;
397 }
399 if($this->old_cn != $this->cn || $this->base != $this->old_base){
400 $ldap = $this->config->get_ldap_link();
401 $ldap->cd(get_ou('conferenceou').$this->base);
402 $ldap->search("(&(objectClass=goFonConference)(cn=".$this->cn."))",array("cn"));
403 if($ldap->count()){
404 $message[] = msgPool::duplicated(_("Name"));
405 }
406 }
407 return $message;
408 }
411 function SQL_add_me($save)
412 {
413 /* Check if there is at least on server configuration */
414 if(!count($this->goFonHomeServers)){
415 return(msgPool::noserver(_("GOfon")));
416 }
418 /********************
419 * Get configuration and try to connect
420 ********************/
422 /* Check if databases are reachable, returns an error string if anything fails */
423 $error_str = $this->check_database_accessibility();
424 if($error_str){
425 return($error_str);
426 }
428 /* Remove old entries, returns an error string if anything fails */
429 $error_str = $this->SQL_remove_me($save);
430 if($error_str){
431 return($error_str);
432 }
434 /* Connect to current database to be able to add new entries */
435 $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer] ;
436 $res_cur = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
437 $db_cur = @mysql_select_db($cfg_Current['DB'],$res_cur);
439 /********************
440 * Remove entries that could cause trouble
441 ********************/
443 /* If the current home server is different to the initial home server,
444 * there may be already some entries with the given telephoneNumber and/or cn.
445 * We must remove those entries to avoid duplicate use of the same extension name.
446 */
447 if($this->goFonHomeServer != $this->init_HomeServer){
448 $query = "SELECT id FROM ".$cfg_Current['EXT_TABLE']." WHERE exten='".$this->telephoneNumber."' OR exten='".$this->cn."';";
449 $res = @mysql_query($query,$res_cur);
450 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
451 if(!$res){
452 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($res_cur));
453 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Current['SERVER']));
454 }
455 if($save && mysql_affected_rows($res_cur)) {
456 $SQL = "DELETE FROM ".$cfg_Current['EXT_TABLE']."
457 WHERE (exten='".$this->telephoneNumber."')
458 OR (exten='".$this->cn."')";
460 /* Query and ensure that everything went fine */
461 $res = @mysql_query($SQL,$res_cur);
462 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query");
463 if(!$res){
464 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($res_cur));
465 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Current['SERVER']));
466 }
467 }
468 }
470 /********************
471 * Add new conference entry
472 ********************/
473 if((!empty($this->telephoneNumber))&&($save==true)){
475 /* Create string out of conference Flags */
476 $parameter ="";
477 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
478 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
479 $parameter .= $this->$attrs;
480 }
482 $i=1;
483 $EXT=array();
484 $context="GOsa";
485 // Set Language to German
486 $EXT[$i]['exten'] =$this->telephoneNumber;
487 $EXT[$i]['context'] = $context;
488 $EXT[$i]['priority']= $i;
489 $EXT[$i]['app'] ="SetLanguage";
490 $EXT[$i]['appdata'] =$this->language;
491 $i++;
493 if($this->goFonConferenceOption_r == "r"){
495 // Recordingformat for conference
496 $EXT[$i]['exten'] =$this->telephoneNumber;
497 $EXT[$i]['context'] =$context;
498 $EXT[$i]['priority']= $i;
499 $EXT[$i]['app'] ="Setvar";
500 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
501 $i++;
503 }
505 // Answer Call
506 $EXT[$i]['exten'] =$this->telephoneNumber;
507 $EXT[$i]['context'] =$context;
508 $EXT[$i]['priority']=$i;
509 $EXT[$i]['app'] ="answer";
510 $EXT[$i]['appdata'] ="";
511 $i++;
513 // Start Conference
514 $EXT[$i]['exten'] =$this->telephoneNumber;
515 $EXT[$i]['context'] =$context;
516 $EXT[$i]['priority']=$i;
517 $EXT[$i]['app'] ="MeetMe";
519 if(empty($this->goFonPIN)) {
520 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
521 }else{
522 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
523 }
524 $i++;
526 // Start Conference
527 $EXT[$i]['exten'] =$this->cn;
528 $EXT[$i]['context'] =$context;
529 $EXT[$i]['priority']=1;
530 $EXT[$i]['app'] ="Goto";
531 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
532 $SQL=array();
534 foreach($EXT as $keytop => $valtop){
535 $s_keys = "";
536 $s_values = "";
537 foreach($valtop as $key=>$val){
538 $s_keys .="`".$key."`,";
539 $s_values .="'".$val."',";
540 }
541 $s_keys =preg_replace("/\,$/","",$s_keys);
542 $s_values =preg_replace("/\,$/","",$s_values);
543 $SQL[]="INSERT INTO ".$cfg_Current['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
544 }
545 foreach($SQL as $sqlsyn){
546 mysql_query($sqlsyn,$res_cur);
547 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$sqlsyn, "Database query");
548 }
549 }
551 @mysql_close($res_cur);
552 }
555 /* Remove initial entry from database
556 * This function checks if there is an entry in the
557 * initial home server that uses this->old_cn or $this->old_tele_number
558 * and removes this entries.
559 * This function is called from save and remove_from parent.
560 *
561 * The parameter '$save' is false if we just
562 * want to check if a remove is possible.
563 * And true if we realy want to remove the entries.
564 */
565 function SQL_remove_me($save)
566 {
567 /* check database access */
568 $str = $this->check_database_accessibility();
569 if($str){
570 return($str);
571 }
573 /* Connect to old database */
574 $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
575 $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
576 $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
578 /* Check if there is an old entry */
579 $query = "SELECT id FROM ".$cfg_Init['EXT_TABLE']." WHERE exten='".$this->old_tele_number."' OR exten='".$this->old_cn."';";
580 $res = @mysql_query($query,$r_init);
581 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
582 if(!$res){
583 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
584 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
585 }
587 /* There are entries using this cn and/or phone number */
588 if($save && mysql_affected_rows($r_init)) {
589 $SQL = "DELETE FROM ".$cfg_Init['EXT_TABLE']."
590 WHERE (exten='".$this->old_tele_number."')
591 OR (exten='".$this->old_cn."')";
593 /* Query and ensure that everything went fine */
594 $res = @mysql_query($SQL,$r_init);
595 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query");
596 if(!$res){
597 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
598 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
599 }
601 }//ENDE old num availiable ...
602 @mysql_close($r_init);
603 return(false);
604 }
608 /* This function checks if the given phonenumbers are available or already in use*/
609 function is_number_used()
610 {
611 $ldap= $this->config->get_ldap_link();
612 $ldap->cd($this->config->current['BASE']);
613 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
614 while($attrs = $ldap->fetch()) {
615 unset($attrs['telephoneNumber']['count']);
616 foreach($attrs['telephoneNumber'] as $tele){
617 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
618 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
619 $numbers[$tele]=$attrs;
620 }
621 }
623 $num = $this->telephoneNumber;
624 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){
625 if(isset($numbers[$num]['uid'][0])){
626 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['uid'][0]);
627 }else{
628 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['cn'][0]);
629 }
630 }
631 }
634 /* Save to LDAP */
635 function save()
636 {
638 if((!isset($this->attrs['goFonPIN']))){
639 $pin_use = false;
640 }else{
641 $pin_use = true;
642 }
644 /* Unset PIN if this is a conference without PIN */
645 if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
646 $this->goFonPIN = "";
647 }
649 plugin::save();
651 if(empty($this->old_tele_number)){
652 $this->old_tele_number= $this->telephoneNumber;
653 }
655 $this->SQL_add_me(true);
657 if(empty($this->goFonConferenceOption_P)){
658 if($pin_use){
659 $this->attrs['goFonPIN']=array();
660 }else{
661 unset($this->attrs['goFonPIN']);
662 }
663 }
664 $this->attrs['goFonConferenceOption']="";
665 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
666 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
667 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
668 unset($this->attrs[$attrs]);
669 }
671 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
672 $this->attrs['goFonConferenceOption'].="|".$this->language;
673 unset($this->attrs['goFonConferenceOptionLifetime']);
675 /* Write back to ldap */
677 unset($this->attrs['base']);
679 $ldap= $this->config->get_ldap_link();
680 $ldap->cd($this->config->current['BASE']);
681 $ldap->cat($this->dn, array('dn'));
683 if ($ldap->count()){
684 $ldap->cd($this->dn);
685 $this->cleanup();
686 $ldap->modify ($this->attrs);
687 $this->handle_post_events('modify');
688 } else {
689 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
690 $ldap->cd($this->dn);
691 $ldap->add($this->attrs);
692 $this->handle_post_events('add');
693 }
695 /* Log last action */
696 if($this->initially_was_account){
697 new log("modify","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
698 }else{
699 new log("create","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
700 }
702 if (!$ldap->success()){
703 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
704 }
706 /* Optionally execute a command after we're done */
707 $this->postcreate();
708 }
711 function getCopyDialog()
712 {
713 $smarty = get_smarty();
714 $smarty->assign("cn" ,$this->cn);
715 $smarty->assign("telephoneNumber" ,$this->telephoneNumber);
716 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
717 $ret = array();
718 $ret['string'] = $str;
719 $ret['status'] = "";
720 return($ret);
721 }
724 function saveCopyDialog()
725 {
726 if(isset($_POST['cn'])){
727 $this->cn = $_POST['cn'];
728 }
729 if(isset($_POST['telephoneNumber'])){
730 $this->telephoneNumber = $_POST['telephoneNumber'];
731 }
732 }
734 function PrepareForCopyPaste($source)
735 {
736 plugin::PrepareForCopyPaste($source) ;
738 $source_o = new conference($this->config,$source['dn']);
740 foreach($this->attributes as $attr){
741 $this->$attr = $source_o->$attr;
742 }
743 }
746 /* Return plugin informations for acl handling */
747 static function plInfo()
748 {
749 return (array(
750 "plShortName" => _("Conference"),
751 "plDescription" => _("Phone conference management"),
752 "plSelfModify" => TRUE,
753 "plDepends" => array(),
754 "plPriority" => 0,
755 "plSection" => array("addons" => _("Addons")),
756 "plCategory" => array("gofonconference" => array("description" => _("GOfon conference"),
757 "objectClass" => "gofonConference")),
759 "plProvidedAcls" => array(
760 "cn" => _("Name"),
761 "base" => _("Base"),
762 "description" => _("Description"),
763 "goFonPIN" => _("Conference PIN"),
765 "goFonHomeServer" => _("Home server"),
766 "goFonConferenceOptionP" => _("Preset PIN"),
767 "goFonConferenceOptionr" => _("Record conference"),
768 "goFonConferenceOptionM" => _("Play music on hold"),
769 "goFonConferenceOptions" => _("Activate menu"),
770 "goFonConferenceOptioni" => _("Announce user activity"),
771 "goFonConferenceOptionc" => _("Count user"),
772 "goFonConferenceOptionD" => _("Conference type"),
774 "goFonConferenceOptionFormat" => _("Format"),
775 "goFonConferenceOptionLifetime" => _("Lifetime"),
776 "telephoneNumber" => _("Telephone number"),
777 "goFonConferenceOwner" => _("Owner"))
778 ));
779 }
782 }
784 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
785 ?>