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;
52 var $baseSelector;
54 /* Headpage attributes */
55 var $view_logged = FALSE;
56 var $dialog ;
58 /* attribute list for save action */
59 var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r","goFonHomeServer",
60 "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c","goFonHomeServer",
61 "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber","goFonConferenceOwner");
63 var $language = "de";
64 var $languages = array();
66 var $objectclasses= array("top", "goFonConference");
68 var $orig_dn ="";
69 var $orig_base = "";
71 function conference (&$config, $dn, $plugin= NULL)
72 {
73 plugin::plugin($config, $dn, $plugin);
74 $this->is_account = TRUE;
75 $this->ui = get_userinfo();
76 $this->orig_dn = $dn;
78 $this->languages= get_languages(TRUE,TRUE);
81 /* Check server configurations
82 * Load all server configuration in $this->goFonHomeServers if available
83 * and use first server as default if necessary.
84 */
85 $a_SETUP= array();
86 $config = session::get('config');
87 if(isset($config->data['SERVERS']['FON']) && is_callable("mysql_connect")) {
89 /* Set available server */
90 $this->goFonHomeServers = $config->data['SERVERS']['FON'];
92 /* Set default server */
93 if($this->dn == "new"){
94 $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
95 }
97 /* Remember inital home server, to be able to remove old entries */
98 $this->init_HomeServer = $this->goFonHomeServer;
100 /* get config */
101 if(!isset($this->goFonHomeServers[$this->goFonHomeServer])){
102 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]['SERVER'])), ERROR_DIALOG);
104 $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
105 $this->init_HomeServer = $this->goFonHomeServers[0]['DN'];
106 }
107 $cur_cfg = $this->goFonHomeServers[$this->goFonHomeServer];
108 }
110 /* Set base */
111 if ($this->dn == "new"){
112 $ui= get_userinfo();
113 if(session::is_set('CurrentMainBase')){
114 $this->base = session::get('CurrentMainBase');
115 }else{
116 $this->base= dn2base($ui->dn);
117 }
118 } else {
120 /* Get base */
121 $this->base = preg_replace ("/^[^,]+,".preg_quote(get_ou('phoneConferenceRDN'), '/')."/i","",$this->dn);;
122 }
124 $this->goFonConferenceOwner=$this->ui->dn;
126 /* Parse Options ...
127 * Parameter|Lifetime|number
128 */
129 if($this->dn!="new"){
130 $tmp1= explode("|",$this->attrs['goFonConferenceOption'][0]);
132 for($i = 0 ; $i < strlen($tmp1[0]);$i++){
133 $varname = "goFonConferenceOption_".$tmp1[0][$i];
134 if($tmp1[0][$i]=="d"){
135 $this->goFonConferenceOption_D = $tmp1[0][$i];
136 }else{
137 $this->$varname = $tmp1[0][$i];
138 }
139 }
141 $this->goFonConferenceOptionLifetime = $tmp1[1];
142 if(isset($tmp1[2]) && isset($this->languages[$tmp1[2]])){
143 $this->language = $tmp1[2];
144 }
146 $this->old_tele_number = $this->telephoneNumber;
147 }
148 $this->old_dn = $this->dn;
149 $this->old_cn = $this->cn;
150 $this->old_base = $this->base;
151 $this->orig_base = $this->base;
152 $this->orig_dn = $this->dn;
154 /* Instanciate base selector */
155 $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
156 $this->baseSelector->setSubmitButton(false);
157 $this->baseSelector->setHeight(300);
158 $this->baseSelector->update(true);
159 }
162 function execute()
163 {
164 /* Call parent execute */
165 plugin::execute();
167 /* Log last action */
168 if($this->is_account && !$this->view_logged){
169 $this->view_logged = TRUE;
170 new log("view","gofonconference/".get_class($this),$this->dn);
171 }
173 $smarty= get_smarty();
176 foreach ($this->attributes as $val){
177 $smarty->assign("$val", $this->$val);
178 if(!$this->$val){
179 $smarty->assign($val."CHK", "");
180 }else{
181 $smarty->assign($val."CHK", " checked ");
182 }
183 }
185 /* Create array with goFonHomeServer */
186 $tmp = array();
187 foreach($this->goFonHomeServers as $dn => $val){
188 if(!is_numeric($dn)){
189 $tmp[$dn] = $val['SERVER'];
190 }
191 }
192 $smarty->assign("language",$this->language);
193 $smarty->assign("languages",$this->languages);
194 $smarty->assign("goFonHomeServers",$tmp);
195 $smarty->assign("goFonConferenceOptions", array("D"=>"Conference ","d"=>"Conference without PIN"));
196 $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
197 $smarty->assign("goFonConferenceOption", $this->goFonConferenceOption_D);
199 $tmp = $this->plInfo();
200 foreach($tmp['plProvidedAcls'] as $name => $translation){
201 $smarty->assign($name."ACL",$this->getacl($name));
202 }
204 $smarty->assign("base" ,$this->baseSelector->render());
206 if(session::get('js')==1){
207 if($this->goFonConferenceOption_P != "P"){
208 $smarty->assign("goFonPINACL", $this->getacl("goFonPIN",TRUE));
209 $smarty->assign("goFonPIN","");
210 }
211 if($this->goFonConferenceOption_r != "r"){
212 $smarty->assign("goFonConferenceOptionFormatACL", $this->getacl("goFonConferenceOptionr",TRUE));
213 }
214 }
215 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
216 }
219 function remove_from_parent()
220 {
221 /* Check if 'old' home server is available in gosa FON server configuration
222 * Try to remove this entry from database and display errors.
223 */
224 if(isset($this->goFonHomeServers[$this->goFonHomeServer])){
225 $str = $this->SQL_remove_me(true);
226 if($str){
227 msg_dialog::display(_("Error"), $str, ERROR_DIALOG);
228 return false;
229 }
230 }else{
231 msg_dialog::display(_("Error"), sprintf(_("Cannot delete entry from server '%s' because it seems to be removed!"), preg_replace("/,/",", ",$this->goFonHomeServer)), ERROR_DIALOG);
232 return false;
233 }
235 /* Remove ldap entry */
236 $ldap= $this->config->get_ldap_link();
237 $ldap->cd ($this->dn);
238 $ldap->recursive_remove();
240 new log("remove","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
242 /* Optionally execute a command after we're done */
243 $this->handle_post_events('remove');
244 }
247 /* Save data to object */
248 function save_object()
249 {
250 if(isset($_POST['phoneConferenceGeneric'])){
252 /* Get selected language */
253 if($this->acl_is_writeable("language") && isset($_POST['language']) && isset($this->languages[get_post('language')])){
254 $this->language = get_post('language');
255 }
257 /* Create a base backup and reset the
258 base directly after calling plugin::save_object();
259 Base will be set seperatly a few lines below */
260 $base_tmp = $this->base;
261 plugin::save_object();
262 $this->base = $base_tmp;
264 /* Refresh base */
265 if ($this->acl_is_moveable($this->base)){
266 if (!$this->baseSelector->update()) {
267 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
268 }
269 if ($this->base != $this->baseSelector->getBase()) {
270 $this->base= $this->baseSelector->getBase();
271 $this->is_modified= TRUE;
272 }
273 }
275 foreach(
276 array("goFonConferenceOption_P","goFonConferenceOption_r",
277 "goFonConferenceOption_M","goFonConferenceOption_s",
278 "goFonConferenceOption_i","goFonConferenceOption_c",
279 "goFonConferenceOption_D") as $attrs){
281 /* Acl can't contain _ so we remove it here. */
282 $acl_name = preg_replace("/_/","",$attrs);
284 if($this->acl_is_writeable($acl_name)){
286 if(isset($_POST[$attrs])){
287 $this->$attrs = $_POST[$attrs];
288 }else{
289 $this->$attrs = false;
290 }
291 }
292 }
293 }
294 }
297 function check_database_accessibility()
298 {
299 /* Check if mysql extension is available */
300 if(!is_callable("mysql_pconnect")){
301 return(msgPool::missingext("php-mysql"));
302 }
304 /********************
305 * Check currently selected home server
306 ********************/
308 $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer];
309 $r_current = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
310 if(!$r_current){
311 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current));
312 return(msgPool::dbconnect("GOfon",@mysql_error($r_current), $cfg_Current['SERVER']));
313 }
314 $db_current = @mysql_select_db($cfg_Current['DB'],$r_current);
315 if(!$db_current){
316 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current));
317 mysql_close($r_current);
318 return(msgPool::dbselect("GOfon",@mysql_error($r_current), $cfg_Current['DB']));
319 }
321 /********************
322 * Check init home server
323 ********************/
325 if($this->goFonHomeServers != $this->init_HomeServer){
326 $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
327 $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
328 if(!$r_init){
329 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
330 return(msgPool::dbconnect("GOfon",@mysql_error($r_current), $cfg_Init['SERVER']));
331 }
332 $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
333 if(!$db_init){
334 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
335 mysql_close($r_init);
336 return(msgPool::dbselect("GOfon",@mysql_error($r_current), $cfg_Init['DB']));
337 }
338 }
339 }
341 /* Check values */
342 function check()
343 {
344 /* Call common method to give check the hook */
345 $message= plugin::check();
347 if($this->is_number_used()){
348 $message[] = $this->is_number_used();
349 }
351 /* Check if previously selected server is still available */
352 if($this->initially_was_account && !isset($this->goFonHomeServers[$this->goFonHomeServer])){
353 $message[]= sprintf(_("The previously selected asterisk home server '%s' is no longer available!"),preg_replace("/,/",", ",$this->goFonHomeServer));
354 return($message);
355 }
357 if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
358 $message[]= msgPool::required(_("PIN"));
359 }
361 // Check if a wrong base was supplied
362 if(!$this->baseSelector->checkLastBaseUpdate()){
363 $message[]= msgPool::check_base();;
364 }
366 if($this->cn == ""){
367 $message[] = msgPool::required(_("Name"));
368 }
370 if(!is_numeric($this->telephoneNumber)){
371 $message[] = msgPool::invalid(_("Number"),$this->telephoneNumber,"/[0-9]/");
372 }
374 if(!((is_numeric($this->goFonConferenceOptionLifetime))||(empty($this->goFonConferenceOptionLifetime)))){
375 $message[] = msgPool::invalid(_("Lifetime"),$this->goFonConferenceOptionLifetime,"/[0-9]/");
376 }
378 /* Check if add could be successful */
379 $str = $this->SQL_add_me(false);
380 if(!empty($str)){
381 $message[] = $str;
382 }
384 if($this->old_cn != $this->cn || $this->base != $this->old_base){
385 $ldap = $this->config->get_ldap_link();
386 $ldap->cd(get_ou('phoneConferenceRDN').$this->base);
387 $ldap->search("(&(objectClass=goFonConference)(cn=".$this->cn."))",array("cn"));
388 if($ldap->count()){
389 $message[] = msgPool::duplicated(_("Name"));
390 }
391 }
393 /* Check if we are allowed to create or move this object
394 */
395 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
396 $message[] = msgPool::permCreate();
397 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
398 $message[] = msgPool::permMove();
399 }
401 return $message;
402 }
405 function SQL_add_me($save)
406 {
407 /* Check if there is at least on server configuration */
408 if(!count($this->goFonHomeServers)){
409 return(msgPool::noserver(_("GOfon")));
410 }
412 /********************
413 * Get configuration and try to connect
414 ********************/
416 /* Check if databases are reachable, returns an error string if anything fails */
417 $error_str = $this->check_database_accessibility();
418 if($error_str){
419 return($error_str);
420 }
422 /* Remove old entries, returns an error string if anything fails */
423 $error_str = $this->SQL_remove_me($save);
424 if($error_str){
425 return($error_str);
426 }
428 /* Connect to current database to be able to add new entries */
429 $SQL=array();
430 $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer] ;
431 $res_cur = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
432 $db_cur = @mysql_select_db($cfg_Current['DB'],$res_cur);
434 /********************
435 * Remove entries that could cause trouble
436 ********************/
439 /* Check table definitions
440 */
441 if($save && !phoneAccount::checkRealtimeTables($cfg_Current)){
442 msg_dialog::display(_("Warning"),
443 sprintf(_("GOsa identified problems with your MySQL table definition, please activate debugging for details.")),
444 WARNING_DIALOG);
445 }
448 /* If the current home server is different to the initial home server,
449 * there may be already some entries with the given telephoneNumber and/or cn.
450 * We must remove those entries to avoid duplicate use of the same extension name.
451 */
452 if($this->goFonHomeServer != $this->init_HomeServer){
453 $query = "SELECT id FROM ".$cfg_Current['EXT_TABLE']." WHERE exten='".$this->telephoneNumber."' OR exten='".$this->cn."';";
454 $res = @mysql_query($query,$res_cur);
455 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
456 if(!$res){
457 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($res_cur));
458 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Current['SERVER']));
459 }
460 if($save && mysql_affected_rows($res_cur)) {
461 $SQL[] = "DELETE FROM ".$cfg_Current['EXT_TABLE']."
462 WHERE (exten='".$this->telephoneNumber."')
463 OR (exten='".$this->cn."')";
464 }
465 }
467 /********************
468 * Add new conference entry
469 ********************/
470 if((!empty($this->telephoneNumber))&&($save==true)){
472 /* Create string out of conference Flags */
473 $parameter ="";
474 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
475 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
476 $parameter .= $this->$attrs;
477 }
479 /*
480 * ringing
481 * set language()=...
482 * wait 2
483 * answer
484 * wait 2
485 * meetme...
486 * hangup
487 * */
489 $i=1;
490 $EXT=array();
491 $context="GOsa";
493 // Ringing
494 $EXT[$i]['exten'] =$this->telephoneNumber;
495 $EXT[$i]['context'] =$context;
496 $EXT[$i]['priority']=$i;
497 $EXT[$i]['app'] ="ringing";
498 $EXT[$i]['appdata'] ="";
499 $i++;
501 // Set Language to German
502 $EXT[$i]['exten'] =$this->telephoneNumber;
503 $EXT[$i]['context'] = $context;
504 $EXT[$i]['priority']= $i;
505 $EXT[$i]['app'] ="Set";
506 $EXT[$i]['appdata'] ="LANGUAGE()=".$this->language;
507 $i++;
509 // Recordingformat for conference
510 if($this->goFonConferenceOption_r == "r"){
511 $EXT[$i]['exten'] =$this->telephoneNumber;
512 $EXT[$i]['context'] =$context;
513 $EXT[$i]['priority']= $i;
514 $EXT[$i]['app'] ="Setvar";
515 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
516 $i++;
517 }
519 // Wait for 2 seconds
520 $EXT[$i]['exten'] =$this->telephoneNumber;
521 $EXT[$i]['context'] =$context;
522 $EXT[$i]['priority']=$i;
523 $EXT[$i]['app'] ="wait";
524 $EXT[$i]['appdata'] ="2";
525 $i++;
527 // Answer Call
528 $EXT[$i]['exten'] =$this->telephoneNumber;
529 $EXT[$i]['context'] =$context;
530 $EXT[$i]['priority']=$i;
531 $EXT[$i]['app'] ="answer";
532 $EXT[$i]['appdata'] ="";
533 $i++;
535 // Wait for 2 seconds
536 $EXT[$i]['exten'] =$this->telephoneNumber;
537 $EXT[$i]['context'] =$context;
538 $EXT[$i]['priority']=$i;
539 $EXT[$i]['app'] ="wait";
540 $EXT[$i]['appdata'] ="2";
541 $i++;
543 // Start Conference
544 $EXT[$i]['exten'] =$this->telephoneNumber;
545 $EXT[$i]['context'] =$context;
546 $EXT[$i]['priority']=$i;
547 $EXT[$i]['app'] ="MeetMe";
548 if(empty($this->goFonPIN)) {
549 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
550 }else{
551 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
552 }
553 $i++;
555 // Hanup command
556 $EXT[$i]['exten'] =$this->telephoneNumber;
557 $EXT[$i]['context'] =$context;
558 $EXT[$i]['priority']=$i;
559 $EXT[$i]['app'] ="hangup";
560 $EXT[$i]['appdata'] ="";
561 $i++;
563 // Map name to number
564 $EXT[$i]['exten'] =$this->cn;
565 $EXT[$i]['context'] =$context;
566 $EXT[$i]['priority']=1;
567 $EXT[$i]['app'] ="Goto";
568 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
571 foreach($EXT as $keytop => $valtop){
572 $s_keys = "";
573 $s_values = "";
574 foreach($valtop as $key=>$val){
575 $s_keys .="`".$key."`,";
576 $s_values .="'".$val."',";
577 }
578 $s_keys =preg_replace("/\,$/","",$s_keys);
579 $s_values =preg_replace("/\,$/","",$s_values);
580 $SQL[]="INSERT INTO ".$cfg_Current['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
581 }
585 /* Start transaction, to be able to rollback
586 */
587 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>---Updating/Inserting entries---</b>","");
589 mysql_query("begin;",$res_cur);
590 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>begin;</b>","<i>Starting transaction!</i>");
592 foreach($SQL as $query){
593 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>".$query."</b>", "");
594 if(!mysql_query($query,$res_cur)){
595 $err = mysql_error($res_cur);
596 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"\n".$err, "<b>FAILED</b>");
597 msg_dialog::display(_("Error"),
598 msgPool::mysqlerror($err,__CLASS__)." ".
599 "\n<p>"._("Please activate debugging for details!")."</p>",
600 ERROR_DIALOG);
602 mysql_query("rollback;",$res_cur);
603 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>rollback;</b>", "<b>ERROR</b> Rollback transaction!");
604 @mysql_close($res_cur);
605 return(false);
606 }
607 }
609 /* Let changes get active, everything was fine;
610 */
611 mysql_query("commit;",$res_cur);
612 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>commit;</b>", "");
613 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>---Transaction sucessful!---</b>", "");
614 }
616 @mysql_close($res_cur);
617 }
620 /* Remove initial entry from database
621 * This function checks if there is an entry in the
622 * initial home server that uses this->old_cn or $this->old_tele_number
623 * and removes this entries.
624 * This function is called from save and remove_from parent.
625 *
626 * The parameter '$save' is false if we just
627 * want to check if a remove is possible.
628 * And true if we realy want to remove the entries.
629 */
630 function SQL_remove_me($save)
631 {
632 /* check database access */
633 $str = $this->check_database_accessibility();
634 if($str){
635 return($str);
636 }
638 /* Connect to old database */
639 $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
640 $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
641 $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
643 /* Check if there is an old entry */
644 $query = "SELECT id FROM ".$cfg_Init['EXT_TABLE']." WHERE exten='".$this->old_tele_number."' OR exten='".$this->old_cn."';";
645 $res = @mysql_query($query,$r_init);
646 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
647 if(!$res){
648 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
649 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
650 }
652 /* There are entries using this cn and/or phone number */
653 if($save && mysql_affected_rows($r_init)) {
654 $SQL = "DELETE FROM ".$cfg_Init['EXT_TABLE']."
655 WHERE (exten='".$this->old_tele_number."')
656 OR (exten='".$this->old_cn."')";
658 /* Query and ensure that everything went fine */
659 $res = @mysql_query($SQL,$r_init);
660 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query");
661 if(!$res){
662 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
663 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
664 }
666 }//ENDE old num availiable ...
667 @mysql_close($r_init);
668 return(false);
669 }
673 /* This function checks if the given phonenumbers are available or already in use*/
674 function is_number_used()
675 {
676 $ldap= $this->config->get_ldap_link();
677 $ldap->cd($this->config->current['BASE']);
678 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
679 while($attrs = $ldap->fetch()) {
680 unset($attrs['telephoneNumber']['count']);
681 foreach($attrs['telephoneNumber'] as $tele){
682 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
683 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
684 $numbers[$tele]=$attrs;
685 }
686 }
688 $num = $this->telephoneNumber;
689 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){
690 if(isset($numbers[$num]['uid'][0])){
691 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['uid'][0]);
692 }else{
693 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['cn'][0]);
694 }
695 }
696 }
699 /* Save to LDAP */
700 function save()
701 {
703 if((!isset($this->attrs['goFonPIN']))){
704 $pin_use = false;
705 }else{
706 $pin_use = true;
707 }
709 /* Unset PIN if this is a conference without PIN */
710 if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
711 $this->goFonPIN = "";
712 }
714 plugin::save();
716 if(empty($this->old_tele_number)){
717 $this->old_tele_number= $this->telephoneNumber;
718 }
720 $this->SQL_add_me(true);
722 if(empty($this->goFonConferenceOption_P)){
723 if($pin_use){
724 $this->attrs['goFonPIN']=array();
725 }else{
726 unset($this->attrs['goFonPIN']);
727 }
728 }
729 $this->attrs['goFonConferenceOption']="";
730 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
731 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
732 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
733 unset($this->attrs[$attrs]);
734 }
736 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
737 $this->attrs['goFonConferenceOption'].="|".$this->language;
738 unset($this->attrs['goFonConferenceOptionLifetime']);
740 /* Write back to ldap */
742 unset($this->attrs['base']);
744 $ldap= $this->config->get_ldap_link();
745 $ldap->cd($this->config->current['BASE']);
746 $ldap->cat($this->dn, array('dn'));
748 if ($ldap->count()){
749 $ldap->cd($this->dn);
750 $this->cleanup();
751 $ldap->modify ($this->attrs);
752 $mode = 'modify';
753 } else {
754 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
755 $ldap->cd($this->dn);
756 $ldap->add($this->attrs);
757 $mode = 'add';
758 }
760 /* Log last action */
761 if($this->initially_was_account){
762 new log("modify","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
763 }else{
764 new log("create","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
765 }
767 if (!$ldap->success()){
768 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
769 }else{
770 $this->handle_post_events($mode);
771 }
772 }
775 function getCopyDialog()
776 {
777 $smarty = get_smarty();
778 $smarty->assign("cn" ,$this->cn);
779 $smarty->assign("telephoneNumber" ,$this->telephoneNumber);
780 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
781 $ret = array();
782 $ret['string'] = $str;
783 $ret['status'] = "";
784 return($ret);
785 }
788 function saveCopyDialog()
789 {
790 if(isset($_POST['cn'])){
791 $this->cn = $_POST['cn'];
792 }
793 if(isset($_POST['telephoneNumber'])){
794 $this->telephoneNumber = $_POST['telephoneNumber'];
795 }
796 }
798 function PrepareForCopyPaste($source)
799 {
800 plugin::PrepareForCopyPaste($source) ;
802 $source_o = new conference($this->config,$source['dn']);
804 foreach($this->attributes as $attr){
805 $this->$attr = $source_o->$attr;
806 }
807 }
810 /* Return plugin informations for acl handling */
811 static function plInfo()
812 {
813 return (array(
814 "plShortName" => _("Conference"),
815 "plDescription" => _("Phone conference management"),
816 "plSelfModify" => TRUE,
817 "plDepends" => array(),
818 "plPriority" => 0,
819 "plSection" => array("administration"),
820 "plCategory" => array("gofonconference" => array("description" => _("GOfon conference"),
821 "objectClass" => "gofonConference")),
823 "plProvidedAcls" => array(
824 "cn" => _("Name"),
825 "base" => _("Base"),
826 "description" => _("Description"),
827 "goFonPIN" => _("Conference PIN"),
829 "language" => _("Language"),
831 "goFonHomeServer" => _("Home server"),
832 "goFonConferenceOptionP" => _("Preset PIN"),
833 "goFonConferenceOptionr" => _("Record conference"),
834 "goFonConferenceOptionM" => _("Play music on hold"),
835 "goFonConferenceOptions" => _("Activate menu"),
836 "goFonConferenceOptioni" => _("Announce user activity"),
837 "goFonConferenceOptionc" => _("Count user"),
838 "goFonConferenceOptionD" => _("Conference type"),
840 "goFonConferenceOptionFormat" => _("Format"),
841 "goFonConferenceOptionLifetime" => _("Lifetime"),
842 "telephoneNumber" => _("Telephone number"),
843 "goFonConferenceOwner" => _("Owner"))
844 ));
845 }
848 }
850 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
851 ?>