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]['DN'])), 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();
174 $smarty->assign("usePrototype", "true");
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(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
276 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
278 /* Acl can't contain _ so we remove it here. */
279 $acl_name = preg_replace("/_/","",$attrs);
281 if($this->acl_is_writeable($acl_name)){
283 if(isset($_POST[$attrs])){
284 $this->$attrs = $_POST[$attrs];
285 }else{
286 $this->$attrs = false;
287 }
288 }
289 }
290 }
291 }
294 function check_database_accessibility()
295 {
296 /* Check if mysql extension is available */
297 if(!is_callable("mysql_pconnect")){
298 return(msgPool::missingext("php-mysql"));
299 }
301 /********************
302 * Check currently selected home server
303 ********************/
305 $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer];
306 $r_current = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
307 if(!$r_current){
308 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current));
309 return(msgPool::dbconnect("GOfon",@mysql_error($r_current), $cfg_Current['SERVER']));
310 }
311 $db_current = @mysql_select_db($cfg_Current['DB'],$r_current);
312 if(!$db_current){
313 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current));
314 mysql_close($r_current);
315 return(msgPool::dbselect("GOfon",@mysql_error($r_current), $cfg_Current['DB']));
316 }
318 /********************
319 * Check init home server
320 ********************/
322 if($this->goFonHomeServers != $this->init_HomeServer){
323 $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
324 $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
325 if(!$r_init){
326 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
327 return(msgPool::dbconnect("GOfon",@mysql_error($r_current), $cfg_Init['SERVER']));
328 }
329 $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
330 if(!$db_init){
331 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
332 mysql_close($r_init);
333 return(msgPool::dbselect("GOfon",@mysql_error($r_current), $cfg_Init['DB']));
334 }
335 }
336 }
338 /* Check values */
339 function check()
340 {
341 /* Call common method to give check the hook */
342 $message= plugin::check();
344 if($this->is_number_used()){
345 $message[] = $this->is_number_used();
346 }
348 /* Check if previously selected server is still available */
349 if($this->initially_was_account && !isset($this->goFonHomeServers[$this->goFonHomeServer])){
350 $message[]= sprintf(_("The previously selected asterisk home server '%s' is no longer available!"),preg_replace("/,/",", ",$this->goFonHomeServer));
351 return($message);
352 }
354 if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
355 $message[]= msgPool::required(_("PIN"));
356 }
358 if($this->cn == ""){
359 $message[] = msgPool::required(_("Name"));
360 }
362 if(!is_numeric($this->telephoneNumber)){
363 $message[] = msgPool::invalid(_("Number"),$this->telephoneNumber,"/[0-9]/");
364 }
366 if(!((is_numeric($this->goFonConferenceOptionLifetime))||(empty($this->goFonConferenceOptionLifetime)))){
367 $message[] = msgPool::invalid(_("Lifetime"),$this->goFonConferenceOptionLifetime,"/[0-9]/");
368 }
370 /* Check if add could be successful */
371 $str = $this->SQL_add_me(false);
372 if(!empty($str)){
373 $message[] = $str;
374 }
376 if($this->old_cn != $this->cn || $this->base != $this->old_base){
377 $ldap = $this->config->get_ldap_link();
378 $ldap->cd(get_ou('phoneConferenceRDN').$this->base);
379 $ldap->search("(&(objectClass=goFonConference)(cn=".$this->cn."))",array("cn"));
380 if($ldap->count()){
381 $message[] = msgPool::duplicated(_("Name"));
382 }
383 }
385 /* Check if we are allowed to create or move this object
386 */
387 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
388 $message[] = msgPool::permCreate();
389 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
390 $message[] = msgPool::permMove();
391 }
393 return $message;
394 }
397 function SQL_add_me($save)
398 {
399 /* Check if there is at least on server configuration */
400 if(!count($this->goFonHomeServers)){
401 return(msgPool::noserver(_("GOfon")));
402 }
404 /********************
405 * Get configuration and try to connect
406 ********************/
408 /* Check if databases are reachable, returns an error string if anything fails */
409 $error_str = $this->check_database_accessibility();
410 if($error_str){
411 return($error_str);
412 }
414 /* Remove old entries, returns an error string if anything fails */
415 $error_str = $this->SQL_remove_me($save);
416 if($error_str){
417 return($error_str);
418 }
420 /* Connect to current database to be able to add new entries */
421 $SQL=array();
422 $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer] ;
423 $res_cur = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
424 $db_cur = @mysql_select_db($cfg_Current['DB'],$res_cur);
426 /********************
427 * Remove entries that could cause trouble
428 ********************/
431 /* Check table definitions
432 */
433 if($save && !phoneAccount::checkRealtimeTables($cfg_Current)){
434 msg_dialog::display(_("Warning"),
435 sprintf(_("GOsa identified problems with your MySQL table definition, please activate debugging for details.")),
436 WARNING_DIALOG);
437 }
440 /* If the current home server is different to the initial home server,
441 * there may be already some entries with the given telephoneNumber and/or cn.
442 * We must remove those entries to avoid duplicate use of the same extension name.
443 */
444 if($this->goFonHomeServer != $this->init_HomeServer){
445 $query = "SELECT id FROM ".$cfg_Current['EXT_TABLE']." WHERE exten='".$this->telephoneNumber."' OR exten='".$this->cn."';";
446 $res = @mysql_query($query,$res_cur);
447 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
448 if(!$res){
449 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($res_cur));
450 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Current['SERVER']));
451 }
452 if($save && mysql_affected_rows($res_cur)) {
453 $SQL[] = "DELETE FROM ".$cfg_Current['EXT_TABLE']."
454 WHERE (exten='".$this->telephoneNumber."')
455 OR (exten='".$this->cn."')";
456 }
457 }
459 /********************
460 * Add new conference entry
461 ********************/
462 if((!empty($this->telephoneNumber))&&($save==true)){
464 /* Create string out of conference Flags */
465 $parameter ="";
466 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
467 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
468 $parameter .= $this->$attrs;
469 }
471 /*
472 * ringing
473 * set language()=...
474 * wait 2
475 * answer
476 * wait 2
477 * meetme...
478 * hangup
479 * */
481 $i=1;
482 $EXT=array();
483 $context="GOsa";
485 // Ringing
486 $EXT[$i]['exten'] =$this->telephoneNumber;
487 $EXT[$i]['context'] =$context;
488 $EXT[$i]['priority']=$i;
489 $EXT[$i]['app'] ="ringing";
490 $EXT[$i]['appdata'] ="";
491 $i++;
493 // Set Language to German
494 $EXT[$i]['exten'] =$this->telephoneNumber;
495 $EXT[$i]['context'] = $context;
496 $EXT[$i]['priority']= $i;
497 $EXT[$i]['app'] ="Set";
498 $EXT[$i]['appdata'] ="LANGUAGE()=".$this->language;
499 $i++;
501 // Recordingformat for conference
502 if($this->goFonConferenceOption_r == "r"){
503 $EXT[$i]['exten'] =$this->telephoneNumber;
504 $EXT[$i]['context'] =$context;
505 $EXT[$i]['priority']= $i;
506 $EXT[$i]['app'] ="Setvar";
507 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
508 $i++;
509 }
511 // Wait for 2 seconds
512 $EXT[$i]['exten'] =$this->telephoneNumber;
513 $EXT[$i]['context'] =$context;
514 $EXT[$i]['priority']=$i;
515 $EXT[$i]['app'] ="wait";
516 $EXT[$i]['appdata'] ="2";
517 $i++;
519 // Answer Call
520 $EXT[$i]['exten'] =$this->telephoneNumber;
521 $EXT[$i]['context'] =$context;
522 $EXT[$i]['priority']=$i;
523 $EXT[$i]['app'] ="answer";
524 $EXT[$i]['appdata'] ="";
525 $i++;
527 // Wait for 2 seconds
528 $EXT[$i]['exten'] =$this->telephoneNumber;
529 $EXT[$i]['context'] =$context;
530 $EXT[$i]['priority']=$i;
531 $EXT[$i]['app'] ="wait";
532 $EXT[$i]['appdata'] ="2";
533 $i++;
535 // Start Conference
536 $EXT[$i]['exten'] =$this->telephoneNumber;
537 $EXT[$i]['context'] =$context;
538 $EXT[$i]['priority']=$i;
539 $EXT[$i]['app'] ="MeetMe";
540 if(empty($this->goFonPIN)) {
541 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
542 }else{
543 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
544 }
545 $i++;
547 // Hanup command
548 $EXT[$i]['exten'] =$this->telephoneNumber;
549 $EXT[$i]['context'] =$context;
550 $EXT[$i]['priority']=$i;
551 $EXT[$i]['app'] ="hangup";
552 $EXT[$i]['appdata'] ="";
553 $i++;
555 // Map name to number
556 $EXT[$i]['exten'] =$this->cn;
557 $EXT[$i]['context'] =$context;
558 $EXT[$i]['priority']=1;
559 $EXT[$i]['app'] ="Goto";
560 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
563 foreach($EXT as $keytop => $valtop){
564 $s_keys = "";
565 $s_values = "";
566 foreach($valtop as $key=>$val){
567 $s_keys .="`".$key."`,";
568 $s_values .="'".$val."',";
569 }
570 $s_keys =preg_replace("/\,$/","",$s_keys);
571 $s_values =preg_replace("/\,$/","",$s_values);
572 $SQL[]="INSERT INTO ".$cfg_Current['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
573 }
577 /* Start transaction, to be able to rollback
578 */
579 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>---Updating/Inserting entries---</b>","");
581 mysql_query("begin;",$res_cur);
582 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>begin;</b>","<i>Starting transaction!</i>");
584 foreach($SQL as $query){
585 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>".$query."</b>", "");
586 if(!mysql_query($query,$res_cur)){
587 $err = mysql_error($res_cur);
588 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"\n".$err, "<b>FAILED</b>");
589 msg_dialog::display(_("Error"),
590 msgPool::mysqlerror($err,__CLASS__)." ".
591 "\n<p>"._("Please activate debugging for details!")."</p>",
592 ERROR_DIALOG);
594 mysql_query("rollback;",$res_cur);
595 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>rollback;</b>", "<b>ERROR</b> Rollback transaction!");
596 @mysql_close($res_cur);
597 return(false);
598 }
599 }
601 /* Let changes get active, everything was fine;
602 */
603 mysql_query("commit;",$res_cur);
604 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>commit;</b>", "");
605 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>---Transaction sucessful!---</b>", "");
606 }
608 @mysql_close($res_cur);
609 }
612 /* Remove initial entry from database
613 * This function checks if there is an entry in the
614 * initial home server that uses this->old_cn or $this->old_tele_number
615 * and removes this entries.
616 * This function is called from save and remove_from parent.
617 *
618 * The parameter '$save' is false if we just
619 * want to check if a remove is possible.
620 * And true if we realy want to remove the entries.
621 */
622 function SQL_remove_me($save)
623 {
624 /* check database access */
625 $str = $this->check_database_accessibility();
626 if($str){
627 return($str);
628 }
630 /* Connect to old database */
631 $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
632 $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
633 $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
635 /* Check if there is an old entry */
636 $query = "SELECT id FROM ".$cfg_Init['EXT_TABLE']." WHERE exten='".$this->old_tele_number."' OR exten='".$this->old_cn."';";
637 $res = @mysql_query($query,$r_init);
638 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
639 if(!$res){
640 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
641 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
642 }
644 /* There are entries using this cn and/or phone number */
645 if($save && mysql_affected_rows($r_init)) {
646 $SQL = "DELETE FROM ".$cfg_Init['EXT_TABLE']."
647 WHERE (exten='".$this->old_tele_number."')
648 OR (exten='".$this->old_cn."')";
650 /* Query and ensure that everything went fine */
651 $res = @mysql_query($SQL,$r_init);
652 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query");
653 if(!$res){
654 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
655 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
656 }
658 }//ENDE old num availiable ...
659 @mysql_close($r_init);
660 return(false);
661 }
665 /* This function checks if the given phonenumbers are available or already in use*/
666 function is_number_used()
667 {
668 $ldap= $this->config->get_ldap_link();
669 $ldap->cd($this->config->current['BASE']);
670 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
671 while($attrs = $ldap->fetch()) {
672 unset($attrs['telephoneNumber']['count']);
673 foreach($attrs['telephoneNumber'] as $tele){
674 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
675 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
676 $numbers[$tele]=$attrs;
677 }
678 }
680 $num = $this->telephoneNumber;
681 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){
682 if(isset($numbers[$num]['uid'][0])){
683 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['uid'][0]);
684 }else{
685 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['cn'][0]);
686 }
687 }
688 }
691 /* Save to LDAP */
692 function save()
693 {
695 if((!isset($this->attrs['goFonPIN']))){
696 $pin_use = false;
697 }else{
698 $pin_use = true;
699 }
701 /* Unset PIN if this is a conference without PIN */
702 if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
703 $this->goFonPIN = "";
704 }
706 plugin::save();
708 if(empty($this->old_tele_number)){
709 $this->old_tele_number= $this->telephoneNumber;
710 }
712 $this->SQL_add_me(true);
714 if(empty($this->goFonConferenceOption_P)){
715 if($pin_use){
716 $this->attrs['goFonPIN']=array();
717 }else{
718 unset($this->attrs['goFonPIN']);
719 }
720 }
721 $this->attrs['goFonConferenceOption']="";
722 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
723 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
724 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
725 unset($this->attrs[$attrs]);
726 }
728 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
729 $this->attrs['goFonConferenceOption'].="|".$this->language;
730 unset($this->attrs['goFonConferenceOptionLifetime']);
732 /* Write back to ldap */
734 unset($this->attrs['base']);
736 $ldap= $this->config->get_ldap_link();
737 $ldap->cd($this->config->current['BASE']);
738 $ldap->cat($this->dn, array('dn'));
740 if ($ldap->count()){
741 $ldap->cd($this->dn);
742 $this->cleanup();
743 $ldap->modify ($this->attrs);
744 $this->handle_post_events('modify');
745 } else {
746 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
747 $ldap->cd($this->dn);
748 $ldap->add($this->attrs);
749 $this->handle_post_events('add');
750 }
752 /* Log last action */
753 if($this->initially_was_account){
754 new log("modify","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
755 }else{
756 new log("create","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
757 }
759 if (!$ldap->success()){
760 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
761 }
763 /* Optionally execute a command after we're done */
764 $this->postcreate();
765 }
768 function getCopyDialog()
769 {
770 $smarty = get_smarty();
771 $smarty->assign("cn" ,$this->cn);
772 $smarty->assign("telephoneNumber" ,$this->telephoneNumber);
773 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
774 $ret = array();
775 $ret['string'] = $str;
776 $ret['status'] = "";
777 return($ret);
778 }
781 function saveCopyDialog()
782 {
783 if(isset($_POST['cn'])){
784 $this->cn = $_POST['cn'];
785 }
786 if(isset($_POST['telephoneNumber'])){
787 $this->telephoneNumber = $_POST['telephoneNumber'];
788 }
789 }
791 function PrepareForCopyPaste($source)
792 {
793 plugin::PrepareForCopyPaste($source) ;
795 $source_o = new conference($this->config,$source['dn']);
797 foreach($this->attributes as $attr){
798 $this->$attr = $source_o->$attr;
799 }
800 }
803 /* Return plugin informations for acl handling */
804 static function plInfo()
805 {
806 return (array(
807 "plShortName" => _("Conference"),
808 "plDescription" => _("Phone conference management"),
809 "plSelfModify" => TRUE,
810 "plDepends" => array(),
811 "plPriority" => 0,
812 "plSection" => array("administration"),
813 "plCategory" => array("gofonconference" => array("description" => _("GOfon conference"),
814 "objectClass" => "gofonConference")),
816 "plProvidedAcls" => array(
817 "cn" => _("Name"),
818 "base" => _("Base"),
819 "description" => _("Description"),
820 "goFonPIN" => _("Conference PIN"),
822 "language" => _("Language"),
824 "goFonHomeServer" => _("Home server"),
825 "goFonConferenceOptionP" => _("Preset PIN"),
826 "goFonConferenceOptionr" => _("Record conference"),
827 "goFonConferenceOptionM" => _("Play music on hold"),
828 "goFonConferenceOptions" => _("Activate menu"),
829 "goFonConferenceOptioni" => _("Announce user activity"),
830 "goFonConferenceOptionc" => _("Count user"),
831 "goFonConferenceOptionD" => _("Conference type"),
833 "goFonConferenceOptionFormat" => _("Format"),
834 "goFonConferenceOptionLifetime" => _("Lifetime"),
835 "telephoneNumber" => _("Telephone number"),
836 "goFonConferenceOwner" => _("Owner"))
837 ));
838 }
841 }
843 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
844 ?>