Code

Js check goFonConferenceOwner added
[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 $goFonConferenceOwner    = "";
41   var $goFonConferenceOptionFormat              = "";
42   var $goFonConferenceOptionLifetime    = "";
43   var $telephoneNumber          = "";
45   var $old_tele_number          = false;
46   var $generate_error           = "";
48   var $old_dn;
50   /* Headpage attributes */
51   var $last_dep_sorting= "invalid";
52   var $departments= array();
54   /* attribute list for save action */
55   var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r",
56                                                  "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c",
57                                                  "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber","goFonConferenceOwner");
59   var $objectclasses= array("top", "goFonConference");
61   function conference ($config, $dn)
62   {
63     plugin::plugin($config, $dn);
64     $this->is_account   = TRUE;
65     $this->ui                   = get_userinfo();
66     $this->dn                   = $dn;
67     $this->orig_dn              = $dn;
68     $this->config               = $config;
70     /* Set base */
71     if ($this->dn == "new"){
72       $ui= get_userinfo();
73       if(isset($_SESSION['conferencefilter']['depselect'])){
74         $this->base = $_SESSION['conferencefilter']['depselect'];
75       }else{
76         $this->base= dn2base($ui->dn);
77       }
78     } else {
79       $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
80     }
82     $this->goFonConferenceOwner=$this->ui->dn;
84     /* Parse Options ... 
85      * Parameter|Lifetime|number
86      */
87     if($this->dn!="new"){
88       $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
90       for($i = 0 ; $i < strlen($tmp1[0]);$i++){
91         $varname = "goFonConferenceOption_".$tmp1[0][$i];
92         if($tmp1[0][$i]=="d"){
93           $this->goFonConferenceOption_D = $tmp1[0][$i];    
94         }else{
95           $this->$varname = $tmp1[0][$i];    
96         }
97       }
99       $this->goFonConferenceOptionLifetime  = $tmp1[1];
100       $this->old_tele_number                = $this->telephoneNumber;
101     }
102     $this->old_dn = $this->dn;
103   }
105   function execute()
106   {
107         $this->config->departments    = get_departments($this->dn);
108         $this->config->make_idepartments();
109         $smarty= get_smarty();
111   $smarty->assign("bases" ,array_flip($this->config->departments));
112   $smarty->assign("base"  ,$this->base);
114         $smarty->assign("goFonConferenceOptions",                   array("D"=>"Conference ","d"=>"Conference without PIN"));
115         $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
116         $smarty->assign("goFonConferenceOption",        $this->goFonConferenceOption_D);
117         
118         foreach ($this->attributes as $val){
119                 $smarty->assign("$val", $this->$val);
120                 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
121                 if(!$this->$val){
122                         $smarty->assign($val."CHK", "");
123                 }else{
124                         $smarty->assign($val."CHK", " checked ");
125                 }
126         }
128   if($_SESSION['js']==1){
129     if($this->goFonConferenceOption_P != "P"){
130       $smarty->assign("goFonPINACL"," disabled ");
131       $smarty->assign("goFonPIN","");
132     }
133     if($this->goFonConferenceOption_r != "r"){
134       $smarty->assign("goFonConferenceOptionFormatACL"," disabled ");
135     }
136   }
137         return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
138   }
140   function remove_from_parent()
141   {
142         $ldap= $this->config->get_ldap_link();
143         $ldap->cd ($this->dn);
144         $ldap->recursive_remove();
146         /* Optionally execute a command after we're done */
147         $this->handle_post_events('remove');
148   }
151   /* Save data to object */
152   function save_object()
153   {
154     plugin::save_object();
155     if(isset($_POST['cn'])){
156       foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
157             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonPIN") as $attrs){
158       if(isset($_POST[$attrs])){
159         $this->$attrs = $_POST[$attrs];
160       }else{
161         $this->$attrs = false;
162         }
163       }
164     }
165   }
168   /* Check values */
169   function check()
170   {
171         $message= array();
172  
173   if($this->is_number_used()){
174     $message[] =  $this->is_number_used();
175   }
177   if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
178     $message[] =_("You have specified a conference 'without PIN' ... please leave the PIN fields empty.");
179   }
181   if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
182     $message[]= _("Please enter a PIN.");
183   }
184  
185   if(empty($this->cn)){
186     $message[] =_("Please enter a name for the conference.");
187   }
188   
189   if(!is_numeric($this->telephoneNumber)){
190     $message[] =_("Only numeric chars are allowed in Number field.");
191   }
193   if(!is_numeric($this->goFonConferenceOptionLifetime)){
194     $message[] =_("Only numbers are allowed in Lifetime.");
195   }
196  
197   $this->SQL_remove_me(false);
198   $this->SQL_add_me(false);
199  
200   if(!empty($this->generate_error)){
201     $message[]=$this->generate_error;
202     $this->generate_error="";
203   }
205         return $message;
206   }
209   function SQL_add_me($save){
210     // Get Configuration for Mysql database Server
211     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
213     // Connect to DB server
214     $r_con =  @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
216     // Check if we are  connected correctly
217     if(!$r_con){
218       $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
219           $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
220       gosa_log(mysql_error());
221       return false;
222     }
224     // Select database for Extensions
225     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
227     // Test if we have the database selected correctly
228     if(!$db){
229       $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
230       gosa_log(mysql_error());
231       return false;
232     }
233    
234     if((!empty($this->telephoneNumber))&&($save==true)){
235       
236       $EXT=array();
238       $parameter  ="";
239       foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
240             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
241         $parameter .= $this->$attrs;
242       }
244       $i=1;
245       $context="GOsa";
246       // Set Language to German
247       $EXT[$i]['exten']   =$this->telephoneNumber;
248       $EXT[$i]['context'] = $context;
249       $EXT[$i]['priority']= $i;
250       $EXT[$i]['app']     ="SetLanguage";
251       $EXT[$i]['appdata'] ="de";
252       $i++;      
254       if($this->goFonConferenceOption_r == "r"){
256       // Recordingformat for conference
257       $EXT[$i]['exten']   =$this->telephoneNumber;
258       $EXT[$i]['context'] =$context;
259       $EXT[$i]['priority']= $i;
260       $EXT[$i]['app']     ="Setvar";
261       $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
262       $i++;      
264       }
266       // Answer Call
267       $EXT[$i]['exten']   =$this->telephoneNumber;
268       $EXT[$i]['context'] =$context;
269       $EXT[$i]['priority']=$i;
270       $EXT[$i]['app']     ="answer";
271       $EXT[$i]['appdata'] ="";
272       $i++;      
274       // Start Conference 
275       $EXT[$i]['exten']   =$this->telephoneNumber;
276       $EXT[$i]['context'] =$context;
277       $EXT[$i]['priority']=$i;
278       $EXT[$i]['app']     ="MeetMe";
279       
280       if(empty($this->goFonPIN)) {
281         $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
282       }else{
283         $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
284       }
285       $i++; 
287       // Start Conference 
288       $EXT[$i]['exten']   =$this->cn;
289       $EXT[$i]['context'] =$context;
290       $EXT[$i]['priority']=1;
291       $EXT[$i]['app']     ="Goto";
292       $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
293       $SQL=array();
294     
295       foreach($EXT as $keytop => $valtop){
296       $s_keys = "";
297       $s_values = ""; 
298         foreach($valtop as $key=>$val){
299           $s_keys   .="`".$key."`,";
300           $s_values .="'".$val."',";
301         }
302         $s_keys   =preg_replace("/\,$/","",$s_keys); 
303         $s_values =preg_replace("/\,$/","",$s_values); 
304         $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");"; 
305       }
306       foreach($SQL as $sqlsyn){
307         mysql_query($sqlsyn);
308       }
309     } 
310     
313     return(true);
314   }
316   function SQL_remove_me($save){
318     if($this->old_tele_number){
319       // Get Configuration for Mysql database Server
320       $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
322       // Connect to DB server
323       $r_con =  @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
325       // Check if we are  connected correctly
326       if(!$r_con){
327         $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
328             $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
329         gosa_log(mysql_error());
330         return false;
331       }
333       // Select database for Extensions
334       $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
336       // Test if we have the database selected correctly
337       if(!$db){
338         $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
339         gosa_log(mysql_error());
340         return false;
341       }
343       $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE   (exten= '".$this->old_tele_number."') 
344                                                         OR  (exten='".$this->telephoneNumber."') 
345                                                         OR  (exten='".$this->cn."')";
346       
347       if($save){
348         @mysql_query($SQL);
349       } 
351     }//ENDE  old num availiable ...
352     return(true);
353   }
357   /* This function checks if the given phonenumbers are available or already in use*/
358   function is_number_used()
359   {
360     $ldap= $this->config->get_ldap_link();
361     $ldap->cd($this->config->current['BASE']);
362     $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
363     while($attrs = $ldap->fetch()) {
364       unset($attrs['telephoneNumber']['count']);
365       foreach($attrs['telephoneNumber'] as $tele){
366         if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
367         if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
368         $numbers[$tele]=$attrs;
369       }
370     }
372     $num = $this->telephoneNumber;
373     if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->cn))){
374       if(isset($numbers[$num]['uid'][0])){
375         return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
376       }else{
377         return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
378       }
379     }
380   }
386   /* Save to LDAP */
387   function save()
388   {
389         plugin::save();
391   $this->SQL_remove_me(true);
392   $this->SQL_add_me(true);
394   if(empty($this->goFonConferenceOption_P)){
395     $this->attrs['goFonPIN']=array();
396   }
397   $this->attrs['goFonConferenceOption']="";
398   foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
399             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
400     $this->attrs['goFonConferenceOption'] .= $this->$attrs;
401     unset($this->attrs[$attrs]);         
402   }
404   $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
405   unset($this->attrs['goFonConferenceOptionLifetime']);
407   /* Write back to ldap */
409   unset($this->attrs['base']);
411         $ldap= $this->config->get_ldap_link();
413         $ldap->cat($this->dn);
414         $a= $ldap->fetch();
415         $ldap->cd($this->dn);
416         if (count($a)){
417                 $ldap->modify($this->attrs);
418                 $this->handle_post_events('modify');
419         } else {
420                 $ldap->add($this->attrs);
421                 $this->handle_post_events('add');
422         }
423         show_ldap_error($ldap->get_error());
425         /* Optionally execute a command after we're done */
426         $this->postcreate();
427   }
431 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
432 ?>