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 .= "
Invalid or Duplicate Logic in use";
// }
}
if ($in['blog_id'] === '') {
$message .= "
Blog Article ID incorrect";
$error_ids[] = 'card_blog_id';
}
if ($in['card_behavior'] === '') {
$message .= "
Card Behavior incorrect";
$error_ids[] = 'card_behavior';
}
if ($in['name'] == '' || strlen($in['name']) > 100) {
$message .= "
Incorrect Card ID";
$error_ids[] = 'cardName';
}
if ($in['title'] == '' || strlen($in['title']) > 100) {
$message .= "
Invalid title";
$error_ids[] = 'cardTitle';
}
if ($in['short_title'] == '' || strlen($in['short_title']) > 35) {
$message .= "
Invalid short title";
$error_ids[] ='cardShortTitle';
}
if ($in['description'] == '' || strlen($in['description']) > 250) {
$message .= "
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 .= "
Invalid background color - please input background color for Active Tip";
}
}else{
$message .= "
Invalid background picture";
}
}
if ($in['button1'] == '' || strlen($in['button1']) > 35) {
$message .= "
Invalid button1";
$error_ids[] ='button1';
}
if ($in['button1_text'] == '' || strlen($in['button1_text']) > 35) {
$message .= "
Invalid button1 text";
$error_ids[] ='button1_text';
}
if ($in['button1_action'] == '' || strlen($in['button1_action']) > 15) {
$message .= "
Invalid category";
}
if ($data['card_canexpire_value'] != '' && $data['card_canexpire_value'] == 1 &&
($data['card_expiration'] == '' || strtotime($data['card_expiration']) < time())) {
$message .= "
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 'Yes'
ELSE 'No' END
AS Instant,
'' AS Release ,
'' 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 .= "
Invalid name";
}
if ($in['title'] == '' || strlen($in['title']) > 100) {
$message .= "
Invalid title";
}
if ($in['short_title'] == '' || strlen($in['short_title']) > 35) {
$message .= "
Invalid short title";
}
if ($in['description'] == '' || strlen($in['description']) > 250) {
$message .= "
Invalid description";
}
if ($in['background_picture'] == '' || strlen($in['background_picture']) > 150) {
$message .= "
Invalid background picture";
}
if ($in['button1'] == '' || strlen($in['button1']) > 35) {
$message .= "
Invalid button1";
}
if ($in['button1_text'] == '' || strlen($in['button1_text']) > 35) {
$message .= "
Invalid button1 text";
}
if ($in['button1_action'] == '' || strlen($in['button1_action']) > 15) {
$message .= "
Invalid category";
}
if ($data['card_canexpire_value'] != '' && $data['card_canexpire_value'] == 1 &&
($data['card_expiration'] == '' || strtotime($data['card_expiration']) < time())) {
$message .= "
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 .= "
Invalid name";
}
if ($in['title'] == '' || strlen($in['title']) > 100) {
$message .= "
Invalid title";
}
if ($in['short_title'] == '' || strlen($in['short_title']) > 35) {
$message .= "
Invalid short title";
}
if ($in['description'] == '' || strlen($in['description']) > 250) {
$message .= "
Invalid description";
}
if ($in['background_picture'] == '' || strlen($in['background_picture']) > 150) {
$message .= "
Invalid background picture";
}
if ($in['button1'] == '' || strlen($in['button1']) > 35) {
$message .= "
Invalid button1";
}
if ($in['button1_text'] == '' || strlen($in['button1_text']) > 35) {
$message .= "
Invalid button1 text";
}
if ($in['button1_action'] == '' || strlen($in['button1_action']) > 15) {
$message .= "
Invalid category";
}
if ($data['card_canexpire_value'] != '' && $data['card_canexpire_value'] == 1 &&
($data['card_expiration'] == '' || strtotime($data['card_expiration']) < time())) {
$message .= "
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 .= "
Invalid name";
}
if ($in['title'] == '' || strlen($in['title']) > 100) {
$message .= "
Invalid title";
}
if ($in['short_title'] == '' || strlen($in['short_title']) > 35) {
$message .= "
Invalid short title";
}
if ($in['description'] == '' || strlen($in['description']) > 250) {
$message .= "
Invalid description";
}
if ($in['background_picture'] == '' || strlen($in['background_picture']) > 150) {
$message .= "
Invalid background picture";
}
if ($in['button1'] == '' || strlen($in['button1']) > 35) {
$message .= "
Invalid button1";
}
if ($in['button1_text'] == '' || strlen($in['button1_text']) > 35) {
$message .= "
Invalid button1 text";
}
if ($in['button1_action'] == '' || strlen($in['button1_action']) > 15) {
$message .= "
Invalid category";
}
if ($data['card_canexpire_value'] != '' && $data['card_canexpire_value'] == 1 &&
($data['card_expiration'] == '' || strtotime($data['card_expiration']) < time())) {
$message .= "
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'] = "
{$selected_card["title"]}
{$selected_card["description"]}
| ', 'heading_cell_end' => ' | ', 'tbody_open' => '', 'tbody_close' => '', 'row_start' => '
|---|
| ', 'cell_end' => ' | ', 'row_alt_start' => '
| ', 'cell_alt_end' => ' | ', 'table_close' => '