Code

02d7803eb5de1e31bbaaaf27817388f1522c357c
[gosa.git] / gosa-plugins / gofon / gofon / conference / class_phoneConferenceGeneric.inc
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("conference", "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", set_post($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",set_post($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 = get_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("conference", "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='".mysql_real_escape_string($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='".mysql_real_escape_string($this->telephoneNumber)."') 
463                     OR    (exten='".mysql_real_escape_string($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'] ="CHANNEL(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']     ="Set";
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             // Hangup 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             if(!is_numeric($this->cn)){
565                 $EXT[$i]['exten']   =$this->cn;
566                 $EXT[$i]['context'] =$context;
567                 $EXT[$i]['priority']=1;
568                 $EXT[$i]['app']     ="Goto";
569                 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
570             }        
572             foreach($EXT as $keytop => $valtop){
573                 $s_keys = "";
574                 $s_values = ""; 
575                 foreach($valtop as $key=>$val){
576                     $s_keys   .="`".$key."`,";
577                     $s_values .="'".mysql_real_escape_string($val)."',";
578                 }
579                 $s_keys   =preg_replace("/\,$/","",$s_keys); 
580                 $s_values =preg_replace("/\,$/","",$s_values); 
581                 $SQL[]="INSERT INTO ".$cfg_Current['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");"; 
582             }
584             /* Start transaction, to be able to rollback
585              */
586             @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>---Updating/Inserting entries---</b>","");
588             mysql_query("begin;",$res_cur);
589             @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>begin;</b>","<i>Starting transaction!</i>");
591             foreach($SQL as $query){
592                 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>".$query."</b>", "");
593                 if(!mysql_query($query,$res_cur)){
594                     $err = mysql_error($res_cur);
595                     @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"\n".$err, "<b>FAILED</b>");
596                     msg_dialog::display(_("Error"),
597                             msgPool::mysqlerror($err,__CLASS__)."&nbsp;".
598                             "\n<p>"._("Please activate debugging for details!")."</p>",
599                             ERROR_DIALOG);
601                     mysql_query("rollback;",$res_cur);
602                     @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>rollback;</b>", "<b>ERROR</b> Rollback transaction!");
603                     @mysql_close($res_cur);
604                     return(false);
605                 }
606             }
608             /* Let changes get active, everything was fine;
609              */
610             mysql_query("commit;",$res_cur);
611             @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>commit;</b>", "");
612             @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>---Transaction sucessful!---</b>", "");
613         } 
615         @mysql_close($res_cur);
616     }
619     /* Remove initial entry from database 
620      * This function checks if there is an entry in the 
621      *  initial home server that uses this->old_cn or $this->old_tele_number
622      *  and removes this entries. 
623      * This function is called from save and remove_from parent.
624      * 
625      *  The parameter '$save' is false if we just 
626      *   want to check if a remove is possible. 
627      *  And true if we realy want to remove the entries.   
628      */
629     function SQL_remove_me($save)
630     {
631         /* check database access */
632         $str = $this->check_database_accessibility();
633         if($str){
634             return($str);
635         }
637         /* Connect to old database */
638         $cfg_Init  = $this->goFonHomeServers[$this->init_HomeServer] ;
639         $r_init    =  @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
640         $db_init   =  @mysql_select_db($cfg_Init['DB'],$r_init);
642         /* Check if there is an old entry */
643         $query = "SELECT id FROM ".$cfg_Init['EXT_TABLE']." WHERE exten='".mysql_real_escape_string($this->old_tele_number)."' OR exten='".mysql_real_escape_string($this->old_cn)."';";
644         $res = @mysql_query($query,$r_init);
645         @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
646         if(!$res){
647             new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
648             return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
649         }
651         /* There are entries using this cn and/or phone number */
652         if($save && mysql_affected_rows($r_init)) {
653             $SQL = "DELETE FROM ".$cfg_Init['EXT_TABLE']." 
654                 WHERE   (exten='".mysql_real_escape_string($this->old_tele_number)."') 
655                 OR    (exten='".mysql_real_escape_string($this->old_cn)."')";
657             /* Query and ensure that everything went fine */
658             $res =  @mysql_query($SQL,$r_init);
659             @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query");
660             if(!$res){
661                 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
662                 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
663             }
665         }//ENDE  old num availiable ...
666         @mysql_close($r_init);
667         return(false);
668     }
672     /* This function checks if the given phonenumbers are available or already in use*/
673     function is_number_used()
674     {
675         $ldap= $this->config->get_ldap_link();
676         $ldap->cd($this->config->current['BASE']);
677         $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
678         while($attrs = $ldap->fetch()) {
679             unset($attrs['telephoneNumber']['count']);
680             foreach($attrs['telephoneNumber'] as $tele){
681                 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
682                 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
683                 $numbers[$tele]=$attrs;
684             }
685         }
687         $num = $this->telephoneNumber;
688         if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){
689             if(isset($numbers[$num]['uid'][0])){
690                 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['uid'][0]);
691             }else{
692                 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['cn'][0]);
693             }
694         }
695     }
698     /* Save to LDAP */
699     function save()
700     {
702         if((!isset($this->attrs['goFonPIN']))){
703             $pin_use = false;
704         }else{
705             $pin_use = true;
706         }
708         /* Unset PIN if this is a conference without PIN */
709         if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
710             $this->goFonPIN = "";
711         }
713         plugin::save();
715         if(empty($this->old_tele_number)){
716             $this->old_tele_number= $this->telephoneNumber;
717         }
719         $this->SQL_add_me(true);
721         if(empty($this->goFonConferenceOption_P)){
722             if($pin_use){
723                 $this->attrs['goFonPIN']=array();
724             }else{
725                 unset($this->attrs['goFonPIN']);
726             }
727         }
728         $this->attrs['goFonConferenceOption']="";
729         foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
730                     "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
731             $this->attrs['goFonConferenceOption'] .= $this->$attrs;
732             unset($this->attrs[$attrs]);         
733         }
735         $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
736         $this->attrs['goFonConferenceOption'].="|".$this->language;
737         unset($this->attrs['goFonConferenceOptionLifetime']);
739         /* Write back to ldap */
741         unset($this->attrs['base']);
743         $ldap= $this->config->get_ldap_link();
744         $ldap->cd($this->config->current['BASE']);
745         $ldap->cat($this->dn, array('dn'));
747         if ($ldap->count()){
748             $ldap->cd($this->dn);
749             $this->cleanup();
750             $ldap->modify ($this->attrs); 
751             $mode = 'modify';
752         } else {
753             $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
754             $ldap->cd($this->dn);
755             $ldap->add($this->attrs);
756             $mode = 'add';
757         }
759         /* Log last action */
760         if($this->initially_was_account){
761             new log("modify","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
762         }else{
763             new log("create","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
764         }
766         if (!$ldap->success()){
767             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
768         }else{
769             $this->handle_post_events($mode);
770         }
771     }
774     function getCopyDialog()
775     {
776         $smarty = get_smarty();
777         $smarty->assign("cn" ,set_post($this->cn));
778         $smarty->assign("telephoneNumber" ,set_post($this->telephoneNumber));
779         $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
780         $ret = array();
781         $ret['string'] = $str;
782         $ret['status'] = "";
783         return($ret);
784     }
787     function saveCopyDialog()
788     {
789         if(isset($_POST['cn'])){
790             $this->cn = get_post('cn');
791         }
792         if(isset($_POST['telephoneNumber'])){
793             $this->telephoneNumber = get_post('telephoneNumber');
794         }
795     }
797     function PrepareForCopyPaste($source)
798     {
799         plugin::PrepareForCopyPaste($source) ;
801         $source_o = new conference($this->config,$source['dn']);
803         foreach($this->attributes as $attr){
804             $this->$attr = $source_o->$attr;
805         }
806     }
809     /* Return plugin informations for acl handling */
810     static function plInfo()
811     {
812         return (array(
813                     "plShortName"   => _("Conference"),
814                     "plDescription" => _("Phone conference management"),
815                     "plSelfModify"  => TRUE,
816                     "plDepends"     => array(),
817                     "plPriority"    => 0,
818                     "plSection"     => array("administration"),
819                     "plRequirements"=> array(
820                         'ldapSchema' => array('goFonConference' => '>=2.7'),
821                         'onFailureDisablePlugin' => array(get_class(),'phoneAccount','phoneConferenceManagment','goFonMacro')
822                         ),
823                     "plCategory"    => array("gofonconference" => array("description" => _("GOfon conference"),
824                             "objectClass" => "goFonConference")),
826                     "plProperties" =>
827                     array(
828                         array(
829                             "name"          => "phoneConferenceRDN",
830                             "type"          => "rdn",
831                             "default"       => "ou=conferences,ou=asterisk,ou=configs,ou=systems,",
832                             "description"   => _("The 'phoneConferenceRDN' statement defines the location where new phone conferences will be created. The default is 'ou=conferences,ou=asterisk,ou=configs,ou=systems,'."),
833                             "check"         => "gosaProperty::isRdn",
834                             "migrate"       => "migrate_phoneConferenceRDN",
835                             "group"         => "plugin",
836                             "mandatory"     => FALSE
837                             )
838                         ),
841             "plProvidedAcls" => array(
842                     "cn"                            => _("Name"),
843                     "base"                          => _("Base"),
844                     "description"                   => _("Description"),
845                     "goFonPIN"                      => _("Conference PIN"),
847                     "language"                      => _("Language"),
849                     "goFonHomeServer"              => _("Home server"),
850                     "goFonConferenceOptionP"       => _("Preset PIN"),
851                     "goFonConferenceOptionr"       => _("Record conference"),
852                     "goFonConferenceOptionM"       => _("Play music on hold"),
853                     "goFonConferenceOptions"       => _("Activate menu"),
854                     "goFonConferenceOptioni"       => _("Announce user activity"),
855                     "goFonConferenceOptionc"       => _("Count user"),
856                     "goFonConferenceOptionD"       => _("Conference type"),
858                     "goFonConferenceOptionFormat"   => _("Format"),
859                     "goFonConferenceOptionLifetime" => _("Lifetime"),
860                     "telephoneNumber"               => _("Telephone number"),
861                     "goFonConferenceOwner"          => _("Owner"))
862                         ));
863     }
868 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
869 ?>