Newer
Older
ubFramework / Portal / docroot / user / dialer / schedule.php
@Christopher W. Olsen Christopher W. Olsen on 10 Dec 2017 8 KB Cleaning Up Making It A Sub Module
<?php

/**
 * ****************************************************************************************
 * Copyright (c) 2013 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: schedule.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", "ubDialin - Broadcast Campaign Schedule" );

/* Main defines */
$ubF->tpl->define ( array (
    "index" => "user/wrapper/default.html" 
) );
$ubF->tpl->define ( array (
    "menu" => "user/dialer/menu.html" 
) );
$ubF->tpl->define ( array (
    "body" => "user/dialer/schedule.html" 
) );

$ubF->session->Validate ( 'U_D_', 1 );

$dow = array (
    '0' => 'Mon',
    '1' => 'Tue',
    '2' => 'Wed',
    '3' => 'Thu',
    '4' => 'Fri',
    '5' => 'Sat',
    '6' => 'Sun' 
);

if ( isset ( $form_data ['dow'] ) ) {
  foreach ( $form_data ['dow'] as $subkey => $val ) {
    $wd = "NNNNNNN";
    foreach ( $val as $key => $subval ) {
      // print "SK[" . $subkey . "], Val[" . $val . "], Key[" . $key . "],SV[" . $subval . "]<br />";
      $wd [$key] = "$subval";
    }
    $query = "UPDATE dialer_schedule SET dow = '" . $wd . "' WHERE dsid = $subkey";
    $ubF->DB['main']->query ( $query );
  }
}

if ( isset ( $form_data ['st'] ) ) {
  foreach ( $form_data ['st'] as $key => $val ) {
    $query = "UPDATE dialer_schedule SET start_time = '$val' WHERE dsid = $key";
    $ubF->DB['main']->query ( $query );
  }
}

if ( isset ( $form_data ['et'] ) ) {
  foreach ( $form_data ['et'] as $key => $val ) {
    $query = "UPDATE dialer_schedule SET end_time = '$val' WHERE dsid = $key";
    $ubF->DB['main']->query ( $query );
  }
}

if ( isset ( $form_data ['active'] ) ) {
  foreach ( $form_data ['active'] as $key => $val ) {
    $query = "UPDATE dialer_schedule SET active = '$val' WHERE dsid = $key";
    $ubF->DB['main']->query ( $query );
  }
}

if ( isset ( $form_data ['auto_dial_level'] ) ) {
  foreach ( $form_data ['auto_dial_level'] as $key => $val ) {
    $query = "UPDATE dialer_schedule SET auto_dial_level = '$val' WHERE dsid = $key";
    $ubF->DB['main']->query ( $query );
  }
}

$query = "SELECT * FROM dialer_schedule WHERE campaign_id = " . $form_data ['cid'] . " AND account_number = '" . $ubF->session->account_number . "'";
$result = $ubF->DB['main']->query ( $query );

if ( $result->num_rows < 5 ) {
  
  $query = "SELECT survey_xfer_exten, auto_dial_level FROM vicidial_campaigns WHERE campaign_id = '" . $form_data ['cid'] . "'";
  if ( ($res = $data ['as-dialer-002']->query ( $query )) === false ) {
    Header ( "Location: /dialer/broadcast.php" );
    exit ( 0 );
  }
  
  $rData = $res->fetch_assoc ();
  
  $rData ['survey_xfer_exten'] = substr ( $rData ['survey_xfer_exten'], -10 );
  
  if ( $result->num_rows == 0 ) {
    $query = "INSERT INTO dialer_schedule (campaign_id, dow, start_time, end_time, account_number, survey_xfer_exten, auto_dial_level, broadcast_server) VALUES(" . $form_data ['cid'] . ", 'YYYYYNN', '09:00', '17:00', '" . $ubF->session->account_number . "', '" . $rData ['survey_xfer_exten'] . "', " . $rData ['auto_dial_level'] . ", '" . $ubF->session->broadcast_server . "')";
    $ubF->DB['main']->query ( $query );
    
    $query = "INSERT INTO dialer_schedule (campaign_id, account_number, survey_xfer_exten, auto_dial_level, broadcast_server) VALUES(" . $form_data ['cid'] . ", '" . $ubF->session->account_number . "', '" . $rData ['survey_xfer_exten'] . "', " . $rData ['auto_dial_level'] . ", '" . $ubF->session->broadcast_server . "')";
    for ( $i = 0 ; $i < 4 ; $i++ )
      $ubF->DB['main']->query ( $query );
  }
  else {
    $query = "INSERT INTO dialer_schedule (campaign_id, account_number, survey_xfer_exten, auto_dial_level, broadcast_server) VALUES(" . $form_data ['cid'] . ", '" . $ubF->session->account_number . "', '" . $rData ['survey_xfer_exten'] . "', " . $rData ['auto_dial_level'] . ", '" . $ubF->session->broadcast_server . "')";
    print "[" . $result->num_rows . "]";
    for ( $i = 0 ; $i < (4 - $result->num_rows) ; $i++ )
      $ubF->DB['main']->query ( $query );
  }
  
  $res->free ();
  
  $result->free ();
  $query = "SELECT * FROM dialer_schedule WHERE campaign_id = " . $form_data ['cid'] . " AND account_number = '" . $ubF->session->account_number . "'";
  $result = $ubF->DB['main']->query ( $query );
}

$rows = "";

if ( $result ) {
  while ( $qData = $result->fetch_assoc () ) {
    $wd = "";
    foreach ( $dow as $key => $val ) {
      if ( $qData ['dow'] [$key] == "Y" )
        $wd .= "<input type=\"checkbox\" name=\"data[dow][" . $qData ['dsid'] . "][$key]\" value=\"Y\" checked> $val";
      else
        $wd .= "<input type=\"checkbox\" name=\"data[dow][" . $qData ['dsid'] . "][$key]\" value=\"Y\"> $val";
    }
    
    if ( $qData ['active'] == 1 )
      $active = "<select name=\"data[active][" . $qData ['dsid'] . "]\"><option value=\"1\" selected>Y</option><option value=\"0\">N</option></select>";
    else
      $active = "<select name=\"data[active][" . $qData ['dsid'] . "]\"><option value=\"1\">Y</option><option value=\"0\" selected>N</option></select>";
    
    $action = "<a href=\"" . $form_data ['url'] . "?data[cid]=" . $form_data ['cid'] . "&data[dsid]=" . $qData ['dsid'] . "\">Delete</a>";
    
    $cs_options = Array (
        1,
        5,
        6,
        7,
        8,
        9,
        10,
        15,
        20,
        25,
        30 
    );
    
    $call_speed = "";
    
    foreach ( $cs_options as $key ) {
      if ( $key == $qData ['auto_dial_level'] )
        $call_speed .= "<option value=\"$key\" selected>" . $key * 10 . "</option>\n";
      else
        $call_speed .= "<option value=\"$key\">" . $key * 10 . "</option>\n";
    }
    
    $rows .= "<tr><td>$wd</td><td><input type=\"text\" name=\"data[st][" . $qData ['dsid'] . "]\" value=\"" . $qData ['start_time'] . "\" size=\"5\"></td>";
    $rows .= "<td><input type=\"text\" name=\"data[et][" . $qData ['dsid'] . "]\" value=\"" . $qData ['end_time'] . "\" size=\"5\"></td>";
    $rows .= "<td><input type=\"text\" name=\"data[survey_xfer_exten][" . $qData ['dsid'] . "]\" value=\"" . $qData ['survey_xfer_exten'] . "\"></td>";
    $rows .= "<td><select name=\"data[auto_dial_level][" . $qData ['dsid'] . "]\">$call_speed</select></td>";
    $rows .= "<td>$active</td></tr>\n";
  }
}

$ubF->tpl->assign ( "ROWS", $rows );
$ubF->tpl->assign ( "CID", $form_data ['cid'] );
$ubF->tpl->assign ( "DIALER_PREPAY", $ubF->session->dialer_prepay );

/* 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" );

?>