Newer
Older
ubFramework / Portal / docroot / admin / voip / firmware.php
@Christopher W. Olsen Christopher W. Olsen on 10 Dec 2017 6 KB Cleaning Up Making It A Sub Module
<?php

/*
 * ****************************************************************************************
 * Copyright (c) 2013, 2014 Christopher W. Olsen <cwolsen@ubixtechnologies.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this list of
 * conditions, the following disclaimer and the list of authors. Redistributions in binary
 * form must reproduce the above copyright notice, this list of conditions, the following
 * disclaimer and the list of authors in the documentation and/or other materials provided
 * with the distribution. Neither the name of the uBix Cube Project nor the names of its
 * contributors may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $Id: firmware.php 940 2017-09-07 20:12:42Z reddawg $
 *
 * ***************************************************************************************
 */

/* Main include info */
ini_set ( 'include_path', $_SERVER ['DOCUMENT_ROOT'] . "/include/" );
include ("config.php");

/* Assign the page title */
$ubF->tpl->assign ( "PAGE_TITLE", "Admin: VoIP - Firmware" );

/* Main defines */
$ubF->tpl->define ( array (
    "index" => "admin/wrapper/default.html" 
) );
$ubF->tpl->define ( array (
    "menu" => "admin/voip/menu.html" 
) );
$ubF->tpl->define ( array (
    "body" => "admin/voip/firmware.html" 
) );

$ubF->session->Validate ( 'A_V_', 0 );

$form_data = $data ['data'];

$query = "SELECT account_number, company FROM accounts ORDER BY company";
$result = $ubF->DB['main']->query ( $query );

$accounts = "<option value=\"\">All</option>";
while ( $qData = $result->fetch_assoc () ) {
  if ( $qData ['account_number'] == $form_data ['account_number'] )
    $accounts .= "<option value=\"" . $qData ['account_number'] . "\" selected>" . $qData ['account_number'] . " : " . $qData ['company'] . "</option>\n";
  else
    $accounts .= "<option value=\"" . $qData ['account_number'] . "\">" . $qData ['account_number'] . " : " . $qData ['company'] . "</option>\n";
}

$result->free ();

$ubF->tpl->assign ( "ACCOUNTS", $data->libs['ubf']->account_getList ( $form_data ['account_number'], true ) );

if ( !isset ( $data ['ob'] ) )
  $data ['ob'] = "obm";

if ( isset ( $data ['obs'] ) && $data ['obs'] == "D" ) {
  $data ['obs'] = "A";
  $arw = " &uarr;";
}
else {
  $data ['obs'] = "D";
  $arw = " &darr;";
}

/* Initialize Variables */
$obm = "";
$obm_a = "";
$obd = "";
$obd_a = "";
$oba = "";
$oba_a = "";
$obl = "";
$obl_a = "";

switch ( $data ['ob'] ) {
  case 'obd' :
    $obd = $data ['obs'];
    $obd_a = $arw;
    
    if ( $data ['obs'] == "A" )
      $orderBy = "vdt.manufacturer, vdt.model, mac";
    else
      $orderBy = "vdt.manufacturer DESC, vdt.model DESC, mac";
    
    break;
  case 'oba' :
    $oba = $data ['obs'];
    $oba_a = $arw;
    
    if ( $data ['obs'] == "A" )
      $orderBy = "account_number, mac ASC";
    else
      $orderBy = "account_number DESC, mac DESC";
    break;
  case 'obl' :
    $obl = $data ['obs'];
    $obl_a = $arw;
    
    if ( $data ['obs'] == "A" )
      $orderBy = "last_config, mac ASC";
    else
      $orderBy = "last_config DESC, mac DESC";
    break;
  default :
    $obm = $data ['obs'];
    $obm_a = $arw;
    
    if ( $data ['obs'] == "A" )
      $orderBy = "mac ASC";
    else
      $orderBy = "mac DESC";
    break;
}

if ( isset ( $form_data ['account_number'] ) && $form_data ['account_number'] != '' )
  $query = "SELECT * FROM voip_devices vd LEFT JOIN voip_device_types vdt ON vd.vdtid = vdt.vdtid WHERE vd.account_number = '" . $form_data ['account_number'] . "' ORDER BY " . $orderBy;
else
  $query = "SELECT * FROM voip_devices vd LEFT JOIN voip_device_types vdt ON vd.vdtid = vdt.vdtid ORDER BY " . $orderBy;
$result = $ubF->DB['main']->query ( $query );

$rows = "";
while ( $qData = $result->fetch_assoc () ) {
  $extension = json_decode ( $qData ['extensions'], true );
  
  $lexts = "";
  $lkeys = "";
  
  foreach ( $extension as $ext => $keys ) {
    if ( $keys ['extension'] != '' ) {
      $lexts .= $keys ['extension'] . "<br />";
      $lkeys .= $keys ['line_keys'] . "<br />";
    }
  }
  
  $rows .= "<tr><td><a href=\"/admin/voip/edit_device.php?data[vdid]=" . $qData ['vdid'] . "\">" . $qData ['mac'] . "</a></td><td>" . $qData ['manufacturer'] . " " . $qData ['model'] . "</td><td>" . $qData ['account_number'] . "</td><td>" . $lexts . "</td><td>" . $lkeys . "</td><td>" . date ( "m/d/Y H:i:s", $qData ['last_config'] ) . "</td>";
  $rows .= "<td><a href=\"/admin/voip/view_log.php?data[mac]=" . $qData ['mac'] . "&data[log]=app\" target=\"_log\">View</a></td><td><a href=\"/admin/voip/view_log.php?data[mac]=" . $qData ['mac'] . "&data[log]=boot\" target=\"_log\">View</a></td></tr>\n";
}

$result->free ();

$ubF->tpl->assign ( "ROWS", $rows );

$ubF->tpl->assign ( "OBM", $obm );
$ubF->tpl->assign ( "OBD", $obd );
$ubF->tpl->assign ( "OBA", $oba );
$ubF->tpl->assign ( "OBL", $obl );

$ubF->tpl->assign ( "OBM_A", $obm_a );
$ubF->tpl->assign ( "OBD_A", $obd_a );
$ubF->tpl->assign ( "OBA_A", $oba_a );
$ubF->tpl->assign ( "OBL_A", $obl_a );

/* Parse and print */
$ubF->tpl->parse ( "MENU", array (
    "menu" 
) );
$ubF->tpl->parse ( "BODY", array (
    "body" 
) );
$ubF->tpl->parse ( "INDEX", array (
    "index" 
) );
$ubF->tpl->FastPrint ( "INDEX" );

?>