Code

Removed divlist class for FAI
[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;
53   /* Headpage attributes */
54   var $last_dep_sorting= "invalid";
55   var $departments= array();
56   var $view_logged = FALSE;
57   var $dialog ;
59   /* attribute list for save action */
60   var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r","goFonHomeServer",
61       "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c","goFonHomeServer",
62       "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber","goFonConferenceOwner");
64   var $language  = "de";
65   var $languages = array();
67   var $objectclasses= array("top", "goFonConference");
69   var $orig_dn ="";
70   var $orig_base = "";
72   function conference (&$config, $dn, $plugin= NULL)
73   {
74     plugin::plugin($config, $dn, $plugin);
75     $this->is_account   = TRUE;
76     $this->ui                       = get_userinfo();
77     $this->orig_dn              = $dn;
79     $this->languages= get_languages(TRUE,TRUE);
82     /* Check server configurations
83      * Load all server configuration in $this->goFonHomeServers if available
84      *  and use first server as default if necessary.
85      */
86     $a_SETUP= array();
87     $config = session::get('config');
88     if(isset($config->data['SERVERS']['FON']) && is_callable("mysql_connect")) {
90       /* Set available server */
91       $this->goFonHomeServers = $config->data['SERVERS']['FON'];
93       /* Set default server */
94       if($this->dn == "new"){
95         $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
96       }
98       /* Remember inital home server, to be able to remove old entries */
99       $this->init_HomeServer = $this->goFonHomeServer;
101       /* get config */
102       if(!isset($this->goFonHomeServers[$this->goFonHomeServer])){
103         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);
105         $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
106         $this->init_HomeServer = $this->goFonHomeServers[0]['DN'];
107       }
108       $cur_cfg = $this->goFonHomeServers[$this->goFonHomeServer]; 
109     }
111     /* Set base */
112     if ($this->dn == "new"){
113       $ui= get_userinfo();
114       if(session::is_set('CurrentMainBase')){
115         $this->base  = session::get('CurrentMainBase');
116       }else{
117         $this->base= dn2base($ui->dn);
118       }
119     } else {
121       /* Get base */ 
122       $this->base = preg_replace ("/^[^,]+,".preg_quote(get_ou('phoneConferenceRDN'), '/')."/i","",$this->dn);;
123     }
125     $this->goFonConferenceOwner=$this->ui->dn;
127     /* Parse Options ... 
128      * Parameter|Lifetime|number
129      */
130     if($this->dn!="new"){
131       $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
133       for($i = 0 ; $i < strlen($tmp1[0]);$i++){
134         $varname = "goFonConferenceOption_".$tmp1[0][$i];
135         if($tmp1[0][$i]=="d"){
136           $this->goFonConferenceOption_D = $tmp1[0][$i];    
137         }else{
138           $this->$varname = $tmp1[0][$i];    
139         }
140       }
142       $this->goFonConferenceOptionLifetime  = $tmp1[1];
143       if(isset($tmp1[2]) && isset($this->languages[$tmp1[2]])){
144         $this->language = $tmp1[2];
145       }
146   
147       $this->old_tele_number                = $this->telephoneNumber;
148     }
149     $this->old_dn = $this->dn;
150     $this->old_cn = $this->cn;
151     $this->old_base = $this->base;
152     $this->orig_base = $this->base;
153     $this->orig_dn = $this->dn;
154   
155   }
158   function execute()
159   {
160     /* Call parent execute */
161     plugin::execute();
163     /* Log last action */
164     if($this->is_account && !$this->view_logged){
165       $this->view_logged = TRUE;
166       new log("view","gofonconference/".get_class($this),$this->dn);
167     }
169     $smarty= get_smarty();
171     $smarty->assign("bases" ,$this->config->idepartments);
172     $smarty->assign("base"  ,$this->base);
174     $once = true; 
175     foreach($_POST as $name => $value){
176       if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){
177         $once = false;
178         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
179         $this->dialog->setCurrentBase($this->base);
180       }
181     }
183     /* Dialog handling */
184     if(is_object($this->dialog)){
185       /* Must be called before save_object */
186       $this->dialog->save_object();
188       if($this->dialog->isClosed()){
189         $this->dialog = false;
190       }elseif($this->dialog->isSelected()){
191         $tmp = $this->get_allowed_bases();
192         if(isset($tmp[$this->dialog->isSelected()])){
193           $this->base = $this->dialog->isSelected();
194         }
195         $this->dialog= false;
196       }else{
197         return($this->dialog->execute());
198       }
199     }
201     foreach ($this->attributes as $val){
202       $smarty->assign("$val", $this->$val);
203       if(!$this->$val){
204         $smarty->assign($val."CHK", "");
205       }else{
206         $smarty->assign($val."CHK", " checked ");
207       }
208     }
210     /* Create array with goFonHomeServer */
211     $tmp = array();
212     foreach($this->goFonHomeServers as $dn => $val){
213       if(!is_numeric($dn)){
214         $tmp[$dn]  = $val['SERVER'];
215       }
216     }
217     $smarty->assign("language",$this->language);
218     $smarty->assign("languages",$this->languages);
219     $smarty->assign("goFonHomeServers",$tmp);
220     $smarty->assign("goFonConferenceOptions",               array("D"=>"Conference ","d"=>"Conference without PIN"));
221     $smarty->assign("goFonConferenceOptionFormats",     array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
222     $smarty->assign("goFonConferenceOption",        $this->goFonConferenceOption_D);
224     $tmp = $this->plInfo();
225     foreach($tmp['plProvidedAcls'] as $name => $translation){
226       $smarty->assign($name."ACL",$this->getacl($name));
227     }
229     if($this->acl_is_writeable("base")){
230       $smarty->assign("baseSelect",true);
231     }else{
232       $smarty->assign("baseSelect",false);
233     }
235     $smarty->assign("bases" ,$this->get_allowed_bases());
236     $smarty->assign("base_select"  ,$this->base);
239     if(session::get('js')==1){
240       if($this->goFonConferenceOption_P != "P"){
241         $smarty->assign("goFonPINACL", $this->getacl("goFonPIN",TRUE));
242         $smarty->assign("goFonPIN","");
243       }
244       if($this->goFonConferenceOption_r != "r"){
245         $smarty->assign("goFonConferenceOptionFormatACL", $this->getacl("goFonConferenceOptionr",TRUE));
246       }
247     }
248     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
249   }
252   function remove_from_parent()
253   {
254     /* Check if 'old' home server is available in gosa FON server configuration 
255      * Try to remove this entry from database and display errors.  
256      */
257     if(isset($this->goFonHomeServers[$this->goFonHomeServer])){
258       $str = $this->SQL_remove_me(true); 
259       if($str){
260         msg_dialog::display(_("Error"), $str, ERROR_DIALOG);
261         return false;
262       }
263     }else{
264       msg_dialog::display(_("Error"), sprintf(_("Cannot delete entry from server '%s' because it seems to be removed!"), preg_replace("/,/",", ",$this->goFonHomeServer)), ERROR_DIALOG);
265       return false;
266     }
268     /* Remove ldap entry */
269     $ldap= $this->config->get_ldap_link();
270     $ldap->cd ($this->dn);
271     $ldap->recursive_remove();
273     new log("remove","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
275     /* Optionally execute a command after we're done */
276     $this->handle_post_events('remove');
277   }
280   /* Save data to object */
281   function save_object()
282   {
283     if(isset($_POST['phoneConferenceGeneric'])){
285       /* Get selected language */
286       if($this->acl_is_writeable("language") && isset($_POST['language']) && isset($this->languages[get_post('language')])){
287         $this->language = get_post('language');
288       }
290       /* Create a base backup and reset the
291          base directly after calling plugin::save_object();
292          Base will be set seperatly a few lines below */
293       $base_tmp = $this->base;
294       plugin::save_object();
295       $this->base = $base_tmp;
297       /* Save base, since this is no LDAP attribute */
298       $tmp = $this->get_allowed_bases();
299       if(isset($_POST['base'])){
300         if(isset($tmp[$_POST['base']])){
301           $this->base= $_POST['base'];
302         }
303       }
304       foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
305             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
307         /* Acl can't contain _ so we remove it here. */
308         $acl_name = preg_replace("/_/","",$attrs);
310         if($this->acl_is_writeable($acl_name)){
312           if(isset($_POST[$attrs])){
313             $this->$attrs = $_POST[$attrs];
314           }else{
315             $this->$attrs = false;
316           }
317         }
318       }
319     }
320   }
323   function check_database_accessibility()
324   {
325     /* Check if mysql extension is available */
326     if(!is_callable("mysql_pconnect")){
327       return(msgPool::missingext("php-mysql"));
328     }
330     /********************
331      * Check currently selected home server 
332      ********************/
334     $cfg_Current  = $this->goFonHomeServers[$this->goFonHomeServer];
335     $r_current    =  @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
336     if(!$r_current){
337       new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current));
338       return(msgPool::dbconnect("GOfon",@mysql_error($r_current), $cfg_Current['SERVER']));
339     }
340     $db_current  =  @mysql_select_db($cfg_Current['DB'],$r_current);
341     if(!$db_current){
342       new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current));
343       mysql_close($r_current);
344       return(msgPool::dbselect("GOfon",@mysql_error($r_current), $cfg_Current['DB']));
345     }
347     /********************
348      * Check init home server 
349      ********************/
351     if($this->goFonHomeServers != $this->init_HomeServer){
352       $cfg_Init  = $this->goFonHomeServers[$this->init_HomeServer] ;
353       $r_init    =  @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
354       if(!$r_init){
355         new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
356         return(msgPool::dbconnect("GOfon",@mysql_error($r_current), $cfg_Init['SERVER']));
357       }
358       $db_init  =  @mysql_select_db($cfg_Init['DB'],$r_init);
359       if(!$db_init){
360         new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
361         mysql_close($r_init);
362         return(msgPool::dbselect("GOfon",@mysql_error($r_current), $cfg_Init['DB']));
363       }
364     }
365   }
367   /* Check values */
368   function check()
369   {
370     /* Call common method to give check the hook */
371     $message= plugin::check();
373     if($this->is_number_used()){
374       $message[] =  $this->is_number_used();
375     }
377     /* Check if previously selected server is still available */
378     if($this->initially_was_account && !isset($this->goFonHomeServers[$this->goFonHomeServer])){
379       $message[]= sprintf(_("The previously selected asterisk home server '%s' is no longer available!"),preg_replace("/,/",", ",$this->goFonHomeServer));
380       return($message);
381     }
383     if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
384       $message[]= msgPool::required(_("PIN"));
385     }
387     if($this->cn == ""){
388       $message[] = msgPool::required(_("Name"));
389     }
391     if(!is_numeric($this->telephoneNumber)){
392       $message[] = msgPool::invalid(_("Number"),$this->telephoneNumber,"/[0-9]/");
393     }
395     if(!((is_numeric($this->goFonConferenceOptionLifetime))||(empty($this->goFonConferenceOptionLifetime)))){
396       $message[] = msgPool::invalid(_("Lifetime"),$this->goFonConferenceOptionLifetime,"/[0-9]/");
397     }
399     /* Check if add could be successful */    
400     $str = $this->SQL_add_me(false);
401     if(!empty($str)){
402       $message[] = $str;
403     }
405     if($this->old_cn != $this->cn || $this->base != $this->old_base){
406       $ldap = $this->config->get_ldap_link();
407       $ldap->cd(get_ou('phoneConferenceRDN').$this->base);
408       $ldap->search("(&(objectClass=goFonConference)(cn=".$this->cn."))",array("cn"));
409       if($ldap->count()){
410         $message[] = msgPool::duplicated(_("Name"));
411       }
412     }
414     /* Check if we are allowed to create or move this object
415      */
416     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
417       $message[] = msgPool::permCreate();
418     }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
419       $message[] = msgPool::permMove();
420     }
422     return $message;
423   }
426   function SQL_add_me($save)
427   {
428     /* Check if there is at least on server configuration */
429     if(!count($this->goFonHomeServers)){
430       return(msgPool::noserver(_("GOfon")));
431     }
432   
433     /********************
434      * Get configuration and try to connect 
435      ********************/
437     /* Check if databases are reachable, returns an error string if anything fails  */
438     $error_str = $this->check_database_accessibility();
439     if($error_str){
440       return($error_str);
441     }
443     /* Remove old entries, returns an error string if anything fails  */
444     $error_str = $this->SQL_remove_me($save);
445     if($error_str){
446       return($error_str);
447     }
449     /* Connect to current database to be able to add new entries */
450     $SQL=array();
451     $cfg_Current  = $this->goFonHomeServers[$this->goFonHomeServer] ;
452     $res_cur      =  @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
453     $db_cur       =  @mysql_select_db($cfg_Current['DB'],$res_cur);
455     /********************
456      * Remove entries that could cause trouble  
457      ********************/
460     /* Check table definitions
461      */
462     if($save && !phoneAccount::checkRealtimeTables($cfg_Current)){
463       msg_dialog::display(_("Warning"),
464           sprintf(_("GOsa identified problems with your MySQL table definition, please activate debugging for details.")),
465           WARNING_DIALOG);
466     }
469     /* If the current home server is different to the initial home server,
470      *  there may be already some entries with the given telephoneNumber and/or cn.
471      * We must remove those entries to avoid duplicate use of the same extension name.
472      */
473     if($this->goFonHomeServer != $this->init_HomeServer){
474       $query = "SELECT id FROM ".$cfg_Current['EXT_TABLE']." WHERE exten='".$this->telephoneNumber."' OR exten='".$this->cn."';";
475       $res = @mysql_query($query,$res_cur);
476       @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
477       if(!$res){
478         new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($res_cur));
479         return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Current['SERVER']));
480       }
481       if($save && mysql_affected_rows($res_cur)) {
482         $SQL[] = "DELETE FROM ".$cfg_Current['EXT_TABLE']." 
483           WHERE   (exten='".$this->telephoneNumber."') 
484           OR    (exten='".$this->cn."')";
485       }
486     }
488     /********************
489      * Add new conference entry  
490      ********************/
491     if((!empty($this->telephoneNumber))&&($save==true)){
493       /* Create string out of conference Flags */
494       $parameter  ="";
495       foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
496             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
497         $parameter .= $this->$attrs;
498       }
500       /* 
501        * ringing
502        * set language()=...
503        * wait 2
504        * answer
505        * wait 2
506        * meetme...
507        * hangup
508        * */
510       $i=1;
511       $EXT=array();
512       $context="GOsa";
514       // Ringing
515       $EXT[$i]['exten']   =$this->telephoneNumber;
516       $EXT[$i]['context'] =$context;
517       $EXT[$i]['priority']=$i;
518       $EXT[$i]['app']     ="ringing";
519       $EXT[$i]['appdata'] ="";
520       $i++;      
522       // Set Language to German
523       $EXT[$i]['exten']   =$this->telephoneNumber;
524       $EXT[$i]['context'] = $context;
525       $EXT[$i]['priority']= $i;
526       $EXT[$i]['app']     ="Set";
527       $EXT[$i]['appdata'] ="LANGUAGE()=".$this->language;
528       $i++;      
530       // Recordingformat for conference
531       if($this->goFonConferenceOption_r == "r"){
532         $EXT[$i]['exten']   =$this->telephoneNumber;
533         $EXT[$i]['context'] =$context;
534         $EXT[$i]['priority']= $i;
535         $EXT[$i]['app']     ="Setvar";
536         $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
537         $i++;      
538       }
540       // Wait for 2 seconds
541       $EXT[$i]['exten']   =$this->telephoneNumber;
542       $EXT[$i]['context'] =$context;
543       $EXT[$i]['priority']=$i;
544       $EXT[$i]['app']     ="wait";
545       $EXT[$i]['appdata'] ="2";
546       $i++;      
548       // Answer Call
549       $EXT[$i]['exten']   =$this->telephoneNumber;
550       $EXT[$i]['context'] =$context;
551       $EXT[$i]['priority']=$i;
552       $EXT[$i]['app']     ="answer";
553       $EXT[$i]['appdata'] ="";
554       $i++;      
556       // Wait for 2 seconds
557       $EXT[$i]['exten']   =$this->telephoneNumber;
558       $EXT[$i]['context'] =$context;
559       $EXT[$i]['priority']=$i;
560       $EXT[$i]['app']     ="wait";
561       $EXT[$i]['appdata'] ="2";
562       $i++;      
564       // Start Conference 
565       $EXT[$i]['exten']   =$this->telephoneNumber;
566       $EXT[$i]['context'] =$context;
567       $EXT[$i]['priority']=$i;
568       $EXT[$i]['app']     ="MeetMe";
569       if(empty($this->goFonPIN)) {
570         $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
571       }else{
572         $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
573       }
574       $i++; 
576       // Hanup command
577       $EXT[$i]['exten']   =$this->telephoneNumber;
578       $EXT[$i]['context'] =$context;
579       $EXT[$i]['priority']=$i;
580       $EXT[$i]['app']     ="hangup";
581       $EXT[$i]['appdata'] ="";
582       $i++;      
584       // Map name to number 
585       $EXT[$i]['exten']   =$this->cn;
586       $EXT[$i]['context'] =$context;
587       $EXT[$i]['priority']=1;
588       $EXT[$i]['app']     ="Goto";
589       $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
592       foreach($EXT as $keytop => $valtop){
593         $s_keys = "";
594         $s_values = ""; 
595         foreach($valtop as $key=>$val){
596           $s_keys   .="`".$key."`,";
597           $s_values .="'".$val."',";
598         }
599         $s_keys   =preg_replace("/\,$/","",$s_keys); 
600         $s_values =preg_replace("/\,$/","",$s_values); 
601         $SQL[]="INSERT INTO ".$cfg_Current['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");"; 
602       }
606       /* Start transaction, to be able to rollback
607        */
608       @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>---Updating/Inserting entries---</b>","");
610       mysql_query("begin;",$res_cur);
611       @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>begin;</b>","<i>Starting transaction!</i>");
613       foreach($SQL as $query){
614         @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>".$query."</b>", "");
615         if(!mysql_query($query,$res_cur)){
616           $err = mysql_error($res_cur);
617           @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"\n".$err, "<b>FAILED</b>");
618           msg_dialog::display(_("Error"),
619               msgPool::mysqlerror($err,__CLASS__)."&nbsp;".
620               "\n<p>"._("Please activate debugging for details!")."</p>",
621               ERROR_DIALOG);
623           mysql_query("rollback;",$res_cur);
624           @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>rollback;</b>", "<b>ERROR</b> Rollback transaction!");
625           @mysql_close($res_cur);
626           return(false);
627         }
628       }
630       /* Let changes get active, everything was fine;
631        */
632       mysql_query("commit;",$res_cur);
633       @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>commit;</b>", "");
634       @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"<b>---Transaction sucessful!---</b>", "");
635     } 
637     @mysql_close($res_cur);
638   }
641   /* Remove initial entry from database 
642    * This function checks if there is an entry in the 
643    *  initial home server that uses this->old_cn or $this->old_tele_number
644    *  and removes this entries. 
645    * This function is called from save and remove_from parent.
646    * 
647    *  The parameter '$save' is false if we just 
648    *   want to check if a remove is possible. 
649    *  And true if we realy want to remove the entries.   
650    */
651   function SQL_remove_me($save)
652   {
653     /* check database access */
654     $str = $this->check_database_accessibility();
655     if($str){
656       return($str);
657     }
659     /* Connect to old database */
660     $cfg_Init  = $this->goFonHomeServers[$this->init_HomeServer] ;
661     $r_init    =  @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
662     $db_init   =  @mysql_select_db($cfg_Init['DB'],$r_init);
663    
664     /* Check if there is an old entry */
665     $query = "SELECT id FROM ".$cfg_Init['EXT_TABLE']." WHERE exten='".$this->old_tele_number."' OR exten='".$this->old_cn."';";
666     $res = @mysql_query($query,$r_init);
667     @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
668     if(!$res){
669       new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
670       return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
671     }
672    
673     /* There are entries using this cn and/or phone number */
674     if($save && mysql_affected_rows($r_init)) {
675       $SQL = "DELETE FROM ".$cfg_Init['EXT_TABLE']." 
676       WHERE   (exten='".$this->old_tele_number."') 
677         OR    (exten='".$this->old_cn."')";
678   
679       /* Query and ensure that everything went fine */
680       $res =  @mysql_query($SQL,$r_init);
681       @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query");
682       if(!$res){
683         new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
684         return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
685       }
687     }//ENDE  old num availiable ...
688     @mysql_close($r_init);
689     return(false);
690   }
694   /* This function checks if the given phonenumbers are available or already in use*/
695   function is_number_used()
696   {
697     $ldap= $this->config->get_ldap_link();
698     $ldap->cd($this->config->current['BASE']);
699     $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
700     while($attrs = $ldap->fetch()) {
701       unset($attrs['telephoneNumber']['count']);
702       foreach($attrs['telephoneNumber'] as $tele){
703         if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
704         if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
705         $numbers[$tele]=$attrs;
706       }
707     }
709     $num = $this->telephoneNumber;
710     if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){
711       if(isset($numbers[$num]['uid'][0])){
712         return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['uid'][0]);
713       }else{
714         return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['cn'][0]);
715       }
716     }
717   }
720   /* Save to LDAP */
721   function save()
722   {
724     if((!isset($this->attrs['goFonPIN']))){
725       $pin_use = false;
726     }else{
727       $pin_use = true;
728     }
730     /* Unset PIN if this is a conference without PIN */
731     if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
732       $this->goFonPIN = "";
733     }
735     plugin::save();
737     if(empty($this->old_tele_number)){
738       $this->old_tele_number= $this->telephoneNumber;
739     }
741     $this->SQL_add_me(true);
743     if(empty($this->goFonConferenceOption_P)){
744       if($pin_use){
745         $this->attrs['goFonPIN']=array();
746       }else{
747         unset($this->attrs['goFonPIN']);
748       }
749     }
750     $this->attrs['goFonConferenceOption']="";
751     foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
752           "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
753       $this->attrs['goFonConferenceOption'] .= $this->$attrs;
754       unset($this->attrs[$attrs]);         
755     }
757     $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
758     $this->attrs['goFonConferenceOption'].="|".$this->language;
759     unset($this->attrs['goFonConferenceOptionLifetime']);
761     /* Write back to ldap */
763     unset($this->attrs['base']);
765     $ldap= $this->config->get_ldap_link();
766     $ldap->cd($this->config->current['BASE']);
767     $ldap->cat($this->dn, array('dn'));
769     if ($ldap->count()){
770       $ldap->cd($this->dn);
771       $this->cleanup();
772       $ldap->modify ($this->attrs); 
773       $this->handle_post_events('modify');
774     } else {
775       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
776       $ldap->cd($this->dn);
777       $ldap->add($this->attrs);
778       $this->handle_post_events('add');
779     }
781     /* Log last action */
782     if($this->initially_was_account){
783       new log("modify","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
784     }else{
785       new log("create","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
786     }
788     if (!$ldap->success()){
789       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
790     }
792     /* Optionally execute a command after we're done */
793     $this->postcreate();
794   }
797   function getCopyDialog()
798   {
799     $smarty = get_smarty();
800     $smarty->assign("cn" ,$this->cn);
801     $smarty->assign("telephoneNumber" ,$this->telephoneNumber);
802     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
803     $ret = array();
804     $ret['string'] = $str;
805     $ret['status'] = "";
806     return($ret);
807   }
810   function saveCopyDialog()
811   {
812     if(isset($_POST['cn'])){
813       $this->cn = $_POST['cn'];
814     }
815     if(isset($_POST['telephoneNumber'])){
816       $this->telephoneNumber = $_POST['telephoneNumber'];
817     }
818   }
820   function PrepareForCopyPaste($source)
821   {
822     plugin::PrepareForCopyPaste($source) ;
824     $source_o = new conference($this->config,$source['dn']);
825   
826     foreach($this->attributes as $attr){
827       $this->$attr = $source_o->$attr;
828     }
829   }
832   /* Return plugin informations for acl handling */
833   static function plInfo()
834   {
835     return (array(
836           "plShortName"   => _("Conference"),
837           "plDescription" => _("Phone conference management"),
838           "plSelfModify"  => TRUE,
839           "plDepends"     => array(),
840           "plPriority"    => 0,
841           "plSection"     => array("administration"),
842           "plCategory"    => array("gofonconference" => array("description" => _("GOfon conference"),
843               "objectClass" => "gofonConference")),
845           "plProvidedAcls" => array(
846             "cn"                            => _("Name"),
847             "base"                          => _("Base"),
848             "description"                   => _("Description"),
849             "goFonPIN"                      => _("Conference PIN"),
851             "language"                      => _("Language"),
852   
853             "goFonHomeServer"              => _("Home server"),
854             "goFonConferenceOptionP"       => _("Preset PIN"),
855             "goFonConferenceOptionr"       => _("Record conference"),
856             "goFonConferenceOptionM"       => _("Play music on hold"),
857             "goFonConferenceOptions"       => _("Activate menu"),
858             "goFonConferenceOptioni"       => _("Announce user activity"),
859             "goFonConferenceOptionc"       => _("Count user"),
860             "goFonConferenceOptionD"       => _("Conference type"),
862             "goFonConferenceOptionFormat"   => _("Format"),
863             "goFonConferenceOptionLifetime" => _("Lifetime"),
864             "telephoneNumber"               => _("Telephone number"),
865             "goFonConferenceOwner"          => _("Owner"))
866             ));
867   }
872 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
873 ?>