<?
/**
 * VoiceOne contacts/list/dial
 *
 * Frontend to dial contact.
 * @package voiceone
 * @subpackage  settings_extensions
 */
  include ("../../../admin/config/cfg.php");
  global $cwlang,$cwUserInfo,$cwUserId;
  require_once("$absBasePath/lib/xajax/xajax.inc.php");
  //================ XAJAX ================
  function sendDial($number){
    global $asterisk,$cwUserInfo;
    // Instantiate the xajaxResponse object
    $objResponse = new xajaxResponse();
    // Process request
    $username=$cwUserInfo["username"];
    $password=$cwUserInfo["password"];
    $exstension=$number;
    $ret=$asterisk->ast_originate($username,$password,$exstension,10000);
    // Return the xajaxResponse object
    $objResponse->addScript(" self.parent.tb_remove() ");
    return $objResponse->getXML();  
  }
  $xajax = new xajax();
  $xajax->registerFunction("sendDial");
  $xajax->processRequests();
  //================ PAGE LOGIC ================
  if(!isset($_GET["contact"])||($_GET["contact"]=="")) die("Error: missing exstension reference");
  if(!isset($_GET["type"])||($_GET["contact"]=="")) die("Error: missing exstension type");
  if((!is_array($cwUserInfo))||(trim($cwUserInfo["exten"])=="")) die("Error: missing exstension for user");
  switch($_GET["type"]){
    case "virtual":
      $contact=$asterisk->getVirtualExtension($_GET["contact"]);
      $name=$contact[0]["name"];
      $surname=$contact[0]["surname"];
      $exstension=$contact[0]["extension"];
      break;
    case "extension":
      $contact=$asterisk->getClient($_GET["contact"],0);
      $name=$contact[0]["name"];
      $surname=$contact[0]["surname"];
      $exstension=$contact[0]["extension"];
      break;
    default:
      die("Error: unknown exstension type");
      break;
  }
  //html
  $html.="<div id=\"dial-fixed\" style=\"background: url($relBasePath/public/img/dial-fixed.jpg) no-repeat;\" onclick=\"xajax_sendDial('".$exstension."'); return false;\">".$exstension."&nbsp;&nbsp;</div>";
  //================ MAIN CONTENTS ================
  ob_start();
  $xajax->printJavascript("../../../admin/lib/xajax/"); ?>
  <div style="text-align: center;">
    <h1 style="color: #333; font-size: 24px; line-height: 1.5em; padding:0; margin: 15px auto 0 auto;"><?=$name?> <?=$surname?></h1>
    <?=$html?>
  </div>
  <?
  $contents=ob_get_contents();
  ob_end_clean();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <link rel="Stylesheet" href="<?=$relBasePath?>/public/css/index.css" type="text/css" media="screen" />
  </head>
  <body style="background:#FFF;">
    <?=$contents?>
  </body>
</html>
