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 = "";
31 var $goFonConferenceOption = "";
32 var $goFonConferenceOption_P = ""; // Set PIN
33 var $goFonConferenceOption_r = ""; // record Conference
34 var $goFonConferenceOption_M = ""; // Play Music opn hold
35 var $goFonConferenceOption_s = ""; // activate menu
36 var $goFonConferenceOption_i = ""; // announce new and leaving user
37 var $goFonConferenceOption_c = ""; // Count User
38 var $goFonConferenceOption_D = ""; // Conference Type, no PIN/PIN
40 var $goFonConferenceOwner = "";
42 var $goFonConferenceOptionFormat = "";
43 var $goFonConferenceOptionLifetime = "";
44 var $telephoneNumber = "";
46 var $old_tele_number = false;
47 var $generate_error = "";
49 var $old_dn;
51 /* Headpage attributes */
52 var $last_dep_sorting= "invalid";
53 var $departments= array();
55 /* attribute list for save action */
56 var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r",
57 "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c",
58 "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber","goFonConferenceOwner");
60 var $objectclasses= array("top", "goFonConference");
62 function conference ($config, $dn)
63 {
64 plugin::plugin($config, $dn);
65 $this->is_account = TRUE;
66 $this->ui = get_userinfo();
67 $this->dn = $dn;
68 $this->orig_dn = $dn;
69 $this->config = $config;
71 /* Set base */
72 if ($this->dn == "new"){
73 $ui= get_userinfo();
74 if(isset($_SESSION['conferencefilter']['depselect'])){
75 $this->base = $_SESSION['conferencefilter']['depselect'];
76 }else{
77 $this->base= dn2base($ui->dn);
78 }
79 } else {
80 $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
81 }
83 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
84 $this->acl= get_module_permission($acl, "goFonConference", $this->dn);
85 $this->goFonConferenceOwner=$this->ui->dn;
87 /* Parse Options ...
88 * Parameter|Lifetime|number
89 */
90 if($this->dn!="new"){
91 $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
93 for($i = 0 ; $i < strlen($tmp1[0]);$i++){
94 $varname = "goFonConferenceOption_".$tmp1[0][$i];
95 if($tmp1[0][$i]=="d"){
96 $this->goFonConferenceOption_D = $tmp1[0][$i];
97 }else{
98 $this->$varname = $tmp1[0][$i];
99 }
100 }
102 $this->goFonConferenceOptionLifetime = $tmp1[1];
103 $this->old_tele_number = $this->telephoneNumber;
104 }
105 $this->old_dn = $this->dn;
106 }
108 function execute()
109 {
110 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
111 $this->acl= get_module_permission($acl, "goFonConference", $this->dn);
113 $this->config->departments = get_departments($this->dn);
114 $this->config->make_idepartments();
115 $smarty= get_smarty();
117 $smarty->assign("bases" ,array_flip($this->config->departments));
118 $smarty->assign("base" ,$this->base);
120 $smarty->assign("goFonConferenceOptions", array("D"=>"Conference ","d"=>"Conference without PIN"));
121 $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
122 $smarty->assign("goFonConferenceOption", $this->goFonConferenceOption_D);
124 foreach ($this->attributes as $val){
125 $smarty->assign("$val", $this->$val);
126 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
127 if(!$this->$val){
128 $smarty->assign($val."CHK", "");
129 }else{
130 $smarty->assign($val."CHK", " checked ");
131 }
132 }
134 if($_SESSION['js']==1){
135 if($this->goFonConferenceOption_P != "P"){
136 $smarty->assign("goFonPINACL"," disabled ");
137 $smarty->assign("goFonPIN","");
138 }
139 if($this->goFonConferenceOption_r != "r"){
140 $smarty->assign("goFonConferenceOptionFormatACL"," disabled ");
141 }
142 }
143 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
144 }
146 function remove_from_parent()
147 {
148 $ldap= $this->config->get_ldap_link();
149 $ldap->cd ($this->dn);
150 $ldap->recursive_remove();
152 /* Optionally execute a command after we're done */
153 $this->handle_post_events('remove');
154 }
157 /* Save data to object */
158 function save_object()
159 {
160 plugin::save_object();
161 if(isset($_POST['cn'])){
162 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
163 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonPIN") as $attrs){
164 if(isset($_POST[$attrs])){
165 $this->$attrs = $_POST[$attrs];
166 }else{
167 $this->$attrs = false;
168 }
169 }
170 }
171 }
174 /* Check values */
175 function check()
176 {
177 $message= array();
179 if($this->is_number_used()){
180 $message[] = $this->is_number_used();
181 }
183 if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
184 $message[] =_("You have specified a conference 'without PIN' ... please leave the PIN fields empty.");
185 }
187 if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
188 $message[]= _("Please enter a PIN.");
189 }
191 if(empty($this->cn)){
192 $message[] =_("Please enter a name for the conference.");
193 }
195 if(!is_numeric($this->telephoneNumber)){
196 $message[] =_("Only numeric chars are allowed in Number field.");
197 }
199 if(!is_numeric($this->goFonConferenceOptionLifetime)){
200 $message[] =_("Only numbers are allowed in Lifetime.");
201 }
203 $this->SQL_remove_me(false);
204 $this->SQL_add_me(false);
206 if(!empty($this->generate_error)){
207 $message[]=$this->generate_error;
208 $this->generate_error="";
209 }
211 return $message;
212 }
215 function SQL_add_me($save){
216 // Get Configuration for Mysql database Server
217 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
219 // Connect to DB server
220 $r_con = @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
222 // Check if we are connected correctly
223 if(!$r_con){
224 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
225 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
226 gosa_log(mysql_error());
227 return false;
228 }
230 // Select database for Extensions
231 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
233 // Test if we have the database selected correctly
234 if(!$db){
235 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
236 gosa_log(mysql_error());
237 return false;
238 }
240 if((!empty($this->telephoneNumber))&&($save==true)){
242 $EXT=array();
244 $parameter ="";
245 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
246 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
247 $parameter .= $this->$attrs;
248 }
250 $i=1;
251 $context="GOsa";
252 // Set Language to German
253 $EXT[$i]['exten'] =$this->telephoneNumber;
254 $EXT[$i]['context'] = $context;
255 $EXT[$i]['priority']= $i;
256 $EXT[$i]['app'] ="SetLanguage";
257 $EXT[$i]['appdata'] ="de";
258 $i++;
260 if($this->goFonConferenceOption_r == "r"){
262 // Recordingformat for conference
263 $EXT[$i]['exten'] =$this->telephoneNumber;
264 $EXT[$i]['context'] =$context;
265 $EXT[$i]['priority']= $i;
266 $EXT[$i]['app'] ="Setvar";
267 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
268 $i++;
270 }
272 // Answer Call
273 $EXT[$i]['exten'] =$this->telephoneNumber;
274 $EXT[$i]['context'] =$context;
275 $EXT[$i]['priority']=$i;
276 $EXT[$i]['app'] ="answer";
277 $EXT[$i]['appdata'] ="";
278 $i++;
280 // Start Conference
281 $EXT[$i]['exten'] =$this->telephoneNumber;
282 $EXT[$i]['context'] =$context;
283 $EXT[$i]['priority']=$i;
284 $EXT[$i]['app'] ="MeetMe";
286 if(empty($this->goFonPIN)) {
287 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
288 }else{
289 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
290 }
291 $i++;
293 // Start Conference
294 $EXT[$i]['exten'] =$this->cn;
295 $EXT[$i]['context'] =$context;
296 $EXT[$i]['priority']=1;
297 $EXT[$i]['app'] ="Goto";
298 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
299 $SQL=array();
301 foreach($EXT as $keytop => $valtop){
302 $s_keys = "";
303 $s_values = "";
304 foreach($valtop as $key=>$val){
305 $s_keys .="`".$key."`,";
306 $s_values .="'".$val."',";
307 }
308 $s_keys =preg_replace("/\,$/","",$s_keys);
309 $s_values =preg_replace("/\,$/","",$s_values);
310 $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
311 }
312 foreach($SQL as $sqlsyn){
313 mysql_query($sqlsyn);
314 }
315 }
319 return(true);
320 }
322 function SQL_remove_me($save){
324 if($this->old_tele_number){
325 // Get Configuration for Mysql database Server
326 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
328 // Connect to DB server
329 $r_con = @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
331 // Check if we are connected correctly
332 if(!$r_con){
333 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
334 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
335 gosa_log(mysql_error());
336 return false;
337 }
339 // Select database for Extensions
340 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
342 // Test if we have the database selected correctly
343 if(!$db){
344 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
345 gosa_log(mysql_error());
346 return false;
347 }
349 $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE (exten= '".$this->old_tele_number."')
350 OR (exten='".$this->telephoneNumber."')
351 OR (exten='".$this->cn."')";
353 if($save){
354 @mysql_query($SQL);
355 }
357 }//ENDE old num availiable ...
358 return(true);
359 }
363 /* This function checks if the given phonenumbers are available or already in use*/
364 function is_number_used()
365 {
366 $ldap= $this->config->get_ldap_link();
367 $ldap->cd($this->config->current['BASE']);
368 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
369 while($attrs = $ldap->fetch()) {
370 unset($attrs['telephoneNumber']['count']);
371 foreach($attrs['telephoneNumber'] as $tele){
372 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
373 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
374 $numbers[$tele]=$attrs;
375 }
376 }
378 $num = $this->telephoneNumber;
379 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->cn))){
380 if(isset($numbers[$num]['uid'][0])){
381 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
382 }else{
383 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
384 }
385 }
386 }
392 /* Save to LDAP */
393 function save()
394 {
395 plugin::save();
397 $this->SQL_remove_me(true);
398 $this->SQL_add_me(true);
400 if(empty($this->goFonConferenceOption_P)){
401 $this->attrs['goFonPIN']=array();
402 }
403 $this->attrs['goFonConferenceOption']="";
404 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
405 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
406 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
407 unset($this->attrs[$attrs]);
408 }
410 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
411 unset($this->attrs['goFonConferenceOptionLifetime']);
413 /* Write back to ldap */
415 unset($this->attrs['base']);
417 foreach($this->attributes as $atr){
418 if(chkacl($this->acl, $atr)!=""){
419 unset($this->attrs[$atr]);
420 }
421 }
423 $ldap= $this->config->get_ldap_link();
425 $ldap->cat($this->dn);
426 $a= $ldap->fetch();
427 $ldap->cd($this->dn);
428 if (count($a)){
429 $ldap->modify($this->attrs);
430 $this->handle_post_events('modify');
431 } else {
432 $ldap->add($this->attrs);
433 $this->handle_post_events('add');
434 }
435 show_ldap_error($ldap->get_error());
437 /* Optionally execute a command after we're done */
438 $this->postcreate();
439 }
441 }
443 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
444 ?>