Code

Added empty lines
[gosa.git] / plugins / 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 $ou                                               = "";
28   var $goFonPIN                         = "";
29   var $acl = "";
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    = "";
43   var $goFonConferenceOptionFormat              = "";
44   var $goFonConferenceOptionLifetime    = "";
45   var $telephoneNumber          = "";
47   var $old_tele_number          = false;
48   var $generate_error           = "";
50   var $old_dn;
52   /* Headpage attributes */
53   var $last_dep_sorting= "invalid";
54   var $departments= array();
56   /* attribute list for save action */
57   var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r",
58       "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c",
59       "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber","goFonConferenceOwner");
61   var $objectclasses= array("top", "goFonConference");
63   function conference ($config, $dn)
64   {
65     plugin::plugin($config, $dn);
66     $this->is_account   = TRUE;
67     $this->ui                   = get_userinfo();
68     $this->dn                   = $dn;
69     $this->orig_dn              = $dn;
70     $this->config               = $config;
72     /* Set base */
73     if ($this->dn == "new"){
74       $ui= get_userinfo();
75       if(isset($_SESSION['conferencefilter']['depselect'])){
76         $this->base = $_SESSION['conferencefilter']['depselect'];
77       }else{
78         $this->base= dn2base($ui->dn);
79       }
80     } else {
81       $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
82     }
84     $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
85     $this->acl= get_module_permission($acl, "goFonConference", $this->dn);
86     $this->goFonConferenceOwner=$this->ui->dn;
88     /* Parse Options ... 
89      * Parameter|Lifetime|number
90      */
91     if($this->dn!="new"){
92       $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
94       for($i = 0 ; $i < strlen($tmp1[0]);$i++){
95         $varname = "goFonConferenceOption_".$tmp1[0][$i];
96         if($tmp1[0][$i]=="d"){
97           $this->goFonConferenceOption_D = $tmp1[0][$i];    
98         }else{
99           $this->$varname = $tmp1[0][$i];    
100         }
101       }
103       $this->goFonConferenceOptionLifetime  = $tmp1[1];
104       $this->old_tele_number                = $this->telephoneNumber;
105     }
106     $this->old_dn = $this->dn;
107     $this->old_cn = $this->cn;
108   }
110   function execute()
111   {
112         /* Call parent execute */
113         plugin::execute();
115     //$acl= get_permissions ($this->dn, $this->ui->subtreeACL);
116     //$this->acl= get_module_permission($acl, "goFonConference", $this->dn);
118     $this->config->departments    = get_departments($this->dn);
119     $this->config->make_idepartments();
120     $smarty= get_smarty();
122     $smarty->assign("bases" ,array_flip($this->config->departments));
123     $smarty->assign("base"  ,$this->base);
125     $smarty->assign("goFonConferenceOptions",               array("D"=>"Conference ","d"=>"Conference without PIN"));
126     $smarty->assign("goFonConferenceOptionFormats",     array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
127     $smarty->assign("goFonConferenceOption",        $this->goFonConferenceOption_D);
129     foreach ($this->attributes as $val){
130       $smarty->assign("$val", $this->$val);
131       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
132       if(!$this->$val){
133         $smarty->assign($val."CHK", "");
134       }else{
135         $smarty->assign($val."CHK", " checked ");
136       }
137     }
139     if($_SESSION['js']==1){
140       if($this->goFonConferenceOption_P != "P"){
141         $smarty->assign("goFonPINACL"," disabled ");
142         $smarty->assign("goFonPIN","");
143       }
144       if($this->goFonConferenceOption_r != "r"){
145         $smarty->assign("goFonConferenceOptionFormatACL"," disabled ");
146       }
147     }
148     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
149   }
151   function remove_from_parent()
152   {
153      $this->SQL_remove_me(true); 
155     $ldap= $this->config->get_ldap_link();
156     $ldap->cd ($this->dn);
157     $ldap->recursive_remove();
159     /* Optionally execute a command after we're done */
160     $this->handle_post_events('remove');
161   }
164   /* Save data to object */
165   function save_object()
166   {
167     plugin::save_object();
168     if(isset($_POST['cn'])){
169       foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
170             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonPIN") as $attrs){
171         if(isset($_POST[$attrs])){
172           $this->$attrs = $_POST[$attrs];
173         }else{
174           $this->$attrs = false;
175         }
176       }
177     }
178   }
181   /* Check values */
182   function check()
183   {
184     $message= array();
186     if($this->is_number_used()){
187       $message[] =  $this->is_number_used();
188     }
190     if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
191       $message[] =_("You have specified a conference 'without PIN' ... please leave the PIN fields empty.");
192     }
194     if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
195       $message[]= _("Please enter a PIN.");
196     }
198     if(empty($this->cn)){
199       $message[] =_("Please enter a name for the conference.");
200     }
202     if(!is_numeric($this->telephoneNumber)){
203       $message[] =_("Only numeric chars are allowed in Number field.");
204     }
206     if(!((is_numeric($this->goFonConferenceOptionLifetime))||(empty($this->goFonConferenceOptionLifetime)))){
207       $message[] =_("Only numbers are allowed in Lifetime.");
208     }
210     $this->SQL_remove_me(false);
211     $this->SQL_add_me(false);
213     if(!empty($this->generate_error)){
214       $message[]=$this->generate_error;
215       $this->generate_error="";
216     }
218     return $message;
219   }
222   function SQL_add_me($save){
224     if(!isset($_SESSION['config']->data['SERVERS']['FON'])){
225       $this->generate_error = _("There is currently no asterisk server defined. Possibly you are missing a server that handles the asterisk management (goFonServer). Your settings can't be saved to asterisk database.");
226       return(false);
227     }
228   
229     // Get Configuration for Mysql database Server
230     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
232     // Connect to DB server
233     $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
235     // Check if we are  connected correctly
236     if(!$r_con){
237       $this->generate_error = sprintf(_("The MySQL server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
238           $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
239       gosa_log(mysql_error());
240       return false;
241     }
243     // Select database for Extensions
244     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
246     // Test if we have the database selected correctly
247     if(!$db){
248       $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
249       gosa_log(mysql_error());
250       return false;
251     }
253     if((!empty($this->telephoneNumber))&&($save==true)){
255       $EXT=array();
257       $parameter  ="";
258       foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
259             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
260         $parameter .= $this->$attrs;
261       }
263       $i=1;
264       $context="GOsa";
265       // Set Language to German
266       $EXT[$i]['exten']   =$this->telephoneNumber;
267       $EXT[$i]['context'] = $context;
268       $EXT[$i]['priority']= $i;
269       $EXT[$i]['app']     ="SetLanguage";
270       $EXT[$i]['appdata'] ="de";
271       $i++;      
273       if($this->goFonConferenceOption_r == "r"){
275         // Recordingformat for conference
276         $EXT[$i]['exten']   =$this->telephoneNumber;
277         $EXT[$i]['context'] =$context;
278         $EXT[$i]['priority']= $i;
279         $EXT[$i]['app']     ="Setvar";
280         $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
281         $i++;      
283       }
285       // Answer Call
286       $EXT[$i]['exten']   =$this->telephoneNumber;
287       $EXT[$i]['context'] =$context;
288       $EXT[$i]['priority']=$i;
289       $EXT[$i]['app']     ="answer";
290       $EXT[$i]['appdata'] ="";
291       $i++;      
293       // Start Conference 
294       $EXT[$i]['exten']   =$this->telephoneNumber;
295       $EXT[$i]['context'] =$context;
296       $EXT[$i]['priority']=$i;
297       $EXT[$i]['app']     ="MeetMe";
299       if(empty($this->goFonPIN)) {
300         $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
301       }else{
302         $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
303       }
304       $i++; 
306       // Start Conference 
307       $EXT[$i]['exten']   =$this->cn;
308       $EXT[$i]['context'] =$context;
309       $EXT[$i]['priority']=1;
310       $EXT[$i]['app']     ="Goto";
311       $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
312       $SQL=array();
314       foreach($EXT as $keytop => $valtop){
315         $s_keys = "";
316         $s_values = ""; 
317         foreach($valtop as $key=>$val){
318           $s_keys   .="`".$key."`,";
319           $s_values .="'".$val."',";
320         }
321         $s_keys   =preg_replace("/\,$/","",$s_keys); 
322         $s_values =preg_replace("/\,$/","",$s_values); 
323         $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");"; 
324       }
325       foreach($SQL as $sqlsyn){
326         mysql_query($sqlsyn);
327       }
328     } 
331     @mysql_close($r_con);
332     return(true);
333   }
335   function SQL_remove_me($save){
337     if($this->old_tele_number){
338       // Get Configuration for Mysql database Server
339       $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
341       // Connect to DB server
342       $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
344       // Check if we are  connected correctly
345       if(!$r_con){
346         $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
347             $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
348         gosa_log(mysql_error());
349         return false;
350       }
352       // Select database for Extensions
353       $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
355       // Test if we have the database selected correctly
356       if(!$db){
357         $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
358         gosa_log(mysql_error());
359         return false;
360       }
362       $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']." 
363       WHERE   (exten='".$this->old_tele_number."') 
364         OR    (exten='".$this->telephoneNumber."') 
365         OR    (exten='".$this->cn."')  
366         OR    (exten='".$this->old_cn."')";
368       if($save){
369         @mysql_query($SQL);
370       } 
372     }//ENDE  old num availiable ...
373     @mysql_close($r_con);
374     return(true);
375   }
379   /* This function checks if the given phonenumbers are available or already in use*/
380   function is_number_used()
381   {
382     $ldap= $this->config->get_ldap_link();
383     $ldap->cd($this->config->current['BASE']);
384     $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
385     while($attrs = $ldap->fetch()) {
386       unset($attrs['telephoneNumber']['count']);
387       foreach($attrs['telephoneNumber'] as $tele){
388         if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
389         if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
390         $numbers[$tele]=$attrs;
391       }
392     }
394     $num = $this->telephoneNumber;
395     if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){
396       if(isset($numbers[$num]['uid'][0])){
397         return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
398       }else{
399         return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
400       }
401     }
402   }
408   /* Save to LDAP */
409   function save()
410   {
412     if((!isset($this->attrs['goFonPIN']))){
413       $pin_use = false;
414     }else{
415       $pin_use = true;
416     }
418     plugin::save();
420     if(empty($this->old_tele_number)){
421       $this->old_tele_number= $this->telephoneNumber;
422     }
424     $this->SQL_remove_me(true);
425     $this->SQL_add_me(true);
427     if(empty($this->goFonConferenceOption_P)){
428       if($pin_use){
429         $this->attrs['goFonPIN']=array();
430       }else{
431         unset($this->attrs['goFonPIN']);
432       }
433     }
434     $this->attrs['goFonConferenceOption']="";
435     foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
436           "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
437       $this->attrs['goFonConferenceOption'] .= $this->$attrs;
438       unset($this->attrs[$attrs]);         
439     }
441     $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
442     unset($this->attrs['goFonConferenceOptionLifetime']);
444     /* Write back to ldap */
446     unset($this->attrs['base']);
448     foreach($this->attributes as $atr){
449       if(chkacl($this->acl, $atr)!=""){
450         unset($this->attrs[$atr]);
451       }
452     }
454     $ldap= $this->config->get_ldap_link();
456     $ldap->cat($this->dn);
457     $a= $ldap->fetch();
458     $ldap->cd($this->dn);
459     if (count($a)){
460       $ldap->modify($this->attrs);
461       $this->handle_post_events('modify');
462     } else {
463       $ldap->add($this->attrs);
464       $this->handle_post_events('add');
465     }
466     show_ldap_error($ldap->get_error());
468     /* Optionally execute a command after we're done */
469     $this->postcreate();
470   }
474 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
475 ?>