Code

disable formatbox, if record is unchecked
[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   $smarty->assign("bases" ,array_flip($this->config->departments));
109   $smarty->assign("base"  ,$this->base);
111         $smarty->assign("goFonConferenceOptions",                   array("D"=>"Conference ","d"=>"Conference without PIN"));
112         $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
113         $smarty->assign("goFonConferenceOption",        $this->goFonConferenceOption_D);
114         
115         foreach ($this->attributes as $val){
116                 $smarty->assign("$val", $this->$val);
117                 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
118                 if(!$this->$val){
119                         $smarty->assign($val."CHK", "");
120                 }else{
121                         $smarty->assign($val."CHK", " checked ");
122                 }
123         }
124  
125   if($this->goFonConferenceOption_P != "P"){
126     $smarty->assign("goFonPINACL"," disabled ");
127     $smarty->assign("goFonPIN","");
128   }
129   if($this->goFonConferenceOption_r != "r"){
130     $smarty->assign("goFonConferenceOptionFormatACL"," disabled ");
131   }
133         return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
134   }
136   function remove_from_parent()
137   {
138         $ldap= $this->config->get_ldap_link();
139         $ldap->cd ($this->dn);
140         $ldap->recursive_remove();
142         /* Optionally execute a command after we're done */
143         $this->handle_post_events('remove');
144   }
147   /* Save data to object */
148   function save_object()
149   {
150     plugin::save_object();
151     if(isset($_POST['cn'])){
152       foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
153             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonPIN") as $attrs){
154       if(isset($_POST[$attrs])){
155         $this->$attrs = $_POST[$attrs];
156       }else{
157         $this->$attrs = false;
158         }
159       }
160     }
161   }
164   /* Check values */
165   function check()
166   {
167         $message= array();
168  
169   if($this->is_number_used()){
170     $message[] =  $this->is_number_used();
171   }
173   if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
174     $message[] =_("You have specified a conference 'without PIN' ... please leave the PIN fields empty.");
175   }
177   if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
178     $message[]= _("Please enter a PIN.");
179   }
180  
181   if(empty($this->cn)){
182     $message[] =_("Please enter a name for the conference.");
183   }
184   
185   if(!is_numeric($this->telephoneNumber)){
186     $message[] =_("Only numeric chars are allowed in Number field.");
187   }
189   if(!is_numeric($this->goFonConferenceOptionLifetime)){
190     $message[] =_("Only numbers are allowed in Lifetime.");
191   }
192  
193   $this->SQL_remove_me(false);
194   $this->SQL_add_me(false);
195  
196   if(!empty($this->generate_error)){
197     $message[]=$this->generate_error;
198     $this->generate_error="";
199   }
201         return $message;
202   }
205   function SQL_add_me($save){
206     // Get Configuration for Mysql database Server
207     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
209     // Connect to DB server
210     $r_con =  @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
212     // Check if we are  connected correctly
213     if(!$r_con){
214       $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
215           $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
216       gosa_log(mysql_error());
217       return false;
218     }
220     // Select database for Extensions
221     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
223     // Test if we have the database selected correctly
224     if(!$db){
225       $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
226       gosa_log(mysql_error());
227       return false;
228     }
229    
230     if((!empty($this->telephoneNumber))&&($save==true)){
231       
232       $EXT=array();
234       $parameter  ="";
235       foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
236             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
237         $parameter .= $this->$attrs;
238       }
240       $i=1;
241       $context="GOsa";
242       // Set Language to German
243       $EXT[$i]['exten']   =$this->telephoneNumber;
244       $EXT[$i]['context'] = $context;
245       $EXT[$i]['priority']= $i;
246       $EXT[$i]['app']     ="SetLanguage";
247       $EXT[$i]['appdata'] ="de";
248       $i++;      
250       if($this->goFonConferenceOption_r == "r"){
252       // Recordingformat for conference
253       $EXT[$i]['exten']   =$this->telephoneNumber;
254       $EXT[$i]['context'] =$context;
255       $EXT[$i]['priority']= $i;
256       $EXT[$i]['app']     ="Setvar";
257       $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
258       $i++;      
260       }
262       // Answer Call
263       $EXT[$i]['exten']   =$this->telephoneNumber;
264       $EXT[$i]['context'] =$context;
265       $EXT[$i]['priority']=$i;
266       $EXT[$i]['app']     ="answer";
267       $EXT[$i]['appdata'] ="";
268       $i++;      
270       // Start Conference 
271       $EXT[$i]['exten']   =$this->telephoneNumber;
272       $EXT[$i]['context'] =$context;
273       $EXT[$i]['priority']=$i;
274       $EXT[$i]['app']     ="MeetMe";
275       
276       if(empty($this->goFonPIN)) {
277         $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
278       }else{
279         $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
280       }
281       $i++; 
283       // Start Conference 
284       $EXT[$i]['exten']   =$this->cn;
285       $EXT[$i]['context'] =$context;
286       $EXT[$i]['priority']=1;
287       $EXT[$i]['app']     ="Goto";
288       $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
289       $SQL=array();
290     
291       foreach($EXT as $keytop => $valtop){
292       $s_keys = "";
293       $s_values = ""; 
294         foreach($valtop as $key=>$val){
295           $s_keys   .="`".$key."`,";
296           $s_values .="'".$val."',";
297         }
298         $s_keys   =preg_replace("/\,$/","",$s_keys); 
299         $s_values =preg_replace("/\,$/","",$s_values); 
300         $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");"; 
301       }
302       foreach($SQL as $sqlsyn){
303         mysql_query($sqlsyn);
304       }
305     } 
306     
309     return(true);
310   }
312   function SQL_remove_me($save){
314     if($this->old_tele_number){
315       // Get Configuration for Mysql database Server
316       $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
318       // Connect to DB server
319       $r_con =  @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
321       // Check if we are  connected correctly
322       if(!$r_con){
323         $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
324             $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
325         gosa_log(mysql_error());
326         return false;
327       }
329       // Select database for Extensions
330       $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
332       // Test if we have the database selected correctly
333       if(!$db){
334         $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
335         gosa_log(mysql_error());
336         return false;
337       }
339       $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE   (exten= '".$this->old_tele_number."') 
340                                                         OR  (exten='".$this->telephoneNumber."') 
341                                                         OR  (exten='".$this->cn."')";
342       
343       if($save){
344         @mysql_query($SQL);
345       } 
347     }//ENDE  old num availiable ...
348     return(true);
349   }
353   /* This function checks if the given phonenumbers are available or already in use*/
354   function is_number_used()
355   {
356     $ldap= $this->config->get_ldap_link();
357     $ldap->cd($this->config->current['BASE']);
358     $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
359     while($attrs = $ldap->fetch()) {
360       unset($attrs['telephoneNumber']['count']);
361       foreach($attrs['telephoneNumber'] as $tele){
362         if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
363         if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
364         $numbers[$tele]=$attrs;
365       }
366     }
368     $num = $this->telephoneNumber;
369     if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->cn))){
370       if(isset($numbers[$num]['uid'][0])){
371         return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
372       }else{
373         return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
374       }
375     }
376   }
382   /* Save to LDAP */
383   function save()
384   {
385         plugin::save();
387   $this->SQL_remove_me(true);
388   $this->SQL_add_me(true);
390   if(empty($this->goFonConferenceOption_P)){
391     $this->attrs['goFonPIN']=array();
392   }
393   $this->attrs['goFonConferenceOption']="";
394   foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
395             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
396     $this->attrs['goFonConferenceOption'] .= $this->$attrs;
397     unset($this->attrs[$attrs]);         
398   }
400   $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
401   unset($this->attrs['goFonConferenceOptionLifetime']);
403   /* Write back to ldap */
405   unset($this->attrs['base']);
407         $ldap= $this->config->get_ldap_link();
409         $ldap->cat($this->dn);
410         $a= $ldap->fetch();
411         $ldap->cd($this->dn);
412         if (count($a)){
413                 $ldap->modify($this->attrs);
414                 $this->handle_post_events('modify');
415         } else {
416                 $ldap->add($this->attrs);
417                 $this->handle_post_events('add');
418         }
419         show_ldap_error($ldap->get_error());
421         /* Optionally execute a command after we're done */
422         $this->postcreate();
423   }
427 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
428 ?>