| 82 | | function parse_zapata(&$zaplines,$conffile) { |
|---|
| 83 | | # LETS PARSE zapata.conf |
|---|
| 84 | | # Allowed format options |
|---|
| 85 | | # %c Zap Channel number |
|---|
| 86 | | # %n Line number |
|---|
| 87 | | # %N Line number, but restart counter |
|---|
| 88 | | # Example: |
|---|
| 89 | | # ;AMPLABEL:Channel %c - Button %n |
|---|
| | 129 | |
|---|
| | 130 | |
|---|
| | 131 | # Conference Rooms not yet implemented in AMP config |
|---|
| | 132 | $conferences=array(); #### ext#, description |
|---|
| | 133 | #array_push($conferences,array( "810","Conf.10" )); |
|---|
| | 134 | #array_push($conferences,array( "811","Conf.11" )); |
|---|
| | 135 | |
|---|
| | 136 | # cool hack by Julien BLACHE <jblache@debian.org> |
|---|
| | 137 | # WARNING: this file will be substituted by the output of this program |
|---|
| | 138 | $op_conf = $amp_conf["AMPWEBROOT"]."/panel/op_buttons_additional.cfg"; |
|---|
| | 139 | # username to connect to the database |
|---|
| | 140 | $username = $amp_conf["AMPDBUSER"]; |
|---|
| | 141 | # password to connect to the database |
|---|
| | 142 | $password = $amp_conf["AMPDBPASS"]; |
|---|
| | 143 | # the name of the box the MySQL database is running on |
|---|
| | 144 | $hostname = $amp_conf["AMPDBHOST"]; |
|---|
| | 145 | # the name of the database our tables are kept |
|---|
| | 146 | $database = $amp_conf["AMPDBNAME"]; |
|---|
| | 147 | #sort option: extension or lastname |
|---|
| | 148 | $sortoption = $amp_conf["FOPSORT"]; |
|---|
| | 149 | |
|---|
| | 150 | ################### END OF CONFIGURATION ####################### |
|---|
| | 151 | |
|---|
| | 152 | $warning_banner = |
|---|
| | 153 | "; do not edit this file, this is an auto-generated file by freepbx |
|---|
| | 154 | ; all modifications must be done from the web gui |
|---|
| | 155 | "; |
|---|
| | 156 | |
|---|
| | 157 | # Get layout-info from a "panel" table in the freepbx database |
|---|
| | 158 | if (fw_fop_table_exists($db,"panel")) { |
|---|
| | 159 | |
|---|
| | 160 | $statement = "SELECT id, legend, startpos, stoppos, color1, color2 from panel"; |
|---|
| | 161 | $results = $db->getAll($statement); |
|---|
| | 162 | if(DB::IsError($results)) { |
|---|
| | 163 | die($results->getMessage()); |
|---|
| | 164 | } |
|---|
| | 165 | if (count($results) < 1) { |
|---|
| | 166 | print "Notice: no panel defined\n"; |
|---|
| | 167 | } |
|---|
| | 168 | $rectangles = $results; |
|---|
| | 169 | } |
|---|
| | 170 | |
|---|
| | 171 | // pass layout info to function explicitly rather than via globals |
|---|
| | 172 | $layoutinfo = array('rectangles'=>$rectangles,'numbuttonsx'=>$numbuttonsx,'numbuttonsy'=>$numbuttonsy); |
|---|
| | 173 | |
|---|
| | 174 | # Automated generation of style-info from layout-info |
|---|
| | 175 | $autoextenpos=fw_fop_get_style_info("extension",$layoutinfo); |
|---|
| | 176 | $autotrunkpos=fw_fop_get_style_info("trunk",$layoutinfo); |
|---|
| | 177 | $autoparkingpos=fw_fop_get_style_info("parking",$layoutinfo); |
|---|
| | 178 | $autoconfepos=fw_fop_get_style_info("conference",$layoutinfo); |
|---|
| | 179 | $autoqueuepos=fw_fop_get_style_info("queue",$layoutinfo); |
|---|
| | 180 | |
|---|
| | 181 | if ($layoutbuttonsonly == 1) {$extenpos = ""; $trunkpos = ""; $parkingpos = ""; $confepos = ""; $queuepos = "";} |
|---|
| | 182 | |
|---|
| | 183 | if (isset($autoextenpos)) {$extenpos = $autoextenpos;} |
|---|
| | 184 | if (isset($autotrunkpos)) {$trunkpos = $autotrunkpos;} |
|---|
| | 185 | if (isset($autoparkingpos)) {$parkingpos = $autoparkingpos;} |
|---|
| | 186 | if (isset($autoconfepos)) {$confepos = $autoconfepos;} |
|---|
| | 187 | if (isset($autoqueuepos)) {$queuepos = $autoqueuepos;} |
|---|
| | 188 | |
|---|
| | 189 | |
|---|
| | 190 | $fhandle = fopen($op_conf,"w" ); |
|---|
| | 191 | if ($fhandle === false) {die("Cannot create/overwrite config file: $op_conf \n");} |
|---|
| | 192 | fwrite($fhandle, $warning_banner); |
|---|
| | 193 | |
|---|
| | 194 | #First, populate extensions |
|---|
| | 195 | |
|---|
| | 196 | $extensionlist=array(); |
|---|
| | 197 | |
|---|
| | 198 | if (fw_fop_table_exists($db,"devices")) { |
|---|
| | 199 | $statement = "SELECT description,id,dial,tech from devices"; |
|---|
| | 200 | $results = $db->getAll($statement); |
|---|
| | 201 | if(DB::IsError($results)) { |
|---|
| | 202 | die($results->getMessage()); |
|---|
| | 203 | } |
|---|
| | 204 | if (count($results) < 1) { |
|---|
| | 205 | print "Notice: no Devices defined\n"; |
|---|
| | 206 | } |
|---|
| | 207 | $extensionlist = $results; |
|---|
| | 208 | } |
|---|
| | 209 | else { print "Table does not exist: devices\n"; } |
|---|
| | 210 | |
|---|
| | 211 | # sort the extensions |
|---|
| | 212 | foreach ($extensionlist as $key=>$extension) { |
|---|
| | 213 | $temparray = explode(" ",$extension[0]); |
|---|
| | 214 | $lastname[$key] = end($temparray); |
|---|
| | 215 | $extnum[$key] = $extension[1]; |
|---|
| | 216 | } |
|---|
| | 217 | |
|---|
| | 218 | if (isset($sortoption) && ($sortoption == "lastname")) { |
|---|
| | 219 | array_multisort($lastname,$extensionlist); |
|---|
| | 220 | } else { |
|---|
| | 221 | array_multisort($extnum,SORT_STRING,$extensionlist); |
|---|
| | 222 | } |
|---|
| | 223 | |
|---|
| | 224 | #Next, populate queues |
|---|
| | 225 | $queues=array(); |
|---|
| | 226 | if (fw_fop_table_exists($db,"queues_config")) { |
|---|
| | 227 | $statement = "SELECT extension,descr from queues_config order by extension"; |
|---|
| | 228 | $results = $db->getAll($statement); |
|---|
| | 229 | if(DB::IsError($results)) { |
|---|
| | 230 | die($results->getMessage()); |
|---|
| | 231 | } |
|---|
| | 232 | if (count($results) < 1) { |
|---|
| | 233 | print "Notice: no Queues defined\n"; |
|---|
| | 234 | } |
|---|
| | 235 | $queues = $results; |
|---|
| | 236 | } |
|---|
| | 237 | else { print "Table does not exist: queues_config\n"; } |
|---|
| | 238 | |
|---|
| | 239 | |
|---|
| | 240 | ## SME server chnges |
|---|
| | 241 | |
|---|
| | 242 | #Next, populate conferences |
|---|
| | 243 | $conferences=array(); |
|---|
| | 244 | if(fw_fop_table_exists($db,"meetme")) { |
|---|
| | 245 | $statement = "SELECT exten,description FROM meetme ORDER BY exten"; |
|---|
| | 246 | $results = $db->getAll($statement); |
|---|
| | 247 | if(DB::IsError($results)) { |
|---|
| | 248 | die($results->getMessage()); |
|---|
| | 249 | } |
|---|
| | 250 | if (count($results) < 1) { |
|---|
| | 251 | print "Notice: no Conferences defined\n"; |
|---|
| | 252 | } |
|---|
| | 253 | $conferences = $results; |
|---|
| | 254 | } |
|---|
| | 255 | else { print "Table does not exist: meetme\n"; } |
|---|
| | 256 | |
|---|
| | 257 | |
|---|
| | 258 | #Next, populate parkings |
|---|
| | 259 | $parkings=array(); |
|---|
| | 260 | if(fw_fop_table_exists($db,"parkinglot")) { |
|---|
| | 261 | $statement = "SELECT keyword,data FROM parkinglot"; |
|---|
| | 262 | $results = $db->getAll($statement); |
|---|
| | 263 | if(DB::IsError($results)) { |
|---|
| | 264 | die($results->getMessage()); |
|---|
| | 265 | } |
|---|
| | 266 | if (count($results) < 1) { |
|---|
| | 267 | print "Notice: no Parking Lots defined\n"; |
|---|
| | 268 | } |
|---|
| | 269 | $parkings = $results; |
|---|
| | 270 | } |
|---|
| | 271 | else { print "Table does not exist: parkinglot\n"; } |
|---|
| | 272 | |
|---|
| | 273 | ## End of changes |
|---|
| | 274 | #Next, populate trunks (sip and iax) |
|---|
| | 275 | $trunklist=array(); |
|---|
| | 276 | $tables = array("sip","iax"); |
|---|
| | 277 | foreach ($tables as $table) { |
|---|
| | 278 | if (fw_fop_table_exists($db,$table)) { |
|---|
| | 279 | $statement = "SELECT data,id,'$table' from $table where keyword='account' and flags <> 1 and id LIKE 'tr-%' group by data order by id"; |
|---|
| | 280 | $results = $db->getAll($statement); |
|---|
| | 281 | if(DB::IsError($results)) { |
|---|
| | 282 | die($results->getMessage()); |
|---|
| | 283 | } |
|---|
| | 284 | if (count($results) < 1) { |
|---|
| | 285 | print "Notice: no $table trunks defined\n"; |
|---|
| | 286 | } |
|---|
| | 287 | $trunklist = array_merge($trunklist,$results); |
|---|
| | 288 | } |
|---|
| | 289 | else { print "Table does not exist: $table \n"; } |
|---|
| | 290 | } |
|---|
| | 291 | |
|---|
| | 292 | #Determine AMP Users |
|---|
| | 293 | $ampusers=array(); |
|---|
| | 294 | if (fw_fop_table_exists($db,"ampusers")) { |
|---|
| | 295 | $statement = 'SELECT deptname,extension_low,extension_high from ampusers WHERE NOT extension_low = "" AND NOT extension_high = ""'; |
|---|
| | 296 | $results = $db->getAll($statement); |
|---|
| | 297 | if(DB::IsError($results)) { |
|---|
| | 298 | die($results->getMessage()); |
|---|
| | 299 | } |
|---|
| | 300 | if (count($results) < 1) { |
|---|
| | 301 | print "Notice: no AMP Users defined\n"; |
|---|
| | 302 | } |
|---|
| | 303 | else { |
|---|
| | 304 | $ampusers = $results; |
|---|
| | 305 | } |
|---|
| | 306 | } |
|---|
| | 307 | else { print "Table does not exist: ampusers\n"; } |
|---|
| | 308 | array_push($ampusers,array("default","0","0")); //add a default panelcontext that can see all extensions |
|---|
| | 309 | |
|---|
| | 310 | #Write a separate panel context from each AMP User department |
|---|
| | 311 | foreach ($ampusers as $pcontext) { |
|---|
| | 312 | $exten_low = $pcontext[1]; |
|---|
| | 313 | $exten_high = $pcontext[2]; |
|---|
| | 314 | $panelcontext = $pcontext[0]; |
|---|
| | 315 | if ($panelcontext == "") { $panelcontext = $exten_low."to".$exten_high; } |
|---|
| | 316 | |
|---|
| | 317 | fwrite($fhandle, "\n\n; Panel Context: " . $panelcontext . "\n"); |
|---|
| | 318 | |
|---|
| | 319 | # WRITE EXTENSIONS |
|---|
| | 320 | |
|---|
| | 321 | $btn=0; |
|---|
| | 322 | if ($exten_low != 0 && $exten_high != 0) { #display only allowed range of extensions for panel_contexts |
|---|
| | 323 | $extensionrange = array(); |
|---|
| | 324 | foreach ($extensionlist as $value) { |
|---|
| | 325 | if (!is_numeric($value[1])) {array_push($extensionrange,$value);} |
|---|
| | 326 | if (($value[1] >= $exten_low) && ($value[1] <= $exten_high)) {array_push($extensionrange,$value);} |
|---|
| | 327 | } |
|---|
| | 328 | } else { |
|---|
| | 329 | $extensionrange = $extensionlist; |
|---|
| | 330 | } |
|---|
| | 331 | |
|---|
| | 332 | foreach ( $extensionrange as $row ) { |
|---|
| | 333 | $description = $row[0]; |
|---|
| | 334 | $id = $row[1]; |
|---|
| | 335 | $dial = $row[2]; |
|---|
| | 336 | |
|---|
| | 337 | |
|---|
| | 338 | # Support for real mailbox settings - |
|---|
| | 339 | $tech = $row[3]; |
|---|
| | 340 | # some sensible defaults for voicemail ext and context |
|---|
| | 341 | $vmext = $row[1]; |
|---|
| | 342 | $vmcontext = "default"; |
|---|
| | 343 | # the device tech table should also have a dial context - if not assume from-internal |
|---|
| | 344 | $context = "from-internal"; |
|---|
| | 345 | # database table name for iax2 is just iax but sip and zap are ok |
|---|
| | 346 | if ($tech == "iax2") {$tech = "iax";} |
|---|
| | 347 | # get mailbox setting from relevant tech table and split into ext and content |
|---|
| | 348 | if (fw_fop_table_exists($db,$tech)) { |
|---|
| | 349 | $statement = "SELECT data from $tech WHERE id = '$id' AND keyword = 'mailbox' "; |
|---|
| | 350 | $results = $db->getAll($statement); |
|---|
| | 351 | if(DB::IsError($results)) { |
|---|
| | 352 | die($results->getMessage()); |
|---|
| | 353 | } |
|---|
| | 354 | if (count($results) < 1) { |
|---|
| | 355 | print "Notice: no Mailboxes defined\n"; |
|---|
| | 356 | } |
|---|
| | 357 | else { |
|---|
| | 358 | $mailbox = $results[0][0]; |
|---|
| | 359 | $values = @explode('@', $mailbox,2); |
|---|
| | 360 | if (strlen($values[0]) > 0) {$vmext = $values[0];} |
|---|
| | 361 | if (strlen($values[1]) > 0) {$vmcontext = $values[1];} |
|---|
| | 362 | } |
|---|
| | 363 | #while in this table lets get the dial context as well |
|---|
| | 364 | $statement = "SELECT data from $tech WHERE id = '$id' AND keyword = 'context' "; |
|---|
| | 365 | $results = $db->getAll($statement); |
|---|
| | 366 | if(DB::IsError($results)) { |
|---|
| | 367 | die($results->getMessage()); |
|---|
| | 368 | } |
|---|
| | 369 | if (count($results) < 1) { |
|---|
| | 370 | print "Notice: no Context defined\n"; |
|---|
| | 371 | } |
|---|
| | 372 | else { |
|---|
| | 373 | $context = $results[0][0]; |
|---|
| | 374 | } |
|---|
| | 375 | } else { print "Table does not exist: $tech\n"; } |
|---|
| | 376 | # - Support for real mailbox settings |
|---|
| | 377 | |
|---|
| | 378 | |
|---|
| | 379 | # Support for real VM_PREFIX - |
|---|
| | 380 | $vmprefix = "*"; |
|---|
| | 381 | if (fw_fop_table_exists($db,"globals")) { |
|---|
| | 382 | $statement = "SELECT value from globals WHERE variable = 'VM_PREFIX' "; |
|---|
| | 383 | $results = $db->getAll($statement); |
|---|
| | 384 | if(DB::IsError($results)) { |
|---|
| | 385 | die($results->getMessage()); |
|---|
| | 386 | } |
|---|
| | 387 | if (count($results) < 1) { |
|---|
| | 388 | print "Notice: no VM Prefix defined\n"; |
|---|
| | 389 | } |
|---|
| | 390 | else { |
|---|
| | 391 | $vmprefix = $results[0][0]; |
|---|
| | 392 | } |
|---|
| | 393 | } else { print "Table does not exist: global\n"; } |
|---|
| | 394 | # - Support for real VM_PREFIX |
|---|
| | 395 | |
|---|
| | 396 | $btn=fw_fop_get_next_btn($extenpos,$btn); |
|---|
| | 397 | $icon='4'; |
|---|
| | 398 | fwrite($fhandle, "\n[$dial]\nPosition=$btn\nLabel=\"$id : $description\"\nExtension=$id\nContext=$context\nIcon=$icon\nVoicemail_Context=$vmcontext\nVoiceMailExt=$vmprefix$vmext@$context\nPanel_Context=$panelcontext\nAstdbkey=$id\n"); |
|---|
| | 399 | } |
|---|
| | 400 | |
|---|
| | 401 | |
|---|
| | 402 | ### NOW WRITE TRUNKS.. WE START WITH ZAP TRUNKS DEFINED ABOVE |
|---|
| | 403 | |
|---|
| | 404 | |
|---|
| | 405 | |
|---|
| | 406 | |
|---|
| | 407 | $btn=0; |
|---|
| | 408 | |
|---|
| | 409 | foreach ($zaplines as $row) { |
|---|
| | 410 | $zapdef=$row[0]; |
|---|
| | 411 | $zapdesc=$row[1]; |
|---|
| | 412 | $icon='3'; |
|---|
| | 413 | # zaplines and trunklist share the trunk positions so need to store previous btn on overflow from zaplines |
|---|
| | 414 | $previousbtn = $btn; |
|---|
| | 415 | $btn=fw_fop_get_next_btn($trunkpos,$btn); |
|---|
| | 416 | if ($btn == 0) {$btn = $previousbtn; break;} |
|---|
| | 417 | if ($zapdef == "Zap/*") { |
|---|
| | 418 | $numbuttons=$row[2]-1; |
|---|
| | 419 | fwrite($fhandle, "\n[$zapdef]\nLabel=\"$zapdesc\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\nPosition=".$btn); |
|---|
| | 420 | while($numbuttons-->0) { |
|---|
| | 421 | $btn=fw_fop_get_next_btn($trunkpos,$btn); |
|---|
| | 422 | fwrite($fhandle, ",".$btn); |
|---|
| | 423 | } |
|---|
| | 424 | |
|---|
| | 425 | fwrite($fhandle, "\n"); |
|---|
| | 426 | } else { |
|---|
| | 427 | fwrite($fhandle, "\n[$zapdef]\nPosition=$btn\nLabel=\"$zapdesc\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\n"); |
|---|
| | 428 | } |
|---|
| | 429 | } |
|---|
| | 430 | |
|---|
| | 431 | |
|---|
| | 432 | foreach ($trunklist as $row) { |
|---|
| | 433 | $account = $row[0]; |
|---|
| | 434 | $id = $row[1]; |
|---|
| | 435 | $table = $row[2]; |
|---|
| | 436 | if ($account == "") {continue;}; |
|---|
| | 437 | $btn=fw_fop_get_next_btn($trunkpos,$btn); |
|---|
| | 438 | if ($btn == 0) {break;} |
|---|
| | 439 | if (fw_fop_table_exists($db,$table)) { |
|---|
| | 440 | $statement = "SELECT keyword,data from $table where id='$id' and keyword <> 'account' and flags <> 1 order by keyword"; |
|---|
| | 441 | $results = $db->getAll($statement); |
|---|
| | 442 | if(DB::IsError($results)) { |
|---|
| | 443 | die($results->getMessage()); |
|---|
| | 444 | } |
|---|
| | 445 | if (count($results) < 1) { |
|---|
| | 446 | print "Notice: no Trunks defined\n"; |
|---|
| | 447 | } |
|---|
| | 448 | } else { print "Table does not exist: $table \n"; } |
|---|
| | 449 | |
|---|
| | 450 | if ($table == "sip") {$tech="SIP";} |
|---|
| | 451 | if ($table == "iax") {$tech="IAX2";} |
|---|
| | 452 | #if ($table == "zap") {$tech="ZAP";} #no zap trunks in db |
|---|
| | 453 | |
|---|
| | 454 | $callerid = $account; #default callerid to account |
|---|
| | 455 | |
|---|
| | 456 | foreach ($results as $drow) { |
|---|
| | 457 | if ( $drow[0] == "callerid" ) { |
|---|
| | 458 | $callerid = $drow[1]; |
|---|
| | 459 | $fields = explode("<",$callerid); |
|---|
| | 460 | $callerid=$fields[1] ." ". $fields[0]; |
|---|
| | 461 | $callerid = str_replace("\t","",$callerid); |
|---|
| | 462 | $callerid = str_replace("\"","",$callerid); |
|---|
| | 463 | $callerid = str_replace("<","",$callerid); |
|---|
| | 464 | $callerid = str_replace(">","",$callerid); |
|---|
| | 465 | } |
|---|
| | 466 | } |
|---|
| | 467 | $icon='3'; |
|---|
| | 468 | fwrite($fhandle, "\n[$tech/$account]\nPosition=$btn\nLabel=\"$callerid\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\n"); |
|---|
| | 469 | } |
|---|
| | 470 | |
|---|
| | 471 | |
|---|
| | 472 | ## SME server changes |
|---|
| | 473 | |
|---|
| | 474 | |
|---|
| | 475 | |
|---|
| | 476 | ### Write Parkings lots |
|---|
| | 477 | $btn=0; |
|---|
| | 478 | $parken="" ; |
|---|
| | 479 | $extpark ; |
|---|
| | 480 | $parkcontext ; |
|---|
| | 481 | $numberlots ; |
|---|
| | 482 | $maxparkingslots ; |
|---|
| | 483 | |
|---|
| | 484 | foreach ($parkings as $row) { |
|---|
| | 485 | if ($row[0] == "parkingenabled") { |
|---|
| | 486 | $parken = $row[1] ; |
|---|
| | 487 | } |
|---|
| | 488 | if ($row[0] == "parkext") { |
|---|
| | 489 | $extpark = $row[1] ; |
|---|
| | 490 | } |
|---|
| | 491 | if ($row[0] == "parkingcontext") { |
|---|
| | 492 | $parkcontext = $row[1] ; |
|---|
| | 493 | } |
|---|
| | 494 | if ($row[0] == "numslots") { |
|---|
| | 495 | $numberlots = $row[1] ; |
|---|
| | 496 | } |
|---|
| | 497 | } |
|---|
| | 498 | if ($parken == "s") { |
|---|
| | 499 | for ($i = 1 ; $i <= $numberlots ; $i++ ) { |
|---|
| | 500 | $btn=fw_fop_get_next_btn($parkingpos,$btn); |
|---|
| | 501 | if ($btn == 0) {break;} |
|---|
| | 502 | $parknum = $extpark + $i ; |
|---|
| | 503 | $icon='1'; |
|---|
| | 504 | fwrite($fhandle, "\n[PARK$parknum]\nPosition=$btn\nLabel=\"Parked ($parknum)\"\nExtension=$parknum\nContext=$parkcontext\nIcon=$icon\nPanel_Context=$panelcontext\n"); |
|---|
| | 505 | } |
|---|
| | 506 | } |
|---|
| | 507 | |
|---|
| | 508 | ## End of chagnes |
|---|
| | 509 | ### Write conferences (meetme) |
|---|
| | 510 | |
|---|
| | 511 | $btn=0; |
|---|
| | 512 | if ($exten_low != 0 && $exten_high != 0) { #display only allowed range of extensions for panel_contexts |
|---|
| | 513 | $confrange = array(); |
|---|
| | 514 | foreach ($conferences as $value) { |
|---|
| | 515 | if (!is_numeric($value)) {array_push($confrange,$value);} |
|---|
| | 516 | if (($value >= $exten_low) && ($value <= $exten_high)) {array_push($confrange,$value);} |
|---|
| | 517 | } |
|---|
| | 518 | } else { |
|---|
| | 519 | $confrange = $conferences; |
|---|
| | 520 | } |
|---|
| | 521 | foreach ($confrange as $row) { |
|---|
| | 522 | $btn=fw_fop_get_next_btn($confepos,$btn); |
|---|
| | 523 | if ($btn == 0) {break;} |
|---|
| | 524 | $confenum=$row[0]; |
|---|
| | 525 | $confedesc=$row[1]; |
|---|
| | 526 | $icon='6'; |
|---|
| | 527 | fwrite($fhandle, "\n[$confenum]\nPosition=$btn\nLabel=\"$confedesc\"\nExtension=$confenum\nContext=from-internal\nIcon=$icon\nPanel_Context=$panelcontext\n"); |
|---|
| | 528 | } |
|---|
| | 529 | |
|---|
| | 530 | ### Write Queues |
|---|
| | 531 | |
|---|
| | 532 | $btn=0; |
|---|
| | 533 | if ($exten_low != 0 && $exten_high != 0) { #display only allowed range of extensions for panel_contexts |
|---|
| | 534 | $queuerange = array(); |
|---|
| | 535 | foreach ($queues as $value) { |
|---|
| | 536 | if (!is_numeric($value)) {array_push($queuerange,$value);} |
|---|
| | 537 | if (($value >= $exten_low) && ($value <= $exten_high)) {array_push($queuerange,$value);} |
|---|
| | 538 | } |
|---|
| | 539 | } else { |
|---|
| | 540 | $queuerange = $queues; |
|---|
| | 541 | } |
|---|
| | 542 | foreach ($queuerange as $row) { |
|---|
| | 543 | $btn=fw_fop_get_next_btn($queuepos,$btn); |
|---|
| | 544 | if ($btn == 0) {break;} |
|---|
| | 545 | $queuename=$row[0]; |
|---|
| | 546 | $queuedesc=$row[1]; |
|---|
| | 547 | $icon='5'; |
|---|
| | 548 | fwrite($fhandle, "\n[QUEUE/$queuename]\nPosition=$btn\nLabel=\"$queuedesc\"\nExtension=-1\nContext=from-internal\nIcon=$icon\nPanel_Context=$panelcontext\n"); |
|---|
| | 549 | } |
|---|
| | 550 | |
|---|
| | 551 | ### Write rectangles |
|---|
| | 552 | |
|---|
| | 553 | foreach ($rectangles as $rect) { |
|---|
| | 554 | $comment = $rect[0]; |
|---|
| | 555 | $color1 = $rect[4]; |
|---|
| | 556 | $color2 = $rect[5]; |
|---|
| | 557 | $start = $rect[2]; |
|---|
| | 558 | $stop = $rect[3]; |
|---|
| | 559 | |
|---|
| | 560 | $xposition = $buttonsoriginx + $buttonsizex * floor(($start-1)/$numbuttonsy); |
|---|
| | 561 | $yposition = $buttonsoriginy + $buttonsizey * (($start-1)%$numbuttonsy); |
|---|
| | 562 | $xsize = $buttonsizex * (1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy)); |
|---|
| | 563 | $ysize = $buttonsizey * (1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy)); |
|---|
| | 564 | |
|---|
| | 565 | if (($xsize <= 0) || ($ysize <= 0)) {continue;} |
|---|
| | 566 | |
|---|
| | 567 | $xposition += $rectmarginx; |
|---|
| | 568 | $yposition += $rectmarginy; |
|---|
| | 569 | $xsize -= 2 * $rectmarginx; |
|---|
| | 570 | $ysize -= 2 * $rectmarginy; |
|---|
| | 571 | |
|---|
| | 572 | fwrite($fhandle, "\n; $comment\n[rectangle]\nx=$xposition\ny=$yposition\nwidth=$xsize\nheight=$ysize\nline_width=0\nline_color=$color1\nfade_color1=$color1\nfade_color2=$color2\nrnd_border=2\nalpha=20\nlayer=bottom\nPanel_Context=$panelcontext\n"); |
|---|
| | 573 | } |
|---|
| | 574 | |
|---|
| | 575 | ### Write legends |
|---|
| | 576 | |
|---|
| | 577 | foreach ($rectangles as $legend) { |
|---|
| | 578 | $text = $legend[1]; |
|---|
| | 579 | $start = $legend[2]; |
|---|
| | 580 | $stop = $legend[3]; |
|---|
| | 581 | |
|---|
| | 582 | $xposition = $buttonsoriginx + $buttonsizex * floor(($start-1)/$numbuttonsy); |
|---|
| | 583 | $yposition = $buttonsoriginy + $buttonsizey * (($start-1)%$numbuttonsy); |
|---|
| | 584 | $xsize = $buttonsizex * (1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy)); |
|---|
| | 585 | $ysize = $buttonsizey * (1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy)); |
|---|
| | 586 | |
|---|
| | 587 | if (($xsize <= 0) || ($ysize <= 0)) {continue;} |
|---|
| | 588 | |
|---|
| | 589 | $xposition += $legendoffsetx; |
|---|
| | 590 | $yposition += $legendoffsety; |
|---|
| | 591 | |
|---|
| | 592 | fwrite($fhandle, "\n[LEGEND]\nx=$xposition\ny=$yposition\ntext=$text\nfont_size=18\nfont_family=Arial\nuse_embed_fonts=1\nPanel_Context=$panelcontext\n"); |
|---|
| | 593 | } |
|---|
| | 594 | |
|---|
| | 595 | } |
|---|
| | 596 | |
|---|
| | 597 | } // function fw_fop_retrieve_op_conf_from_mysql() |
|---|
| | 598 | |
|---|
| | 599 | |
|---|
| | 600 | function fw_fop_get_next_btn($data,$last) { |
|---|
| | 601 | $rangelist=explode(",",$data); |
|---|
| | 602 | foreach ($rangelist as $range) { |
|---|
| | 603 | $rangeval=explode("-",$range,2); |
|---|
| | 604 | if ($last < $rangeval[0]) {return $rangeval[0] ;} |
|---|
| | 605 | if (isset($rangeval[1]) && ($last < $rangeval[1])) {return $last+1;} |
|---|
| | 606 | #Need to try another range def... |
|---|
| | 607 | } |
|---|
| | 608 | #If we get here, we ran out of positions :( |
|---|
| | 609 | return 0; #????? |
|---|
| | 610 | } |
|---|
| | 611 | |
|---|
| | 612 | #this sub checks for the existance of a table |
|---|
| | 613 | function fw_fop_table_exists($db,$table) { |
|---|
| | 614 | $result = mysql_query("SHOW TABLES LIKE '" . $table . "'"); |
|---|
| | 615 | if(mysql_fetch_row($result) === false) {return(false);} |
|---|
| | 616 | return(true); |
|---|
| | 617 | } |
|---|
| | 618 | |
|---|
| | 619 | function fw_fop_get_style_info($id,$layoutinfo) { |
|---|
| | 620 | // do not use globals - instead pass layout info into function explicitly |
|---|
| | 621 | // global $rectangles; |
|---|
| | 622 | // global $numbuttonsx; |
|---|
| | 623 | // global $numbuttonsy; |
|---|
| | 624 | $rectangles = $layoutinfo['rectangles']; |
|---|
| | 625 | $numbuttonsx = $layoutinfo['numbuttonsx']; |
|---|
| | 626 | $numbuttonsy = $layoutinfo['numbuttonsy']; |
|---|
| | 627 | |
|---|
| | 628 | |
|---|
| | 629 | foreach ($rectangles as $rect) { |
|---|
| | 630 | if ($id == $rect[0]) { |
|---|
| | 631 | |
|---|
| | 632 | $start = $rect[2]; |
|---|
| | 633 | $stop = $rect[3]; |
|---|
| | 634 | |
|---|
| | 635 | $xposition = floor(($start-1)/$numbuttonsy); |
|---|
| | 636 | $yposition = (($start-1)%$numbuttonsy); |
|---|
| | 637 | $xsize = 1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy); |
|---|
| | 638 | $ysize = 1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy); |
|---|
| | 639 | |
|---|
| | 640 | if (($xsize <= 0) || ($ysize <= 0)) {print "Warning: rectange '$id' has negative area\n"; break;} |
|---|
| | 641 | $styleinfo = ""; |
|---|
| | 642 | if ($ysize > 2) { |
|---|
| | 643 | $styleinfo .= ($start + 1) . "-" . ($start + $ysize - 1) . ","; |
|---|
| | 644 | } |
|---|
| | 645 | elseif ($ysize == 2) { |
|---|
| | 646 | $styleinfo .= ($start + 1) . ","; |
|---|
| | 647 | } |
|---|
| | 648 | |
|---|
| | 649 | for ($i = 1 ; $i < $xsize ; $i++ ) { |
|---|
| | 650 | if ($ysize > 1) { |
|---|
| | 651 | $styleinfo .= (($i + $xposition) * $numbuttonsy + $yposition + 1) . "-" . (($i + $xposition) * $numbuttonsy + $yposition + $ysize) . ","; |
|---|
| | 652 | } |
|---|
| | 653 | else { |
|---|
| | 654 | $styleinfo .= (($i + $xposition) * $numbuttonsy + $yposition + 1) . ","; |
|---|
| | 655 | } |
|---|
| | 656 | } |
|---|
| | 657 | $retval = $styleinfo; |
|---|
| | 658 | break; |
|---|
| | 659 | } |
|---|
| | 660 | } |
|---|
| | 661 | return $retval; |
|---|
| | 662 | } |
|---|
| | 663 | |
|---|
| | 664 | function fw_fop_parse_zapata(&$zaplines,$conffile) { |
|---|
| | 665 | // LETS PARSE zapata.conf |
|---|
| | 666 | // Allowed format options |
|---|
| | 667 | // %c Zap Channel number |
|---|
| | 668 | // %n Line number |
|---|
| | 669 | // %N Line number, but restart counter |
|---|
| | 670 | // Example: |
|---|
| | 671 | // ;AMPLABEL:Channel %c - Button %n |
|---|
| 211 | | #Finished parsing zapata.conf |
|---|
| 212 | | |
|---|
| 213 | | |
|---|
| 214 | | # Conference Rooms not yet implemented in AMP config |
|---|
| 215 | | $conferences=array(); #### ext#, description |
|---|
| 216 | | #array_push($conferences,array( "810","Conf.10" )); |
|---|
| 217 | | #array_push($conferences,array( "811","Conf.11" )); |
|---|
| 218 | | |
|---|
| 219 | | # cool hack by Julien BLACHE <jblache@debian.org> |
|---|
| 220 | | # WARNING: this file will be substituted by the output of this program |
|---|
| 221 | | $op_conf = $amp_conf["AMPWEBROOT"]."/panel/op_buttons_additional.cfg"; |
|---|
| 222 | | # username to connect to the database |
|---|
| 223 | | $username = $amp_conf["AMPDBUSER"]; |
|---|
| 224 | | # password to connect to the database |
|---|
| 225 | | $password = $amp_conf["AMPDBPASS"]; |
|---|
| 226 | | # the name of the box the MySQL database is running on |
|---|
| 227 | | $hostname = $amp_conf["AMPDBHOST"]; |
|---|
| 228 | | # the name of the database our tables are kept |
|---|
| 229 | | $database = $amp_conf["AMPDBNAME"]; |
|---|
| 230 | | #sort option: extension or lastname |
|---|
| 231 | | $sortoption = $amp_conf["FOPSORT"]; |
|---|
| 232 | | |
|---|
| 233 | | ################### END OF CONFIGURATION ####################### |
|---|
| 234 | | |
|---|
| 235 | | $warning_banner = |
|---|
| 236 | | "; do not edit this file, this is an auto-generated file by freepbx |
|---|
| 237 | | ; all modifications must be done from the web gui |
|---|
| 238 | | "; |
|---|
| 239 | | |
|---|
| 240 | | # Get layout-info from a "panel" table in the freepbx database |
|---|
| 241 | | if (table_exists($db,"panel")) { |
|---|
| 242 | | |
|---|
| 243 | | $statement = "SELECT id, legend, startpos, stoppos, color1, color2 from panel"; |
|---|
| 244 | | $results = $db->getAll($statement); |
|---|
| 245 | | if(DB::IsError($results)) { |
|---|
| 246 | | die($results->getMessage()); |
|---|
| 247 | | } |
|---|
| 248 | | if (count($results) < 1) { |
|---|
| 249 | | print "Notice: no panel defined\n"; |
|---|
| 250 | | } |
|---|
| 251 | | $rectangles = $results; |
|---|
| 252 | | } |
|---|
| 253 | | |
|---|
| 254 | | // pass layout info to function explicitly rather than via globals |
|---|
| 255 | | $layoutinfo = array('rectangles'=>$rectangles,'numbuttonsx'=>$numbuttonsx,'numbuttonsy'=>$numbuttonsy); |
|---|
| 256 | | |
|---|
| 257 | | # Automated generation of style-info from layout-info |
|---|
| 258 | | $autoextenpos=get_styleinfo("extension",$layoutinfo); |
|---|
| 259 | | $autotrunkpos=get_styleinfo("trunk",$layoutinfo); |
|---|
| 260 | | $autoparkingpos=get_styleinfo("parking",$layoutinfo); |
|---|
| 261 | | $autoconfepos=get_styleinfo("conference",$layoutinfo); |
|---|
| 262 | | $autoqueuepos=get_styleinfo("queue",$layoutinfo); |
|---|
| 263 | | |
|---|
| 264 | | if ($layoutbuttonsonly == 1) {$extenpos = ""; $trunkpos = ""; $parkingpos = ""; $confepos = ""; $queuepos = "";} |
|---|
| 265 | | |
|---|
| 266 | | if (isset($autoextenpos)) {$extenpos = $autoextenpos;} |
|---|
| 267 | | if (isset($autotrunkpos)) {$trunkpos = $autotrunkpos;} |
|---|
| 268 | | if (isset($autoparkingpos)) {$parkingpos = $autoparkingpos;} |
|---|
| 269 | | if (isset($autoconfepos)) {$confepos = $autoconfepos;} |
|---|
| 270 | | if (isset($autoqueuepos)) {$queuepos = $autoqueuepos;} |
|---|
| 271 | | |
|---|
| 272 | | |
|---|
| 273 | | $fhandle = fopen($op_conf,"w" ); |
|---|
| 274 | | if ($fhandle === false) {die("Cannot create/overwrite config file: $op_conf \n");} |
|---|
| 275 | | fwrite($fhandle, $warning_banner); |
|---|
| 276 | | |
|---|
| 277 | | #First, populate extensions |
|---|
| 278 | | |
|---|
| 279 | | $extensionlist=array(); |
|---|
| 280 | | |
|---|
| 281 | | if (table_exists($db,"devices")) { |
|---|
| 282 | | $statement = "SELECT description,id,dial,tech from devices"; |
|---|
| 283 | | $results = $db->getAll($statement); |
|---|
| 284 | | if(DB::IsError($results)) { |
|---|
| 285 | | die($results->getMessage()); |
|---|
| 286 | | } |
|---|
| 287 | | if (count($results) < 1) { |
|---|
| 288 | | print "Notice: no Devices defined\n"; |
|---|
| 289 | | } |
|---|
| 290 | | $extensionlist = $results; |
|---|
| 291 | | } |
|---|
| 292 | | else { print "Table does not exist: devices\n"; } |
|---|
| 293 | | |
|---|
| 294 | | # sort the extensions |
|---|
| 295 | | foreach ($extensionlist as $key=>$extension) { |
|---|
| 296 | | $temparray = explode(" ",$extension[0]); |
|---|
| 297 | | $lastname[$key] = end($temparray); |
|---|
| 298 | | $extnum[$key] = $extension[1]; |
|---|
| 299 | | } |
|---|
| 300 | | |
|---|
| 301 | | if (isset($sortoption) && ($sortoption == "lastname")) { |
|---|
| 302 | | array_multisort($lastname,$extensionlist); |
|---|
| 303 | | } else { |
|---|
| 304 | | array_multisort($extnum,SORT_STRING,$extensionlist); |
|---|
| 305 | | } |
|---|
| 306 | | |
|---|
| 307 | | #Next, populate queues |
|---|
| 308 | | $queues=array(); |
|---|
| 309 | | if (table_exists($db,"queues_config")) { |
|---|
| 310 | | $statement = "SELECT extension,descr from queues_config order by extension"; |
|---|
| 311 | | $results = $db->getAll($statement); |
|---|
| 312 | | if(DB::IsError($results)) { |
|---|
| 313 | | die($results->getMessage()); |
|---|
| 314 | | } |
|---|
| 315 | | if (count($results) < 1) { |
|---|
| 316 | | print "Notice: no Queues defined\n"; |
|---|
| 317 | | } |
|---|
| 318 | | $queues = $results; |
|---|
| 319 | | } |
|---|
| 320 | | else { print "Table does not exist: queues_config\n"; } |
|---|
| 321 | | |
|---|
| 322 | | |
|---|
| 323 | | ## SME server chnges |
|---|
| 324 | | |
|---|
| 325 | | #Next, populate conferences |
|---|
| 326 | | $conferences=array(); |
|---|
| 327 | | if(table_exists($db,"meetme")) { |
|---|
| 328 | | $statement = "SELECT exten,description FROM meetme ORDER BY exten"; |
|---|
| 329 | | $results = $db->getAll($statement); |
|---|
| 330 | | if(DB::IsError($results)) { |
|---|
| 331 | | die($results->getMessage()); |
|---|
| 332 | | } |
|---|
| 333 | | if (count($results) < 1) { |
|---|
| 334 | | print "Notice: no Conferences defined\n"; |
|---|
| 335 | | } |
|---|
| 336 | | $conferences = $results; |
|---|
| 337 | | } |
|---|
| 338 | | else { print "Table does not exist: meetme\n"; } |
|---|
| 339 | | |
|---|
| 340 | | |
|---|
| 341 | | #Next, populate parkings |
|---|
| 342 | | $parkings=array(); |
|---|
| 343 | | if(table_exists($db,"parkinglot")) { |
|---|
| 344 | | $statement = "SELECT keyword,data FROM parkinglot"; |
|---|
| 345 | | $results = $db->getAll($statement); |
|---|
| 346 | | if(DB::IsError($results)) { |
|---|
| 347 | | die($results->getMessage()); |
|---|
| 348 | | } |
|---|
| 349 | | if (count($results) < 1) { |
|---|
| 350 | | print "Notice: no Parking Lots defined\n"; |
|---|
| 351 | | } |
|---|
| 352 | | $parkings = $results; |
|---|
| 353 | | } |
|---|
| 354 | | else { print "Table does not exist: parkinglot\n"; } |
|---|
| 355 | | |
|---|
| 356 | | ## End of changes |
|---|
| 357 | | #Next, populate trunks (sip and iax) |
|---|
| 358 | | $trunklist=array(); |
|---|
| 359 | | $tables = array("sip","iax"); |
|---|
| 360 | | foreach ($tables as $table) { |
|---|
| 361 | | if (table_exists($db,$table)) { |
|---|
| 362 | | $statement = "SELECT data,id,'$table' from $table where keyword='account' and flags <> 1 and id LIKE 'tr-%' group by data order by id"; |
|---|
| 363 | | $results = $db->getAll($statement); |
|---|
| 364 | | if(DB::IsError($results)) { |
|---|
| 365 | | die($results->getMessage()); |
|---|
| 366 | | } |
|---|
| 367 | | if (count($results) < 1) { |
|---|
| 368 | | print "Notice: no $table trunks defined\n"; |
|---|
| 369 | | } |
|---|
| 370 | | $trunklist = array_merge($trunklist,$results); |
|---|
| 371 | | } |
|---|
| 372 | | else { print "Table does not exist: $table \n"; } |
|---|
| 373 | | } |
|---|
| 374 | | |
|---|
| 375 | | #Determine AMP Users |
|---|
| 376 | | $ampusers=array(); |
|---|
| 377 | | if (table_exists($db,"ampusers")) { |
|---|
| 378 | | $statement = 'SELECT deptname,extension_low,extension_high from ampusers WHERE NOT extension_low = "" AND NOT extension_high = ""'; |
|---|
| 379 | | $results = $db->getAll($statement); |
|---|
| 380 | | if(DB::IsError($results)) { |
|---|
| 381 | | die($results->getMessage()); |
|---|
| 382 | | } |
|---|
| 383 | | if (count($results) < 1) { |
|---|
| 384 | | print "Notice: no AMP Users defined\n"; |
|---|
| 385 | | } |
|---|
| 386 | | else { |
|---|
| 387 | | $ampusers = $results; |
|---|
| 388 | | } |
|---|
| 389 | | } |
|---|
| 390 | | else { print "Table does not exist: ampusers\n"; } |
|---|
| 391 | | array_push($ampusers,array("default","0","0")); //add a default panelcontext that can see all extensions |
|---|
| 392 | | |
|---|
| 393 | | #Write a separate panel context from each AMP User department |
|---|
| 394 | | foreach ($ampusers as $pcontext) { |
|---|
| 395 | | $exten_low = $pcontext[1]; |
|---|
| 396 | | $exten_high = $pcontext[2]; |
|---|
| 397 | | $panelcontext = $pcontext[0]; |
|---|
| 398 | | if ($panelcontext == "") { $panelcontext = $exten_low."to".$exten_high; } |
|---|
| 399 | | |
|---|
| 400 | | fwrite($fhandle, "\n\n; Panel Context: " . $panelcontext . "\n"); |
|---|
| 401 | | |
|---|
| 402 | | # WRITE EXTENSIONS |
|---|
| 403 | | |
|---|
| 404 | | $btn=0; |
|---|
| 405 | | if ($exten_low != 0 && $exten_high != 0) { #display only allowed range of extensions for panel_contexts |
|---|
| 406 | | $extensionrange = array(); |
|---|
| 407 | | foreach ($extensionlist as $value) { |
|---|
| 408 | | if (!is_numeric($value[1])) {array_push($extensionrange,$value);} |
|---|
| 409 | | if (($value[1] >= $exten_low) && ($value[1] <= $exten_high)) {array_push($extensionrange,$value);} |
|---|
| 410 | | } |
|---|
| 411 | | } else { |
|---|
| 412 | | $extensionrange = $extensionlist; |
|---|
| 413 | | } |
|---|
| 414 | | |
|---|
| 415 | | foreach ( $extensionrange as $row ) { |
|---|
| 416 | | $description = $row[0]; |
|---|
| 417 | | $id = $row[1]; |
|---|
| 418 | | $dial = $row[2]; |
|---|
| 419 | | |
|---|
| 420 | | |
|---|
| 421 | | # Support for real mailbox settings - |
|---|
| 422 | | $tech = $row[3]; |
|---|
| 423 | | # some sensible defaults for voicemail ext and context |
|---|
| 424 | | $vmext = $row[1]; |
|---|
| 425 | | $vmcontext = "default"; |
|---|
| 426 | | # the device tech table should also have a dial context - if not assume from-internal |
|---|
| 427 | | $context = "from-internal"; |
|---|
| 428 | | # database table name for iax2 is just iax but sip and zap are ok |
|---|
| 429 | | if ($tech == "iax2") {$tech = "iax";} |
|---|
| 430 | | # get mailbox setting from relevant tech table and split into ext and content |
|---|
| 431 | | if (table_exists($db,$tech)) { |
|---|
| 432 | | $statement = "SELECT data from $tech WHERE id = '$id' AND keyword = 'mailbox' "; |
|---|
| 433 | | $results = $db->getAll($statement); |
|---|
| 434 | | if(DB::IsError($results)) { |
|---|
| 435 | | die($results->getMessage()); |
|---|
| 436 | | } |
|---|
| 437 | | if (count($results) < 1) { |
|---|
| 438 | | print "Notice: no Mailboxes defined\n"; |
|---|
| 439 | | } |
|---|
| 440 | | else { |
|---|
| 441 | | $mailbox = $results[0][0]; |
|---|
| 442 | | $values = @explode('@', $mailbox,2); |
|---|
| 443 | | if (strlen($values[0]) > 0) {$vmext = $values[0];} |
|---|
| 444 | | if (strlen($values[1]) > 0) {$vmcontext = $values[1];} |
|---|
| 445 | | } |
|---|
| 446 | | #while in this table lets get the dial context as well |
|---|
| 447 | | $statement = "SELECT data from $tech WHERE id = '$id' AND keyword = 'context' "; |
|---|
| 448 | | $results = $db->getAll($statement); |
|---|
| 449 | | if(DB::IsError($results)) { |
|---|
| 450 | | die($results->getMessage()); |
|---|
| 451 | | } |
|---|
| 452 | | if (count($results) < 1) { |
|---|
| 453 | | print "Notice: no Context defined\n"; |
|---|
| 454 | | } |
|---|
| 455 | | else { |
|---|
| 456 | | $context = $results[0][0]; |
|---|
| 457 | | } |
|---|
| 458 | | } else { print "Table does not exist: $tech\n"; } |
|---|
| 459 | | # - Support for real mailbox settings |
|---|
| 460 | | |
|---|
| 461 | | |
|---|
| 462 | | # Support for real VM_PREFIX - |
|---|
| 463 | | $vmprefix = "*"; |
|---|
| 464 | | if (table_exists($db,"globals")) { |
|---|
| 465 | | $statement = "SELECT value from globals WHERE variable = 'VM_PREFIX' "; |
|---|
| 466 | | $results = $db->getAll($statement); |
|---|
| 467 | | if(DB::IsError($results)) { |
|---|
| 468 | | die($results->getMessage()); |
|---|
| 469 | | } |
|---|
| 470 | | if (count($results) < 1) { |
|---|
| 471 | | print "Notice: no VM Prefix defined\n"; |
|---|
| 472 | | } |
|---|
| 473 | | else { |
|---|
| 474 | | $vmprefix = $results[0][0]; |
|---|
| 475 | | } |
|---|
| 476 | | } else { print "Table does not exist: global\n"; } |
|---|
| 477 | | # - Support for real VM_PREFIX |
|---|
| 478 | | |
|---|
| 479 | | $btn=get_next_btn($extenpos,$btn); |
|---|
| 480 | | $icon='4'; |
|---|
| 481 | | fwrite($fhandle, "\n[$dial]\nPosition=$btn\nLabel=\"$id : $description\"\nExtension=$id\nContext=$context\nIcon=$icon\nVoicemail_Context=$vmcontext\nVoiceMailExt=$vmprefix$vmext@$context\nPanel_Context=$panelcontext\nAstdbkey=$id\n"); |
|---|
| 482 | | } |
|---|
| 483 | | |
|---|
| 484 | | |
|---|
| 485 | | ### NOW WRITE TRUNKS.. WE START WITH ZAP TRUNKS DEFINED ABOVE |
|---|
| 486 | | |
|---|
| 487 | | |
|---|
| 488 | | |
|---|
| 489 | | |
|---|
| 490 | | $btn=0; |
|---|
| 491 | | |
|---|
| 492 | | foreach ($zaplines as $row) { |
|---|
| 493 | | $zapdef=$row[0]; |
|---|
| 494 | | $zapdesc=$row[1]; |
|---|
| 495 | | $icon='3'; |
|---|
| 496 | | # zaplines and trunklist share the trunk positions so need to store previous btn on overflow from zaplines |
|---|
| 497 | | $previousbtn = $btn; |
|---|
| 498 | | $btn=get_next_btn($trunkpos,$btn); |
|---|
| 499 | | if ($btn == 0) {$btn = $previousbtn; break;} |
|---|
| 500 | | if ($zapdef == "Zap/*") { |
|---|
| 501 | | $numbuttons=$row[2]-1; |
|---|
| 502 | | fwrite($fhandle, "\n[$zapdef]\nLabel=\"$zapdesc\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\nPosition=".$btn); |
|---|
| 503 | | while($numbuttons-->0) { |
|---|
| 504 | | $btn=get_next_btn($trunkpos,$btn); |
|---|
| 505 | | fwrite($fhandle, ",".$btn); |
|---|
| 506 | | } |
|---|
| 507 | | |
|---|
| 508 | | fwrite($fhandle, "\n"); |
|---|
| 509 | | } else { |
|---|
| 510 | | fwrite($fhandle, "\n[$zapdef]\nPosition=$btn\nLabel=\"$zapdesc\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\n"); |
|---|
| 511 | | } |
|---|
| 512 | | } |
|---|
| 513 | | |
|---|
| 514 | | |
|---|
| 515 | | foreach ($trunklist as $row) { |
|---|
| 516 | | $account = $row[0]; |
|---|
| 517 | | $id = $row[1]; |
|---|
| 518 | | $table = $row[2]; |
|---|
| 519 | | if ($account == "") {continue;}; |
|---|
| 520 | | $btn=get_next_btn($trunkpos,$btn); |
|---|
| 521 | | if ($btn == 0) {break;} |
|---|
| 522 | | if (table_exists($db,$table)) { |
|---|
| 523 | | $statement = "SELECT keyword,data from $table where id='$id' and keyword <> 'account' and flags <> 1 order by keyword"; |
|---|
| 524 | | $results = $db->getAll($statement); |
|---|
| 525 | | if(DB::IsError($results)) { |
|---|
| 526 | | die($results->getMessage()); |
|---|
| 527 | | } |
|---|
| 528 | | if (count($results) < 1) { |
|---|
| 529 | | print "Notice: no Trunks defined\n"; |
|---|
| 530 | | } |
|---|
| 531 | | } else { print "Table does not exist: $table \n"; } |
|---|
| 532 | | |
|---|
| 533 | | if ($table == "sip") {$tech="SIP";} |
|---|
| 534 | | if ($table == "iax") {$tech="IAX2";} |
|---|
| 535 | | #if ($table == "zap") {$tech="ZAP";} #no zap trunks in db |
|---|
| 536 | | |
|---|
| 537 | | $callerid = $account; #default callerid to account |
|---|
| 538 | | |
|---|
| 539 | | foreach ($results as $drow) { |
|---|
| 540 | | if ( $drow[0] == "callerid" ) { |
|---|
| 541 | | $callerid = $drow[1]; |
|---|
| 542 | | $fields = explode("<",$callerid); |
|---|
| 543 | | $callerid=$fields[1] ." ". $fields[0]; |
|---|
| 544 | | $callerid = str_replace("\t","",$callerid); |
|---|
| 545 | | $callerid = str_replace("\"","",$callerid); |
|---|
| 546 | | $callerid = str_replace("<","",$callerid); |
|---|
| 547 | | $callerid = str_replace(">","",$callerid); |
|---|
| 548 | | } |
|---|
| 549 | | } |
|---|
| 550 | | $icon='3'; |
|---|
| 551 | | fwrite($fhandle, "\n[$tech/$account]\nPosition=$btn\nLabel=\"$callerid\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\n"); |
|---|
| 552 | | } |
|---|
| 553 | | |
|---|
| 554 | | |
|---|
| 555 | | ## SME server changes |
|---|
| 556 | | |
|---|
| 557 | | |
|---|
| 558 | | |
|---|
| 559 | | ### Write Parkings lots |
|---|
| 560 | | $btn=0; |
|---|
| 561 | | $parken="" ; |
|---|
| 562 | | $extpark ; |
|---|
| 563 | | $parkcontext ; |
|---|
| 564 | | $numberlots ; |
|---|
| 565 | | $maxparkingslots ; |
|---|
| 566 | | |
|---|
| 567 | | foreach ($parkings as $row) { |
|---|
| 568 | | if ($row[0] == "parkingenabled") { |
|---|
| 569 | | $parken = $row[1] ; |
|---|
| 570 | | } |
|---|
| 571 | | if ($row[0] == "parkext") { |
|---|
| 572 | | $extpark = $row[1] ; |
|---|
| 573 | | } |
|---|
| 574 | | if ($row[0] == "parkingcontext") { |
|---|
| 575 | | $parkcontext = $row[1] ; |
|---|
| 576 | | } |
|---|
| 577 | | if ($row[0] == "numslots") { |
|---|
| 578 | | $numberlots = $row[1] ; |
|---|
| 579 | | } |
|---|
| 580 | | } |
|---|
| 581 | | if ($parken == "s") { |
|---|
| 582 | | for ($i = 1 ; $i <= $numberlots ; $i++ ) { |
|---|
| 583 | | $btn=get_next_btn($parkingpos,$btn); |
|---|
| 584 | | if ($btn == 0) {break;} |
|---|
| 585 | | $parknum = $extpark + $i ; |
|---|
| 586 | | $icon='1'; |
|---|
| 587 | | fwrite($fhandle, "\n[PARK$parknum]\nPosition=$btn\nLabel=\"Parked ($parknum)\"\nExtension=$parknum\nContext=$parkcontext\nIcon=$icon\nPanel_Context=$panelcontext\n"); |
|---|
| 588 | | } |
|---|
| 589 | | } |
|---|
| 590 | | |
|---|
| 591 | | ## End of chagnes |
|---|
| 592 | | ### Write conferences (meetme) |
|---|
| 593 | | |
|---|
| 594 | | $btn=0; |
|---|
| 595 | | if ($exten_low != 0 && $exten_high != 0) { #display only allowed range of extensions for panel_contexts |
|---|
| 596 | | $confrange = array(); |
|---|
| 597 | | foreach ($conferences as $value) { |
|---|
| 598 | | if (!is_numeric($value)) {array_push($confrange,$value);} |
|---|
| 599 | | if (($value >= $exten_low) && ($value <= $exten_high)) {array_push($confrange,$value);} |
|---|
| 600 | | } |
|---|
| 601 | | } else { |
|---|
| 602 | | $confrange = $conferences; |
|---|
| 603 | | } |
|---|
| 604 | | foreach ($confrange as $row) { |
|---|
| 605 | | $btn=get_next_btn($confepos,$btn); |
|---|
| 606 | | if ($btn == 0) {break;} |
|---|
| 607 | | $confenum=$row[0]; |
|---|
| 608 | | $confedesc=$row[1]; |
|---|
| 609 | | $icon='6'; |
|---|
| 610 | | fwrite($fhandle, "\n[$confenum]\nPosition=$btn\nLabel=\"$confedesc\"\nExtension=$confenum\nContext=from-internal\nIcon=$icon\nPanel_Context=$panelcontext\n"); |
|---|
| 611 | | } |
|---|
| 612 | | |
|---|
| 613 | | ### Write Queues |
|---|
| 614 | | |
|---|
| 615 | | $btn=0; |
|---|
| 616 | | if ($exten_low != 0 && $exten_high != 0) { #display only allowed range of extensions for panel_contexts |
|---|
| 617 | | $queuerange = array(); |
|---|
| 618 | | foreach ($queues as $value) { |
|---|
| 619 | | if (!is_numeric($value)) {array_push($queuerange,$value);} |
|---|
| 620 | | if (($value >= $exten_low) && ($value <= $exten_high)) {array_push($queuerange,$value);} |
|---|
| 621 | | } |
|---|
| 622 | | } else { |
|---|
| 623 | | $queuerange = $queues; |
|---|
| 624 | | } |
|---|
| 625 | | foreach ($queuerange as $row) { |
|---|
| 626 | | $btn=get_next_btn($queuepos,$btn); |
|---|
| 627 | | if ($btn == 0) {break;} |
|---|
| 628 | | $queuename=$row[0]; |
|---|
| 629 | | $queuedesc=$row[1]; |
|---|
| 630 | | $icon='5'; |
|---|
| 631 | | fwrite($fhandle, "\n[QUEUE/$queuename]\nPosition=$btn\nLabel=\"$queuedesc\"\nExtension=-1\nContext=from-internal\nIcon=$icon\nPanel_Context=$panelcontext\n"); |
|---|
| 632 | | } |
|---|
| 633 | | |
|---|
| 634 | | ### Write rectangles |
|---|
| 635 | | |
|---|
| 636 | | foreach ($rectangles as $rect) { |
|---|
| 637 | | $comment = $rect[0]; |
|---|
| 638 | | $color1 = $rect[4]; |
|---|
| 639 | | $color2 = $rect[5]; |
|---|
| 640 | | $start = $rect[2]; |
|---|
| 641 | | $stop = $rect[3]; |
|---|
| 642 | | |
|---|
| 643 | | $xposition = $buttonsoriginx + $buttonsizex * floor(($start-1)/$numbuttonsy); |
|---|
| 644 | | $yposition = $buttonsoriginy + $buttonsizey * (($start-1)%$numbuttonsy); |
|---|
| 645 | | $xsize = $buttonsizex * (1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy)); |
|---|
| 646 | | $ysize = $buttonsizey * (1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy)); |
|---|
| 647 | | |
|---|
| 648 | | if (($xsize <= 0) || ($ysize <= 0)) {continue;} |
|---|
| 649 | | |
|---|
| 650 | | $xposition += $rectmarginx; |
|---|
| 651 | | $yposition += $rectmarginy; |
|---|
| 652 | | $xsize -= 2 * $rectmarginx; |
|---|
| 653 | | $ysize -= 2 * $rectmarginy; |
|---|
| 654 | | |
|---|
| 655 | | fwrite($fhandle, "\n; $comment\n[rectangle]\nx=$xposition\ny=$yposition\nwidth=$xsize\nheight=$ysize\nline_width=0\nline_color=$color1\nfade_color1=$color1\nfade_color2=$color2\nrnd_border=2\nalpha=20\nlayer=bottom\nPanel_Context=$panelcontext\n"); |
|---|
| 656 | | } |
|---|
| 657 | | |
|---|
| 658 | | ### Write legends |
|---|
| 659 | | |
|---|
| 660 | | foreach ($rectangles as $legend) { |
|---|
| 661 | | $text = $legend[1]; |
|---|
| 662 | | $start = $legend[2]; |
|---|
| 663 | | $stop = $legend[3]; |
|---|
| 664 | | |
|---|
| 665 | | $xposition = $buttonsoriginx + $buttonsizex * floor(($start-1)/$numbuttonsy); |
|---|
| 666 | | $yposition = $buttonsoriginy + $buttonsizey * (($start-1)%$numbuttonsy); |
|---|
| 667 | | $xsize = $buttonsizex * (1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy)); |
|---|
| 668 | | $ysize = $buttonsizey * (1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy)); |
|---|
| 669 | | |
|---|
| 670 | | if (($xsize <= 0) || ($ysize <= 0)) {continue;} |
|---|
| 671 | | |
|---|
| 672 | | $xposition += $legendoffsetx; |
|---|
| 673 | | $yposition += $legendoffsety; |
|---|
| 674 | | |
|---|
| 675 | | fwrite($fhandle, "\n[LEGEND]\nx=$xposition\ny=$yposition\ntext=$text\nfont_size=18\nfont_family=Arial\nuse_embed_fonts=1\nPanel_Context=$panelcontext\n"); |
|---|
| 676 | | } |
|---|
| 677 | | |
|---|
| 678 | | } |
|---|
| 679 | | |
|---|
| 680 | | function get_next_btn($data,$last) { |
|---|
| 681 | | $rangelist=explode(",",$data); |
|---|
| 682 | | foreach ($rangelist as $range) { |
|---|
| 683 | | $rangeval=explode("-",$range,2); |
|---|
| 684 | | if ($last < $rangeval[0]) {return $rangeval[0] ;} |
|---|
| 685 | | if (isset($rangeval[1]) && ($last < $rangeval[1])) {return $last+1;} |
|---|
| 686 | | #Need to try another range def... |
|---|
| 687 | | } |
|---|
| 688 | | #If we get here, we ran out of positions :( |
|---|
| 689 | | return 0; #????? |
|---|
| 690 | | } |
|---|
| 691 | | #this sub checks for the existance of a table |
|---|
| 692 | | function table_exists($db,$table) { |
|---|
| 693 | | $result = mysql_query("SHOW TABLES LIKE '" . $table . "'"); |
|---|
| 694 | | if(mysql_fetch_row($result) === false) {return(false);} |
|---|
| 695 | | return(true); |
|---|
| 696 | | } |
|---|
| 697 | | |
|---|
| 698 | | function get_styleinfo($id,$layoutinfo) { |
|---|
| 699 | | // do not use globals - instead pass layout info into function explicitly |
|---|
| 700 | | // global $rectangles; |
|---|
| 701 | | // global $numbuttonsx; |
|---|
| 702 | | // global $numbuttonsy; |
|---|
| 703 | | $rectangles = $layoutinfo['rectangles']; |
|---|
| 704 | | $numbuttonsx = $layoutinfo['numbuttonsx']; |
|---|
| 705 | | $numbuttonsy = $layoutinfo['numbuttonsy']; |
|---|
| 706 | | |
|---|
| 707 | | |
|---|
| 708 | | foreach ($rectangles as $rect) { |
|---|
| 709 | | if ($id == $rect[0]) { |
|---|
| 710 | | |
|---|
| 711 | | $start = $rect[2]; |
|---|
| 712 | | $stop = $rect[3]; |
|---|
| 713 | | |
|---|
| 714 | | $xposition = floor(($start-1)/$numbuttonsy); |
|---|
| 715 | | $yposition = (($start-1)%$numbuttonsy); |
|---|
| 716 | | $xsize = 1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy); |
|---|
| 717 | | $ysize = 1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy); |
|---|
| 718 | | |
|---|
| 719 | | if (($xsize <= 0) || ($ysize <= 0)) {print "Warning: rectange '$id' has negative area\n"; break;} |
|---|
| 720 | | $styleinfo = ""; |
|---|
| 721 | | if ($ysize > 2) { |
|---|
| 722 | | $styleinfo .= ($start + 1) . "-" . ($start + $ysize - 1) . ","; |
|---|
| 723 | | } |
|---|
| 724 | | elseif ($ysize == 2) { |
|---|
| 725 | | $styleinfo .= ($start + 1) . ","; |
|---|
| 726 | | } |
|---|
| 727 | | |
|---|
| 728 | | for ($i = 1 ; $i < $xsize ; $i++ ) { |
|---|
| 729 | | if ($ysize > 1) { |
|---|
| 730 | | $styleinfo .= (($i + $xposition) * $numbuttonsy + $yposition + 1) . "-" . (($i + $xposition) * $numbuttonsy + $yposition + $ysize) . ","; |
|---|
| 731 | | } |
|---|
| 732 | | else { |
|---|
| 733 | | $styleinfo .= (($i + $xposition) * $numbuttonsy + $yposition + 1) . ","; |
|---|
| 734 | | } |
|---|
| 735 | | } |
|---|
| 736 | | $retval = $styleinfo; |
|---|
| 737 | | break; |
|---|
| 738 | | } |
|---|
| 739 | | } |
|---|
| 740 | | return $retval; |
|---|
| 741 | | } |
|---|
| | 793 | //Finished parsing zapata.conf |
|---|