Code

We are able to choose the base now:
[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                         = "";
30   var $goFonConferenceOption    = "";
31   var $goFonConferenceOption_P  = "";   // Set PIN 
32   var $goFonConferenceOption_r  = "";   // record Conference
33   var $goFonConferenceOption_M  = "";   // Play Music opn hold
34   var $goFonConferenceOption_s  = "";   // activate menu
35   var $goFonConferenceOption_i  = "";   // announce new and leaving user
36   var $goFonConferenceOption_c  = "";   // Count User
37   var $goFonConferenceOption_D  = "";   // Conference Type, no PIN/PIN
39   var $goFonConferenceOptionFormat              = "";
40   var $goFonConferenceOptionLifetime    = "";
41   var $telephoneNumber          = "";
43   var $old_tele_number          = false;
44   var $generate_error           = "";
46   var $old_dn;
48   /* Headpage attributes */
49   var $last_dep_sorting= "invalid";
50   var $departments= array();
52   /* attribute list for save action */
53   var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r",
54                                                  "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c",
55                                                  "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber");
57   var $objectclasses= array("top", "goFonConference");
59   function conference ($config, $dn)
60   {
61     plugin::plugin($config, $dn);
62     $this->is_account   = TRUE;
63     $this->ui                   = get_userinfo();
64     $this->dn                   = $dn;
65     $this->orig_dn              = $dn;
66     $this->config               = $config;
68     /* Set base */
69     if ($this->dn == "new"){
70       $ui= get_userinfo();
71       if(isset($_SESSION['conferencefilter']['depselect'])){
72         $this->base = $_SESSION['conferencefilter']['depselect'];
73       }else{
74         $this->base= dn2base($ui->dn);
75       }
76     } else {
77       $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
78     }
81     /* Parse Options ... 
82      * Parameter|Lifetime|number
83      */
84     if($this->dn!="new"){
85       $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
87       for($i = 0 ; $i < strlen($tmp1[0]);$i++){
88         $varname = "goFonConferenceOption_".$tmp1[0][$i];
89         if($tmp1[0][$i]=="d"){
90           $this->goFonConferenceOption_D = $tmp1[0][$i];    
91         }else{
92           $this->$varname = $tmp1[0][$i];    
93         }
94       }
96       $this->goFonConferenceOptionLifetime  = $tmp1[1];
97       $this->old_tele_number                = $this->telephoneNumber;
98     }
99     $this->old_dn = $this->dn;
100   }
102   function execute()
103   {
104         $this->config->departments    = get_departments($this->dn);
105         $this->config->make_idepartments();
106         $smarty= get_smarty();
108   print_a($_POST);
110   $smarty->assign("bases" ,array_flip($this->config->departments));
111   $smarty->assign("base"  ,$this->base);
113         $smarty->assign("goFonConferenceOptions",                   array("D"=>"Conference ","d"=>"Conference without PIN"));
114         $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
115         $smarty->assign("goFonConferenceOption",        $this->goFonConferenceOption_D);
116         
117         foreach ($this->attributes as $val){
118                 $smarty->assign("$val", $this->$val);
119                 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
120                 if(!$this->$val){
121                         $smarty->assign($val."CHK", "");
122                 }else{
123                         $smarty->assign($val."CHK", " checked ");
124                 }
125         }
126         return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
127   }
129   function remove_from_parent()
130   {
131         $ldap= $this->config->get_ldap_link();
132         $ldap->cd ($this->dn);
133         $ldap->recursive_remove();
135         /* Optionally execute a command after we're done */
136         $this->handle_post_events('remove');
137   }
140   /* Save data to object */
141   function save_object()
142   {
143     plugin::save_object();
144     if(isset($_POST['cn'])){
145       foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
146             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
147       if(isset($_POST[$attrs])){
148         $this->$attrs = $_POST[$attrs];
149       }else{
150         $this->$attrs = false;
151         }
152       }
153     }
154   }
157   /* Check values */
158   function check()
159   {
160         $message= array();
161  
162   if($this->is_number_used()){
163     $message[] =  $this->is_number_used();
164   }
166   if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
167     $message[] =_("You have specified a conference 'without PIN' ... please leave the PIN fields empty.");
168   }
170   if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
171     $message[]= _("Please enter a PIN.");
172   }
173  
174   if(empty($this->cn)){
175     $message[] =_("Please enter a name for the conference.");
176   }
177   
178   if(!is_numeric($this->telephoneNumber)){
179     $message[] =_("Only numeric chars are allowed in Number field.");
180   }
182   if(!is_numeric($this->goFonConferenceOptionLifetime)){
183     $message[] =_("Only numbers are allowed in Lifetime.");
184   }
185  
186   $this->SQL_remove_me(false);
187   $this->SQL_add_me(false);
188  
189   if(!empty($this->generate_error)){
190     $message[]=$this->generate_error;
191     $this->generate_error="";
192   }
194         return $message;
195   }
198   function SQL_add_me($save){
199     // Get Configuration for Mysql database Server
200     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
202     // Connect to DB server
203     $r_con =  @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
205     // Check if we are  connected correctly
206     if(!$r_con){
207       $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
208           $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
209       gosa_log(mysql_error());
210       return false;
211     }
213     // Select database for Extensions
214     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
216     // Test if we have the database selected correctly
217     if(!$db){
218       $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
219       gosa_log(mysql_error());
220       return false;
221     }
222    
223     if((!empty($this->telephoneNumber))&&($save==true)){
224       
225       $EXT=array();
227       $parameter  ="";
228       foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
229             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
230         $parameter .= $this->$attrs;
231       }
233       $i=1;
234       $context="GOsa";
235       // Set Language to German
236       $EXT[$i]['exten']   =$this->telephoneNumber;
237       $EXT[$i]['context'] = $context;
238       $EXT[$i]['priority']= $i;
239       $EXT[$i]['app']     ="SetLanguage";
240       $EXT[$i]['appdata'] ="de";
241       $i++;      
243       if($this->goFonConferenceOption_r == "r"){
245       // Recordingformat for conference
246       $EXT[$i]['exten']   =$this->telephoneNumber;
247       $EXT[$i]['context'] =$context;
248       $EXT[$i]['priority']= $i;
249       $EXT[$i]['app']     ="Setvar";
250       $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
251       $i++;      
253       }
255       // Answer Call
256       $EXT[$i]['exten']   =$this->telephoneNumber;
257       $EXT[$i]['context'] =$context;
258       $EXT[$i]['priority']=$i;
259       $EXT[$i]['app']     ="answer";
260       $EXT[$i]['appdata'] ="";
261       $i++;      
263       // Start Conference 
264       $EXT[$i]['exten']   =$this->telephoneNumber;
265       $EXT[$i]['context'] =$context;
266       $EXT[$i]['priority']=$i;
267       $EXT[$i]['app']     ="MeetMe";
268       
269       if(empty($this->goFonPIN)) {
270         $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
271       }else{
272         $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
273       }
274       $i++; 
276       // Start Conference 
277       $EXT[$i]['exten']   =$this->cn;
278       $EXT[$i]['context'] =$context;
279       $EXT[$i]['priority']=1;
280       $EXT[$i]['app']     ="Goto";
281       $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
282       $SQL=array();
283     
284       foreach($EXT as $keytop => $valtop){
285       $s_keys = "";
286       $s_values = ""; 
287         foreach($valtop as $key=>$val){
288           $s_keys   .="`".$key."`,";
289           $s_values .="'".$val."',";
290         }
291         $s_keys   =preg_replace("/\,$/","",$s_keys); 
292         $s_values =preg_replace("/\,$/","",$s_values); 
293         $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");"; 
294       }
295       foreach($SQL as $sqlsyn){
296         mysql_query($sqlsyn);
297       }
298     } 
299     
302     return(true);
303   }
305   function SQL_remove_me($save){
307     if($this->old_tele_number){
308       // Get Configuration for Mysql database Server
309       $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
311       // Connect to DB server
312       $r_con =  @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
314       // Check if we are  connected correctly
315       if(!$r_con){
316         $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
317             $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
318         gosa_log(mysql_error());
319         return false;
320       }
322       // Select database for Extensions
323       $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
325       // Test if we have the database selected correctly
326       if(!$db){
327         $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
328         gosa_log(mysql_error());
329         return false;
330       }
332       $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE   (exten= '".$this->old_tele_number."') 
333                                                         OR  (exten='".$this->telephoneNumber."') 
334                                                         OR  (exten='".$this->cn."')";
335       
336       if($save){
337         @mysql_query($SQL);
338       } 
340     }//ENDE  old num availiable ...
341     return(true);
342   }
346   /* This function checks if the given phonenumbers are available or already in use*/
347   function is_number_used()
348   {
349     $ldap= $this->config->get_ldap_link();
350     $ldap->cd($this->config->current['BASE']);
351     $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
352     while($attrs = $ldap->fetch()) {
353       unset($attrs['telephoneNumber']['count']);
354       foreach($attrs['telephoneNumber'] as $tele){
355         if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
356         if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
357         $numbers[$tele]=$attrs;
358       }
359     }
361     $num = $this->telephoneNumber;
362     if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->cn))){
363       if(isset($numbers[$num]['uid'][0])){
364         return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
365       }else{
366         return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
367       }
368     }
369   }
375   /* Save to LDAP */
376   function save()
377   {
378         plugin::save();
380   $this->SQL_remove_me(true);
381   $this->SQL_add_me(true);
383   $this->attrs['goFonConferenceOption']="";
384   foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
385             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
386     $this->attrs['goFonConferenceOption'] .= $this->$attrs;
387     unset($this->attrs[$attrs]);         
388   }
390   $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
391   unset($this->attrs['goFonConferenceOptionLifetime']);
393   /* Write back to ldap */
395   unset($this->attrs['base']);
397         $ldap= $this->config->get_ldap_link();
399         $ldap->cat($this->dn);
400         $a= $ldap->fetch();
401         $ldap->cd($this->dn);
402         if (count($a)){
403                 $ldap->modify($this->attrs);
404                 $this->handle_post_events('modify');
405         } else {
406                 $ldap->add($this->attrs);
407                 $this->handle_post_events('add');
408         }
409         show_ldap_error($ldap->get_error());
411         /* Optionally execute a command after we're done */
412         $this->postcreate();
413   }
417 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
418 ?>