Newer
Older
ubFramework / Portal / docroot / user / dialer / edit.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@ubixos.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: edit.php 939 2017-09-07 20:10:45Z reddawg $
 *
 * ***************************************************************************************
 */

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

/* Assign the page title */
$ubF->tpl->assign ( "PAGE_TITLE", "Dialer - Edit Broadcast Campaign" );

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

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

$messages = "";

if ( isset ( $form_data ['up'] ) && $form_data ['up'] == "Update" ) {
  if ( strlen ( $form_data ['survey_xfer_exten'] ) == 10 && $form_data ['survey_xfer_exten'] [0] != 1 )
    $form_data ['survey_xfer_exten'] = "31" . $form_data ['survey_xfer_exten'];
  else if ( strlen ( $form_data ['survey_xfer_exten'] ) == 11 )
    $form_data ['survey_xfer_exten'] = "3" . $form_data ['survey_xfer_exten'];
  else
    $messages .= "Invalid Ring-To #<br />";
  
  if ( strlen ( $form_data ['campaign_name'] ) < 3 )
    $messages .= "Invalid Campaign Name<br />";
  
  if ( $form_data ['daily_limit'] < 25 )
    $messages .= "Spending Limit Must Be $25 Or More<br />";
  
  if ( $messages == "" ) {
    $query = "UPDATE vicidial_campaigns SET campaign_name = '" . $form_data ['campaign_name'] . "',daily_limit = " . $form_data ['daily_limit'] . ",survey_xfer_exten = '" . $form_data ['survey_xfer_exten'] . "',campaign_cid = '" . substr ( $form_data ['campaign_cid'], -10 ) . "', auto_dial_level = " . $form_data ['auto_dial_level'] . ",local_call_time = '" . $form_data ['call_time'] . "' WHERE campaign_id = '" . $form_data ['cid'] . "' AND user_group = '" . $ubF->session->press1_group . "'";
    
    if ( $data ['as-dialer-002']->query ( $query ) === false ) {
      Header ( "Location: /dialer/broadcast.php" );
      exit ();
    }
    $messages = "<h3>Campaign Updated</h3>Click <a href=\"/dialer/broadcast.php\">here</a> to return to campaign list.";
  }
  $qData ['campaign_name'] = $form_data ['campaign_name'];
  $qData ['daily_limit'] = $form_data ['daily_limit'];
  $qData ['survey_xfer_exten'] = $form_data ['survey_xfer_exten'];
  $qData ['campaign_cid'] = $form_data ['campaign_cid'];
  $qData ['auto_dial_level'] = $form_data ['auto_dial_level'];
  $qData ['local_call_time'] = $form_data ['call_time'];
}
else {
  $query = "SELECT campaign_id,campaign_name,daily_limit,survey_xfer_exten,campaign_cid,auto_dial_level,local_call_time FROM vicidial_campaigns WHERE campaign_id = '" . $form_data ['cid'] . "' AND user_group = '" . $ubF->session->press1_group . "'";
  $result = $data ['as-dialer-002']->query ( $query );
  
  $qData = $result->fetch_assoc ();
  
  if ( $result->num_rows == 0 ) {
    Header ( "Location: /dialer/broadcast.php" );
    exit ();
  }
}

$cs_options = Array (
    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";
}

$query = "SELECT call_time_id FROM vicidial_call_times ORDER BY call_time_id";
$ctRes = $data ['as-dialer-002']->query ( $query );

$call_time = "";
while ( $ctData = $ctRes->fetch_row () ) {
  if ( $ctData [0] == $qData ['local_call_time'] )
    $call_time .= "<option value=\"" . $ctData [0] . "\" selected>" . $ctData [0] . "</option>\n";
  else
    $call_time .= "<option value=\"" . $ctData [0] . "\">" . $ctData [0] . "</option>\n";
}

$ubF->tpl->assign ( "CAMPAIGN_ID", $form_data ['cid'] );
$ubF->tpl->assign ( "CAMPAIGN_NAME", $qData ['campaign_name'] );
$ubF->tpl->assign ( "DAILY_LIMIT", $qData ['daily_limit'] );
$ubF->tpl->assign ( "RING_TO", substr ( $qData ['survey_xfer_exten'], -11 ) );
$ubF->tpl->assign ( "CALLER_ID", $qData ['campaign_cid'] );
$ubF->tpl->assign ( "CALL_SPEED", $call_speed );
$ubF->tpl->assign ( "CALL_TIME", $call_time );

if ( isset ( $result ) )
  $result->free ();

$ctRes->free ();

$ubF->tpl->assign ( "MESSAGES", $messages );

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

?>