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);
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 }
125 if($this->goFonConferenceOption_P != "P"){
126 $smarty->assign("goFonPINACL"," disabled ");
127 $smarty->assign("goFonPIN","");
128 }
130 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
131 }
133 function remove_from_parent()
134 {
135 $ldap= $this->config->get_ldap_link();
136 $ldap->cd ($this->dn);
137 $ldap->recursive_remove();
139 /* Optionally execute a command after we're done */
140 $this->handle_post_events('remove');
141 }
144 /* Save data to object */
145 function save_object()
146 {
147 plugin::save_object();
148 if(isset($_POST['cn'])){
149 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
150 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonPIN") as $attrs){
151 if(isset($_POST[$attrs])){
152 $this->$attrs = $_POST[$attrs];
153 }else{
154 $this->$attrs = false;
155 }
156 }
157 }
158 }
161 /* Check values */
162 function check()
163 {
164 $message= array();
166 if($this->is_number_used()){
167 $message[] = $this->is_number_used();
168 }
170 if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
171 $message[] =_("You have specified a conference 'without PIN' ... please leave the PIN fields empty.");
172 }
174 if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
175 $message[]= _("Please enter a PIN.");
176 }
178 if(empty($this->cn)){
179 $message[] =_("Please enter a name for the conference.");
180 }
182 if(!is_numeric($this->telephoneNumber)){
183 $message[] =_("Only numeric chars are allowed in Number field.");
184 }
186 if(!is_numeric($this->goFonConferenceOptionLifetime)){
187 $message[] =_("Only numbers are allowed in Lifetime.");
188 }
190 $this->SQL_remove_me(false);
191 $this->SQL_add_me(false);
193 if(!empty($this->generate_error)){
194 $message[]=$this->generate_error;
195 $this->generate_error="";
196 }
198 return $message;
199 }
202 function SQL_add_me($save){
203 // Get Configuration for Mysql database Server
204 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
206 // Connect to DB server
207 $r_con = @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
209 // Check if we are connected correctly
210 if(!$r_con){
211 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
212 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
213 gosa_log(mysql_error());
214 return false;
215 }
217 // Select database for Extensions
218 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
220 // Test if we have the database selected correctly
221 if(!$db){
222 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
223 gosa_log(mysql_error());
224 return false;
225 }
227 if((!empty($this->telephoneNumber))&&($save==true)){
229 $EXT=array();
231 $parameter ="";
232 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
233 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
234 $parameter .= $this->$attrs;
235 }
237 $i=1;
238 $context="GOsa";
239 // Set Language to German
240 $EXT[$i]['exten'] =$this->telephoneNumber;
241 $EXT[$i]['context'] = $context;
242 $EXT[$i]['priority']= $i;
243 $EXT[$i]['app'] ="SetLanguage";
244 $EXT[$i]['appdata'] ="de";
245 $i++;
247 if($this->goFonConferenceOption_r == "r"){
249 // Recordingformat for conference
250 $EXT[$i]['exten'] =$this->telephoneNumber;
251 $EXT[$i]['context'] =$context;
252 $EXT[$i]['priority']= $i;
253 $EXT[$i]['app'] ="Setvar";
254 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
255 $i++;
257 }
259 // Answer Call
260 $EXT[$i]['exten'] =$this->telephoneNumber;
261 $EXT[$i]['context'] =$context;
262 $EXT[$i]['priority']=$i;
263 $EXT[$i]['app'] ="answer";
264 $EXT[$i]['appdata'] ="";
265 $i++;
267 // Start Conference
268 $EXT[$i]['exten'] =$this->telephoneNumber;
269 $EXT[$i]['context'] =$context;
270 $EXT[$i]['priority']=$i;
271 $EXT[$i]['app'] ="MeetMe";
273 if(empty($this->goFonPIN)) {
274 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
275 }else{
276 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
277 }
278 $i++;
280 // Start Conference
281 $EXT[$i]['exten'] =$this->cn;
282 $EXT[$i]['context'] =$context;
283 $EXT[$i]['priority']=1;
284 $EXT[$i]['app'] ="Goto";
285 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
286 $SQL=array();
288 foreach($EXT as $keytop => $valtop){
289 $s_keys = "";
290 $s_values = "";
291 foreach($valtop as $key=>$val){
292 $s_keys .="`".$key."`,";
293 $s_values .="'".$val."',";
294 }
295 $s_keys =preg_replace("/\,$/","",$s_keys);
296 $s_values =preg_replace("/\,$/","",$s_values);
297 $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
298 }
299 foreach($SQL as $sqlsyn){
300 mysql_query($sqlsyn);
301 }
302 }
306 return(true);
307 }
309 function SQL_remove_me($save){
311 if($this->old_tele_number){
312 // Get Configuration for Mysql database Server
313 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
315 // Connect to DB server
316 $r_con = @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
318 // Check if we are connected correctly
319 if(!$r_con){
320 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
321 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
322 gosa_log(mysql_error());
323 return false;
324 }
326 // Select database for Extensions
327 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
329 // Test if we have the database selected correctly
330 if(!$db){
331 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
332 gosa_log(mysql_error());
333 return false;
334 }
336 $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE (exten= '".$this->old_tele_number."')
337 OR (exten='".$this->telephoneNumber."')
338 OR (exten='".$this->cn."')";
340 if($save){
341 @mysql_query($SQL);
342 }
344 }//ENDE old num availiable ...
345 return(true);
346 }
350 /* This function checks if the given phonenumbers are available or already in use*/
351 function is_number_used()
352 {
353 $ldap= $this->config->get_ldap_link();
354 $ldap->cd($this->config->current['BASE']);
355 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
356 while($attrs = $ldap->fetch()) {
357 unset($attrs['telephoneNumber']['count']);
358 foreach($attrs['telephoneNumber'] as $tele){
359 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
360 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
361 $numbers[$tele]=$attrs;
362 }
363 }
365 $num = $this->telephoneNumber;
366 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->cn))){
367 if(isset($numbers[$num]['uid'][0])){
368 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
369 }else{
370 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
371 }
372 }
373 }
379 /* Save to LDAP */
380 function save()
381 {
382 plugin::save();
384 $this->SQL_remove_me(true);
385 $this->SQL_add_me(true);
387 if(empty($this->goFonConferenceOption_P)){
388 $this->attrs['goFonPIN']=array();
389 }
390 $this->attrs['goFonConferenceOption']="";
391 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
392 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
393 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
394 unset($this->attrs[$attrs]);
395 }
397 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
398 unset($this->attrs['goFonConferenceOptionLifetime']);
400 /* Write back to ldap */
402 unset($this->attrs['base']);
404 $ldap= $this->config->get_ldap_link();
406 $ldap->cat($this->dn);
407 $a= $ldap->fetch();
408 $ldap->cd($this->dn);
409 if (count($a)){
410 $ldap->modify($this->attrs);
411 $this->handle_post_events('modify');
412 } else {
413 $ldap->add($this->attrs);
414 $this->handle_post_events('add');
415 }
416 show_ldap_error($ldap->get_error());
418 /* Optionally execute a command after we're done */
419 $this->postcreate();
420 }
422 }
424 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
425 ?>