Code

b277a3b4167e40b2d49c8e1e0455eda1c30765e4
[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_D  = "";   // 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_P  = "";   // Conference Type, no PIN/PIN
39   var $goFonConferenceOptionFormat              = "";
40   var $goFonConferenceOptionLifetime    = "";
41   var $goFonConferenceOptionNumber              = "";
43   var $old_tele_number          = false;
44   var $generate_error           = "";
46   /* Headpage attributes */
47   var $last_dep_sorting= "invalid";
48   var $departments= array();
50   /* attribute list for save action */
51   var $attributes= array("cn", "description", "goFonPIN","goFonConferenceOption_D","goFonConferenceOption_r",
52                                                  "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c",
53                                                  "goFonConferenceOption_P","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","goFonConferenceOptionNumber");
55   var $objectclasses= array("top", "goFonConference");
57   function conference ($config, $dn)
58   {
59     plugin::plugin($config, $dn);
60     $this->is_account   = TRUE;
61     $this->ui                   = get_userinfo();
62     $this->dn                   = $dn;
63     $this->orig_dn              = $dn;
64     $this->config               = $config;
66     /* Set base */
67     if ($this->dn == "new"){
68       $ui= get_userinfo();
69       if(isset($_SESSION['conferencefilter']['depselect'])){
70         $this->base = $_SESSION['conferencefilter']['depselect'];
71       }else{
72         $this->base= dn2base($ui->dn);
73       }
74     } else {
75       $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
76     }
79     /* Parse Options ... 
80      * Parameter|Lifetime|number
81      */
82     if($this->dn!="new"){
83       $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
85       for($i = 0 ; $i < strlen($tmp1[0]);$i++){
86         $varname = "goFonConferenceOption_".$tmp1[0][$i];
87         $this->$varname = $tmp1[0][$i];    
88       }
90       $this->goFonConferenceOptionLifetime  = $tmp1[1];
91       $this->goFonConferenceOptionNumber    = $tmp1[2];
92       $this->old_tele_number                = $tmp1[2];
93     }
94   }
96   function execute()
97   {
98         $this->config->departments    = get_departments($this->dn);
99         $this->config->make_idepartments();
100         $smarty= get_smarty();
102         $smarty->assign("goFonConferenceOptions",                   array("P"=>"Conference ",""=>"Conference without PIN"));
103         $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
104         $smarty->assign("goFonConferenceOption",        $this->goFonConferenceOption_P);
105         
106         foreach ($this->attributes as $val){
107                 $smarty->assign("$val", $this->$val);
108                 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
109                 if(!$this->$val){
110                         $smarty->assign($val."CHK", "");
111                 }else{
112                         $smarty->assign($val."CHK", " checked ");
113                 }
114         }
115         return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
116   }
118   function remove_from_parent()
119   {
120         $ldap= $this->config->get_ldap_link();
121         $ldap->cd ($this->dn);
122         $ldap->recursive_remove();
124         /* Optionally execute a command after we're done */
125         $this->handle_post_events('remove');
126   }
129   /* Save data to object */
130   function save_object()
131   {
132     plugin::save_object();
133     if(isset($_POST['cn'])){
134       foreach(array("goFonConferenceOption_D","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
135             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_P") as $attrs){
136       if(isset($_POST[$attrs])){
137         $this->$attrs = $_POST[$attrs];
138       }else{
139         $this->$attrs = false;
140         }
141       }
142     }
143   }
146   /* Check values */
147   function check()
148   {
149         $message= array();
150   
151   if(empty($this->cn)){
152     $message[] =_("Please enter a name for the conference.");
153   }
154   
155   if(!is_numeric($this->goFonConferenceOptionNumber)){
156     $message[] =_("Only numeric chars are allowed in Number field.");
157   }
159   if(!is_numeric($this->goFonConferenceOptionLifetime)){
160     $message[] =_("Only numbers are allowed in Lifetime.");
161   }
162  
163   $this->SQL_remove_me(false);
164   $this->SQL_add_me(false);
165  
166   if(!empty($this->generate_error)){
167     $message[]=$this->generate_error;
168     $this->generate_error="";
169   }
171         return $message;
172   }
175   function SQL_add_me($save){
176     // Get Configuration for Mysql database Server
177     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
179     // Connect to DB server
180     $r_con =  @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
182     // Check if we are  connected correctly
183     if(!$r_con){
184       $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
185           $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
186       gosa_log(mysql_error());
187       return false;
188     }
190     // Select database for Extensions
191     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
193     // Test if we have the database selected correctly
194     if(!$db){
195       $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
196       gosa_log(mysql_error());
197       return false;
198     }
199    
200     if((!empty($this->goFonConferenceOptionNumber))&&($save==true)){
201       
202       $EXT=array();
204       $parameter  ="";
205       foreach(array("goFonConferenceOption_D","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
206             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_P") as $attrs){
207         $parameter .= $this->$attrs;
208       }
210       $i=1;
211       $context="GOsa";
212       // Set Language to German
213       $EXT[$i]['exten']   =$this->goFonConferenceOptionNumber;
214       $EXT[$i]['context'] = $context;
215       $EXT[$i]['priority']= $i;
216       $EXT[$i]['app']     ="SetLanguage";
217       $EXT[$i]['appdata'] ="de";
218       $i++;      
220       if($this->goFonConferenceOption_r == "r"){
222       // Recordingformat for conference
223       $EXT[$i]['exten']   =$this->goFonConferenceOptionNumber;
224       $EXT[$i]['context'] =$context;
225       $EXT[$i]['priority']= $i;
226       $EXT[$i]['app']     ="Setvar";
227       $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
228       $i++;      
230       }
232       // Answer Call
233       $EXT[$i]['exten']   =$this->goFonConferenceOptionNumber;
234       $EXT[$i]['context'] =$context;
235       $EXT[$i]['priority']=$i;
236       $EXT[$i]['app']     ="answer";
237       $EXT[$i]['appdata'] ="";
238       $i++;      
240       // Start Conference 
241       $EXT[$i]['exten']   =$this->goFonConferenceOptionNumber;
242       $EXT[$i]['context'] =$context;
243       $EXT[$i]['priority']=$i;
244       $EXT[$i]['app']     ="MeetMe";
245       $EXT[$i]['appdata'] =$this->goFonConferenceOptionNumber."|".$parameter."|".$this->goFonPIN;
246       $i++; 
248       // Start Conference 
249       $EXT[$i]['exten']   =$this->cn;
250       $EXT[$i]['context'] =$context;
251       $EXT[$i]['priority']=1;
252       $EXT[$i]['app']     ="Goto";
253       $EXT[$i]['appdata'] =$this->goFonConferenceOptionNumber."|1";
254       $SQL=array();
255     
256       foreach($EXT as $keytop => $valtop){
257       $s_keys = "";
258       $s_values = ""; 
259         foreach($valtop as $key=>$val){
260           $s_keys   .="`".$key."`,";
261           $s_values .="'".$val."',";
262         }
263         $s_keys   =preg_replace("/\,$/","",$s_keys); 
264         $s_values =preg_replace("/\,$/","",$s_values); 
265         $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");"; 
266       }
267       foreach($SQL as $sqlsyn){
268         mysql_query($sqlsyn);
269       }
270     } 
271     
274     return(true);
275   }
277   function SQL_remove_me($save){
279     if($this->old_tele_number){
280       // Get Configuration for Mysql database Server
281       $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
283       // Connect to DB server
284       $r_con =  @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
286       // Check if we are  connected correctly
287       if(!$r_con){
288         $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
289             $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
290         gosa_log(mysql_error());
291         return false;
292       }
294       // Select database for Extensions
295       $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
297       // Test if we have the database selected correctly
298       if(!$db){
299         $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
300         gosa_log(mysql_error());
301         return false;
302       }
304       $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE (exten= '".$this->old_tele_number."') OR (exten='".$this->goFonConferenceOptionNumber."')";
305       
306       if($save){
307         @mysql_query($SQL);
308       } 
310     }//ENDE  old num availiable ...
311     return(true);
312   }
316   /* This function checks if the given phonenumbers are available or already in use*/
317   function is_number_used()
318   {
319     $ldap= $this->config->get_ldap_link();
320     $ldap->cd($this->config->current['BASE']);
321     $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
322     while($attrs = $ldap->fetch()) {
323       unset($attrs['telephoneNumber']['count']);
324       foreach($attrs['telephoneNumber'] as $tele){
325         if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
326         if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
327         $numbers[$tele]=$attrs;
328       }
329     }
331     foreach($this->phoneNumbers as $num){
332       if(!isset($this->cn)) $this->cn = "";
334       if((isset($numbers[$num]))&&(($numbers[$num]['uid'][0]!=$this->uid))){
335         if(isset($numbers[$num]['uid'][0])){
336           return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
337         }else{
338           return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
339         }
340       }
341     }
342   }
349   /* Save to LDAP */
350   function save()
351   {
352         plugin::save();
354   $this->SQL_remove_me(true);
355   $this->SQL_add_me(true);
357   $this->attrs['goFonConferenceOption']="";
358   foreach(array("goFonConferenceOption_D","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
359             "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_P","goFonConferenceOptionFormat") as $attrs){
360     $this->attrs['goFonConferenceOption'] .= $this->$attrs;
361     unset($this->attrs[$attrs]);         
362   }
364   $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
365   unset($this->attrs['goFonConferenceOptionLifetime']);
367   $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionNumber;
368   unset($this->attrs['goFonConferenceOptionNumber']);
369         
371   /* Write back to ldap */
372         $ldap= $this->config->get_ldap_link();
373         $ldap->cat($this->dn);
374         $a= $ldap->fetch();
375         $ldap->cd($this->dn);
376         if (count($a)){
377                 $ldap->modify($this->attrs);
378                 $this->handle_post_events('modify');
379         } else {
380                 $ldap->add($this->attrs);
381                 $this->handle_post_events('add');
382         }
383         show_ldap_error($ldap->get_error());
385         /* Optionally execute a command after we're done */
386         $this->postcreate();
387   }
391 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
392 ?>