Newer
Older
ubFramework / Portal / docroot / user / dialer / edit_dc.php
@Christopher W. Olsen Christopher W. Olsen on 10 Dec 2017 5 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: edit_dc.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", "ubDialin - Edit Predictive Campaigns" );

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

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

$messages = "";

if ( isset ( $data ['up'] ) && $data ['up'] == "Update" ) {
  if ( strlen ( $data ['campaign_name'] ) < 3 )
    $messages .= "Invalid Campaign Name<br />";
  if ( $data ['daily_limit'] < 25 )
    $messages .= "Invalid Spending Limit Must Be $25.00 Or More<br />";
  if ( strlen ( $data ['campaign_cid'] ) != 10 )
    $messages .= "Invalid Caller ID<br />";
  
  if ( $messages == "" ) {
    $query = "UPDATE vicidial_campaigns SET campaign_name = '" . $data ['campaign_name'] . "', daily_limit = " . $data ['daily_limit'] . ", campaign_cid = '" . $data ['campaign_cid'] . "', auto_dial_level = " . $data ['auto_dial_level'] . ", local_call_time = '" . $data ['local_call_time'] . "' WHERE campaign_id = '" . $data ['cid'] . "' AND user_group = '" . $ubF->session->dialer_group . "'";
    if ( $data ['dialer_db']->query ( $query ) === true )
      $messages = "<h3>Campaign Updated</h3>Click <a href=\"/dialer/dialer.php\">here</a> to return to campaign list.";
    else
      $messages = "Error Updating Campaign";
  }
}
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 = '" . $data ['cid'] . "' AND user_group = '" . $ubF->session->dialer_group . "'";
  $result = $data ['dialer_db']->query ( $query );
  
  $qData = $result->fetch_assoc ();
  
  if ( $result->num_rows == 0 ) {
    Header ( "Location: /dialer/dialer.php" );
    exit ();
  }
  
  $data ['campaign_name'] = $qData ['campaign_name'];
  $data ['daily_limit'] = $qData ['daily_limit'];
  $data ['survey_xfer_exten'] = substr ( $qData ['survey_xfer_exten'], -11 );
  $data ['campaign_cid'] = $qData ['campaign_cid'];
  $data ['auto_dial_level'] = $qData ['auto_dial_level'];
  $data ['local_call_time'] = $qData ['local_call_time'];
  
  $result->free ();
}

$call_speed = "";

for ( $i = 1 ; $i < 10 ; $i++ ) {
  if ( $i == $data ['auto_dial_level'] )
    $call_speed .= "<option value=\"$i\" selected>$i</option>\n";
  else
    $call_speed .= "<option value=\"$i\">$i</option>\n";
}

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

$call_time = "";
while ( $ctData = $ctRes->fetch_row () ) {
  if ( $ctData [0] == $data ['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", $data ['cid'] );
$ubF->tpl->assign ( "CAMPAIGN_NAME", $data ['campaign_name'] );
$ubF->tpl->assign ( "DAILY_LIMIT", $data ['daily_limit'] );
$ubF->tpl->assign ( "RING_TO", substr ( $data ['survey_xfer_exten'], -11 ) );
$ubF->tpl->assign ( "CALLER_ID", $data ['campaign_cid'] );
$ubF->tpl->assign ( "CALL_SPEED", $call_speed );
$ubF->tpl->assign ( "CALL_TIME", $call_time );

$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" );

?>