2414 lines
113 KiB
PHP
2414 lines
113 KiB
PHP
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Cards extends Admin_Controller {
|
|
|
|
const TEMPLATE_ACTIVE_TIP= 7;
|
|
const TEMPLATE_UPPER_TITLE = 8;
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
|
|
$this->load->model('main_cards_model');
|
|
}
|
|
|
|
public function index() {
|
|
$this->cardspage();
|
|
}
|
|
|
|
public function cardspage() {
|
|
$data = array();
|
|
$data["page_title"] = "Cards";
|
|
$data["form_button"] = "Add";
|
|
$data["images"] = array();
|
|
|
|
$this->load->model('combo_model');
|
|
|
|
$data['card_order'] = trim($this->input->post('card_order'));
|
|
$data['background_color'] = trim($this->input->post('background_color'));
|
|
$data['target_key_value'] = trim($this->input->post('target_key'));
|
|
|
|
$data['card_behavior_value'] = trim($this->input->post('card_behavior'));
|
|
$data['card_blog_id_value'] = trim($this->input->post('card_blog_id'));
|
|
|
|
$data['card_category_vaue'] = trim($this->input->post('card_category'));
|
|
|
|
$data['card_can_save_value'] = trim($this->input->post('card_can_save'));
|
|
$data['card_pictures_value'] = trim($this->input->post('card_pictures'));
|
|
$data['card_status_value'] = trim($this->input->post('card_status'));
|
|
$data['card_template_value'] = trim($this->input->post('card_template'));
|
|
$data['card_canexpire_value'] = trim($this->input->post('card_canexpire'));
|
|
$data['card_notify_value'] = trim($this->input->post('card_notify'));
|
|
$data['card_country_value'] = trim($this->input->post('card_country'));
|
|
$data['card_titleshow_value'] = trim($this->input->post('card_titleshow'));
|
|
//$data['card_timed_value'] = trim($this->input->post('card_timed'));
|
|
|
|
$data['use_short_title_value'] = trim($this->input->post('use_short_title'));
|
|
|
|
$data['card_category_type_value'] = trim($this->input->post('card_category_type'));
|
|
|
|
$data['card_type_value'] = trim($this->input->post('card_type')); // $selected_card['card_type'];
|
|
$data['card_time_value'] = trim($this->input->post('card_time')); // $selected_card['card_time'];
|
|
$data['card_location_value'] = trim($this->input->post('card_location')); //$selected_card['card_location'];
|
|
|
|
$data['card_points_value'] = trim($this->input->post('card_points')); //$selected_card['card_location'];
|
|
$data['card_reciept_value'] = trim($this->input->post('card_reciept')); //$selected_card['card_location'];
|
|
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
if (!empty($card_category)) {
|
|
$data['card_category_vaue'] = trim($card_category);
|
|
} else {
|
|
$card_category = $data['card_category_vaue'];
|
|
}
|
|
|
|
$data['card_reciept'] = $this->combo_model->getReciept('card_reciept', $data['card_reciept_value']);
|
|
$data['card_points'] = $this->combo_model->getCardPoint('card_points', $data['card_points_value']);
|
|
|
|
$data['card_type'] = $this->combo_model->getCardCategoryType('card_type', $data['card_type_value']);
|
|
$data['card_time'] = $this->combo_model->getCardTime('card_time', $data['card_time_value']);
|
|
$data['card_location'] = $this->combo_model->getCardLocation('card_location', $data['card_location_value']);
|
|
|
|
$data['card_behavior'] = $this->combo_model->getCardBehaveCombo('card_behavior', $data['card_behavior_value']);
|
|
$data['card_blog_id'] = $this->combo_model->getCardblogIdCombo('card_blog_id', $data['card_blog_id_value']);
|
|
|
|
$data['target_key'] = $this->combo_model->getCardTargetActionCombo('target_key', $data['target_key_value']);
|
|
|
|
$data['card_category'] = $this->combo_model->getCardCategoryCombo('card_category', $data['card_category_vaue']);
|
|
$data['card_can_save'] = $this->combo_model->getYesNoCombo('card_can_save', $data['card_can_save_value']);
|
|
|
|
// $data['card_timed'] = $this->combo_model->getYesNoCombo('card_timed', $data['card_timed_value']);
|
|
|
|
$data['card_pictures'] = $this->combo_model->getCardPicturesCombo('card_pictures', $data['card_pictures_value']);
|
|
|
|
$data['use_short_title_combo'] = $this->combo_model->getYesNoCombo('use_short_title', $data['use_short_title_value']);
|
|
|
|
$data['card_status'] = $this->combo_model->getStatusCombo('card_status', $data['card_status_value']);
|
|
$data['card_template'] = $this->combo_model->getCardTemplateCombo('card_template', $data['card_template_value']);
|
|
$data['card_canexpire'] = $this->combo_model->getYesNoCombo('card_canexpire', $data['card_canexpire_value']);
|
|
$data['card_notify'] = $this->combo_model->getYesNoCombo('card_notify', $data['card_notify_value']);
|
|
$data['card_country'] = $this->combo_model->getCountryCombo('card_country', $data['card_country_value']);
|
|
|
|
$data['card_titleshow'] = $this->combo_model->getTitleShowCombo('card_titleshow', $data['card_titleshow_value']);
|
|
|
|
$data['card_name'] = trim($this->input->post('card_name'));
|
|
$data['card_title'] = trim($this->input->post('card_title'));
|
|
$data['short_title'] = trim($this->input->post('short_title'));
|
|
$data['description'] = trim($this->input->post('description'));
|
|
$data['background_picture'] = trim($this->input->post('background_picture'));
|
|
$data['button1'] = trim($this->input->post('button1'));
|
|
$data['button1_text'] = trim($this->input->post('button1_text'));
|
|
$data['button1_action'] = trim($this->input->post('button1_action'));
|
|
$data['card_expiration'] = trim($this->input->post('card_expiration'));
|
|
|
|
$data['target_text'] = trim($this->input->post('target_text'));
|
|
$data['long_description'] = trim($this->input->post('long_description'));
|
|
$data['card_logic'] = trim($this->input->post('card_logic'));
|
|
|
|
// show_area & activity_screen
|
|
$data['show_area_value'] = trim($this->input->post('show_area'));
|
|
$data['activity_screen_value'] = trim($this->input->post('activity_screen'));
|
|
$data['show_area'] = $this->combo_model->getCardShowArea('show_area', $data['show_area_value']);
|
|
$data['activity_screen'] = $this->combo_model->getCardActivityScreen('activity_screen', $data['activity_screen_value']);
|
|
|
|
// Expiration dropdown
|
|
$data['expiration_value'] = trim($this->input->post('expiration'));
|
|
$data['expiration'] = $this->combo_model->getCardExpiration('expiration', $data['expiration_value']);
|
|
|
|
// $in['card_logic'] = $data['card_logic'];
|
|
// $data['card_points'] = trim($this->input->post('card_points'));
|
|
// $data['card_reciept'] = trim($this->input->post('card_reciept'));
|
|
//$data['card_template'] = trim($this->input->post('card_template'));
|
|
|
|
$message = '';
|
|
if ($_POST) {
|
|
$error_ids = [];
|
|
$id = $this->input->post('id');
|
|
if ($id > 0) {
|
|
$in['action'] = SAVVY_BKO_MAINCARD_UPDATE;
|
|
$in['id'] = $id;
|
|
$data["form_button"] = "Update";
|
|
$data["card_id"] = $id;
|
|
} else {
|
|
$in['action'] = SAVVY_BKO_MAINCARD_CREATE;
|
|
}
|
|
//SAVVY_BKO_MAINCARD_UPDATE
|
|
$in['backoffice'] = 1;
|
|
$in['member_id'] = 0; // for session testing - not used
|
|
$in['name'] = $data['card_name'];
|
|
$in['title'] = $data['card_title'];
|
|
$in['short_title'] = $data['short_title'];
|
|
$in['description'] = $data['description'];
|
|
$in['long_description'] = $data['long_description'];
|
|
|
|
$in['background_picture'] = $data['card_pictures_value'];
|
|
$in['button1'] = $data['button1'];
|
|
$in['button1_text'] = $data['button1_text'];
|
|
$in['button1_action'] = $data['card_category_vaue']; // note category drives this action
|
|
$in['status'] = (int) $data['card_status_value'];
|
|
$in['can_save'] = (int) $data['card_can_save_value'];
|
|
$in['template'] = (int) $data['card_template_value'];
|
|
$in['card_canexpire'] = (int) $data['card_canexpire_value'];
|
|
$in['card_expiration'] = $data['card_expiration'];
|
|
$in['card_notify'] = (int) $data['card_notify_value'];
|
|
$in['titleshow'] = (int) $data['card_titleshow_value'];
|
|
|
|
$in['target_text'] = $data['target_text'];
|
|
$in['target_key'] = $data['target_key_value'];
|
|
|
|
$in['card_behavior'] = $data['card_behavior_value'];
|
|
$in['use_short_title'] = $data['use_short_title_value'];
|
|
|
|
|
|
$in['card_type'] = $data['card_type_value'];
|
|
$in['card_time'] = $data['card_time_value'];
|
|
$in['card_location'] = $data['card_location_value'];
|
|
|
|
$in['card_points'] = $data['card_points_value'];
|
|
$in['card_reciept'] = $data['card_reciept_value'];
|
|
$in['card_logic'] = $data['card_logic'];
|
|
|
|
//$in["card_country"] = $data["card_country"];
|
|
$in['card_country'] = $data['card_country_value'];
|
|
|
|
$in['card_order'] = (int) $data['card_order'];
|
|
$in['background_color'] = strtoupper($data['background_color']);
|
|
$in['blog_id'] = $data['card_blog_id_value'];
|
|
|
|
$in['activity_screen'] = (int)$data['activity_screen_value'];
|
|
$in['show_area'] = (int)$data['show_area_value'];
|
|
$in['expiration'] = (int)$data['expiration_value'];
|
|
|
|
//print_r($in);
|
|
|
|
if ($in['card_logic'] != '') {
|
|
// if ( verifyCardLogic())
|
|
// {
|
|
// // $message .= "<br/>Invalid or Duplicate Logic in use";
|
|
// }
|
|
}
|
|
if ($in['blog_id'] === '') {
|
|
$message .= "<br/>Blog Article ID incorrect";
|
|
$error_ids[] = 'card_blog_id';
|
|
}
|
|
if ($in['card_behavior'] === '') {
|
|
$message .= "<br/>Card Behavior incorrect";
|
|
$error_ids[] = 'card_behavior';
|
|
}
|
|
if ($in['name'] == '' || strlen($in['name']) > 100) {
|
|
$message .= "<br/>Incorrect Card ID";
|
|
$error_ids[] = 'cardName';
|
|
}
|
|
if ($in['title'] == '' || strlen($in['title']) > 100) {
|
|
$message .= "<br/>Invalid title";
|
|
$error_ids[] = 'cardTitle';
|
|
}
|
|
if ($in['short_title'] == '' || strlen($in['short_title']) > 35) {
|
|
$message .= "<br/>Invalid short title";
|
|
$error_ids[] ='cardShortTitle';
|
|
}
|
|
if ($in['description'] == '' || strlen($in['description']) > 250) {
|
|
$message .= "<br/>Invalid description";
|
|
$error_ids[] ='description';
|
|
}
|
|
if ( $in['background_picture'] == '' || strlen($in['background_picture']) > 150 ) {
|
|
if($in['template']== self::TEMPLATE_ACTIVE_TIP){
|
|
// Active tip don't use picture but API require it => get default value
|
|
$in['background_picture'] = $this->main_cards_model->getDefaultCardPictureValue();
|
|
// Validate background color require for Active Tip
|
|
if(empty($in['background_color'])){
|
|
$message .= "<br/>Invalid background color - please input background color for Active Tip";
|
|
}
|
|
}else{
|
|
$message .= "<br/>Invalid background picture";
|
|
}
|
|
}
|
|
if ($in['button1'] == '' || strlen($in['button1']) > 35) {
|
|
$message .= "<br/>Invalid button1";
|
|
$error_ids[] ='button1';
|
|
}
|
|
if ($in['button1_text'] == '' || strlen($in['button1_text']) > 35) {
|
|
$message .= "<br/>Invalid button1 text";
|
|
$error_ids[] ='button1_text';
|
|
}
|
|
if ($in['button1_action'] == '' || strlen($in['button1_action']) > 15) {
|
|
$message .= "<br/>Invalid category";
|
|
}
|
|
if ($data['card_canexpire_value'] != '' && $data['card_canexpire_value'] == 1 &&
|
|
($data['card_expiration'] == '' || strtotime($data['card_expiration']) < time())) {
|
|
$message .= "<br/>Invalid expiration date";
|
|
}
|
|
|
|
$success = false;
|
|
if ($message == '') {
|
|
$out = array();
|
|
$ret = $this->savvy_api($in, $out);
|
|
if ($ret == PHP_API_OK) {
|
|
$message = $id > 0 ? 'Updated!' : 'Created!';
|
|
$success = true;
|
|
} else {
|
|
$message = 'Failed to ' . ($id > 0 ? 'update' : 'create') . ' card: ' . isset($out["status"]) ? $out["status"] : '';
|
|
}
|
|
}
|
|
|
|
$response = array(
|
|
'success' => $success,
|
|
'message' => $message,
|
|
'error_ids' => $error_ids,
|
|
'fragments' => array(
|
|
'id' => $id,
|
|
'html' => $this->refresh_card_items( $in )
|
|
)
|
|
);
|
|
|
|
if ( $this->input->is_ajax_request() ) {
|
|
return $this->output
|
|
->set_content_type('application/json')
|
|
->set_output( json_encode( $response ) );
|
|
}
|
|
} else {
|
|
$in['card_expiration'] = date("Y-m-d", strtotime("+3 months"));
|
|
}
|
|
|
|
$data['message'] = $message;
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
|
|
$params = $this->input->get();
|
|
$params['card_category'] = $card_category;
|
|
$data['cart_filter_by_selectbox'] = $this->getCardFilterByFields('filter_name', $params['filter_name'] ?? '');
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_heading(
|
|
['data' => 'View', 'style' => 'width:50px'], 'Card', ['data' => 'Image', 'style' => 'width:120px'], ['data' => 'Country', 'style' => 'width:120px']
|
|
);
|
|
|
|
$query = $this->main_cards_model->getCardsQuery($params);
|
|
$tableData = $this->returnAdminTable(
|
|
[
|
|
'count_query' => $query,
|
|
'query' => $query,
|
|
],
|
|
'/cards/cardspage/' . $card_category . '/',
|
|
[
|
|
'per_page' => 6,
|
|
'reuse_query_string' => TRUE,
|
|
'uri_segment' => 4,
|
|
]
|
|
);
|
|
|
|
$data['filterData'] = $params;
|
|
$data['card_table'] = $tableData['output_table'];
|
|
$data['links'] = $tableData['links'];
|
|
|
|
$this->renderCardPage('view_cards', $data);
|
|
}
|
|
|
|
public function cardorder() {
|
|
$data = array();
|
|
$data["page_title"] = "Cards Order";
|
|
$data["form_button"] = "Add";
|
|
$data["images"] = array();
|
|
|
|
$this->load->model('combo_model');
|
|
|
|
$data['card_order'] = trim($this->input->post('card_order'));
|
|
$data['card_category_vaue'] = trim($this->input->post('card_category'));
|
|
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
if (!empty($card_category)) {
|
|
$data['card_category_vaue'] = trim($card_category);
|
|
} else {
|
|
$card_category = $data['card_category_vaue'];
|
|
}
|
|
|
|
|
|
|
|
$data['card_category'] = $this->combo_model->getCardCategoryComboAll('card_category', $data['card_category_vaue']);
|
|
$message = '';
|
|
|
|
$data['message'] = $message;
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
|
|
$params = $this->input->get();
|
|
$params['card_category'] = $card_category;
|
|
$data['cart_filter_by_selectbox'] = $this->getCardFilterByFields('filter_name', $params['filter_name'] ?? '');
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_heading(
|
|
['data' => 'Card Order', 'style' => 'width:150px'], ['data' => 'Card Id', 'style' => 'width:50px'], 'Card', ['data' => 'Image', 'style' => 'width:120px'], ['data' => 'Country', 'style' => 'width:120px']
|
|
);
|
|
|
|
$query = $this->main_cards_model->getCardsOrderQuery($params);
|
|
$tableData = $this->returnAdminTable(
|
|
[
|
|
'count_query' => $query,
|
|
'query' => $query,
|
|
], '/cards/cardorder/' . $card_category . '/', [
|
|
'per_page' => 15,
|
|
'reuse_query_string' => TRUE,
|
|
'uri_segment' => 4,
|
|
]
|
|
);
|
|
|
|
$data['filterData'] = $params;
|
|
$data['card_table'] = $tableData['output_table'];
|
|
$data['links'] = $tableData['links'];
|
|
|
|
$this->renderCardPage('view_cardorder', $data);
|
|
}
|
|
|
|
//dynamic_card_table
|
|
public function dynamiccards() {
|
|
$data = array();
|
|
$this->load->library( 'table' );
|
|
$this->table->set_template( $this->template );
|
|
|
|
$data["page_title"] = "Dynamic Cards";
|
|
|
|
|
|
$mysql = "SELECT dynamic_key,name,title,
|
|
CASE WHEN (SELECT COUNT(*) FROM members_notification as mn WHERE mn.trigger_key = name and mn.notice_type='INSTANT')>0 THEN '<span style=\"font-weight:bold;\">Yes</span>'
|
|
ELSE '<span style=\"color:#716e6e\">No</span>' END
|
|
AS Instant,
|
|
'<button style=\"padding:3px;\" type=\"button\" class=\"btn btn-danger btn-xs\" >Release</button>' AS Release ,
|
|
'<button style=\"padding:3px;\" type=\"button\" class=\"btn btn-info btn-xs\" >View</button>' AS View from main_cards where dynamic_key IS NOT NULL ";
|
|
$query = $this->read_replica->query( $mysql );
|
|
$data["dynamic_card_table"] = $this->table->generate( $query );
|
|
|
|
$this->renderCardPage('view_dynamiccards', $data);
|
|
}
|
|
|
|
public function dynamiccards_retired() {
|
|
$data = array();
|
|
$data["page_title"] = "Dynamic Cards";
|
|
$data["form_button"] = "Add";
|
|
$data["images"] = array();
|
|
|
|
$this->load->model('combo_model');
|
|
|
|
$data['card_order'] = trim($this->input->post('card_order'));
|
|
$data['background_color'] = trim($this->input->post('background_color'));
|
|
|
|
$data['card_behavior_value'] = trim($this->input->post('card_behavior'));
|
|
$data['card_blog_id_value'] = trim($this->input->post('card_blog_id'));
|
|
|
|
$data['multiple_answer_value'] = trim($this->input->post('multiple_answer'));
|
|
$data['card_category_value'] = trim($this->input->post('card_category'));
|
|
$data['card_can_save_value'] = trim($this->input->post('card_can_save'));
|
|
$data['card_pictures_value'] = trim($this->input->post('card_pictures'));
|
|
$data['card_status_value'] = trim($this->input->post('card_status'));
|
|
$data['card_template_value'] = trim($this->input->post('card_template'));
|
|
$data['card_canexpire_value'] = trim($this->input->post('card_canexpire'));
|
|
$data['card_notify_value'] = trim($this->input->post('card_notify'));
|
|
$data['card_country_value'] = trim($this->input->post('card_country'));
|
|
$data['card_titleshow_value'] = trim($this->input->post('card_titleshow'));
|
|
$data['use_short_title_value'] = trim($this->input->post('use_short_title'));
|
|
|
|
$data['card_type_value'] = trim($this->input->post('card_type')); // $selected_card['card_type'];
|
|
$data['card_time_value'] = trim($this->input->post('card_time')); // $selected_card['card_time'];
|
|
$data['card_location_value'] = trim($this->input->post('card_location')); //$selected_card['card_location'];
|
|
|
|
$data['card_points_value'] = trim($this->input->post('card_points')); //$selected_card['card_location'];
|
|
$data['card_reciept_value'] = trim($this->input->post('card_reciept')); //$selected_card['card_location'];
|
|
$data['card_logic'] = trim($this->input->post('card_logic')); //$selected_card['card_location'];
|
|
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
if (!empty($card_category)) {
|
|
$data['card_category_value'] = trim($card_category);
|
|
} else {
|
|
$card_category = $data['card_category_value'];
|
|
}
|
|
|
|
$data['card_reciept'] = $this->combo_model->getReciept('card_reciept', $data['card_reciept_value']);
|
|
$data['card_points'] = $this->combo_model->getCardPoint('card_points', $data['card_points_value']);
|
|
|
|
$card_category = 'CARDDYNAMIC';
|
|
$data['card_behavior'] = $this->combo_model->getCardBehaveCombo('card_behavior', $data['card_behavior_value']);
|
|
$data['card_blog_id'] = $this->combo_model->getCardblogIdCombo('card_blog_id', $data['card_blog_id_value']);
|
|
|
|
$data['multiple_answer'] = $this->combo_model->getYesNoCombo('multiple_answer', $data['multiple_answer_value']);
|
|
|
|
|
|
$data['card_type'] = $this->combo_model->getCardCategoryType('card_type', $data['card_type_value']);
|
|
$data['card_time'] = $this->combo_model->getCardTime('card_time', $data['card_time_value']);
|
|
$data['card_location'] = $this->combo_model->getCardLocation('card_location', $data['card_location_value']);
|
|
|
|
$data['card_category'] = $this->combo_model->getCardCategoryCombo('card_category', $data['card_category_value'], 'CARDDYNAMIC');
|
|
$data['card_can_save'] = $this->combo_model->getYesNoCombo('card_can_save', $data['card_can_save_value']);
|
|
$data['card_pictures'] = $this->combo_model->getCardPicturesCombo('card_pictures', $data['card_pictures_value']);
|
|
$data['card_status'] = $this->combo_model->getStatusCombo('card_status', $data['card_status_value']);
|
|
$data['card_template'] = $this->combo_model->getSurveyCardTemplateCombo('card_template', $data['card_template_value']);
|
|
$data['card_canexpire'] = $this->combo_model->getYesNoCombo('card_canexpire', $data['card_canexpire_value']);
|
|
$data['card_notify'] = $this->combo_model->getYesNoCombo('card_notify', $data['card_notify_value']);
|
|
$data['card_country'] = $this->combo_model->getCountryCombo('card_country', $data['card_country_value']);
|
|
|
|
$data['use_short_title_combo'] = $this->combo_model->getYesNoCombo('use_short_title', $data['use_short_title_value']);
|
|
|
|
|
|
$data['card_titleshow'] = $this->combo_model->getTitleShowCombo('card_titleshow', $data['card_titleshow_value']);
|
|
|
|
$data['card_name'] = trim($this->input->post('card_name'));
|
|
$data['card_title'] = trim($this->input->post('card_title'));
|
|
$data['short_title'] = trim($this->input->post('short_title'));
|
|
$data['description'] = trim($this->input->post('description'));
|
|
$data['long_description'] = trim($this->input->post('long_description'));
|
|
|
|
$data['background_picture'] = trim($this->input->post('background_picture'));
|
|
$data['button1'] = trim($this->input->post('button1'));
|
|
$data['button1_text'] = trim($this->input->post('button1_text'));
|
|
$data['button1_action'] = trim($this->input->post('button1_action'));
|
|
$data['card_expiration'] = trim($this->input->post('card_expiration'));
|
|
$data['card_logic'] = trim($this->input->post('card_logic'));
|
|
//$data['card_template'] = trim($this->input->post('card_template'));
|
|
|
|
$message = '';
|
|
if ($_POST) {
|
|
$id = $this->input->post('id');
|
|
if ($id > 0) {
|
|
$in['action'] = SAVVY_BKO_MAINCARD_UPDATE;
|
|
$in['id'] = $id;
|
|
$data["form_button"] = "Update";
|
|
$data["card_id"] = $id;
|
|
} else {
|
|
$in['action'] = SAVVY_BKO_MAINCARD_CREATE;
|
|
}
|
|
//SAVVY_BKO_MAINCARD_UPDATE
|
|
$in['backoffice'] = 1;
|
|
$in['member_id'] = 0; // for session testing - not used
|
|
$in['name'] = $data['card_name'];
|
|
$in['title'] = $data['card_title'];
|
|
$in['short_title'] = $data['short_title'];
|
|
$in['description'] = $data['description'];
|
|
$in['long_description'] = $data['long_description'];
|
|
$in['card_logic'] = $data['card_logic'];
|
|
|
|
$in['background_picture'] = $data['card_pictures_value'];
|
|
$in['button1'] = $data['button1'];
|
|
$in['button1_text'] = $data['button1_text'];
|
|
$in['button1_action'] = $data['card_category_value']; // note category drives this action
|
|
$in['status'] = (int) $data['card_status_value'];
|
|
$in['can_save'] = (int) $data['card_can_save_value'];
|
|
$in['template'] = (int) $data['card_template_value'];
|
|
$in['card_canexpire'] = (int) $data['card_canexpire_value'];
|
|
$in['card_expiration'] = $data['card_expiration'];
|
|
$in['card_notify'] = (int) $data['card_notify_value'];
|
|
$in['titleshow'] = (int) $data['card_titleshow_value'];
|
|
$in['multiple_answer'] = (int) $data['multiple_answer'];
|
|
|
|
$in['card_behavior'] = $data['card_behavior_value'];
|
|
$in['blog_id'] = $data['card_blog_id_value'];
|
|
|
|
$in['use_short_title'] = $data['use_short_title_value'];
|
|
|
|
|
|
$in['card_type'] = $data['card_type_value'];
|
|
$in['card_time'] = $data['card_time_value'];
|
|
$in['card_location'] = $data['card_location_value'];
|
|
|
|
$in['card_points'] = $data['card_points_value'];
|
|
$in['card_reciept'] = $data['card_reciept_value'];
|
|
|
|
// $in["card_country"] = $data["card_country"];
|
|
$in['card_country'] = $data['card_country_value'];
|
|
// $in['target_text'] = "";
|
|
// $in['card_target'] = "";
|
|
|
|
$in['card_order'] = (int) $data['card_order'];
|
|
$in['background_color'] = strtoupper($data['background_color']);
|
|
|
|
|
|
if ($in['name'] == '' || strlen($in['name']) > 100) {
|
|
$message .= "<br/>Invalid name";
|
|
}
|
|
if ($in['title'] == '' || strlen($in['title']) > 100) {
|
|
$message .= "<br/>Invalid title";
|
|
}
|
|
if ($in['short_title'] == '' || strlen($in['short_title']) > 35) {
|
|
$message .= "<br/>Invalid short title";
|
|
}
|
|
if ($in['description'] == '' || strlen($in['description']) > 250) {
|
|
$message .= "<br/>Invalid description";
|
|
}
|
|
if ($in['background_picture'] == '' || strlen($in['background_picture']) > 150) {
|
|
$message .= "<br/>Invalid background picture";
|
|
}
|
|
if ($in['button1'] == '' || strlen($in['button1']) > 35) {
|
|
$message .= "<br/>Invalid button1";
|
|
}
|
|
if ($in['button1_text'] == '' || strlen($in['button1_text']) > 35) {
|
|
$message .= "<br/>Invalid button1 text";
|
|
}
|
|
if ($in['button1_action'] == '' || strlen($in['button1_action']) > 15) {
|
|
$message .= "<br/>Invalid category";
|
|
}
|
|
if ($data['card_canexpire_value'] != '' && $data['card_canexpire_value'] == 1 &&
|
|
($data['card_expiration'] == '' || strtotime($data['card_expiration']) < time())) {
|
|
$message .= "<br/>Invalid expiration date";
|
|
}
|
|
if ($message == '') {
|
|
$out = array();
|
|
$ret = $this->savvy_api($in, $out);
|
|
if ($ret == PHP_API_OK) {
|
|
$message = $id > 0 ? 'Updated!' : 'Created!';
|
|
} else {
|
|
$message = 'Failed to ' . ($id > 0 ? 'update' : 'create') . ' card: ' . $out["status"];
|
|
}
|
|
}
|
|
} else {
|
|
$in['card_expiration'] = date("Y-m-d", strtotime("+3 months"));
|
|
}
|
|
$data['message'] = $message;
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
$card_category = 'CARDDYNAMIC';
|
|
|
|
$params = $this->input->get();
|
|
$params['card_category'] = $card_category;
|
|
$custom_filter_options = [
|
|
[
|
|
"id" => 'name',
|
|
"name" => 'Card ID',
|
|
],
|
|
[
|
|
"id" => 'title',
|
|
"name" => 'Question',
|
|
],
|
|
[
|
|
"id" => 'description',
|
|
"name" => 'Answers Options',
|
|
],
|
|
];
|
|
$data['cart_filter_by_selectbox'] = $this->getCardFilterByFields('filter_name', $params['filter_name'] ?? '', $custom_filter_options);
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_heading(
|
|
'Detail', ['data' => 'Image', 'style' => 'width:50px'], ['data' => 'Image', 'style' => 'width:120px']
|
|
);
|
|
|
|
$query = $this->main_cards_model->getDynamicCardsQuery($params);
|
|
$tableData = $this->returnAdminTable(
|
|
[
|
|
'count_query' => $query,
|
|
'query' => $query,
|
|
], '/cards/dynamiccards/' . $card_category . '/', [
|
|
'per_page' => 6,
|
|
'reuse_query_string' => TRUE,
|
|
'uri_segment' => 4,
|
|
]
|
|
);
|
|
|
|
$data['filterData'] = $params;
|
|
$data['card_table'] = $tableData['output_table'];
|
|
$data['links'] = $tableData['links'];
|
|
|
|
$this->renderCardPage('view_dynamiccards', $data);
|
|
}
|
|
|
|
public function surveycards() {
|
|
$data = array();
|
|
$data["page_title"] = "Survey Cards";
|
|
$data["form_button"] = "Add";
|
|
$data["images"] = array();
|
|
|
|
$this->load->model('combo_model');
|
|
|
|
$data['card_order'] = trim($this->input->post('card_order'));
|
|
$data['background_color'] = trim($this->input->post('background_color'));
|
|
|
|
$data['card_behavior_value'] = trim($this->input->post('card_behavior'));
|
|
$data['card_blog_id_value'] = trim($this->input->post('card_blog_id'));
|
|
|
|
$data['multiple_answer_value'] = trim($this->input->post('multiple_answer'));
|
|
$data['card_category_value'] = trim($this->input->post('card_category'));
|
|
$data['card_can_save_value'] = trim($this->input->post('card_can_save'));
|
|
$data['card_pictures_value'] = trim($this->input->post('card_pictures'));
|
|
$data['card_status_value'] = trim($this->input->post('card_status'));
|
|
$data['card_template_value'] = trim($this->input->post('card_template'));
|
|
$data['card_canexpire_value'] = trim($this->input->post('card_canexpire'));
|
|
$data['card_notify_value'] = trim($this->input->post('card_notify'));
|
|
$data['card_country_value'] = trim($this->input->post('card_country'));
|
|
$data['card_titleshow_value'] = trim($this->input->post('card_titleshow'));
|
|
$data['use_short_title_value'] = trim($this->input->post('use_short_title'));
|
|
|
|
$data['card_type_value'] = trim($this->input->post('card_type')); // $selected_card['card_type'];
|
|
$data['card_time_value'] = trim($this->input->post('card_time')); // $selected_card['card_time'];
|
|
$data['card_location_value'] = trim($this->input->post('card_location')); //$selected_card['card_location'];
|
|
|
|
$data['card_points_value'] = trim($this->input->post('card_points')); //$selected_card['card_location'];
|
|
$data['card_reciept_value'] = trim($this->input->post('card_reciept')); //$selected_card['card_location'];
|
|
$data['card_logic'] = trim($this->input->post('card_logic')); //$selected_card['card_location'];
|
|
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
if (!empty($card_category)) {
|
|
$data['card_category_value'] = trim($card_category);
|
|
} else {
|
|
$card_category = $data['card_category_value'];
|
|
}
|
|
|
|
$data['card_reciept'] = $this->combo_model->getReciept('card_reciept', $data['card_reciept_value']);
|
|
$data['card_points'] = $this->combo_model->getCardPoint('card_points', $data['card_points_value']);
|
|
|
|
$card_category = 'SURVEYA';
|
|
$data['card_behavior'] = $this->combo_model->getCardBehaveCombo('card_behavior', $data['card_behavior_value']);
|
|
$data['card_blog_id'] = $this->combo_model->getCardblogIdCombo('card_blog_id', $data['card_blog_id_value']);
|
|
|
|
$data['multiple_answer'] = $this->combo_model->getYesNoCombo('multiple_answer', $data['multiple_answer_value']);
|
|
|
|
|
|
$data['card_type'] = $this->combo_model->getCardCategoryType('card_type', $data['card_type_value']);
|
|
$data['card_time'] = $this->combo_model->getCardTime('card_time', $data['card_time_value']);
|
|
$data['card_location'] = $this->combo_model->getCardLocation('card_location', $data['card_location_value']);
|
|
|
|
$data['card_category'] = $this->combo_model->getCardCategoryCombo('card_category', $data['card_category_value'], 'SURVEYA');
|
|
$data['card_can_save'] = $this->combo_model->getYesNoCombo('card_can_save', $data['card_can_save_value']);
|
|
$data['card_pictures'] = $this->combo_model->getCardPicturesCombo('card_pictures', $data['card_pictures_value']);
|
|
$data['card_status'] = $this->combo_model->getStatusCombo('card_status', $data['card_status_value']);
|
|
$data['card_template'] = $this->combo_model->getSurveyCardTemplateCombo('card_template', $data['card_template_value']);
|
|
$data['card_canexpire'] = $this->combo_model->getYesNoCombo('card_canexpire', $data['card_canexpire_value']);
|
|
$data['card_notify'] = $this->combo_model->getYesNoCombo('card_notify', $data['card_notify_value']);
|
|
$data['card_country'] = $this->combo_model->getCountryCombo('card_country', $data['card_country_value']);
|
|
|
|
$data['use_short_title_combo'] = $this->combo_model->getYesNoCombo('use_short_title', $data['use_short_title_value']);
|
|
|
|
|
|
$data['card_titleshow'] = $this->combo_model->getTitleShowCombo('card_titleshow', $data['card_titleshow_value']);
|
|
|
|
$data['card_name'] = trim($this->input->post('card_name'));
|
|
$data['card_title'] = trim($this->input->post('card_title'));
|
|
$data['short_title'] = trim($this->input->post('short_title'));
|
|
$data['description'] = trim($this->input->post('description'));
|
|
$data['long_description'] = trim($this->input->post('long_description'));
|
|
|
|
$data['background_picture'] = trim($this->input->post('background_picture'));
|
|
$data['button1'] = trim($this->input->post('button1'));
|
|
$data['button1_text'] = trim($this->input->post('button1_text'));
|
|
$data['button1_action'] = trim($this->input->post('button1_action'));
|
|
$data['card_expiration'] = trim($this->input->post('card_expiration'));
|
|
$data['card_logic'] = trim($this->input->post('card_logic'));
|
|
//$data['card_template'] = trim($this->input->post('card_template'));
|
|
|
|
// show_area & activity_screen
|
|
$data['show_area_value'] = trim($this->input->post('show_area'));
|
|
$data['activity_screen_value'] = trim($this->input->post('activity_screen'));
|
|
$data['show_area'] = $this->combo_model->getCardShowArea('show_area', $data['show_area_value']);
|
|
$data['activity_screen'] = $this->combo_model->getCardActivityScreen('activity_screen', $data['activity_screen_value']);
|
|
|
|
$message = '';
|
|
if ($_POST) {
|
|
$id = $this->input->post('id');
|
|
if ($id > 0) {
|
|
$in['action'] = SAVVY_BKO_MAINCARD_UPDATE;
|
|
$in['id'] = $id;
|
|
$data["form_button"] = "Update";
|
|
$data["card_id"] = $id;
|
|
} else {
|
|
$in['action'] = SAVVY_BKO_MAINCARD_CREATE;
|
|
}
|
|
//SAVVY_BKO_MAINCARD_UPDATE
|
|
$in['backoffice'] = 1;
|
|
$in['member_id'] = 0; // for session testing - not used
|
|
$in['name'] = $data['card_name'];
|
|
$in['title'] = $data['card_title'];
|
|
$in['short_title'] = $data['short_title'];
|
|
$in['description'] = $data['description'];
|
|
$in['long_description'] = $data['long_description'];
|
|
$in['card_logic'] = $data['card_logic'];
|
|
|
|
$in['background_picture'] = $data['card_pictures_value'];
|
|
$in['button1'] = $data['button1'];
|
|
$in['button1_text'] = $data['button1_text'];
|
|
$in['button1_action'] = $data['card_category_value']; // note category drives this action
|
|
$in['status'] = (int) $data['card_status_value'];
|
|
$in['can_save'] = (int) $data['card_can_save_value'];
|
|
$in['template'] = (int) $data['card_template_value'];
|
|
$in['card_canexpire'] = (int) $data['card_canexpire_value'];
|
|
$in['card_expiration'] = $data['card_expiration'];
|
|
$in['card_notify'] = (int) $data['card_notify_value'];
|
|
$in['titleshow'] = (int) $data['card_titleshow_value'];
|
|
$in['multiple_answer'] = (int) $data['multiple_answer'];
|
|
|
|
$in['card_behavior'] = $data['card_behavior_value'];
|
|
$in['blog_id'] = $data['card_blog_id_value'];
|
|
|
|
$in['use_short_title'] = $data['use_short_title_value'];
|
|
|
|
|
|
$in['card_type'] = $data['card_type_value'];
|
|
$in['card_time'] = $data['card_time_value'];
|
|
$in['card_location'] = $data['card_location_value'];
|
|
|
|
$in['card_points'] = $data['card_points_value'];
|
|
$in['card_reciept'] = $data['card_reciept_value'];
|
|
|
|
// $in["card_country"] = $data["card_country"];
|
|
$in['card_country'] = $data['card_country_value'];
|
|
// $in['target_text'] = "";
|
|
// $in['card_target'] = "";
|
|
|
|
$in['card_order'] = (int) $data['card_order'];
|
|
$in['background_color'] = strtoupper($data['background_color']);
|
|
|
|
$in['activity_screen'] = (int)$data['activity_screen_value'];
|
|
$in['show_area'] = (int)$data['show_area_value'];
|
|
|
|
if ($in['name'] == '' || strlen($in['name']) > 100) {
|
|
$message .= "<br/>Invalid name";
|
|
}
|
|
if ($in['title'] == '' || strlen($in['title']) > 100) {
|
|
$message .= "<br/>Invalid title";
|
|
}
|
|
if ($in['short_title'] == '' || strlen($in['short_title']) > 35) {
|
|
$message .= "<br/>Invalid short title";
|
|
}
|
|
if ($in['description'] == '' || strlen($in['description']) > 250) {
|
|
$message .= "<br/>Invalid description";
|
|
}
|
|
if ($in['background_picture'] == '' || strlen($in['background_picture']) > 150) {
|
|
$message .= "<br/>Invalid background picture";
|
|
}
|
|
if ($in['button1'] == '' || strlen($in['button1']) > 35) {
|
|
$message .= "<br/>Invalid button1";
|
|
}
|
|
if ($in['button1_text'] == '' || strlen($in['button1_text']) > 35) {
|
|
$message .= "<br/>Invalid button1 text";
|
|
}
|
|
if ($in['button1_action'] == '' || strlen($in['button1_action']) > 15) {
|
|
$message .= "<br/>Invalid category";
|
|
}
|
|
if ($data['card_canexpire_value'] != '' && $data['card_canexpire_value'] == 1 &&
|
|
($data['card_expiration'] == '' || strtotime($data['card_expiration']) < time())) {
|
|
$message .= "<br/>Invalid expiration date";
|
|
}
|
|
|
|
if ($message == '') {
|
|
$out = array();
|
|
$ret = $this->savvy_api($in, $out);
|
|
if ($ret == PHP_API_OK) {
|
|
$message = $id > 0 ? 'Updated!' : 'Created!';
|
|
} else {
|
|
$message = 'Failed to ' . ($id > 0 ? 'update' : 'create') . ' card: ' . $out["status"];
|
|
}
|
|
}
|
|
} else {
|
|
$in['card_expiration'] = date("Y-m-d", strtotime("+3 months"));
|
|
}
|
|
$data['message'] = $message;
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
$card_category = 'SURVEYA';
|
|
|
|
$params = $this->input->get();
|
|
$params['card_category'] = $card_category;
|
|
$custom_filter_options = [
|
|
[
|
|
"id" => 'name',
|
|
"name" => 'Card ID',
|
|
],
|
|
[
|
|
"id" => 'title',
|
|
"name" => 'Question',
|
|
],
|
|
[
|
|
"id" => 'description',
|
|
"name" => 'Answers Options',
|
|
],
|
|
];
|
|
$data['cart_filter_by_selectbox'] = $this->getCardFilterByFields('filter_name', $params['filter_name'] ?? '', $custom_filter_options);
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_heading(
|
|
['data' => 'View', 'style' => 'width:50px'], 'Card', ['data' => 'Image', 'style' => 'width:120px']
|
|
);
|
|
|
|
$query = $this->main_cards_model->getSurveyCardsQuery($params);
|
|
$tableData = $this->returnAdminTable(
|
|
[
|
|
'count_query' => $query,
|
|
'query' => $query,
|
|
], '/cards/surveycards/' . $card_category . '/', [
|
|
'per_page' => 6,
|
|
'reuse_query_string' => TRUE,
|
|
'uri_segment' => 4,
|
|
]
|
|
);
|
|
|
|
$data['filterData'] = $params;
|
|
$data['card_table'] = $tableData['output_table'];
|
|
$data['links'] = $tableData['links'];
|
|
|
|
$this->renderCardPage('view_surveycards', $data);
|
|
}
|
|
|
|
public function deletedcards() {
|
|
$data = array();
|
|
$data["page_title"] = "Deleted Cards";
|
|
$data["form_button"] = "Add";
|
|
$data["images"] = array();
|
|
|
|
$this->load->model('combo_model');
|
|
|
|
$data['card_category_vaue'] = trim($this->input->post('card_category'));
|
|
$data['card_can_save_value'] = trim($this->input->post('card_can_save'));
|
|
$data['card_pictures_value'] = trim($this->input->post('card_pictures'));
|
|
$data['card_status_value'] = trim($this->input->post('card_status'));
|
|
$data['card_template_value'] = trim($this->input->post('card_template'));
|
|
$data['card_canexpire_value'] = trim($this->input->post('card_canexpire'));
|
|
$data['card_notify_value'] = trim($this->input->post('card_notify'));
|
|
$data['card_country_value'] = trim($this->input->post('card_country'));
|
|
$data['card_titleshow_value'] = trim($this->input->post('card_titleshow'));
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
if (!empty($card_category)) {
|
|
$data['card_category_vaue'] = trim($card_category);
|
|
} else {
|
|
$card_category = $data['card_category_vaue'];
|
|
}
|
|
|
|
$data['card_category'] = $this->combo_model->getCardCategoryCombo('card_category', $data['card_category_vaue']);
|
|
$data['card_can_save'] = $this->combo_model->getYesNoCombo('card_can_save', $data['card_can_save_value']);
|
|
$data['card_pictures'] = $this->combo_model->getCardPicturesCombo('card_pictures', $data['card_pictures_value']);
|
|
$data['card_status'] = $this->combo_model->getStatusCombo('card_status', $data['card_status_value']);
|
|
$data['card_template'] = $this->combo_model->getCardTemplateCombo('card_template', $data['card_template_value']);
|
|
$data['card_canexpire'] = $this->combo_model->getYesNoCombo('card_canexpire', $data['card_canexpire_value']);
|
|
$data['card_notify'] = $this->combo_model->getYesNoCombo('card_notify', $data['card_notify_value']);
|
|
$data['card_country'] = $this->combo_model->getCountryCombo('card_country', $data['card_country_value']);
|
|
|
|
$data['card_titleshow'] = $this->combo_model->getTitleShowCombo('card_titleshow', $data['card_titleshow_value']);
|
|
|
|
$data['card_name'] = trim($this->input->post('card_name'));
|
|
$data['card_title'] = trim($this->input->post('card_title'));
|
|
$data['short_title'] = trim($this->input->post('short_title'));
|
|
$data['description'] = trim($this->input->post('description'));
|
|
$data['background_picture'] = trim($this->input->post('background_picture'));
|
|
$data['button1'] = trim($this->input->post('button1'));
|
|
$data['button1_text'] = trim($this->input->post('button1_text'));
|
|
$data['button1_action'] = trim($this->input->post('button1_action'));
|
|
$data['card_expiration'] = trim($this->input->post('card_expiration'));
|
|
//$data['card_template'] = trim($this->input->post('card_template'));
|
|
|
|
$message = '';
|
|
|
|
$data['message'] = $message;
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
|
|
$params = $this->input->get();
|
|
$params['card_category'] = $card_category;
|
|
$data['cart_filter_by_selectbox'] = $this->getCardFilterByFields('filter_name', $params['filter_name'] ?? '');
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_heading(
|
|
['data' => 'View', 'style' => 'width:50px'], 'Card', ['data' => 'Image', 'style' => 'width:120px']
|
|
);
|
|
|
|
$query = $this->main_cards_model->getDeletedCardsQuery($params);
|
|
$tableData = $this->returnAdminTable(
|
|
[
|
|
'count_query' => $query,
|
|
'query' => $query,
|
|
], '/cards/deletedcards/' . $card_category . '/', [
|
|
'per_page' => 6,
|
|
'reuse_query_string' => TRUE,
|
|
'uri_segment' => 4,
|
|
]
|
|
);
|
|
|
|
$data['filterData'] = $params;
|
|
$data['card_table'] = $tableData['output_table'];
|
|
$data['links'] = $tableData['links'];
|
|
|
|
$this->renderCardPage('view_deletedcards', $data);
|
|
}
|
|
|
|
public function editSurveycard() {
|
|
|
|
$data = array();
|
|
$card_id = $this->input->get('card_id');
|
|
|
|
if ($card_id != '' && $card_id > 0) {
|
|
|
|
$mysql = "SELECT * FROM main_cards WHERE id = $card_id";
|
|
$query = $this->read_replica->query($mysql);
|
|
$selected_card = $query->row_array();
|
|
|
|
$data["images"] = array();
|
|
$data["form_button"] = "Update";
|
|
|
|
$this->load->model('combo_model');
|
|
$card_category = 'SURVEYA';
|
|
$data['card_category_value'] = $card_category;
|
|
$data['card_behavior_value'] = $selected_card['card_behavior'];
|
|
$data['card_blog_id_value'] = $selected_card['blog_id'];
|
|
|
|
|
|
$data['card_can_save_value'] = 0;
|
|
//$selected_card['can_save'];
|
|
$data['multiple_answer_value'] = $selected_card['multiple_answer'];
|
|
$data['card_pictures_value'] = $selected_card['background_picture'];
|
|
$data['card_status_value'] = $selected_card['status'];
|
|
$data['card_template_value'] = $selected_card['template'];
|
|
$data['card_canexpire_value'] = $selected_card['card_canexpire'];
|
|
|
|
$data['card_type_value'] = $selected_card['card_type'];
|
|
$data['card_time_value'] = $selected_card['card_time'];
|
|
$data['card_location_value'] = $selected_card['card_location'];
|
|
$data['card_logic'] = $selected_card['card_logic'];
|
|
|
|
|
|
|
|
$data['card_notify_value'] = $selected_card['notify'];
|
|
$data['card_country_value'] = $selected_card['card_country'];
|
|
|
|
$data['card_titleshow_value'] = $selected_card['titleshow'];
|
|
|
|
$data['card_category'] = $card_category;
|
|
$data['card_can_save'] = 0;
|
|
|
|
$data['card_points_value'] = $selected_card['card_points'];
|
|
|
|
$data['card_reciept_value'] = $selected_card['card_reciept'];
|
|
|
|
// show_area & activity_screen
|
|
$data['show_area_value'] = $selected_card['show_area'];
|
|
$data['activity_screen_value'] = $selected_card['activity_screen'];
|
|
$data['show_area'] = $this->combo_model->getCardShowArea('show_area', $data['show_area_value']);
|
|
$data['activity_screen'] = $this->combo_model->getCardActivityScreen('activity_screen', $data['activity_screen_value']);
|
|
|
|
|
|
$data['card_reciept'] = $this->combo_model->getReciept('card_reciept', $data['card_reciept_value']);
|
|
$data['card_points'] = $this->combo_model->getCardPoint('card_points', $data['card_points_value']);
|
|
|
|
|
|
$data['multiple_answer'] = $this->combo_model->getYesNoCombo('multiple_answer', $data['multiple_answer_value']);
|
|
$data['card_pictures'] = $this->combo_model->getCardPicturesCombo('card_pictures', $data['card_pictures_value']);
|
|
$data['card_status'] = $this->combo_model->getStatusCombo('card_status', $data['card_status_value']);
|
|
$data['card_template'] = $this->combo_model->getSurveyCardTemplateCombo('card_template', $data['card_template_value']);
|
|
$data['card_canexpire'] = $this->combo_model->getYesNoCombo('card_canexpire', $data['card_canexpire_value']);
|
|
$data['card_behavior'] = $this->combo_model->getCardBehaveCombo('card_behavior', $data['card_behavior_value']);
|
|
$data['card_blog_id'] = $this->combo_model->getCardblogIdCombo('card_blog_id', $data['card_blog_id_value']);
|
|
|
|
|
|
$data['card_notify'] = $this->combo_model->getYesNoCombo('card_notify', $data['card_notify_value']);
|
|
$data['card_country'] = $this->combo_model->getCountryCombo('card_country', $data['card_country_value']);
|
|
|
|
$data['card_titleshow'] = $this->combo_model->getTitleShowCombo('card_titleshow', $data['card_titleshow_value']);
|
|
|
|
$data['card_type'] = $this->combo_model->getCardCategoryType('card_type', $data['card_type_value']);
|
|
$data['card_time'] = $this->combo_model->getCardTime('card_time', $data['card_time_value']);
|
|
$data['card_location'] = $this->combo_model->getCardLocation('card_location', $data['card_location_value']);
|
|
|
|
$data['use_short_title_value'] = $selected_card['use_short_title'];
|
|
$data['use_short_title_combo'] = $this->combo_model->getYesNoCombo('use_short_title', $data['use_short_title_value']);
|
|
|
|
|
|
$data['card_name'] = $selected_card['name'];
|
|
$data['card_title'] = $selected_card['title'];
|
|
$data['short_title'] = $selected_card['short_title'];
|
|
$data['description'] = $selected_card['description'];
|
|
$data['background_picture'] = $selected_card['background_picture'];
|
|
$data['button1'] = $selected_card['button1'];
|
|
$data['button1_text'] = $selected_card['button1_text'];
|
|
$data['button1_action'] = $selected_card['button1_action'];
|
|
$data['card_expiration'] = $selected_card['card_expiration'];
|
|
$data['long_description'] = $selected_card['long_description'];
|
|
|
|
$data['card_order'] = $selected_card['card_order'];
|
|
$data['background_color'] = $selected_card['background_color'];
|
|
|
|
$data['card_id'] = $card_id;
|
|
|
|
$this->load->view('cards/common/card_surveyform', $data);
|
|
}
|
|
}
|
|
|
|
public function editcard() {
|
|
|
|
$data = array();
|
|
$card_id = $this->input->get('card_id');
|
|
|
|
if ($card_id != '' && $card_id > 0) {
|
|
|
|
$mysql = "SELECT * FROM main_cards WHERE id = $card_id";
|
|
$query = $this->read_replica->query($mysql);
|
|
$selected_card = $query->row_array();
|
|
|
|
$data["images"] = array();
|
|
$data["form_button"] = "Update";
|
|
|
|
$this->load->model('combo_model');
|
|
|
|
$data['target_key_value'] = $selected_card['target_key'];
|
|
$data['card_behavior_value'] = $selected_card['card_behavior'];
|
|
$data['card_blog_id_value'] = $selected_card['blog_id'];
|
|
|
|
|
|
$data['card_category_value'] = $selected_card['button1_action'];
|
|
$data['card_can_save_value'] = $selected_card['can_save'];
|
|
$data['card_pictures_value'] = $selected_card['background_picture'];
|
|
$data['card_status_value'] = $selected_card['status'];
|
|
$data['card_template_value'] = $selected_card['template'];
|
|
$data['card_canexpire_value'] = $selected_card['card_canexpire'];
|
|
|
|
$data['card_notify_value'] = $selected_card['notify'];
|
|
$data['card_country_value'] = $selected_card['card_country'];
|
|
|
|
$data['card_type_value'] = $selected_card['card_type'];
|
|
$data['card_time_value'] = $selected_card['card_time'];
|
|
$data['card_location_value'] = $selected_card['card_location'];
|
|
|
|
$data['card_logic'] = $selected_card['card_logic'];
|
|
|
|
$data['card_titleshow_value'] = $selected_card['titleshow'];
|
|
|
|
$data['card_points_value'] = $selected_card['card_points'];
|
|
|
|
$data['card_reciept_value'] = $selected_card['card_reciept'];
|
|
|
|
// show_area & activity_screen
|
|
$data['show_area_value'] = $selected_card['show_area'];
|
|
$data['activity_screen_value'] = $selected_card['activity_screen'];
|
|
$data['show_area'] = $this->combo_model->getCardShowArea('show_area', $data['show_area_value']);
|
|
$data['activity_screen'] = $this->combo_model->getCardActivityScreen('activity_screen', $data['activity_screen_value']);
|
|
|
|
//Expiration
|
|
$data['expiration_value'] = $selected_card['expiration'];
|
|
$data['expiration'] = $this->combo_model->getCardExpiration('expiration', $data['expiration_value']);
|
|
|
|
|
|
$data['card_reciept'] = $this->combo_model->getReciept('card_reciept', $data['card_reciept_value']);
|
|
$data['card_points'] = $this->combo_model->getCardPoint('card_points', $data['card_points_value']);
|
|
|
|
$data['target_key'] = $this->combo_model->getCardTargetActionCombo('target_key', $data['target_key_value']);
|
|
|
|
$data['card_behavior'] = $this->combo_model->getCardBehaveCombo('card_behavior', $data['card_behavior_value']);
|
|
$data['card_blog_id'] = $this->combo_model->getCardblogIdCombo('card_blog_id', $data['card_blog_id_value']);
|
|
|
|
$data['use_short_title_value'] = $selected_card['use_short_title'];
|
|
$data['use_short_title_combo'] = $this->combo_model->getYesNoCombo('use_short_title', $data['use_short_title_value']);
|
|
|
|
$data['card_category'] = $this->combo_model->getCardCategoryCombo('card_category', $data['card_category_value']);
|
|
$data['card_can_save'] = $this->combo_model->getYesNoCombo('card_can_save', $data['card_can_save_value']);
|
|
|
|
// active tip don't use picture
|
|
$card_pictures_value = $data['card_pictures_value'];
|
|
if($selected_card['template'] == self::TEMPLATE_ACTIVE_TIP){
|
|
$card_pictures_value = '';
|
|
}
|
|
$data['card_pictures'] = $this->combo_model->getCardPicturesCombo('card_pictures', $card_pictures_value);
|
|
$data['card_status'] = $this->combo_model->getStatusCombo('card_status', $data['card_status_value']);
|
|
$data['card_template'] = $this->combo_model->getCardTemplateCombo('card_template', $data['card_template_value']);
|
|
$data['card_canexpire'] = $this->combo_model->getYesNoCombo('card_canexpire', $data['card_canexpire_value']);
|
|
$data['card_notify'] = $this->combo_model->getYesNoCombo('card_notify', $data['card_notify_value']);
|
|
$data['card_country'] = $this->combo_model->getCountryCombo('card_country', $data['card_country_value']);
|
|
$data['card_titleshow'] = $this->combo_model->getTitleShowCombo('card_titleshow', $data['card_titleshow_value']);
|
|
|
|
|
|
|
|
$data['card_type'] = $this->combo_model->getCardCategoryType('card_type', $data['card_type_value']);
|
|
$data['card_time'] = $this->combo_model->getCardTime('card_time', $data['card_time_value']);
|
|
$data['card_location'] = $this->combo_model->getCardLocation('card_location', $data['card_location_value']);
|
|
|
|
$data['card_name'] = $selected_card['name'];
|
|
$data['card_title'] = $selected_card['title'];
|
|
$data['short_title'] = $selected_card['short_title'];
|
|
$data['description'] = $selected_card['description'];
|
|
$data['long_description'] = $selected_card['long_description'];
|
|
|
|
$data['background_picture'] = $selected_card['background_picture'];
|
|
$data['button1'] = $selected_card['button1'];
|
|
$data['button1_text'] = $selected_card['button1_text'];
|
|
$data['button1_action'] = $selected_card['button1_action'];
|
|
$data['card_expiration'] = $selected_card['card_expiration'];
|
|
|
|
$data['target_text'] = $selected_card['target_text'];
|
|
$data['card_order'] = $selected_card['card_order'];
|
|
$data['background_color'] = $selected_card['background_color'];
|
|
|
|
$data["dynamic_key"] = $selected_card['dynamic_key'];
|
|
|
|
|
|
$data['card_id'] = $card_id;
|
|
|
|
$data['TEMPLATE_ACTIVE_TIP'] = self::TEMPLATE_ACTIVE_TIP;
|
|
$this->load->view('cards/common/card_form', $data);
|
|
}
|
|
}
|
|
|
|
public function generalcards() {
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_template($this->template);
|
|
|
|
//echo "";
|
|
$data = array();
|
|
$data["page_title"] = "Cards";
|
|
$data["form_button"] = "Add";
|
|
$data["images"] = array();
|
|
|
|
$this->load->model('combo_model');
|
|
|
|
|
|
$data['card_category_vaue'] = trim($this->input->post('card_category'));
|
|
$data['card_can_save_value'] = trim($this->input->post('card_can_save'));
|
|
$data['card_pictures_value'] = trim($this->input->post('card_pictures'));
|
|
$data['card_status_value'] = trim($this->input->post('card_status'));
|
|
$data['card_template_value'] = trim($this->input->post('card_template'));
|
|
$data['card_canexpire_value'] = trim($this->input->post('card_canexpire'));
|
|
$data['card_notify_value'] = trim($this->input->post('card_notify'));
|
|
$data['card_country_value'] = trim($this->input->post('card_country'));
|
|
$data['card_titleshow_value'] = trim($this->input->post('card_titleshow'));
|
|
$data['card_blog_id_value'] = trim($this->input->post('card_blog_id'));
|
|
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
if ($card_category != '' && $card_category != '0') {
|
|
$data['card_category_vaue'] = trim($card_category);
|
|
} else {
|
|
$card_category = $data['card_category_vaue'];
|
|
}
|
|
|
|
$data['card_category'] = $this->combo_model->getCardCategoryCombo('card_category', $data['card_category_vaue']);
|
|
$data['card_can_save'] = $this->combo_model->getYesNoCombo('card_can_save', $data['card_can_save_value']);
|
|
$data['card_pictures'] = $this->combo_model->getCardPicturesCombo('card_pictures', $data['card_pictures_value']);
|
|
$data['card_status'] = $this->combo_model->getStatusCombo('card_status', $data['card_status_value']);
|
|
$data['card_template'] = $this->combo_model->getCardTemplateCombo('card_template', $data['card_template_value']);
|
|
$data['card_canexpire'] = $this->combo_model->getYesNoCombo('card_canexpire', $data['card_canexpire_value']);
|
|
$data['card_notify'] = $this->combo_model->getYesNoCombo('card_notify', $data['card_notify_value']);
|
|
$data['card_country'] = $this->combo_model->getCountryCombo('card_country', $data['card_country_value']);
|
|
|
|
$data['card_titleshow'] = $this->combo_model->getTitleShowCombo('card_titleshow', $data['card_titleshow_value']);
|
|
|
|
$data['card_name'] = trim($this->input->post('card_name'));
|
|
$data['card_title'] = trim($this->input->post('card_title'));
|
|
$data['short_title'] = trim($this->input->post('short_title'));
|
|
$data['description'] = trim($this->input->post('description'));
|
|
$data['background_picture'] = trim($this->input->post('background_picture'));
|
|
$data['button1'] = trim($this->input->post('button1'));
|
|
$data['button1_text'] = trim($this->input->post('button1_text'));
|
|
$data['button1_action'] = trim($this->input->post('button1_action'));
|
|
$data['card_expiration'] = trim($this->input->post('card_expiration'));
|
|
|
|
|
|
$data['blog_id'] = $this->combo_model->getCardblogIdCombo('card_blog_id', $data['card_blog_id_value']);
|
|
|
|
//$data['card_template'] = trim($this->input->post('card_template'));
|
|
//print_r($data);
|
|
|
|
$data['card_order'] = trim($this->input->post('card_order'));
|
|
$data['background_color'] = trim($this->input->post('background_color'));
|
|
|
|
$message = '';
|
|
if ($_POST) {
|
|
$id = $this->input->post('id');
|
|
if ($id > 0) {
|
|
$in['action'] = SAVVY_BKO_MAINCARD_UPDATE;
|
|
$in['id'] = $id;
|
|
$data["form_button"] = "Update";
|
|
$data["card_id"] = $id;
|
|
} else {
|
|
$in['action'] = SAVVY_BKO_MAINCARD_CREATE;
|
|
}
|
|
//SAVVY_BKO_MAINCARD_UPDATE
|
|
$in['name'] = $data['card_name'];
|
|
$in['title'] = $data['card_title'];
|
|
$in['short_title'] = $data['short_title'];
|
|
$in['description'] = $data['description'];
|
|
$in['background_picture'] = $data['card_pictures_value'];
|
|
$in['button1'] = $data['button1'];
|
|
$in['button1_text'] = $data['button1_text'];
|
|
$in['button1_action'] = $data['card_category_vaue']; // note category drives this action
|
|
$in['status'] = (int) $data['card_status_value'];
|
|
$in['can_save'] = (int) $data['card_can_save_value'];
|
|
$in['template'] = (int) $data['card_template_value'];
|
|
$in['card_canexpire'] = (int) $data['card_canexpire_value'];
|
|
$in['card_expiration'] = $data['card_expiration'];
|
|
$in['card_notify'] = (int) $data['card_notify_value'];
|
|
$in['titleshow'] = (int) $data['card_titleshow_value'];
|
|
$in['card_country'] = $data['card_country_value'];
|
|
$in['blog_id'] = $data['blog_id'];
|
|
|
|
$in['card_order'] = $data['card_order'];
|
|
$in['background_color'] = $data['background_color'];
|
|
|
|
|
|
if ($in['name'] == '' || strlen($in['name']) > 100) {
|
|
$message .= "<br/>Invalid name";
|
|
}
|
|
if ($in['title'] == '' || strlen($in['title']) > 100) {
|
|
$message .= "<br/>Invalid title";
|
|
}
|
|
if ($in['short_title'] == '' || strlen($in['short_title']) > 35) {
|
|
$message .= "<br/>Invalid short title";
|
|
}
|
|
if ($in['description'] == '' || strlen($in['description']) > 250) {
|
|
$message .= "<br/>Invalid description";
|
|
}
|
|
if ($in['background_picture'] == '' || strlen($in['background_picture']) > 150) {
|
|
$message .= "<br/>Invalid background picture";
|
|
}
|
|
if ($in['button1'] == '' || strlen($in['button1']) > 35) {
|
|
$message .= "<br/>Invalid button1";
|
|
}
|
|
if ($in['button1_text'] == '' || strlen($in['button1_text']) > 35) {
|
|
$message .= "<br/>Invalid button1 text";
|
|
}
|
|
if ($in['button1_action'] == '' || strlen($in['button1_action']) > 15) {
|
|
$message .= "<br/>Invalid category";
|
|
}
|
|
if ($data['card_canexpire_value'] != '' && $data['card_canexpire_value'] == 1 &&
|
|
($data['card_expiration'] == '' || strtotime($data['card_expiration']) < time())) {
|
|
$message .= "<br/>Invalid expiration date";
|
|
}
|
|
|
|
// print_r($in);
|
|
|
|
if ($message == '') {
|
|
$out = array();
|
|
$ret = $this->savvy_api($in, $out);
|
|
if ($ret == PHP_API_OK) {
|
|
$message = $id > 0 ? 'Updated!' : 'Created!';
|
|
} else {
|
|
$message = 'Failed to ' . ($id > 0 ? 'update' : 'create') . ' card: ' . $out["status"];
|
|
}
|
|
}
|
|
} else {
|
|
$in['card_expiration'] = date("Y-m-d", strtotime("+3 months"));
|
|
}
|
|
$data['message'] = $message;
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
|
|
$this->load->library('pagination');
|
|
$config = array();
|
|
$q = "SELECT * FROM main_cards WHERE status=1";
|
|
if ($card_category != '' && $card_category != '0') {
|
|
$q .= " AND button1_action='" . pg_escape_string($card_category) . "'";
|
|
}
|
|
$query = $this->read_replica->query($q);
|
|
$config["total_rows"] = $query->num_rows();
|
|
$config["base_url"] = '/bkoadmin/cards/' . $card_category . '/';
|
|
$config["per_page"] = 6;
|
|
$config["uri_segment"] = 4;
|
|
$config["num_links"] = 5;
|
|
$config['full_tag_open'] = "<ul class='pagination'>";
|
|
$config['full_tag_close'] = "</ul>";
|
|
$config['num_tag_open'] = '<li>';
|
|
$config['num_tag_close'] = '</li>';
|
|
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
|
|
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
|
|
$config['next_tag_open'] = "<li>";
|
|
$config['next_tagl_close'] = "</li>";
|
|
$config['prev_tag_open'] = "<li>";
|
|
$config['prev_tagl_close'] = "</li>";
|
|
$config['first_tag_open'] = "<li>";
|
|
$config['first_tagl_close'] = "</li>";
|
|
$config['last_tag_open'] = "<li>";
|
|
$config['last_tagl_close'] = "</li>";
|
|
$this->pagination->initialize($config);
|
|
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
|
|
$page = is_numeric($page) ? $page : 0;
|
|
$data["links"] = $this->pagination->create_links();
|
|
|
|
$mysql = "SELECT '<button id=\"acc'||id||'\" type=\"button\" class=\"btn btn-primary btn-xs\" block onclick=\"viewCard('||id||');\">View-'||id||'</button>' ||'<br><hr>'|| "
|
|
. "'<button id=\"edit'||id||'\" type=\"button\" class=\"btn btn-warning btn-xs\" block onclick=\"editCard('||id||');\">Edit-'||id||'</button>' AS Edit,"
|
|
. " '<b>Name:</b>'|| name||'<br><b>Title:</b>'||title||'<br><b>Short Title</b>'||short_title||'<br><b>Desc :</b>'||description
|
|
||'<br><b>Button :</b>'||button1||'<br><b>Button Text :</b>'
|
|
||button1_text||'<br><b>Action :</>'||button1_action AS description, '<img onclick=\"viewCard('||id||');\" style=\"height:120px; \" src=\"'||background_picture||'\" ><br>
|
|
<div id=\"del_form'||id||'\"><a href=\"#\" onclick=\"deleteCard('||id||');\" class=\"text-danger\">archive</a></div> ' As button FROM main_cards WHERE status = 1 ";
|
|
if ($card_category != '' && $card_category != '0') {
|
|
$mysql .= " AND button1_action='" . pg_escape_string($card_category) . "'";
|
|
}
|
|
$mysql .= " ORDER BY id DESC LIMIT " . $config["per_page"] . " OFFSET " . $page;
|
|
$query = $this->read_replica->query($mysql);
|
|
$this->table->set_heading(array('data' => 'View', 'style' => 'width:50px'), 'Card', array('data' => 'Image', 'style' => 'width:120px'));
|
|
$data["card_table"] = $this->table->generate($query);
|
|
|
|
$this->renderCardPage('view_cards', $data);
|
|
}
|
|
|
|
/**
|
|
* List cards which have expired time
|
|
* @return mixed
|
|
*/
|
|
public function expiredcards() {
|
|
$data = array();
|
|
$data['page_title'] = 'Expired Cards';
|
|
$this->load->model( 'combo_model' );
|
|
$data['card_category_vaue'] = trim($this->input->post('card_category'));
|
|
$data['card_can_save_value'] = trim($this->input->post('card_can_save'));
|
|
$data['card_pictures_value'] = trim($this->input->post('card_pictures'));
|
|
$data['card_status_value'] = trim($this->input->post('card_status'));
|
|
$data['card_template_value'] = trim($this->input->post('card_template'));
|
|
$data['card_canexpire_value'] = trim($this->input->post('card_canexpire'));
|
|
$data['card_notify_value'] = trim($this->input->post('card_notify'));
|
|
$data['card_country_value'] = trim($this->input->post('card_country'));
|
|
$data['card_titleshow_value'] = trim($this->input->post('card_titleshow'));
|
|
$card_filter_by_field = trim($this->input->get('card_filter_by'));
|
|
$card_filter_by_value = trim($this->input->get('filter_by_value'));
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
|
|
if ( !empty($card_category) ) {
|
|
$data['card_category_vaue'] = trim($card_category);
|
|
} else {
|
|
$card_category = $data['card_category_vaue'];
|
|
}
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
$params = $this->input->get();
|
|
$params['card_category'] = $card_category;
|
|
$data['cart_filter_by_selectbox'] = $this->getCardFilterByFields('filter_name', $params['filter_name'] ?? '');
|
|
$data['card_category'] = $this->combo_model->getCardCategoryCombo('card_category', $data['card_category_vaue']);
|
|
$data['card_can_save'] = $this->combo_model->getYesNoCombo('card_can_save', $data['card_can_save_value']);
|
|
$data['card_pictures'] = $this->combo_model->getCardPicturesCombo('card_pictures', $data['card_pictures_value']);
|
|
$data['card_status'] = $this->combo_model->getStatusCombo('card_status', $data['card_status_value']);
|
|
$data['card_template'] = $this->combo_model->getCardTemplateCombo('card_template', $data['card_template_value']);
|
|
$data['card_canexpire'] = $this->combo_model->getYesNoCombo('card_canexpire', $data['card_canexpire_value']);
|
|
$data['card_notify'] = $this->combo_model->getYesNoCombo('card_notify', $data['card_notify_value']);
|
|
$data['card_country'] = $this->combo_model->getCountryCombo('card_country', $data['card_country_value']);
|
|
|
|
$data['card_titleshow'] = $this->combo_model->getTitleShowCombo('card_titleshow', $data['card_titleshow_value']);
|
|
|
|
$data['card_name'] = trim($this->input->post('card_name'));
|
|
$data['card_title'] = trim($this->input->post('card_title'));
|
|
$data['short_title'] = trim($this->input->post('short_title'));
|
|
$data['description'] = trim($this->input->post('description'));
|
|
$data['background_picture'] = trim($this->input->post('background_picture'));
|
|
$data['button1'] = trim($this->input->post('button1'));
|
|
$data['button1_text'] = trim($this->input->post('button1_text'));
|
|
$data['button1_action'] = trim($this->input->post('button1_action'));
|
|
$data['card_expiration'] = trim($this->input->post('card_expiration'));
|
|
|
|
// prepare table
|
|
$this->load->library('table');
|
|
$this->table->set_heading(
|
|
array( 'data' => 'View', 'style' => 'width:50px' ),
|
|
'Card',
|
|
array( 'data' => 'Image', 'style' => 'width:120px' ),
|
|
array( 'data' => 'Delete', 'style' => 'width:120px' )
|
|
);
|
|
|
|
$results = $this->main_cards_model->getCardsExpired( $params );
|
|
$tableData = $this->returnAdminTable(
|
|
array(
|
|
'count_query' => $results,
|
|
'query' => $results
|
|
),
|
|
'/cards/expiredcards/' . $card_category,
|
|
array(
|
|
'per_page' => 6,
|
|
'reuse_query_string' => TRUE,
|
|
'uri_segment' => 4
|
|
)
|
|
);
|
|
|
|
$data['filterData'] = $params;
|
|
$data['card_table'] = $tableData['output_table'];
|
|
$data['links'] = $tableData['links'];
|
|
|
|
$this->renderCardPage('view_expirecards', $data);
|
|
}
|
|
|
|
public function arcvcards() {
|
|
$data = array();
|
|
$data["page_title"] = "Inactive or Archived Cards";
|
|
$data["form_button"] = "Add";
|
|
$data["images"] = array();
|
|
|
|
$this->load->model('combo_model');
|
|
|
|
$data['card_category_vaue'] = trim($this->input->post('card_category'));
|
|
$data['card_can_save_value'] = trim($this->input->post('card_can_save'));
|
|
$data['card_pictures_value'] = trim($this->input->post('card_pictures'));
|
|
$data['card_status_value'] = trim($this->input->post('card_status'));
|
|
$data['card_template_value'] = trim($this->input->post('card_template'));
|
|
$data['card_canexpire_value'] = trim($this->input->post('card_canexpire'));
|
|
$data['card_notify_value'] = trim($this->input->post('card_notify'));
|
|
$data['card_country_value'] = trim($this->input->post('card_country'));
|
|
$data['card_titleshow_value'] = trim($this->input->post('card_titleshow'));
|
|
$card_filter_by_field = trim($this->input->get('card_filter_by'));
|
|
$card_filter_by_value = trim($this->input->get('filter_by_value'));
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
if (!empty($card_category)) {
|
|
$data['card_category_vaue'] = trim($card_category);
|
|
} else {
|
|
$card_category = $data['card_category_vaue'];
|
|
}
|
|
|
|
$data['card_category'] = $this->combo_model->getCardCategoryCombo('card_category', $data['card_category_vaue']);
|
|
$data['card_can_save'] = $this->combo_model->getYesNoCombo('card_can_save', $data['card_can_save_value']);
|
|
$data['card_pictures'] = $this->combo_model->getCardPicturesCombo('card_pictures', $data['card_pictures_value']);
|
|
$data['card_status'] = $this->combo_model->getStatusCombo('card_status', $data['card_status_value']);
|
|
$data['card_template'] = $this->combo_model->getCardTemplateCombo('card_template', $data['card_template_value']);
|
|
$data['card_canexpire'] = $this->combo_model->getYesNoCombo('card_canexpire', $data['card_canexpire_value']);
|
|
$data['card_notify'] = $this->combo_model->getYesNoCombo('card_notify', $data['card_notify_value']);
|
|
$data['card_country'] = $this->combo_model->getCountryCombo('card_country', $data['card_country_value']);
|
|
|
|
$data['card_titleshow'] = $this->combo_model->getTitleShowCombo('card_titleshow', $data['card_titleshow_value']);
|
|
|
|
$data['card_name'] = trim($this->input->post('card_name'));
|
|
$data['card_title'] = trim($this->input->post('card_title'));
|
|
$data['short_title'] = trim($this->input->post('short_title'));
|
|
$data['description'] = trim($this->input->post('description'));
|
|
$data['background_picture'] = trim($this->input->post('background_picture'));
|
|
$data['button1'] = trim($this->input->post('button1'));
|
|
$data['button1_text'] = trim($this->input->post('button1_text'));
|
|
$data['button1_action'] = trim($this->input->post('button1_action'));
|
|
$data['card_expiration'] = trim($this->input->post('card_expiration'));
|
|
// $data['card_template'] = trim($this->input->post('card_template'));
|
|
|
|
$message = '';
|
|
|
|
$data['message'] = $message;
|
|
|
|
$card_category = ($this->uri->segment(3)) ? $this->uri->segment(3) : '0';
|
|
|
|
$params = $this->input->get();
|
|
$params['card_category'] = $card_category;
|
|
$data['cart_filter_by_selectbox'] = $this->getCardFilterByFields('filter_name', $params['filter_name'] ?? '');
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_heading(
|
|
['data' => 'View', 'style' => 'width:50px'], 'Card', ['data' => 'Image', 'style' => 'width:220px'], ['data' => 'Delete', 'style' => 'width:10px']
|
|
);
|
|
|
|
$query = $this->main_cards_model->getArchivedCardsQuery($params);
|
|
$tableData = $this->returnAdminTable(
|
|
[
|
|
'count_query' => $query,
|
|
'query' => $query,
|
|
], '/cards/arcvcards/' . $card_category . '/', [
|
|
'per_page' => 6,
|
|
'reuse_query_string' => TRUE,
|
|
'uri_segment' => 4,
|
|
]
|
|
);
|
|
|
|
$data['filterData'] = $params;
|
|
$data['card_table'] = $tableData['output_table'];
|
|
$data['links'] = $tableData['links'];
|
|
|
|
$this->renderCardPage('view_arcvcards', $data);
|
|
}
|
|
|
|
public function deletecard() {
|
|
|
|
$card_id = (int) $this->input->get('card_id');
|
|
|
|
if ($card_id > 0) {
|
|
// $card_id = $this->input->get('card_id');
|
|
$mysql = "UPDATE main_cards SET deleted = now(),status=0 WHERE deleted IS NULL AND id = " . $card_id;
|
|
$this->db->query($mysql);
|
|
echo "Deleted." . $card_id;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public function deletetoinactive() {
|
|
|
|
$card_id = (int) $this->input->get('card_id');
|
|
|
|
if ($card_id > 0) {
|
|
// $card_id = $this->input->get('card_id');
|
|
$mysql = "UPDATE main_cards SET deleted = NULL,status=0 WHERE deleted IS NOT NULL AND id = " . $card_id;
|
|
$this->db->query($mysql);
|
|
echo "Deleted." . $card_id;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public function cardsettings() {
|
|
|
|
echo 'ffffffff';
|
|
return 0;
|
|
}
|
|
|
|
//set_form
|
|
public function updatesettings() {
|
|
//echo 'uuu';
|
|
if ($_GET) {
|
|
$setting_id = $this->input->get('setting_id');
|
|
$setting_key = $this->input->get('setting_key');
|
|
$setting_value = $this->input->get("setting_value");
|
|
|
|
$mysql = "UPDATE app_settings SET value = '" . pg_escape_string($setting_value) . "' WHERE id = " . $setting_id . " AND setting_key = '$setting_key' ";
|
|
//echo $mysql;
|
|
$this->db->query($mysql);
|
|
echo "Updated.";
|
|
} else {
|
|
echo "Invalid request.";
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public function cardarchive() {
|
|
if ($_GET) {
|
|
$card_id = $this->input->get('card_id');
|
|
$mysql = "UPDATE main_cards SET status = 0 WHERE id = " . $card_id;
|
|
// echo $sql;
|
|
$this->db->query($mysql);
|
|
echo "Archived.";
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public function cardactivate() {
|
|
if ($_GET) {
|
|
$card_id = $this->input->get('card_id');
|
|
$mysql = "UPDATE main_cards SET status = 1 WHERE id = " . $card_id;
|
|
// echo $sql;
|
|
$this->db->query($mysql);
|
|
echo "Activated.";
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public function cardactions() {
|
|
$data = array();
|
|
$data["page_title"] = "Cards";
|
|
$data["form_button"] = "Add";
|
|
$data["links"] = "";
|
|
$data["card_category"] = "";
|
|
|
|
$this->load->model('combo_model');
|
|
|
|
$message = "";
|
|
$this->load->library('table');
|
|
$this->table->set_template($this->template);
|
|
|
|
$data["card_action_id"] = 0;
|
|
$data["name"] = $this->input->post('name');
|
|
$data["type"] = $this->input->post('type');
|
|
$data["type_combo"] = $this->combo_model->getCardActionTypeCombo('type', $data['type']);
|
|
$data["data"] = $this->input->post('data');
|
|
if ($_POST) {
|
|
$message = 'Not implemented!';
|
|
$id = $this->input->post('id');
|
|
if ($id > 0) {
|
|
$in['action'] = SAVVY_BKO_MAINCARD_UPDATE; // TODO
|
|
$in['id'] = $id;
|
|
$data["form_button"] = "Update";
|
|
$data["card_action_id"] = $id;
|
|
} else {
|
|
$in['action'] = SAVVY_BKO_MAINCARD_CREATE; // TODO
|
|
}
|
|
}
|
|
// id, name, type, data
|
|
//echo "";
|
|
/*
|
|
<button id=\"acc'||id||'\" type=\"button\" class=\"btn btn-primary btn-xs\" block onclick=\"viewCardAction('||id||');\">View-'||id||'</button>' ||'<br><hr>'|| "
|
|
. "'<button id=\"edit'||id||'\" type=\"button\" class=\"btn btn-warning btn-xs\" block onclick=\"editCardAction('||id||');\">Edit-'||id||'</button>' AS Edit,"
|
|
. "
|
|
*/
|
|
$mysql = "SELECT id, name, type, data FROM card_actions ORDER BY name";
|
|
$query = $this->read_replica->query($mysql);
|
|
$data["card_action_table"] = $this->table->generate($query);
|
|
|
|
$data["message"] = $message;
|
|
|
|
$this->renderCardPage('view_cardactions', $data);
|
|
}
|
|
|
|
public function DELtransport() {
|
|
$data = [
|
|
"id" => "0",
|
|
"message" => "",
|
|
"name" => "",
|
|
"client" => "",
|
|
"token" => "",
|
|
"code" => "",
|
|
"access_token" => "",
|
|
"form_button" => "Create"
|
|
];
|
|
try {
|
|
$this->load->model('combo_model');
|
|
$data['provider_status_value'] = (int) $this->input->post('card_status');
|
|
$data['provider_status'] = $this->combo_model->getStatusCombo('card_status', $data['provider_status_value']);
|
|
if ($_POST) {
|
|
$data['name'] = trim($this->input->post('name'));
|
|
$data['client'] = trim($this->input->post('client'));
|
|
$data['token'] = trim($this->input->post('token'));
|
|
$data['code'] = trim($this->input->post('code'));
|
|
$data['access_token'] = trim($this->input->post('access_token'));
|
|
$data['active'] = $data['provider_status_value'];
|
|
/*
|
|
name | character varying(50) | not null
|
|
client | character varying(100) |
|
|
token | character varying(200) |
|
|
code | character varying(100) |
|
|
access_token | character varying(200) |
|
|
active | smallint | default 1
|
|
*/
|
|
if ($data['name'] == '' || strlen($data['name']) > 100) {
|
|
$data['message'] .= "<br/>Invalid name";
|
|
}
|
|
if (strlen($data['client']) > 100) {
|
|
$data['message'] .= "<br/>Invalid client ID";
|
|
}
|
|
if (strlen($data['token']) > 200) {
|
|
$data['message'] .= "<br/>Invalid token";
|
|
}
|
|
if (strlen($data['code']) > 100) {
|
|
$data['message'] .= "<br/>Invalid access code";
|
|
}
|
|
if (strlen($data['access_token']) > 200) {
|
|
$data['message'] .= "<br/>Invalid access token";
|
|
}
|
|
$id = $this->input->post('id');
|
|
if ($id > 0) {
|
|
// Update
|
|
$q = "UPDATE transport_providers SET name='" . pg_escape_string($data['name']) . "',
|
|
client='" . pg_escape_string($data['client']) . "',token='" . pg_escape_string($data['token']) . "',
|
|
code='" . pg_escape_string($data['code']) . "',access_token='" . pg_escape_string($data['access_token']) . "',
|
|
active=" . $data["active"] . " WHERE id=${id} RETURNING id";
|
|
} else {
|
|
// Insert
|
|
$q = "INSERT INTO transport_providers (name,client,token,code,access_token,active) VALUES(
|
|
'" . pg_escape_string($data['name']) . "',
|
|
'" . pg_escape_string($data['client']) . "',
|
|
'" . pg_escape_string($data['token']) . "',
|
|
'" . pg_escape_string($data['code']) . "',
|
|
'" . pg_escape_string($data['access_token']) . "',
|
|
" . $data["active"] . "
|
|
) RETURNING id";
|
|
}
|
|
if ($data['message'] == "") {
|
|
$r = $this->db->query($q);
|
|
$f = $r->row_array();
|
|
if ($f != NULL && isset($f["id"]) && $f["id"] > 0) {
|
|
$data["id"] = $f["id"];
|
|
$data['message'] = 'Provider ' . ($id > 0 ? 'updated' : 'created') . '!';
|
|
$data["form_button"] = 'Update';
|
|
} else {
|
|
$data['message'] = 'Failed to ' . ($id > 0 ? 'update' : 'create') . ' provider!';
|
|
}
|
|
}
|
|
} else {
|
|
$data['provider_status'] = $this->combo_model->getStatusCombo('card_status', 1);
|
|
}
|
|
$mysql = "SELECT id,concat('<a href=\"/bkoadmin/transportApps?id=',id,'\">',name,'</a>') as Name,concat('<b>Client:</b> ',client,'<br/><b>Token:</b> ',token,'<br/><b>Code:</b> ',code,'<br/><b>Access Token:</b> ',access_token) as Credentials,(CASE active WHEN 1 THEN 'Yes' ELSE 'No' END) as Active,'<input type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"return EditTransportProvider('||id||');\" value=\"Edit\" />' as action FROM transport_providers ORDER BY name";
|
|
$query = $this->read_replica->query($mysql);
|
|
$this->load->library('table');
|
|
$this->table->set_template($this->template);
|
|
$this->table->set_heading(
|
|
array('data' => 'ID', 'style' => 'width:50px'), array('data' => 'Name', 'style' => 'width:190px'), 'Credentials', array('data' => 'Active?', 'style' => 'width:50px'), array('data' => 'Action', 'style' => 'width:90px'));
|
|
$data["transporter_table"] = $this->table->generate($query);
|
|
$data["transport_providers"] = [];
|
|
$q = "SELECT * FROM transport_providers";
|
|
$r = $this->read_replica->query($q);
|
|
foreach ($r->result() as $row) {
|
|
$data["transport_providers"][$row->{'id'}] = (array) $row;
|
|
}
|
|
$q = "select b.name,a.country,a.ios_app_id,a.android_app_id,concat('<button type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"document.location=''/bkoadmin/transportApps?id=',b.id,'&app_id=',a.id,''';return false;\">Edit</button>') as Action
|
|
from transport_provider_apps a, transport_providers b where b.id=a.transport_provider_id order by b.name,a.country";
|
|
$r = $this->read_replica->query($q);
|
|
$data["transporter_apps"] = $this->table->generate($r);
|
|
} catch (Exception $e) {
|
|
$data["transporter_table"] = "";
|
|
$data["transporter_apps"] = "";
|
|
$data["message"] = $e->getMessage();
|
|
}
|
|
$this->renderCardPage('view_transporter', $data);
|
|
return 0;
|
|
}
|
|
|
|
public function DELmytransport() {
|
|
$data = array();
|
|
$data["images"] = array();
|
|
$this->renderCardPage('view_mytransport', $data);
|
|
}
|
|
|
|
public function transportApps() {
|
|
$data = [];
|
|
$id = (int) $this->input->get('id');
|
|
$app_id = (int) $this->input->get('app_id');
|
|
if ($id > 0) {
|
|
$q = "SELECT * FROM transport_providers WHERE id=${id}";
|
|
$r = $this->read_replica->query($q);
|
|
$f = $r->row_array();
|
|
if ($f != NULL && isset($f["id"]) && $f["id"] > 0) {
|
|
$data = $f;
|
|
}
|
|
}
|
|
if (count($data) < 1) {
|
|
$this->load->helper('url');
|
|
redirect('/bkoadmin/transport', 'refresh');
|
|
return 0;
|
|
}
|
|
$data["message"] = "";
|
|
$data["form_button"] = "Add";
|
|
$data["app_id"] = $app_id;
|
|
$data["country"] = "SG";
|
|
$data["ios_app_id"] = "";
|
|
$data["android_app_id"] = "";
|
|
|
|
if ($_POST) {
|
|
$data['country_value'] = trim($this->input->post('country'));
|
|
$data['ios_app_id'] = trim($this->input->post('ios_app_id'));
|
|
$data['android_app_id'] = trim($this->input->post('android_app_id'));
|
|
|
|
if (strlen($data['country_value']) != 2) {
|
|
$data['message'] .= "<br/>Invalid country";
|
|
}
|
|
if (strlen($data['ios_app_id']) > 100) {
|
|
$data['message'] .= "<br/>Invalid iOS app ID";
|
|
}
|
|
if (strlen($data['android_app_id']) > 100) {
|
|
$data['message'] .= "<br/>Invalid Android app ID";
|
|
}
|
|
$id = (int) $this->input->post('id');
|
|
$app_id = (int) $this->input->post('app_id');
|
|
if ($app_id > 0) {
|
|
// Update
|
|
$q = "UPDATE transport_provider_apps SET country='" . pg_escape_string($data["country_value"]) . "',
|
|
ios_app_id='" . pg_escape_string($data["ios_app_id"]) . "',android_app_id='" . pg_escape_string($data["android_app_id"]) . "'
|
|
WHERE id=${app_id} AND transport_provider_id=${id} RETURNING id";
|
|
} else {
|
|
// Insert
|
|
$q = "INSERT INTO transport_provider_apps (transport_provider_id,country,ios_app_id,android_app_id) VALUES(
|
|
${id},
|
|
'" . pg_escape_string($data["country_value"]) . "',
|
|
'" . pg_escape_string($data["ios_app_id"]) . "',
|
|
'" . pg_escape_string($data["android_app_id"]) . "'
|
|
) RETURNING id";
|
|
}
|
|
if ($data['message'] == "") {
|
|
$r = $this->db->query($q);
|
|
$f = $r->row_array();
|
|
if ($f != NULL && isset($f["id"]) && $f["id"] > 0) {
|
|
$data["app_id"] = $f["id"];
|
|
$data['message'] = 'Provider app ' . ($id > 0 ? 'updated' : 'created') . '!';
|
|
$data["form_button"] = 'Update';
|
|
} else {
|
|
$data['message'] = 'Failed to ' . ($id > 0 ? 'update' : 'create') . ' provider app!';
|
|
}
|
|
}
|
|
} else {
|
|
$data['country_value'] = 'SG';
|
|
}
|
|
|
|
$this->load->model('combo_model');
|
|
$this->load->library('table');
|
|
$this->table->set_template($this->template);
|
|
|
|
$data["country_select"] = $this->combo_model->getCountryCombo('country', $data['country_value']);
|
|
|
|
$q = "SELECT country,ios_app_id AS \"iOS App ID\",android_app_id AS \"Android App ID\",'<input type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"return EditTransportProviderApp('||id||');\" value=\"Edit\" />' as action FROM transport_provider_apps WHERE transport_provider_id=${id}";
|
|
$r = $this->read_replica->query($q);
|
|
$data["transporter_apps"] = $this->table->generate($r);
|
|
$data["transport_apps"] = [];
|
|
$q = "SELECT * FROM transport_provider_apps WHERE transport_provider_id=${id}";
|
|
$r = $this->read_replica->query($q);
|
|
foreach ($r->result() as $row) {
|
|
$data["transport_apps"][$row->{'id'}] = (array) $row;
|
|
}
|
|
$this->renderCardPage('view_transporter_apps', $data);
|
|
return 0;
|
|
}
|
|
|
|
public function viewcard() {
|
|
|
|
|
|
$card_id = $this->input->get('card_id');
|
|
|
|
if ($card_id != '' && $card_id > 0) {
|
|
|
|
$mysql = "SELECT * FROM main_cards WHERE id = $card_id";
|
|
$query = $this->read_replica->query($mysql);
|
|
$selected_card = $query->row_array();
|
|
|
|
$slogan_style = ($selected_card['titleshow'] == 0 || empty($selected_card["title"]) || strtolower(trim($selected_card["title"])) == 'n/a')
|
|
? 'style="display:none;"'
|
|
: '';
|
|
// 7: Active tip => show background only
|
|
$background_color = !empty($selected_card['background_color']) ? $selected_card['background_color'] : 'fff';
|
|
$card_bg = $selected_card['template']==self::TEMPLATE_ACTIVE_TIP?"background-color: #{$background_color};" :"background-image: url('{$selected_card["background_picture"]}')";
|
|
echo
|
|
"<div class=\"card-template-wrap-{$selected_card['template']}\">
|
|
<div class=\"card-bg card-template-{$selected_card['template']}\" style=\"{$card_bg}\">
|
|
<div class=\"card-bg-gradient-sub\">
|
|
<div class=\"card-bg-gradient-main\">
|
|
<div class=\"card-header-wrapper\">
|
|
<img src=\"/assets/images/cards/diamond-icon.svg\" alt=\"\" width=\"26.8px\" height=\"23.93px\">
|
|
</div>
|
|
<div class=\"card-body-wrapper\">
|
|
<p class=\"slogan\" {$slogan_style}>{$selected_card["title"]}</p>
|
|
<div class=\"relative\">
|
|
<p class=\"description\">{$selected_card["description"]}</p>
|
|
<img class=\"nav-right-icon-rocket\" src=\"/assets/images/cards/rocket.svg\" alt=\"\" width=\"60px\" height=\"auto\">
|
|
<img class=\"nav-right-icon\" src=\"/assets/images/cards/navigation-right-circle.svg\" alt=\"\" width=\"26px\" height=\"26px\">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class=\"relative-bottom\" style=\"display:none;\">
|
|
<p class=\"slogan\" {$slogan_style}>{$selected_card["title"]}</p>
|
|
<p class=\"description\">{$selected_card["description"]}</p>
|
|
<img class=\"nav-right-icon\" src=\"/assets/images/cards/black-next.svg\" alt=\"\" width=\"26px\" height=\"26px\">
|
|
</div>
|
|
</div>";
|
|
}
|
|
}
|
|
|
|
public function compare() {
|
|
$this->load->library('table');
|
|
$this->table->set_template($this->template);
|
|
|
|
$data = array();
|
|
$data["from"] = 2; //"Marina Bay Sands, 10 Bayfront Ave, Singapore 018956";
|
|
$data["to"] = 3; //"97 Meyer Road, Singapore";
|
|
$data["all"] = 1;
|
|
$data["date_from"] = date("Y-m-1", strtotime("-2 months"));
|
|
$data["date_to"] = date("Y-m-d");
|
|
if ($this->input->post()) {
|
|
$data["from"] = $this->input->post('from');
|
|
$data["to"] = $this->input->post('to');
|
|
$data["all"] = (int) $this->input->post('all');
|
|
$dates = explode(' - ', $this->input->post('daterange'));
|
|
$data["date_from"] = date("Y-m-d", strtotime($dates[0]));
|
|
$data["date_to"] = date("Y-m-d", strtotime($dates[1]));
|
|
|
|
$db_from = (int) ($data["from"]);
|
|
$db_to = (int) ($data["to"]);
|
|
|
|
$q = "select distinct
|
|
travel_date AS \"Travel Date\",
|
|
travel_date_end \"Travel Date End\",
|
|
cost AS \"Cost\",
|
|
duration AS \"Duration\",
|
|
distance AS \"Distance\",
|
|
transport_provider_id as \"Transport\"
|
|
from parsedemail_item
|
|
where dup_id is null and
|
|
location_start_id='${db_from}' and location_end_id='${db_to}'";
|
|
if ($data["all"] != 1) {
|
|
$q .= " and travel_date between '" . $data["date_from"] . "' and '" . $data["date_to"] . "'";
|
|
}
|
|
$q .= " order by travel_date";
|
|
$query = $this->read_replica->query($q);
|
|
//$this->table->set_heading(array('data' => 'Count', 'style' => 'width:10px'), 'Start Location', 'End Location');
|
|
$data['past_trips'] = $this->table->generate($query);
|
|
|
|
$bulk_data = [];
|
|
$by_vendor = [];
|
|
$day_hour = [];
|
|
foreach ($query->result() as $row) {
|
|
$bulk_data[$row->{'Travel Date'}] = $row->{'Cost'};
|
|
$by_vendor[$row->{'Travel Date'}][$row->{'Transport'}] = $row->{'Cost'};
|
|
$hr = date("H", strtotime($row->{'Travel Date'}));
|
|
if (!isset($day_hour[$hr]))
|
|
$day_hour[$hr] = [];
|
|
$day_hour[$hr][] = $row->{'Cost'};
|
|
}
|
|
|
|
$q = "select distinct
|
|
to_char(a.completed, 'yyyy-mm-dd HH24:MI:SS') AS \"Quote Date\",
|
|
to_char(a.created, 'yyyy-mm-dd HH24:MI:SS') \"Request Date\",
|
|
a.cost AS \"Cost\",
|
|
'N/A' AS \"Duration\",
|
|
'N/A' AS \"Distance\",
|
|
a.transport_provider_id as \"Transport\"
|
|
from quotes a, address b, address c
|
|
where a.cost>0 and a.completed is not null and
|
|
b.id=a.location_start_id and c.id=a.location_end_id and
|
|
b.id='${db_from}' and c.id='${db_to}'";
|
|
if ($data["all"] != 1) {
|
|
$q .= " and a.completed::date between '" . $data["date_from"] . "' and '" . $data["date_to"] . "'";
|
|
}
|
|
$q .= " order by \"Quote Date\"";
|
|
$query = $this->read_replica->query($q);
|
|
$data['quotes'] = $this->table->generate($query);
|
|
|
|
foreach ($query->result() as $row) {
|
|
$bulk_data[$row->{'Quote Date'}] = $row->{'Cost'};
|
|
$by_vendor[$row->{'Quote Date'}][$row->{'Transport'}] = $row->{'Cost'};
|
|
$hr = date("H", strtotime($row->{'Quote Date'}));
|
|
if (!isset($day_hour[$hr]))
|
|
$day_hour[$hr] = [];
|
|
$day_hour[$hr][] = $row->{'Cost'};
|
|
}
|
|
foreach ($day_hour as $hr => $val) {
|
|
asort($val);
|
|
$pk = NULL;
|
|
$pv = NULL;
|
|
foreach ($val as $k => $v) {
|
|
if ($v == $pv) {
|
|
unset($day_hour[$hr][$k]);
|
|
} else {
|
|
$pk = $k;
|
|
$pv = $v;
|
|
}
|
|
}
|
|
}
|
|
asort($day_hour);
|
|
$data["bulk_data"] = $bulk_data;
|
|
$data["by_vendor"] = $by_vendor;
|
|
$data["day_hour"] = $day_hour;
|
|
} else {
|
|
$data['past_trips'] = "";
|
|
$data['quotes'] = "";
|
|
$data["bulk_data"] = array();
|
|
$data["by_vendor"] = array();
|
|
$data["day_hour"] = array();
|
|
}
|
|
|
|
$q = "SELECT id,address FROM address ORDER BY address";
|
|
$query = $this->read_replica->query($q);
|
|
$address = [];
|
|
foreach ($query->result() as $row) {
|
|
$address[$row->{"id"}] = $row->{"address"};
|
|
}
|
|
$data["address"] = $address;
|
|
|
|
$this->renderCardPage('view_compare', $data);
|
|
}
|
|
|
|
public function country() {
|
|
global $savvyext;
|
|
$data['storage'] = $savvyext->cfgReadChar('system.storage_url');
|
|
$data["message"] = "";
|
|
if ($this->input->post()) {
|
|
$data = $this->countryImageUpload($data);
|
|
}
|
|
$data["images"] = array();
|
|
$data["page_title"] = "Country";
|
|
|
|
$this->load->library('pagination');
|
|
$config = array();
|
|
$q = "SELECT * FROM country a LEFT JOIN card_images b ON (b.id=a.top_image) ORDER BY a.country";
|
|
$query = $this->read_replica->query($q);
|
|
$config["total_rows"] = $query->num_rows();
|
|
$config["base_url"] = '/bkoadmin/country';
|
|
$config["per_page"] = 10;
|
|
$config["uri_segment"] = 3;
|
|
$config["num_links"] = 5;
|
|
$config['full_tag_open'] = "<ul class='pagination'>";
|
|
$config['full_tag_close'] = "</ul>";
|
|
$config['num_tag_open'] = '<li>';
|
|
$config['num_tag_close'] = '</li>';
|
|
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
|
|
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
|
|
$config['next_tag_open'] = "<li>";
|
|
$config['next_tagl_close'] = "</li>";
|
|
$config['prev_tag_open'] = "<li>";
|
|
$config['prev_tagl_close'] = "</li>";
|
|
$config['first_tag_open'] = "<li>";
|
|
$config['first_tagl_close'] = "</li>";
|
|
$config['last_tag_open'] = "<li>";
|
|
$config['last_tagl_close'] = "</li>";
|
|
$this->pagination->initialize($config);
|
|
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
|
|
$page = is_numeric($page) ? $page : 0;
|
|
$data["links"] = $this->pagination->create_links();
|
|
|
|
$q = "SELECT a.*,b.uniqueid,b.name,b.format FROM country a LEFT JOIN card_images b ON (b.id=a.top_image) ORDER BY a.country";
|
|
$q .= " LIMIT " . $config["per_page"] . " OFFSET " . $page;
|
|
$r = $this->read_replica->query($q);
|
|
$countries = [];
|
|
foreach ($r->result() as $row) {
|
|
$countries[] = (array) $row;
|
|
}
|
|
$data["countries"] = $countries;
|
|
$this->renderCardPage('view_country', $data);
|
|
}
|
|
|
|
private function countryImageUpload($data) {
|
|
$id = (int) $this->input->post('id');
|
|
$catid = (int) $this->input->post('catid'); // 4 - adminsavvy_card_image_category_country
|
|
if ($id > 0 && $catid > 0) {
|
|
$this->load->library('uploadhelper');
|
|
$q = "SELECT code FROM country WHERE id=" . $id;
|
|
$r = $this->read_replica->query($q);
|
|
$f = $r->result_array()[0];
|
|
ob_start();
|
|
$data = $this->uploadhelper->cardimagesPost($data, $this, $f["code"]);
|
|
$str = ob_get_clean();
|
|
if (substr($str, 0, 8) == 'Uploaded' && (!isset($data["card_image_id"]) || $data["card_image_id"] < 1)) {
|
|
if (preg_match('/^Uploaded ([a-zA-Z0-9]+) to gs:\/\/(.*)\/(.*)\.(.*)$/', $str, $arr) == 1 &&
|
|
count($arr) > 4 && $arr[2] == 'adminsavvy_card_image_category_country') {
|
|
$uniqueId = pg_escape_string($arr[3]);
|
|
$fmt = $arr[4];
|
|
$q = "SELECT id FROM card_images WHERE uniqueid='${uniqueId}'";
|
|
$r = $this->read_replica->query($q);
|
|
$f = $r->row_array();
|
|
if ($f != NULL && is_array($f) && $f["id"] > 0) {
|
|
$data["card_image_id"] = $f["id"];
|
|
}
|
|
}
|
|
}
|
|
// Uploaded phpGUIDjh to gs://adminsavvy_card_image_category_country/RATEMKrK9B.jpg
|
|
if (isset($data["card_image_id"]) && $data["card_image_id"] > 0) {
|
|
$q = "UPDATE country SET top_image='" . $data["card_image_id"] . "' WHERE id=${id}";
|
|
$this->db->query($q);
|
|
} else if (!isset($data["message"]) || $data["message"] == "") {
|
|
$data["message"] = "Failed to save image";
|
|
}
|
|
} else {
|
|
$data["message"] = "Invalid ID";
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function countryStatus() {
|
|
$id = (int) $this->input->get('id');
|
|
$status = (int) $this->input->get('status');
|
|
if ($id > 0) {
|
|
$q = "UPDATE country SET status=${status} WHERE id=${id}";
|
|
$r = $this->db->query($q);
|
|
echo "Status updated";
|
|
} else {
|
|
echo "Invalid ID!";
|
|
}
|
|
}
|
|
|
|
public function countryImageDelete() {
|
|
$data = [];
|
|
$id = (int) $this->input->get('id');
|
|
if ($id > 0) {
|
|
$q = "SELECT top_image FROM country WHERE id='${id}'";
|
|
$r = $this->read_replica->query($q);
|
|
$f = $r->row_array();
|
|
if ($f != NULL && is_array($f) && $f["top_image"] > 0) {
|
|
$data["id"] = $f["top_image"];
|
|
$this->load->library('uploadhelper');
|
|
$data = $this->uploadhelper->deleteCardimageFile($data, $this, 'country', 'top_image');
|
|
if (isset($data["deleted"]) && $data["deleted"] > 0) {
|
|
$q = "UPDATE country SET top_image=NULL WHERE top_image='" . $data["deleted"] . "'";
|
|
$this->db->query($q);
|
|
echo "Image deleted";
|
|
} else if (!isset($data["message"]) || $data["message"] == "") {
|
|
echo "Delete failed!";
|
|
} else {
|
|
echo $data["message"];
|
|
}
|
|
} else {
|
|
echo "Not top image found";
|
|
}
|
|
} else {
|
|
echo "Invalid ID!";
|
|
}
|
|
}
|
|
|
|
private function getAddressByAddress($addr) {
|
|
$db_addr = pg_escape_string($addr);
|
|
$q = "SELECT * FROM address WHERE lower(address)=lower('${db_addr}')";
|
|
$r = $this->read_replica->query($q);
|
|
if ($row = $r->result()) {
|
|
//var_dump($row[0]);
|
|
return $row[0];
|
|
}
|
|
// TODO: Geocoding
|
|
return NULL;
|
|
}
|
|
|
|
private function getAddress($id) {
|
|
$db_id = (int) $id;
|
|
$q = "SELECT * FROM address WHERE id=${id}";
|
|
$r = $this->read_replica->query($q);
|
|
if ($row = $r->result()) {
|
|
//var_dump($row[0]);
|
|
return $row[0];
|
|
}
|
|
// TODO: Geocoding
|
|
return NULL;
|
|
}
|
|
|
|
private function geofenceTrip($areas, $data_from, $data_to, $data) {
|
|
$str = "Geofencing failed!";
|
|
$travel_time = 0;
|
|
$distance = 0;
|
|
$min_cost = PHP_INT_MAX;
|
|
$max_cost = 0;
|
|
$avg_cost = 0;
|
|
$avg_cnt = 0;
|
|
$route_overlay = [];
|
|
// Get Area
|
|
$postal_from = substr($data_from->{"postal"}, 0, 2);
|
|
$postal_to = substr($data_to->{"postal"}, 0, 2);
|
|
$area_from = array();
|
|
$area_to = array();
|
|
foreach ($areas as $f) {
|
|
$codes = json_decode($f->{"postal_code"}, true);
|
|
foreach ($codes["postal_code"] as $code) {
|
|
if ($postal_from == $code) {
|
|
$area_from = $f;
|
|
$str_from = "Travelling from '" . $f->{"name"} . "' (" . $f->{"id"} . ") ";
|
|
}
|
|
if ($postal_to == $code) {
|
|
$area_to = $f;
|
|
$str_to = " to '" . $f->{"name"} . "' (" . $f->{"id"} . ") ";
|
|
}
|
|
}
|
|
}
|
|
$history = [];
|
|
if (isset($area_from->{"postal_code"}) && isset($area_to->{"postal_code"})) {
|
|
try {
|
|
// Get distance
|
|
$distance = $this->distance_between_two_gps_coordinates(
|
|
$data_from->{"latitude"}, $data_from->{"longitude"}, $data_to->{"latitude"}, $data_to->{"longitude"}, 'K');
|
|
$resp = $this->geocode($data_from->{"address"}, $data_to->{"address"});
|
|
$route_overlay = $resp["options"]["route_overlay"];
|
|
$travel_time = $resp["options"]["travel_time"] / 60; //840;
|
|
$distance = $resp["options"]["travel_distance"] / 1000.0; //7043
|
|
$str = $str_from . $str_to . ' for ' . sprintf("%0.02f", $distance) . ' km';
|
|
$str .= ' and ' . ((int) $travel_time) . 'minutes';
|
|
// Get history
|
|
$postals_from = json_decode($area_from->{"postal_code"}, true)["postal_code"];
|
|
$postals_to = json_decode($area_to->{"postal_code"}, true)["postal_code"];
|
|
$postals_from_str = implode("','", $postals_from);
|
|
$postals_to_str = implode("','", $postals_to);
|
|
$q = "SELECT a.*, b.postal AS spostal, b.address AS saddress, c.postal AS epostal, c.address AS eaddress
|
|
FROM parsedemail_item a
|
|
LEFT JOIN address b ON (b.id=a.location_start_id)
|
|
LEFT JOIN address c ON (c.id=a.location_end_id)
|
|
WHERE substring(b.postal from 1 for 2) IN ('${postals_from_str}')
|
|
AND substring(c.postal from 1 for 2) IN ('${postals_to_str}')
|
|
AND a.dup_id IS NULL
|
|
ORDER BY a.distance";
|
|
$r = $this->read_replica->query($q);
|
|
$k1 = $distance - $data["threshold"];
|
|
$k2 = $distance + $data["threshold"];
|
|
foreach ($r->result() as $row) {
|
|
$history[] = (array) $row;
|
|
$c = $row->{"cost"};
|
|
$d = $row->{"distance"};
|
|
if (is_numeric($d) && is_numeric($c) && $c > 0 && $k1 <= $d && $d <= $k2) {
|
|
$avg_cnt++;
|
|
$avg_cost += $c;
|
|
if ($max_cost < $c)
|
|
$max_cost = $c;
|
|
if ($min_cost > $c)
|
|
$min_cost = $c;
|
|
}
|
|
}
|
|
$avg_cost = $avg_cost / $avg_cnt;
|
|
$str .= '<br/>';
|
|
$str .= 'Average trip cost is SGD$' . sprintf("%0.02f", $avg_cost) . ' based of ' . $avg_cnt . ' trips matching +/- ' . $data["threshold"] . 'km';
|
|
$str .= '<br/>';
|
|
$str .= 'Minimal trip cost is SDG$' . sprintf("%0.02f", $min_cost) . ', maximal trip cost is SDG$' . sprintf("%0.02f", $max_cost);
|
|
} catch (Exception $e) {
|
|
error_log($e->getMessage());
|
|
}
|
|
}
|
|
$data["geofence"] = $str;
|
|
$data["area_from"] = $area_from;
|
|
$data["area_to"] = $area_to;
|
|
$data["history"] = $history;
|
|
$data["distance"] = $distance;
|
|
$data["travel_time"] = $travel_time;
|
|
$data["route_overlay"] = $route_overlay;
|
|
$data["min_cost"] = $min_cost;
|
|
$data["max_cost"] = $max_cost;
|
|
$data["avg_cost"] = $avg_cost;
|
|
$data["avg_cnt"] = $avg_cnt;
|
|
return $data;
|
|
}
|
|
|
|
public function geofencing() {
|
|
$this->load->library('table');
|
|
$this->table->set_template($this->template);
|
|
|
|
$data = array("geofence" => "");
|
|
$data["from"] = 2; //"Marina Bay Sands, 10 Bayfront Ave, Singapore 018956";
|
|
$data["to"] = 3; //"97 Meyer Road, Singapore";
|
|
$data["threshold"] = 1.1; // +/- km
|
|
|
|
$areas = array();
|
|
$q = 'SELECT a.*,b.name AS sector,c.name AS region FROM singapore_districts a, singapore_sectors b, singapore_regions c WHERE b.id=a.sector_id AND c.id=a.region_id';
|
|
$query = $this->read_replica->query($q);
|
|
foreach ($query->result() as $row) {
|
|
$areas[] = $row;
|
|
}
|
|
$data['areas'] = $areas;
|
|
|
|
if ($this->input->post()) {
|
|
$data["from"] = $this->input->post('from');
|
|
$data["to"] = $this->input->post('to');
|
|
$data["threshold"] = $this->input->post('threshold');
|
|
$data["data_from"] = $this->getAddress($data["from"]);
|
|
$data["data_to"] = $this->getAddress($data["to"]);
|
|
$data = $this->geofenceTrip($areas, $data["data_from"], $data["data_to"], $data);
|
|
}
|
|
|
|
$q = "SELECT id, address FROM address ORDER BY address";
|
|
$query = $this->read_replica->query($q);
|
|
$address = [];
|
|
foreach ($query->result() as $row) {
|
|
$address[$row->{"id"}] = $row->{"address"};
|
|
}
|
|
$data["address"] = $address;
|
|
|
|
$this->renderCardPage('view_geofencing', $data);
|
|
}
|
|
|
|
private function getCardFilterByFields($name, $curVal = '', $custom_options = []) {
|
|
/**
|
|
* Prepare filter options for cards fields
|
|
*/
|
|
$options = [];
|
|
$options[] = [
|
|
"id" => '',
|
|
"name" => 'All'
|
|
];
|
|
$options[] = [
|
|
"id" => 'name',
|
|
"name" => 'Name',
|
|
];
|
|
$options[] = [
|
|
"id" => 'title',
|
|
"name" => 'Title',
|
|
];
|
|
$options[] = [
|
|
"id" => 'short_title',
|
|
"name" => 'Short Title',
|
|
];
|
|
$options[] = [
|
|
"id" => 'description',
|
|
"name" => 'Desc',
|
|
];
|
|
$options[] = [
|
|
"id" => 'button1_action',
|
|
"name" => 'Action',
|
|
];
|
|
|
|
$elem = '<select class="form-control" name="' . $name . '" style="width: 100%;">';
|
|
|
|
foreach ($options as $opt) {
|
|
if (!empty($custom_options)) {
|
|
foreach ($custom_options as $custom_opt) {
|
|
if ($opt['id'] == $custom_opt['id']) {
|
|
$opt['name'] = $custom_opt['name'];
|
|
}
|
|
}
|
|
}
|
|
|
|
$selected = $opt['id'] == $curVal ? 'selected' : '';
|
|
$elem .= '<option value="' . $opt['id'] . '"' . $selected . '>' . $opt['name'] . "</option>";
|
|
}
|
|
|
|
$elem .= "</select>";
|
|
return $elem;
|
|
}
|
|
|
|
private function distance_between_two_gps_coordinates($lat1, $lon1, $lat2, $lon2, $unit) {
|
|
if (($lat1 == $lat2) && ($lon1 == $lon2)) {
|
|
return 0;
|
|
} else {
|
|
$theta = $lon1 - $lon2;
|
|
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
|
|
$dist = acos($dist);
|
|
$dist = rad2deg($dist);
|
|
$miles = $dist * 60 * 1.1515;
|
|
$unit = strtoupper($unit);
|
|
|
|
if ($unit == "K") {
|
|
return ($miles * 1.609344);
|
|
} else if ($unit == "N") {
|
|
return ($miles * 0.8684);
|
|
} else {
|
|
return $miles;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function geocode($addrFrom, $addrTo) {
|
|
global $savvyext;
|
|
$httpAuthToken = $savvyext->cfgReadChar('system.oauth2_token');
|
|
$encryptionAlg = $savvyext->cfgReadChar('encryption.algorithm');
|
|
$encryptionKey = $savvyext->cfgReadChar('encryption.key');
|
|
$encryptionIV = $savvyext->cfgReadChar('encryption.iv');
|
|
$api_url = $savvyext->cfgReadChar('system.api_url');
|
|
|
|
$payload = "{
|
|
\"addresses\":[
|
|
{\"address\":\"${addrFrom}\",\"type\":1},
|
|
{\"address\":\"${addrTo}\",\"type\":2}
|
|
],
|
|
\"options\":{
|
|
\"travel_time\": true,
|
|
\"route_overlay\": true
|
|
}
|
|
}";
|
|
$encrypted_payload = bin2hex(
|
|
openssl_encrypt(
|
|
$payload, $encryptionAlg, $encryptionKey, OPENSSL_RAW_DATA, $encryptionIV
|
|
));
|
|
|
|
$postdata = "{\"encrypted_payload\": \"${encrypted_payload}\"}";
|
|
|
|
$url = $api_url . "/trips/api/geocode";
|
|
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
'Content-Type: application/json',
|
|
'Content-Length: ' . strlen($postdata),
|
|
'Authorization: Server-Token ' . $httpAuthToken,
|
|
"client_id: BackOffice"
|
|
)
|
|
);
|
|
|
|
$body = curl_exec($ch);
|
|
$result = json_decode($body, true);
|
|
|
|
$payload = openssl_decrypt(
|
|
hex2bin(
|
|
$result['payload']
|
|
), $encryptionAlg, $encryptionKey, OPENSSL_RAW_DATA, $encryptionIV
|
|
);
|
|
return json_decode($payload, true);
|
|
}
|
|
|
|
var $template2 = array(
|
|
'table_open' => "<table style='background-color:aliceblue' class='table table-striped table-hover table-bordered table-condensed'>",
|
|
'thead_open' => '<thead class=\'bg-indigo\'>',
|
|
'thead_close' => '</thead>',
|
|
'heading_row_start' => '<tr>',
|
|
'heading_row_end' => '</tr>',
|
|
'heading_cell_start' => '<th>',
|
|
'heading_cell_end' => '</th>',
|
|
'tbody_open' => '<tbody>',
|
|
'tbody_close' => '</tbody>',
|
|
'row_start' => '<tr style=\'padding:3px;\'>',
|
|
'row_end' => '</tr>',
|
|
'cell_start' => '<td>',
|
|
'cell_end' => '</td>',
|
|
'row_alt_start' => '<tr style=\'padding:3px;\'>',
|
|
'row_alt_end' => '</tr>',
|
|
'cell_alt_start' => '<td>',
|
|
'cell_alt_end' => '</td>',
|
|
'table_close' => '</table>'
|
|
);
|
|
|
|
// card update refresh fragments
|
|
private function refresh_card_items( $newData ) {
|
|
ob_start();
|
|
printf('
|
|
<b>Name: </b>%s <br>
|
|
<b>Title: </b>%s <br>
|
|
<b>Short Title: </b>%s <br>
|
|
<b>Desc: </b>%s <br>
|
|
<b>Button: </b>%s <br>
|
|
<b>Button Text: </b>%s <br>
|
|
<b>Action: %s
|
|
',
|
|
$newData['name'], $newData['title'], $newData['short_title'], $newData['description'], $newData['button1'], $newData['button1_text'], $newData['button1_action']
|
|
);
|
|
$card_section = ob_get_clean();
|
|
|
|
return $card_section;
|
|
}
|
|
}
|