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 = "";
29 var $acl = "";
30 var $old_cn = "";
32 var $goFonConferenceOption = "";
33 var $goFonConferenceOption_P = ""; // Set PIN
34 var $goFonConferenceOption_r = ""; // record Conference
35 var $goFonConferenceOption_M = ""; // Play Music opn hold
36 var $goFonConferenceOption_s = ""; // activate menu
37 var $goFonConferenceOption_i = ""; // announce new and leaving user
38 var $goFonConferenceOption_c = ""; // Count User
39 var $goFonConferenceOption_D = ""; // Conference Type, no PIN/PIN
41 var $goFonConferenceOwner = "";
43 var $goFonConferenceOptionFormat = "";
44 var $goFonConferenceOptionLifetime = "";
45 var $telephoneNumber = "";
47 var $old_tele_number = false;
48 var $generate_error = "";
50 var $old_dn;
52 /* Headpage attributes */
53 var $last_dep_sorting= "invalid";
54 var $departments= array();
56 /* attribute list for save action */
57 var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r",
58 "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c",
59 "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber","goFonConferenceOwner");
61 var $objectclasses= array("top", "goFonConference");
63 function conference ($config, $dn)
64 {
65 plugin::plugin($config, $dn);
66 $this->is_account = TRUE;
67 $this->ui = get_userinfo();
68 $this->dn = $dn;
69 $this->orig_dn = $dn;
70 $this->config = $config;
72 /* Set base */
73 if ($this->dn == "new"){
74 $ui= get_userinfo();
75 if(isset($_SESSION['conferencefilter']['depselect'])){
76 $this->base = $_SESSION['conferencefilter']['depselect'];
77 }else{
78 $this->base= dn2base($ui->dn);
79 }
80 } else {
81 $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
82 }
84 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
85 $this->acl= get_module_permission($acl, "goFonConference", $this->dn);
86 $this->goFonConferenceOwner=$this->ui->dn;
88 /* Parse Options ...
89 * Parameter|Lifetime|number
90 */
91 if($this->dn!="new"){
92 $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
94 for($i = 0 ; $i < strlen($tmp1[0]);$i++){
95 $varname = "goFonConferenceOption_".$tmp1[0][$i];
96 if($tmp1[0][$i]=="d"){
97 $this->goFonConferenceOption_D = $tmp1[0][$i];
98 }else{
99 $this->$varname = $tmp1[0][$i];
100 }
101 }
103 $this->goFonConferenceOptionLifetime = $tmp1[1];
104 $this->old_tele_number = $this->telephoneNumber;
105 }
106 $this->old_dn = $this->dn;
107 $this->old_cn = $this->cn;
108 }
110 function execute()
111 {
112 //$acl= get_permissions ($this->dn, $this->ui->subtreeACL);
113 //$this->acl= get_module_permission($acl, "goFonConference", $this->dn);
115 $this->config->departments = get_departments($this->dn);
116 $this->config->make_idepartments();
117 $smarty= get_smarty();
119 $smarty->assign("bases" ,array_flip($this->config->departments));
120 $smarty->assign("base" ,$this->base);
122 $smarty->assign("goFonConferenceOptions", array("D"=>"Conference ","d"=>"Conference without PIN"));
123 $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
124 $smarty->assign("goFonConferenceOption", $this->goFonConferenceOption_D);
126 foreach ($this->attributes as $val){
127 $smarty->assign("$val", $this->$val);
128 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
129 if(!$this->$val){
130 $smarty->assign($val."CHK", "");
131 }else{
132 $smarty->assign($val."CHK", " checked ");
133 }
134 }
136 if($_SESSION['js']==1){
137 if($this->goFonConferenceOption_P != "P"){
138 $smarty->assign("goFonPINACL"," disabled ");
139 $smarty->assign("goFonPIN","");
140 }
141 if($this->goFonConferenceOption_r != "r"){
142 $smarty->assign("goFonConferenceOptionFormatACL"," disabled ");
143 }
144 }
145 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
146 }
148 function remove_from_parent()
149 {
150 $ldap= $this->config->get_ldap_link();
151 $ldap->cd ($this->dn);
152 $ldap->recursive_remove();
154 /* Optionally execute a command after we're done */
155 $this->handle_post_events('remove');
156 }
159 /* Save data to object */
160 function save_object()
161 {
162 plugin::save_object();
163 if(isset($_POST['cn'])){
164 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
165 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonPIN") as $attrs){
166 if(isset($_POST[$attrs])){
167 $this->$attrs = $_POST[$attrs];
168 }else{
169 $this->$attrs = false;
170 }
171 }
172 }
173 }
176 /* Check values */
177 function check()
178 {
179 $message= array();
181 if($this->is_number_used()){
182 $message[] = $this->is_number_used();
183 }
185 if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
186 $message[] =_("You have specified a conference 'without PIN' ... please leave the PIN fields empty.");
187 }
189 if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
190 $message[]= _("Please enter a PIN.");
191 }
193 if(empty($this->cn)){
194 $message[] =_("Please enter a name for the conference.");
195 }
197 if(!is_numeric($this->telephoneNumber)){
198 $message[] =_("Only numeric chars are allowed in Number field.");
199 }
201 if(!is_numeric($this->goFonConferenceOptionLifetime)){
202 $message[] =_("Only numbers are allowed in Lifetime.");
203 }
205 $this->SQL_remove_me(false);
206 $this->SQL_add_me(false);
208 if(!empty($this->generate_error)){
209 $message[]=$this->generate_error;
210 $this->generate_error="";
211 }
213 return $message;
214 }
217 function SQL_add_me($save){
219 if(!isset($_SESSION['config']->data['SERVERS']['FON'])){
220 $this->generate_error = _("There is currently no asterisk server defined. Possibly you are missing a server that handles the asterisk management (goFonServer). \n Your Settings can't be saved to asterisk Database. ");
221 return(false);
222 }
224 // Get Configuration for Mysql database Server
225 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
227 // Connect to DB server
228 $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
230 // Check if we are connected correctly
231 if(!$r_con){
232 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
233 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
234 gosa_log(mysql_error());
235 return false;
236 }
238 // Select database for Extensions
239 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
241 // Test if we have the database selected correctly
242 if(!$db){
243 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
244 gosa_log(mysql_error());
245 return false;
246 }
248 if((!empty($this->telephoneNumber))&&($save==true)){
250 $EXT=array();
252 $parameter ="";
253 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
254 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
255 $parameter .= $this->$attrs;
256 }
258 $i=1;
259 $context="GOsa";
260 // Set Language to German
261 $EXT[$i]['exten'] =$this->telephoneNumber;
262 $EXT[$i]['context'] = $context;
263 $EXT[$i]['priority']= $i;
264 $EXT[$i]['app'] ="SetLanguage";
265 $EXT[$i]['appdata'] ="de";
266 $i++;
268 if($this->goFonConferenceOption_r == "r"){
270 // Recordingformat for conference
271 $EXT[$i]['exten'] =$this->telephoneNumber;
272 $EXT[$i]['context'] =$context;
273 $EXT[$i]['priority']= $i;
274 $EXT[$i]['app'] ="Setvar";
275 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
276 $i++;
278 }
280 // Answer Call
281 $EXT[$i]['exten'] =$this->telephoneNumber;
282 $EXT[$i]['context'] =$context;
283 $EXT[$i]['priority']=$i;
284 $EXT[$i]['app'] ="answer";
285 $EXT[$i]['appdata'] ="";
286 $i++;
288 // Start Conference
289 $EXT[$i]['exten'] =$this->telephoneNumber;
290 $EXT[$i]['context'] =$context;
291 $EXT[$i]['priority']=$i;
292 $EXT[$i]['app'] ="MeetMe";
294 if(empty($this->goFonPIN)) {
295 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
296 }else{
297 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
298 }
299 $i++;
301 // Start Conference
302 $EXT[$i]['exten'] =$this->cn;
303 $EXT[$i]['context'] =$context;
304 $EXT[$i]['priority']=1;
305 $EXT[$i]['app'] ="Goto";
306 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
307 $SQL=array();
309 foreach($EXT as $keytop => $valtop){
310 $s_keys = "";
311 $s_values = "";
312 foreach($valtop as $key=>$val){
313 $s_keys .="`".$key."`,";
314 $s_values .="'".$val."',";
315 }
316 $s_keys =preg_replace("/\,$/","",$s_keys);
317 $s_values =preg_replace("/\,$/","",$s_values);
318 $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
319 }
320 foreach($SQL as $sqlsyn){
321 mysql_query($sqlsyn);
322 }
323 }
326 @mysql_close($r_con);
327 return(true);
328 }
330 function SQL_remove_me($save){
332 if($this->old_tele_number){
333 // Get Configuration for Mysql database Server
334 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
336 // Connect to DB server
337 $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
339 // Check if we are connected correctly
340 if(!$r_con){
341 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
342 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
343 gosa_log(mysql_error());
344 return false;
345 }
347 // Select database for Extensions
348 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
350 // Test if we have the database selected correctly
351 if(!$db){
352 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
353 gosa_log(mysql_error());
354 return false;
355 }
357 $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']."
358 WHERE (exten='".$this->old_tele_number."')
359 OR (exten='".$this->telephoneNumber."')
360 OR (exten='".$this->cn."')
361 OR (exten='".$this->old_cn."')";
363 if($save){
364 @mysql_query($SQL);
365 }
367 }//ENDE old num availiable ...
368 @mysql_close($r_con);
369 return(true);
370 }
374 /* This function checks if the given phonenumbers are available or already in use*/
375 function is_number_used()
376 {
377 $ldap= $this->config->get_ldap_link();
378 $ldap->cd($this->config->current['BASE']);
379 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
380 while($attrs = $ldap->fetch()) {
381 unset($attrs['telephoneNumber']['count']);
382 foreach($attrs['telephoneNumber'] as $tele){
383 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
384 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
385 $numbers[$tele]=$attrs;
386 }
387 }
389 $num = $this->telephoneNumber;
390 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){
391 if(isset($numbers[$num]['uid'][0])){
392 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
393 }else{
394 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
395 }
396 }
397 }
403 /* Save to LDAP */
404 function save()
405 {
407 if((!isset($this->attrs['goFonPIN']))){
408 $pin_use = false;
409 }else{
410 $pin_use = true;
411 }
413 plugin::save();
415 $this->SQL_remove_me(true);
416 $this->SQL_add_me(true);
418 if(empty($this->goFonConferenceOption_P)){
419 if($pin_use){
420 $this->attrs['goFonPIN']=array();
421 }else{
422 unset($this->attrs['goFonPIN']);
423 }
424 }
425 $this->attrs['goFonConferenceOption']="";
426 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
427 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
428 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
429 unset($this->attrs[$attrs]);
430 }
432 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
433 unset($this->attrs['goFonConferenceOptionLifetime']);
435 /* Write back to ldap */
437 unset($this->attrs['base']);
439 foreach($this->attributes as $atr){
440 if(chkacl($this->acl, $atr)!=""){
441 unset($this->attrs[$atr]);
442 }
443 }
445 $ldap= $this->config->get_ldap_link();
447 $ldap->cat($this->dn);
448 $a= $ldap->fetch();
449 $ldap->cd($this->dn);
450 if (count($a)){
451 $ldap->modify($this->attrs);
452 $this->handle_post_events('modify');
453 } else {
454 $ldap->add($this->attrs);
455 $this->handle_post_events('add');
456 }
457 show_ldap_error($ldap->get_error());
459 /* Optionally execute a command after we're done */
460 $this->postcreate();
461 }
463 }
465 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
466 ?>