first commit
This commit is contained in:
Vendored
BIN
Binary file not shown.
+386
@@ -0,0 +1,386 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
include_once __DIR__ . '/../../middlewares/Token_middleware.php';
|
||||
include_once __DIR__ . '/../../middlewares/Token_acl_middleware.php';
|
||||
include_once __DIR__ . '/../../middlewares/Maintenance_middleware.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* API Portal Abstract Controller
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*/
|
||||
class Admin_api_controller extends CI_Controller
|
||||
{
|
||||
protected $_model_file = NULL;
|
||||
|
||||
public $_valid_roles = [2];
|
||||
public $_user_id = 0;
|
||||
public $_role_id = 0;
|
||||
|
||||
protected $_supported_formats = [
|
||||
'json' => 'application/json',
|
||||
'test' => 'application/json',
|
||||
'array' => 'application/json',
|
||||
'csv' => 'application/csv',
|
||||
'html' => 'text/html',
|
||||
'jsonp' => 'application/javascript',
|
||||
'php' => 'text/plain',
|
||||
'xml' => 'application/xml'
|
||||
];
|
||||
|
||||
public $_format = 'json';
|
||||
|
||||
protected $_test_mode = FALSE;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->config->load('setting');
|
||||
$this->_setting = $this->config->item('setting');
|
||||
|
||||
$this->_run_middlewares();
|
||||
|
||||
$this->load->database();
|
||||
|
||||
if (!is_null($this->_model_file))
|
||||
{
|
||||
$this->load->model($this->_model_file);
|
||||
}
|
||||
}
|
||||
|
||||
protected function _middleware()
|
||||
{
|
||||
return [
|
||||
'token',
|
||||
'token_acl',
|
||||
'maintenance'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Controller into test mode
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_test_mode ()
|
||||
{
|
||||
$this->_test_mode = TRUE;
|
||||
$this->_format = 'test';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render api output
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param number $code
|
||||
* @return string
|
||||
*/
|
||||
public function render($data, $code)
|
||||
{
|
||||
http_response_code($code);
|
||||
header('Content-Type: ' . $this->_supported_formats[$this->_format]);
|
||||
switch ($this->_format)
|
||||
{
|
||||
case 'json':
|
||||
return $this->output->set_content_type($this->_supported_formats[$this->_format])
|
||||
->set_status_header($code)
|
||||
->set_output(json_encode($data));
|
||||
break;
|
||||
case 'test':
|
||||
return $data;
|
||||
break;
|
||||
default:
|
||||
return '<pre>' . print_r($data, TRUE) . '</pre>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User token invalid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function unauthorize_error_message()
|
||||
{
|
||||
return $this->output->set_content_type($this->_supported_formats[$this->_format])
|
||||
->set_status_header(401)
|
||||
->set_output(json_encode([
|
||||
'code' => 401,
|
||||
'success' => FALSE,
|
||||
'message' => 'invalid credentials'
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* User Role invalid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function unauthorize_resource_error_message()
|
||||
{
|
||||
return $this->output->set_content_type($this->_supported_formats[$this->_format])
|
||||
->set_status_header(406)
|
||||
->set_output(json_encode([
|
||||
'code' => 406,
|
||||
'success' => FALSE,
|
||||
'message' => 'cannot access resource'
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Success API Call
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function success($success)
|
||||
{
|
||||
$success['code'] = 200;
|
||||
$success['success'] = TRUE;
|
||||
return $this->output->set_content_type($this->_supported_formats[$this->_format])
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($success));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid form input
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _render_validation_error ()
|
||||
{
|
||||
$data = [];
|
||||
$data['code'] = 403;
|
||||
$data['success'] = FALSE;
|
||||
$data['error'] = $this->form_validation->error_array();
|
||||
return $this->output->set_content_type($this->_supported_formats[$this->_format])
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render Custom Error
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _render_custom_error ($errors)
|
||||
{
|
||||
$data = [];
|
||||
$data['code'] = 403;
|
||||
$data['success'] = FALSE;
|
||||
$data['error'] = $errors;
|
||||
return $this->output->set_content_type($this->_supported_formats[$this->_format])
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dl($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : <pre>' . print_r($data, TRUE) . '</pre>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug json Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dj($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : ' . json_encode($data));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Session
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_session()
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
return $_SESSION;
|
||||
}
|
||||
|
||||
$session = $this->config->item('session_test');
|
||||
|
||||
if (!$session)
|
||||
{
|
||||
$session = [];
|
||||
}
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Session Field
|
||||
*
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function set_session($field, $value)
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
$_SESSION[$field] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$session = $this->config->item('session_test');
|
||||
if (!$session)
|
||||
{
|
||||
$session = [];
|
||||
}
|
||||
$session[$field] = $value;
|
||||
$this->config->set_item('session_test', $session);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Session
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function destroy_session()
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
unset($_SESSION);
|
||||
session_unset();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->config->set_item('session_test', []);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to send Emails given slug, payload and email
|
||||
*
|
||||
* @param string $slug
|
||||
* @param mixed $payload
|
||||
* @param string $email
|
||||
* @return void
|
||||
*/
|
||||
protected function _send_email_notification($slug, $payload, $email)
|
||||
{
|
||||
$this->load->model('email_model');
|
||||
$this->load->library('mail_service');
|
||||
$this->mail_service->set_adapter('smtp');
|
||||
$email_template = $this->email_model->get_template($slug, $payload);
|
||||
|
||||
if ($email_template)
|
||||
{
|
||||
$from = $this->config->item('from_email');
|
||||
return $this->mail_service->send($from, $email, $email_template->subject, $email_template->html);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to send Sms given slug, payload and phone #
|
||||
*
|
||||
* @param string $slug
|
||||
* @param mixed $payload
|
||||
* @param string $to
|
||||
* @return void
|
||||
*/
|
||||
protected function _send_sms_notification($slug, $payload, $to)
|
||||
{
|
||||
$this->load->model('sms_model');
|
||||
$this->load->library('sms_service');
|
||||
$this->sms_service->set_adapter('sms');
|
||||
$sms_template = $this->sms_model->get_template($slug, $payload);
|
||||
|
||||
if ($sms_template)
|
||||
{
|
||||
return $this->sms_service->send($to, $sms_template->content);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to send Push notification
|
||||
*
|
||||
* @param string $slug
|
||||
* @param mixed $payload
|
||||
* @param string $to
|
||||
* @return void
|
||||
*/
|
||||
protected function _send_push_notification($device_type, $device_id, $title, $message, $image)
|
||||
{
|
||||
$this->load->library('push_notification_service');
|
||||
$this->push_notification_service->init();
|
||||
return $this->push_notification_service->send($device_type, $device_id, $title, $message, $image);
|
||||
}
|
||||
|
||||
protected function _run_middlewares ()
|
||||
{
|
||||
$middlewares = [
|
||||
'token' => new Token_middleware($this, $this->config),
|
||||
'token_acl' => new Token_acl_middleware($this, $this->config),
|
||||
'maintenance' => new Maintenance_middleware($this, $this->config)
|
||||
];
|
||||
|
||||
foreach ($this->_middleware() as $middleware_key)
|
||||
{
|
||||
if (isset($middlewares[$middleware_key]))
|
||||
{
|
||||
$result = $middlewares[$middleware_key]->run();
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get_user_id ()
|
||||
{
|
||||
return $this->_user_id;
|
||||
}
|
||||
|
||||
public function set_user_id ($user_id)
|
||||
{
|
||||
$this->_user_id = $user_id;
|
||||
}
|
||||
|
||||
public function get_role_id ()
|
||||
{
|
||||
return $this->_role_id;
|
||||
}
|
||||
|
||||
public function set_role_id ($role_id)
|
||||
{
|
||||
$this->_role_id = $role_id;
|
||||
}
|
||||
|
||||
public function get_valid_role ()
|
||||
{
|
||||
return $this->_valid_roles;
|
||||
}
|
||||
|
||||
public function get_setting()
|
||||
{
|
||||
return $this->_setting;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Attribute_type Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_attribute_type_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'attribute_type_model';
|
||||
public $_page_name = 'Attribute Type';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Attribute_type_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Attribute_type_admin_list_paginate_view_model(
|
||||
$this->attribute_type_model,
|
||||
$this->pagination,
|
||||
'/admin/attribute_type/0');
|
||||
$this->_data['view_model']->set_heading('Attribute Type');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_type(($this->input->get('type', TRUE) != NULL) ? $this->input->get('type', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_field(($this->input->get('field', TRUE) != NULL) ? $this->input->get('field', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_options(($this->input->get('options', TRUE) != NULL) ? $this->input->get('options', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'type' => $this->_data['view_model']->get_type(),
|
||||
'field' => $this->_data['view_model']->get_field(),
|
||||
'options' => $this->_data['view_model']->get_options(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->attribute_type_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/attribute_type/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->attribute_type_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Attribute_type', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Attribute_type_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->attribute_type_model->set_form_validation(
|
||||
$this->form_validation, $this->attribute_type_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Attribute_type_admin_add_view_model($this->attribute_type_model);
|
||||
$this->_data['view_model']->set_heading('Attribute Type');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/Attribute_typeAdd', $this->_data);
|
||||
}
|
||||
|
||||
$type = $this->input->post('type', TRUE);
|
||||
$field = $this->input->post('field', TRUE);
|
||||
$options = $this->input->post('options', TRUE);
|
||||
|
||||
$result = $this->attribute_type_model->create([
|
||||
'type' => $type,
|
||||
'field' => $field,
|
||||
'options' => $options,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/attribute_type/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/Attribute_typeAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->attribute_type_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/attribute_type/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Attribute_type_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->attribute_type_model->set_form_validation(
|
||||
$this->form_validation, $this->attribute_type_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Attribute_type_admin_edit_view_model($this->attribute_type_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Attribute Type');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/Attribute_typeEdit', $this->_data);
|
||||
}
|
||||
|
||||
$type = $this->input->post('type', TRUE);
|
||||
$field = $this->input->post('field', TRUE);
|
||||
$options = $this->input->post('options', TRUE);
|
||||
|
||||
$result = $this->attribute_type_model->edit([
|
||||
'type' => $type,
|
||||
'field' => $field,
|
||||
'options' => $options,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/attribute_type/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/Attribute_typeEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->attribute_type_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/attribute_type/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Attribute_type_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Attribute_type_admin_view_view_model($this->attribute_type_model);
|
||||
$this->_data['view_model']->set_heading('Attribute Type');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/Attribute_typeView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->attribute_type_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->attribute_type_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function bulk_delete()
|
||||
{
|
||||
|
||||
$bulk_items = $this->input->post('bulk_items');
|
||||
foreach ($bulk_items as $key => $id) {
|
||||
$this->attribute_type_model->real_delete($id);
|
||||
}
|
||||
echo 'success';
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Cart Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_cart_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'cart_model';
|
||||
public $_page_name = 'Cart';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Cart_admin_list_paginate_view_model.php';
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
$session = $this->get_session();
|
||||
$where = [];
|
||||
$this->_data['view_model'] = new Cart_admin_list_paginate_view_model(
|
||||
$this->cart_model,
|
||||
$this->pagination,
|
||||
'/admin/cart/0');
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
$this->_data['view_model']->set_total_rows($this->cart_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/cart/0');
|
||||
$this->_data['view_model']->set_list($this->cart_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Cart', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Cart_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->cart_model->set_form_validation(
|
||||
$this->form_validation, $this->cart_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Cart_admin_add_view_model($this->cart_model);
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/CartAdd', $this->_data);
|
||||
}
|
||||
|
||||
$product_id = $this->input->post('product_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$session_id = $this->input->post('session_id', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$quantity = $this->input->post('quantity', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
|
||||
$result = $this->cart_model->create([
|
||||
'product_id' => $product_id,
|
||||
'user_id' => $user_id,
|
||||
'session_id' => $session_id,
|
||||
'subtotal' => $subtotal,
|
||||
'quantity' => $quantity,
|
||||
'total' => $total,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/cart/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/CartAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->cart_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/cart/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Cart_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->cart_model->set_form_validation(
|
||||
$this->form_validation, $this->cart_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Cart_admin_edit_view_model($this->cart_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/CartEdit', $this->_data);
|
||||
}
|
||||
|
||||
$product_id = $this->input->post('product_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$session_id = $this->input->post('session_id', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$quantity = $this->input->post('quantity', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
|
||||
$result = $this->cart_model->edit([
|
||||
'product_id' => $product_id,
|
||||
'user_id' => $user_id,
|
||||
'session_id' => $session_id,
|
||||
'subtotal' => $subtotal,
|
||||
'quantity' => $quantity,
|
||||
'total' => $total,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/cart/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/CartEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->cart_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/cart/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Cart_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Cart_admin_view_view_model($this->cart_model);
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/CartView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$model = $this->cart_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/cart/0');
|
||||
}
|
||||
|
||||
$result = $this->cart_model->delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
return $this->redirect('/admin/cart/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->error('Error');
|
||||
return redirect('/admin/cart/0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Category Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_category_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'category_model';
|
||||
public $_page_name = 'Category';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Category_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Category_admin_list_paginate_view_model(
|
||||
$this->category_model,
|
||||
$this->pagination,
|
||||
'/admin/category/0');
|
||||
$this->_data['view_model']->set_heading('Category');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'name' => $this->_data['view_model']->get_name(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->category_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/category/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->category_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Category', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Category_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->category_model->set_form_validation(
|
||||
$this->form_validation, $this->category_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Category_admin_add_view_model($this->category_model);
|
||||
$this->_data['view_model']->set_heading('Category');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/CategoryAdd', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->category_model->create([
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Category added.');
|
||||
|
||||
return $this->redirect('/admin/category/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/CategoryAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->category_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/category/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Category_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->category_model->set_form_validation(
|
||||
$this->form_validation, $this->category_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Category_admin_edit_view_model($this->category_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Category');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/CategoryEdit', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->category_model->edit([
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Category updated.');
|
||||
|
||||
return $this->redirect('/admin/category/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/CategoryEdit', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->category_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->category_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Class Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_class_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'classes_model';
|
||||
public $_page_name = 'Class';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Class_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Class_admin_list_paginate_view_model(
|
||||
$this->classes_model,
|
||||
$this->pagination,
|
||||
'/admin/class/0');
|
||||
$this->_data['view_model']->set_heading('Class');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'name' => $this->_data['view_model']->get_name(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->classes_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/class/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->classes_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Class', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Class_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->classes_model->set_form_validation(
|
||||
$this->form_validation, $this->classes_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Class_admin_add_view_model($this->classes_model);
|
||||
$this->_data['view_model']->set_heading('Class');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/ClassAdd', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->classes_model->create([
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Class added.');
|
||||
|
||||
return $this->redirect('/admin/class/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/ClassAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->classes_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/class/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Class_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->classes_model->set_form_validation(
|
||||
$this->form_validation, $this->classes_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Class_admin_edit_view_model($this->classes_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Class');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/ClassEdit', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->classes_model->edit([
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Class updated.');
|
||||
|
||||
return $this->redirect('/admin/class/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/ClassEdit', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->classes_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->classes_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Color Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_color_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'color_model';
|
||||
public $_page_name = 'Color';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Color_admin_list_paginate_view_model.php';
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
$session = $this->get_session();
|
||||
$where = [];
|
||||
$this->_data['view_model'] = new Color_admin_list_paginate_view_model(
|
||||
$this->color_model,
|
||||
$this->pagination,
|
||||
'/admin/color/0');
|
||||
$this->_data['view_model']->set_heading('Color');
|
||||
$this->_data['view_model']->set_total_rows($this->color_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/color/0');
|
||||
$this->_data['view_model']->set_list($this->color_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Color', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Color_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->color_model->set_form_validation(
|
||||
$this->form_validation, $this->color_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Color_admin_add_view_model($this->color_model);
|
||||
$this->_data['view_model']->set_heading('Color');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/ColorAdd', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->color_model->create([
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/color/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/ColorAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->color_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/color/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Color_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->color_model->set_form_validation(
|
||||
$this->form_validation, $this->color_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Color_admin_edit_view_model($this->color_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Color');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/ColorEdit', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->color_model->edit([
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/color/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/ColorEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->color_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/color/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Color_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Color_admin_view_view_model($this->color_model);
|
||||
$this->_data['view_model']->set_heading('Color');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/ColorView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$model = $this->color_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/color/0');
|
||||
}
|
||||
|
||||
$result = $this->color_model->delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
return $this->redirect('/admin/color/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->error('Error');
|
||||
return redirect('/admin/color/0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Contact_us Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_contact_us_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'contact_us_model';
|
||||
public $_page_name = 'Contact';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Contact_us_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Contact_us_admin_list_paginate_view_model(
|
||||
$this->contact_us_model,
|
||||
$this->pagination,
|
||||
'/admin/contact_us/0');
|
||||
$this->_data['view_model']->set_heading('Contact');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_email(($this->input->get('email', TRUE) != NULL) ? $this->input->get('email', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_message(($this->input->get('message', TRUE) != NULL) ? $this->input->get('message', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'name' => $this->_data['view_model']->get_name(),
|
||||
'email' => $this->_data['view_model']->get_email(),
|
||||
'message' => $this->_data['view_model']->get_message(),
|
||||
'created_at' => $this->_data['view_model']->get_created_at(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->contact_us_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/contact_us/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->contact_us_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Contact_us', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->contact_us_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/contact_us/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Contact_us_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Contact_us_admin_view_view_model($this->contact_us_model);
|
||||
$this->_data['view_model']->set_heading('Contact');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/Contact_usView', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+245
@@ -0,0 +1,245 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Content Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_content_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'content_model';
|
||||
public $_page_name = 'Content';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Content_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Content_admin_list_paginate_view_model(
|
||||
$this->content_model,
|
||||
$this->pagination,
|
||||
'/admin/content/0');
|
||||
$this->_data['view_model']->set_heading('Content');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_content_name(($this->input->get('content_name', TRUE) != NULL) ? $this->input->get('content_name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_content_type(($this->input->get('content_type', TRUE) != NULL) ? $this->input->get('content_type', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'content_name' => $this->_data['view_model']->get_content_name(),
|
||||
'content_type' => $this->_data['view_model']->get_content_type(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->content_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/content/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->content_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Content', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return $this->redirect('admin/content');
|
||||
include_once __DIR__ . '/../../view_models/Content_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->content_model->set_form_validation(
|
||||
$this->form_validation, $this->content_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Content_admin_add_view_model($this->content_model);
|
||||
$this->_data['view_model']->set_heading('Content');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/ContentAdd', $this->_data);
|
||||
}
|
||||
|
||||
$content_name = $this->input->post('content_name', TRUE);
|
||||
$content_type = $this->input->post('content_type', TRUE);
|
||||
$content = $this->input->post('content', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->content_model->create([
|
||||
'content_name' => $content_name,
|
||||
'content_type' => $content_type,
|
||||
'content' => $content,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Content added.');
|
||||
|
||||
return $this->redirect('/admin/content/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/ContentAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->content_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/content/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Content_admin_edit_view_model.php';
|
||||
// $this->form_validation = $this->content_model->set_form_validation(
|
||||
// $this->form_validation, $this->content_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Content_admin_edit_view_model($this->content_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Content');
|
||||
|
||||
|
||||
|
||||
|
||||
if (!$this->input->post('content'))
|
||||
{
|
||||
return $this->render('Admin/ContentEdit', $this->_data);
|
||||
}
|
||||
|
||||
// $content_name = $this->input->post('content_name', TRUE);
|
||||
// $content_type = $this->input->post('content_type', TRUE);
|
||||
$content = $this->input->post('content', TRUE);
|
||||
// $status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->content_model->edit([
|
||||
// 'content_name' => $content_name,
|
||||
// 'content_type' => $content_type,
|
||||
'content' => $content,
|
||||
// 'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Content updated.');
|
||||
|
||||
return $this->redirect('/admin/content/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/ContentEdit', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->content_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->content_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/**
|
||||
* Admin Controller
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_controller extends Manaknight_Controller
|
||||
{
|
||||
|
||||
public $_page_name ='dashboard';
|
||||
|
||||
public $_valid_roles = [2];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->_data['page_name'] = $this->_page_name;
|
||||
$this->_data['setting'] = $this->_setting;
|
||||
$this->_data['layout_clean_mode'] = FALSE;
|
||||
$this->_run_middlewares();
|
||||
$layout_mode = $this->input->get('layout_clean_mode', TRUE);
|
||||
if (isset($layout_mode) && $layout_mode === '1')
|
||||
{
|
||||
$this->_data['layout_clean_mode'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
protected function _middleware()
|
||||
{
|
||||
return [
|
||||
'auth', 'acl'
|
||||
];
|
||||
}
|
||||
|
||||
public function render($template, $data)
|
||||
{
|
||||
return (!$this->_test_mode) ? $this->_render($template, $data) : $this->_render_test($template, $data);
|
||||
}
|
||||
|
||||
protected function _render_test($template, $data)
|
||||
{
|
||||
return [
|
||||
'header' => $this->load->view('Layout/AdminHeader', $data, TRUE),
|
||||
'body' => $this->load->view($template, $data, TRUE),
|
||||
'footer' => $this->load->view('Layout/AdminFooter', $data, TRUE),
|
||||
'data' => $data,
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Function to return the images for media gallery
|
||||
*/
|
||||
public function get_all_images()
|
||||
{
|
||||
$this->load->model('image_model');
|
||||
$images = $this->image_model->get_all();
|
||||
return $images;
|
||||
}
|
||||
|
||||
protected function _render($template, $data)
|
||||
{
|
||||
$data['images'] = $this->get_all_images();
|
||||
$data['page_section'] = $template;
|
||||
$this->load->view('Layout/AdminHeader', $data);
|
||||
$this->load->view($template, $data);
|
||||
$this->load->view('Layout/AdminFooter',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* User token invalid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function unauthorize_error_message()
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(401)
|
||||
->set_output(json_encode([
|
||||
'code' => 401,
|
||||
'success' => FALSE,
|
||||
'message' => 'invalid credentials'
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* User Role invalid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function unauthorize_resource_error_message()
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(406)
|
||||
->set_output(json_encode([
|
||||
'code' => 406,
|
||||
'success' => FALSE,
|
||||
'message' => 'cannot access resource'
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Success API Call
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function success2($success)
|
||||
{
|
||||
$success['code'] = 200;
|
||||
$success['success'] = TRUE;
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($success));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid form input
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _render_validation_error ()
|
||||
{
|
||||
$data = [];
|
||||
$data['code'] = 403;
|
||||
$data['success'] = FALSE;
|
||||
$data['error'] = $this->form_validation->error_array();
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render Custom Error
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _render_custom_error ($errors)
|
||||
{
|
||||
$data = [];
|
||||
$data['code'] = 403;
|
||||
$data['success'] = FALSE;
|
||||
$data['error'] = $errors;
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode($data));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_api_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* User API Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_credential_api_controller extends Admin_api_controller
|
||||
{
|
||||
protected $_model_file = 'credential_model';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/User_admin_list_paginate_view_model.php';
|
||||
|
||||
$this->_data['view_model'] = new User_admin_list_paginate_view_model(
|
||||
$this->credential_model,
|
||||
$this->pagination,
|
||||
'/admin/users/0');
|
||||
$this->_data['view_model']->set_heading('{{{page_name}}}');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_email(($this->input->get('email', TRUE) != NULL) ? $this->input->get('email', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_first_name(($this->input->get('first_name', TRUE) != NULL) ? $this->input->get('first_name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_last_name(($this->input->get('last_name', TRUE) != NULL) ? $this->input->get('last_name', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'email' => $this->_data['view_model']->get_email(),
|
||||
'first_name' => $this->_data['view_model']->get_first_name(),
|
||||
'last_name' => $this->_data['view_model']->get_last_name(),
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->credential_model->count_paginated($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page(10);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->credential_model->get_user_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where));
|
||||
return $this->success($this->_data['view_model']->to_json(), 200);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$this->form_validation = $this->credential_model->set_form_validation(
|
||||
$this->form_validation, $this->credential_model->get_all_validation_rule());
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->_render_validation_error();
|
||||
}
|
||||
|
||||
$email = $this->input->post('email', TRUE);
|
||||
$first_name = $this->input->post('first_name', TRUE);
|
||||
$last_name = $this->input->post('last_name', TRUE);
|
||||
$phone = $this->input->post('phone', TRUE);
|
||||
$image = $this->input->post('image', TRUE);
|
||||
$image_id = $this->input->post('image_id', TRUE);
|
||||
|
||||
$result = $this->credential_model->create([
|
||||
'email' => $email,
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'phone' => $phone,
|
||||
'image' => $image,
|
||||
'image_id' => $image_id,
|
||||
"password" => str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT)),
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->success([], 200);
|
||||
}
|
||||
|
||||
return $this->_render_custom_error([
|
||||
'error' => 'Error'
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->credential_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
return $this->_render_custom_error([
|
||||
'error' => 'Error'
|
||||
]);
|
||||
}
|
||||
|
||||
$this->form_validation = $this->credential_model->set_form_validation(
|
||||
$this->form_validation, $this->credential_model->get_all_edit_validation_rule());
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->_render_validation_error();
|
||||
}
|
||||
|
||||
$email = $this->input->post('email', TRUE);
|
||||
$first_name = $this->input->post('first_name', TRUE);
|
||||
$last_name = $this->input->post('last_name', TRUE);
|
||||
$phone = $this->input->post('phone', TRUE);
|
||||
$role_id = $this->input->post('role_id', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
$image = $this->input->post('image', TRUE);
|
||||
$image_id = $this->input->post('image_id', TRUE);
|
||||
|
||||
$result = $this->credential_model->edit([
|
||||
'email' => $email,
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'phone' => $phone,
|
||||
'role_id' => $role_id,
|
||||
'status' => $status,
|
||||
'image' => $image,
|
||||
'image_id' => $image_id,
|
||||
"password" => str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT)),
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->success([], 200);
|
||||
}
|
||||
|
||||
return $this->_render_custom_error([
|
||||
'error' => 'Error'
|
||||
]);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->credential_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
return $this->_render_custom_error([
|
||||
'error' => 'Error'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/User_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new User_admin_view_view_model($this->credential_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
return $this->success(['data' => $this->_data['view_model']->to_json()], 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
include_once __DIR__ . '/../../services/User_service.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* User Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_credential_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'credential_model';
|
||||
public $_page_name = 'Users';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('admin_operation_model');
|
||||
$this->load->model('credential_model');
|
||||
}
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/User_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
|
||||
if ($order_by == "id")
|
||||
{
|
||||
$order_by = 'b_id';
|
||||
}
|
||||
$this->_data['view_model'] = new User_admin_list_paginate_view_model(
|
||||
$this->credential_model,
|
||||
$this->pagination,
|
||||
'/admin/users/0');
|
||||
$this->_data['view_model']->set_heading('Users');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_email(($this->input->get('email', TRUE) != NULL) ? $this->input->get('email', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_first_name(($this->input->get('first_name', TRUE) != NULL) ? $this->input->get('first_name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_last_name(($this->input->get('last_name', TRUE) != NULL) ? $this->input->get('last_name', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'user_id' => $this->_data['view_model']->get_id(),
|
||||
'email' => $this->_data['view_model']->get_email(),
|
||||
'first_name' => $this->_data['view_model']->get_first_name(),
|
||||
'last_name' => $this->_data['view_model']->get_last_name()
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->credential_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page(25);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/users/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->credential_model->get_user_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/User', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
include_once __DIR__ . '/../../view_models/User_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$custom_validation = [
|
||||
['email', 'Email', 'trim|required|valid_email|is_unique[credential.email]'],
|
||||
['password', 'Password', 'required']
|
||||
];
|
||||
|
||||
$custom_validation = array_merge($custom_validation, $this->user_model->get_all_validation_rule());
|
||||
|
||||
$this->form_validation = $this->user_model->set_form_validation($this->form_validation, $custom_validation);
|
||||
$this->_data['view_model'] = new User_admin_add_view_model($this->credential_model);
|
||||
$this->_data['view_model']->set_heading('Users');
|
||||
$this->_data['view_data']['roles'] = $this->credential_model->role_id_mapping();
|
||||
$this->load->model('image_model');
|
||||
$gallery_images = $this->image_model->get_all();
|
||||
foreach ($gallery_images as $key => $image)
|
||||
{
|
||||
if ($image->type == 4)
|
||||
{
|
||||
$image->show_url = $image->url;
|
||||
}
|
||||
else
|
||||
{
|
||||
$image->show_url = $image->url;
|
||||
}
|
||||
$image->type = $this->image_model->type_mapping()[$image->type];
|
||||
}
|
||||
$this->_data['gallery_images'] = $gallery_images;
|
||||
|
||||
$service = new User_service($this->credential_model, $this->user_model);
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/UserAdd', $this->_data);
|
||||
}
|
||||
|
||||
$email = $this->input->post('email', TRUE);
|
||||
$first_name = $this->input->post('first_name', TRUE);
|
||||
$last_name = $this->input->post('last_name', TRUE);
|
||||
$phone = $this->input->post('phone', TRUE);
|
||||
$image = $this->input->post('image', TRUE);
|
||||
$image_id = $this->input->post('image_id', TRUE);
|
||||
$password = $this->input->post('password');
|
||||
$role_id = $this->input->post('role_id');
|
||||
|
||||
$created_user = $service->create($email, $password, $first_name, $last_name, $role_id, '');
|
||||
|
||||
if ($created_user)
|
||||
{
|
||||
$params = [
|
||||
'image' => $image,
|
||||
'phone' => $phone,
|
||||
'image_id' => $image_id
|
||||
];
|
||||
$this->user_model->edit($params, $created_user->id);
|
||||
|
||||
return $this->redirect('/admin/users/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/UserAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
$model = $this->credential_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/users/0');
|
||||
}
|
||||
|
||||
$user = $this->user_model->get($model->user_id);
|
||||
include_once __DIR__ . '/../../view_models/User_credentials_admin_edit_view_model.php';
|
||||
$custom_validation = [
|
||||
['role_id', 'Role', 'required']
|
||||
];
|
||||
|
||||
$custom_validation = array_merge($custom_validation, $this->user_model->get_all_validation_rule());
|
||||
$this->form_validation = $this->user_model->set_form_validation($this->form_validation, $custom_validation);
|
||||
$this->_data['view_model'] = new User_credentials_admin_edit_view_model($this->credential_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Users');
|
||||
$this->_data['view_model']->set_first_name($user->first_name);
|
||||
$this->_data['view_model']->set_last_name($user->last_name);
|
||||
$this->_data['view_model']->set_phone($user->phone);
|
||||
$this->_data['view_model']->set_image($user->image);
|
||||
$this->_data['view_model']->set_image_id($user->image_id);
|
||||
$this->_data['view_data']['roles'] = $this->credential_model->role_id_mapping();
|
||||
$this->_data['view_data']['status'] = $this->credential_model->status_mapping();
|
||||
$this->load->model('image_model');
|
||||
$gallery_images = $this->image_model->get_all();
|
||||
foreach ($gallery_images as $key => $image)
|
||||
{
|
||||
if ($image->type == 4)
|
||||
{
|
||||
$image->show_url = $image->url;
|
||||
}
|
||||
else
|
||||
{
|
||||
$image->show_url = $image->url;
|
||||
}
|
||||
$image->type = $this->image_model->type_mapping()[$image->type];
|
||||
}
|
||||
$this->_data['gallery_images'] = $gallery_images;
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/UserEdit', $this->_data);
|
||||
}
|
||||
|
||||
$email = $this->input->post('email', TRUE);
|
||||
$first_name = $this->input->post('first_name', TRUE);
|
||||
$last_name = $this->input->post('last_name', TRUE);
|
||||
$phone = $this->input->post('phone', TRUE);
|
||||
$role_id = $this->input->post('role_id', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
$image = $this->input->post('image', TRUE);
|
||||
$image_id = $this->input->post('image_id', TRUE);
|
||||
$password = $this->input->post('password', TRUE);
|
||||
|
||||
$credential_params = [
|
||||
'email' => $email,
|
||||
'role_id' => $role_id,
|
||||
'status' => $status
|
||||
];
|
||||
|
||||
if (strlen($password) > 2)
|
||||
{
|
||||
$credential_params['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
$params = [
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'phone' => $phone,
|
||||
'image' => $image,
|
||||
'image_id' => $image_id
|
||||
];
|
||||
$credential_obj = $this->credential_model->get_by_field('user_id', $model->user_id);
|
||||
$credential_result = $this->credential_model->edit($credential_params, $credential_obj->id);
|
||||
$result = $this->user_model->edit($params, $model->id);
|
||||
if ($result && $credential_result)
|
||||
{
|
||||
$this->success('Saved');
|
||||
return $this->redirect('/admin/users/0', 'refresh');
|
||||
}
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/UserEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->credential_model->get($id);
|
||||
$this->load->model('user_model');
|
||||
$user = $this->user_model->get_by_field('id', $model->user_id);
|
||||
$model->first_name = $user->first_name ? $user->first_name : 'N/A';
|
||||
$model->last_name = $user->last_name ? $user->last_name : 'N/A';
|
||||
$model->image = $user->image ? $user->image : '';
|
||||
$model->image_id = $user->image_id ? $user->image_id : '0';
|
||||
$model->phone = $user->phone ? $user->phone : 'N/A';
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/users/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/User_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new User_admin_view_view_model($this->credential_model);
|
||||
$this->_data['view_model']->set_heading('Users');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_first_name($user->first_name);
|
||||
$this->_data['view_model']->set_last_name($user->last_name);
|
||||
$this->_data['view_model']->set_phone($user->phone);
|
||||
$this->_data['view_model']->set_role_id($model->role_id);
|
||||
$this->_data['view_model']->set_image($user->image);
|
||||
$this->_data['view_model']->set_image_id($user->image_id);
|
||||
|
||||
$this->_data['view_model']->set_id($model->user_id);
|
||||
|
||||
return $this->render('Admin/UserView', $this->_data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
|
||||
/**
|
||||
* Admin Dashboard Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_dashboard_controller extends Admin_controller
|
||||
{
|
||||
public $_page_name = 'Dashboard';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('Admin_operation_model');
|
||||
}
|
||||
|
||||
public function index ()
|
||||
{
|
||||
$this->_data['member_accounts'] = $this->Admin_operation_model->getMemberAccountData();
|
||||
$this->_data['member_uploads'] = $this->Admin_operation_model->getMemberUploadData();
|
||||
$this->_data['top_school_account'] = $this->Admin_operation_model->getAccountsBySchool();
|
||||
$this->_data['top_school_upload'] = $this->Admin_operation_model->getUploadsBySchool();
|
||||
return $this->render('Admin/Dashboard', $this->_data);
|
||||
}
|
||||
}
|
||||
+216
@@ -0,0 +1,216 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Dispute Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_dispute_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'dispute_model';
|
||||
public $_page_name = 'Dispute';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Dispute_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Dispute_admin_list_paginate_view_model(
|
||||
$this->dispute_model,
|
||||
$this->pagination,
|
||||
'/admin/dispute/0');
|
||||
$this->_data['view_model']->set_heading('Dispute');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_reason(($this->input->get('reason', TRUE) != NULL) ? $this->input->get('reason', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_stripe_charge_id(($this->input->get('stripe_charge_id', TRUE) != NULL) ? $this->input->get('stripe_charge_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_stripe_dispute_id(($this->input->get('stripe_dispute_id', TRUE) != NULL) ? $this->input->get('stripe_dispute_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'user_id' => $this->_data['view_model']->get_user_id(),
|
||||
'reason' => $this->_data['view_model']->get_reason(),
|
||||
'stripe_charge_id' => $this->_data['view_model']->get_stripe_charge_id(),
|
||||
'stripe_dispute_id' => $this->_data['view_model']->get_stripe_dispute_id(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->dispute_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/dispute/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->dispute_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Dispute', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Dispute_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->dispute_model->set_form_validation(
|
||||
$this->form_validation, $this->dispute_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Dispute_admin_add_view_model($this->dispute_model);
|
||||
$this->_data['view_model']->set_heading('Dispute');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/DisputeAdd', $this->_data);
|
||||
}
|
||||
|
||||
$order_id = $this->input->post('order_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$reason = $this->input->post('reason', TRUE);
|
||||
$explanation = $this->input->post('explanation', TRUE);
|
||||
$stripe_charge_id = $this->input->post('stripe_charge_id', TRUE);
|
||||
$stripe_dispute_id = $this->input->post('stripe_dispute_id', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->dispute_model->create([
|
||||
'order_id' => $order_id,
|
||||
'user_id' => $user_id,
|
||||
'reason' => $reason,
|
||||
'explanation' => $explanation,
|
||||
'stripe_charge_id' => $stripe_charge_id,
|
||||
'stripe_dispute_id' => $stripe_dispute_id,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/dispute/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/DisputeAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->dispute_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/dispute/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Dispute_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->dispute_model->set_form_validation(
|
||||
$this->form_validation, $this->dispute_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Dispute_admin_edit_view_model($this->dispute_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Dispute');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/DisputeEdit', $this->_data);
|
||||
}
|
||||
|
||||
$order_id = $this->input->post('order_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$reason = $this->input->post('reason', TRUE);
|
||||
$explanation = $this->input->post('explanation', TRUE);
|
||||
$stripe_charge_id = $this->input->post('stripe_charge_id', TRUE);
|
||||
$stripe_dispute_id = $this->input->post('stripe_dispute_id', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->dispute_model->edit([
|
||||
'order_id' => $order_id,
|
||||
'user_id' => $user_id,
|
||||
'reason' => $reason,
|
||||
'explanation' => $explanation,
|
||||
'stripe_charge_id' => $stripe_charge_id,
|
||||
'stripe_dispute_id' => $stripe_dispute_id,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/dispute/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/DisputeEdit', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+222
@@ -0,0 +1,222 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Email Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_email_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'email_model';
|
||||
public $_page_name = 'Emails';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Email_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Email_admin_list_paginate_view_model(
|
||||
$this->email_model,
|
||||
$this->pagination,
|
||||
'/admin/emails/0');
|
||||
$this->_data['view_model']->set_heading('Emails');
|
||||
$this->_data['view_model']->set_slug(($this->input->get('slug', TRUE) != NULL) ? $this->input->get('slug', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_subject(($this->input->get('subject', TRUE) != NULL) ? $this->input->get('subject', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_tag(($this->input->get('tag', TRUE) != NULL) ? $this->input->get('tag', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'slug' => $this->_data['view_model']->get_slug(),
|
||||
'subject' => $this->_data['view_model']->get_subject(),
|
||||
'tag' => $this->_data['view_model']->get_tag(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->email_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/emails/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->email_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Email', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Email_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->email_model->set_form_validation(
|
||||
$this->form_validation, $this->email_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Email_admin_add_view_model($this->email_model);
|
||||
$this->_data['view_model']->set_heading('Emails');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/EmailAdd', $this->_data);
|
||||
}
|
||||
|
||||
$slug = $this->input->post('slug', TRUE);
|
||||
$subject = $this->input->post('subject', TRUE);
|
||||
$email_header = $this->input->post('email_header', TRUE);
|
||||
$email_footer = $this->input->post('email_footer', TRUE);
|
||||
$subject = $this->input->post('subject', TRUE);
|
||||
$tag = $this->input->post('tag', TRUE);
|
||||
$html = $this->input->post('html', TRUE);
|
||||
|
||||
$result = $this->email_model->create([
|
||||
'slug' => $slug,
|
||||
'subject' => $subject,
|
||||
'email_header' => $email_header,
|
||||
'email_footer' => $email_footer,
|
||||
'subject' => $subject,
|
||||
'tag' => $tag,
|
||||
'html' => $html,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/emails/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/EmailAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->email_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/emails/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Email_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->email_model->set_form_validation(
|
||||
$this->form_validation, $this->email_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Email_admin_edit_view_model($this->email_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Emails');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/EmailEdit', $this->_data);
|
||||
}
|
||||
|
||||
$subject = $this->input->post('subject', TRUE);
|
||||
$email_header = $this->input->post('email_header', TRUE);
|
||||
$html = $this->input->post('html', TRUE);
|
||||
$email_footer = $this->input->post('email_footer', TRUE);
|
||||
$tag = $this->input->post('tag', TRUE);
|
||||
|
||||
$result = $this->email_model->edit([
|
||||
'subject' => $subject,
|
||||
'email_header' => $email_header,
|
||||
'html' => $html,
|
||||
'email_footer' => $email_footer,
|
||||
'tag' => $tag,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/emails/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/EmailEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->email_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/emails/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Email_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Email_admin_view_view_model($this->email_model);
|
||||
$this->_data['view_model']->set_heading('Emails');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/EmailView', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Image Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_image_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'image_model';
|
||||
public $_page_name = 'Images';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Image_admin_list_paginate_view_model.php';
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
$session = $this->get_session();
|
||||
$where = [];
|
||||
$this->_data['view_model'] = new Image_admin_list_paginate_view_model(
|
||||
$this->image_model,
|
||||
$this->pagination,
|
||||
'/admin/image/0');
|
||||
$this->_data['view_model']->set_heading('Images');
|
||||
$this->_data['view_model']->set_total_rows($this->image_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/image/0');
|
||||
$this->_data['view_model']->set_list($this->image_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Image', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Image_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->image_model->set_form_validation(
|
||||
$this->form_validation, $this->image_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Image_admin_add_view_model($this->image_model);
|
||||
$this->_data['view_model']->set_heading('Images');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/ImageAdd', $this->_data);
|
||||
}
|
||||
|
||||
$url = $this->input->post('url', TRUE);
|
||||
$type = $this->input->post('type', TRUE);
|
||||
$type_2 = $this->input->post('type_2', TRUE);
|
||||
|
||||
$result = $this->image_model->create([
|
||||
'url' => $url,
|
||||
'type' => $type,
|
||||
'type_2' => $type_2,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/image/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/ImageAdd', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->image_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/image/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Image_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Image_admin_view_view_model($this->image_model);
|
||||
$this->_data['view_model']->set_heading('Images');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/ImageView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->image_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->image_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Inventory_attribute Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_inventory_attribute_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'inventory_attribute_model';
|
||||
public $_page_name = 'Inventory Attribute';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Inventory_attribute_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Inventory_attribute_admin_list_paginate_view_model(
|
||||
$this->inventory_attribute_model,
|
||||
$this->pagination,
|
||||
'/admin/inventory_attribute/0');
|
||||
$this->_data['view_model']->set_heading('Inventory Attribute');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_inventory_id(($this->input->get('inventory_id', TRUE) != NULL) ? $this->input->get('inventory_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_attribute_id(($this->input->get('attribute_id', TRUE) != NULL) ? $this->input->get('attribute_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_value(($this->input->get('value', TRUE) != NULL) ? $this->input->get('value', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'inventory_id' => $this->_data['view_model']->get_inventory_id(),
|
||||
'attribute_id' => $this->_data['view_model']->get_attribute_id(),
|
||||
'value' => $this->_data['view_model']->get_value(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->inventory_attribute_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/inventory_attribute/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->inventory_attribute_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Inventory_attribute', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Inventory_attribute_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->inventory_attribute_model->set_form_validation(
|
||||
$this->form_validation, $this->inventory_attribute_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Inventory_attribute_admin_add_view_model($this->inventory_attribute_model);
|
||||
$this->_data['view_model']->set_heading('Inventory Attribute');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/Inventory_attributeAdd', $this->_data);
|
||||
}
|
||||
|
||||
$inventory_id = $this->input->post('inventory_id', TRUE);
|
||||
$attribute_id = $this->input->post('attribute_id', TRUE);
|
||||
$value = $this->input->post('value', TRUE);
|
||||
|
||||
$result = $this->inventory_attribute_model->create([
|
||||
'inventory_id' => $inventory_id,
|
||||
'attribute_id' => $attribute_id,
|
||||
'value' => $value,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/inventory_attribute/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/Inventory_attributeAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->inventory_attribute_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/inventory_attribute/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Inventory_attribute_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->inventory_attribute_model->set_form_validation(
|
||||
$this->form_validation, $this->inventory_attribute_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Inventory_attribute_admin_edit_view_model($this->inventory_attribute_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Inventory Attribute');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/Inventory_attributeEdit', $this->_data);
|
||||
}
|
||||
|
||||
$inventory_id = $this->input->post('inventory_id', TRUE);
|
||||
$attribute_id = $this->input->post('attribute_id', TRUE);
|
||||
$value = $this->input->post('value', TRUE);
|
||||
|
||||
$result = $this->inventory_attribute_model->edit([
|
||||
'inventory_id' => $inventory_id,
|
||||
'attribute_id' => $attribute_id,
|
||||
'value' => $value,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/inventory_attribute/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/Inventory_attributeEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->inventory_attribute_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/inventory_attribute/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Inventory_attribute_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Inventory_attribute_admin_view_view_model($this->inventory_attribute_model);
|
||||
$this->_data['view_model']->set_heading('Inventory Attribute');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/Inventory_attributeView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->inventory_attribute_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->inventory_attribute_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function bulk_delete()
|
||||
{
|
||||
|
||||
$bulk_items = $this->input->post('bulk_items');
|
||||
foreach ($bulk_items as $key => $id) {
|
||||
$this->inventory_attribute_model->real_delete($id);
|
||||
}
|
||||
echo 'success';
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,474 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Inventory Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_inventory_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'inventory_model';
|
||||
public $_page_name = 'Inventory';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('school_model');
|
||||
$this->load->model('professor_model');
|
||||
$this->load->model('textbook_model');
|
||||
$this->load->model('classes_model');
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('credential_model');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Inventory_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
$previews = $this->input->get('previews', TRUE) ?? "";
|
||||
|
||||
$this->_data['view_model'] = new Inventory_admin_list_paginate_view_model(
|
||||
$this->inventory_model,
|
||||
$this->pagination,
|
||||
'/admin/inventory/0');
|
||||
$this->_data['view_model']->set_heading('Inventory');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_title(($this->input->get('title', TRUE) != NULL) ? $this->input->get('title', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_school_id(($this->input->get('school_id', TRUE) != NULL) ? $this->input->get('school_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_professor_id(($this->input->get('professor_id', TRUE) != NULL) ? $this->input->get('professor_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_class_id(($this->input->get('class_id', TRUE) != NULL) ? $this->input->get('class_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_textbook_id(($this->input->get('textbook_id', TRUE) != NULL) ? $this->input->get('textbook_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_word_count(($this->input->get('word_count', TRUE) != NULL) ? $this->input->get('word_count', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_year(($this->input->get('year', TRUE) != NULL) ? $this->input->get('year', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
$this->_data['email'] = ( $this->input->get('email', TRUE) != NULL ) ? $this->input->get('email', TRUE) : NULL;
|
||||
|
||||
$where = [
|
||||
'inventory.id' => $this->_data['view_model']->get_id(),
|
||||
'inventory.title' => $this->_data['view_model']->get_title(),
|
||||
'inventory.school_id' => $this->_data['view_model']->get_school_id(),
|
||||
'inventory.professor_id' => $this->_data['view_model']->get_professor_id(),
|
||||
'inventory.class_id' => $this->_data['view_model']->get_class_id(),
|
||||
'inventory.isbn' => ($_GET['isbn'] ?? ''),
|
||||
'inventory.word_count' => $this->_data['view_model']->get_word_count(),
|
||||
'inventory.year' => $this->_data['view_model']->get_year(),
|
||||
'inventory.status' => $this->_data['view_model']->get_status(),
|
||||
'credential.email' => $this->_data['email'],
|
||||
];
|
||||
|
||||
if ($previews == 2)
|
||||
{
|
||||
$this->db->group_start();
|
||||
$this->db->where(' feature_image = "" AND feature_image2 = "" AND feature_image3 = "" ');
|
||||
$this->db->group_end();
|
||||
}elseif ($previews == 1)
|
||||
{
|
||||
$this->db->group_start();
|
||||
$this->db->where(' feature_image != "" OR feature_image2 != "" OR feature_image3 != "" ');
|
||||
$this->db->group_end();
|
||||
}
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->inventory_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/inventory/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
|
||||
if ($previews == 2)
|
||||
{
|
||||
$this->db->group_start();
|
||||
$this->db->where(' feature_image = "" AND feature_image2 = "" AND feature_image3 = "" ');
|
||||
$this->db->group_end();
|
||||
}elseif ($previews == 1)
|
||||
{
|
||||
$this->db->group_start();
|
||||
$this->db->where(' feature_image != "" OR feature_image2 != "" OR feature_image3 != "" ');
|
||||
$this->db->group_end();
|
||||
}
|
||||
|
||||
$this->_data['view_model']->set_list($this->inventory_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->input->get('school_id', TRUE))
|
||||
{
|
||||
$schools = $this->school_model->get_all(['status' => 1, 'id' => $this->input->get('school_id') ]);
|
||||
}
|
||||
|
||||
|
||||
if ($this->input->get('professor_id', TRUE))
|
||||
{
|
||||
$professors = $this->professor_model->get_all(['status' => 1, 'id' => $this->input->get('professor_id') ]);
|
||||
}
|
||||
|
||||
|
||||
if ($this->input->get('class_id', TRUE))
|
||||
{
|
||||
$classes = $this->classes_model->get_all(['status' => 1, 'id' => $this->input->get('class_id') ]);
|
||||
}
|
||||
|
||||
|
||||
if ($this->input->get('isbn', TRUE))
|
||||
{
|
||||
$is_bn = $this->input->get('isbn', TRUE);
|
||||
$textbooks = $this->db->select('isbn')->from('inventory')->where('isbn', $is_bn)->get()->result_array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if( $this->_data['view_model']->get_list())
|
||||
{
|
||||
|
||||
foreach ( $this->_data['view_model']->get_list() as $key => &$value)
|
||||
{
|
||||
$school_data = $this->school_model->get($value->school_id);
|
||||
$professor_data = $this->professor_model->get($value->professor_id);
|
||||
$classes_data = $this->classes_model->get($value->class_id);
|
||||
$user_data = $this->user_model->get($value->user_id);
|
||||
$user_data2 = $this->credential_model->get_by_fields(['user_id' => $user_data->id]);
|
||||
|
||||
$value->school_id = isset($school_data->name) ? $school_data->name : '';
|
||||
$value->professor_id = isset($professor_data->name) ? $professor_data->name : '';
|
||||
$value->class_id = isset($classes_data->name) ? $classes_data->name : '';
|
||||
$value->user_id = isset($user_data->first_name) ? $user_data->first_name . " " . $user_data->last_name : '';
|
||||
$value->email = isset($user_data2->email) ? $user_data2->email : '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->_data['previews'] = $previews;
|
||||
if (!empty($schools))
|
||||
{
|
||||
$this->_data['schools'] = $schools;
|
||||
}
|
||||
|
||||
if (!empty($professors))
|
||||
{
|
||||
$this->_data['professors'] = $professors;
|
||||
}
|
||||
|
||||
if (isset($textbooks) && !empty($textbooks))
|
||||
{
|
||||
$this->_data['textbooks'] = $textbooks;
|
||||
}
|
||||
|
||||
if (!empty($classes))
|
||||
{
|
||||
$this->_data['classes'] = $classes;
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Inventory', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Inventory_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->inventory_model->set_form_validation(
|
||||
$this->form_validation, $this->inventory_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Inventory_admin_add_view_model($this->inventory_model);
|
||||
$this->_data['view_model']->set_heading('Inventory');
|
||||
|
||||
$this->load->model('image_model');
|
||||
$gallery_images = $this->image_model->get_all();
|
||||
foreach ($gallery_images as $key => $image) {
|
||||
if($image->type == 4){
|
||||
$image->show_url = $image->url;
|
||||
}else
|
||||
{
|
||||
$image->show_url = $image->url;
|
||||
}$image->type = $this->image_model->type_mapping()[$image->type];
|
||||
}
|
||||
$this->_data['gallery_images'] = $gallery_images;
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/InventoryAdd', $this->_data);
|
||||
}
|
||||
|
||||
$title = $this->input->post('title', TRUE);
|
||||
$school_id = $this->input->post('school_id', TRUE);
|
||||
$professor_id = $this->input->post('professor_id', TRUE);
|
||||
$class_id = $this->input->post('class_id', TRUE);
|
||||
$textbook_id = $this->input->post('textbook_id', TRUE);
|
||||
$word_count = $this->input->post('word_count', TRUE);
|
||||
$year = $this->input->post('year', TRUE);
|
||||
$isbn = $this->input->post('isbn', TRUE);
|
||||
$paypal_email = $this->input->post('paypal_email', TRUE);
|
||||
$file = $this->input->post('file', TRUE);
|
||||
$file_id = $this->input->post('file_id', TRUE);
|
||||
$feature_image = $this->input->post('feature_image', TRUE);
|
||||
$feature_image_id = $this->input->post('feature_image_id', TRUE);
|
||||
$note_type = $this->input->post('note_type', TRUE);
|
||||
$description = $this->input->post('description', TRUE);
|
||||
$inventory_note = $this->input->post('inventory_note', TRUE);
|
||||
$pin_to_top = $this->input->post('pin_to_top', TRUE);
|
||||
$approve = $this->input->post('approve', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->inventory_model->create([
|
||||
'title' => $title,
|
||||
'school_id' => $school_id,
|
||||
'professor_id' => $professor_id,
|
||||
'class_id' => $class_id,
|
||||
'textbook_id' => $textbook_id,
|
||||
'word_count' => $word_count,
|
||||
'year' => $year,
|
||||
'isbn' => $isbn,
|
||||
'paypal_email' => $paypal_email,
|
||||
'file' => $file,
|
||||
'file_id' => $file_id,
|
||||
'feature_image' => $feature_image,
|
||||
'feature_image_id' => $feature_image_id,
|
||||
'note_type' => $note_type,
|
||||
'description' => $description,
|
||||
'inventory_note' => $inventory_note,
|
||||
'pin_to_top' => $pin_to_top,
|
||||
'approve' => $approve,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
$this->success('Data has been added successfully.');
|
||||
return $this->redirect('/admin/inventory/0?order_by=id&direction=DESC', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/InventoryAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->inventory_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/inventory/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Inventory_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->inventory_model->set_form_validation(
|
||||
$this->form_validation, $this->inventory_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Inventory_admin_edit_view_model($this->inventory_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Inventory');
|
||||
|
||||
$this->load->model('image_model');
|
||||
$gallery_images = $this->image_model->get_all();
|
||||
foreach ($gallery_images as $key => $image) {
|
||||
if($image->type == 4){
|
||||
$image->show_url = $image->url;
|
||||
}else
|
||||
{
|
||||
$image->show_url = $image->url;
|
||||
}$image->type = $this->image_model->type_mapping()[$image->type];
|
||||
}
|
||||
$this->_data['gallery_images'] = $gallery_images;
|
||||
|
||||
|
||||
$this->_data['schools'] = $this->school_model->get_all(['status' => 1 , 'id' => $model->school_id]);
|
||||
$this->_data['professors'] = $this->professor_model->get_all(['status' => 1, 'id' => $model->professor_id]);
|
||||
$this->_data['classes'] = $this->classes_model->get_all(['status' => 1, 'id' => $model->class_id]);
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/InventoryEdit', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
$school_id = $this->input->post('school_id', TRUE);
|
||||
$professor_id = $this->input->post('professor_id', TRUE);
|
||||
$class_id = $this->input->post('class_id', TRUE);
|
||||
$word_count = $this->input->post('word_count', TRUE);
|
||||
$year = $this->input->post('year', TRUE);
|
||||
$isbn = $this->input->post('isbn', TRUE);
|
||||
$note_type = $this->input->post('note_type', TRUE);
|
||||
$feature_image3 = $this->input->post('feature_image3', TRUE);
|
||||
$feature_image2 = $this->input->post('feature_image2', TRUE);
|
||||
$feature_image = $this->input->post('feature_image', TRUE);
|
||||
|
||||
|
||||
$result = $this->inventory_model->edit([
|
||||
'school_id' => $school_id,
|
||||
'professor_id' => $professor_id,
|
||||
'class_id' => $class_id,
|
||||
'word_count' => $word_count,
|
||||
'year' => $year,
|
||||
'isbn' => $isbn,
|
||||
'note_type' => $note_type,
|
||||
'feature_image' => $feature_image,
|
||||
'feature_image3' => $feature_image3,
|
||||
'feature_image2' => $feature_image2,
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Data has been updated successfully.');
|
||||
return $this->redirect('/admin/inventory/0?order_by=id&direction=DESC', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/InventoryEdit', $this->_data);
|
||||
}
|
||||
|
||||
// public function view($id)
|
||||
// {
|
||||
// $model = $this->inventory_model->get($id);
|
||||
|
||||
// if (!$model)
|
||||
// {
|
||||
// $this->error('Error');
|
||||
// return redirect('/admin/inventory/0');
|
||||
// }
|
||||
|
||||
|
||||
// include_once __DIR__ . '/../../view_models/Inventory_admin_view_view_model.php';
|
||||
// $this->_data['view_model'] = new Inventory_admin_view_view_model($this->inventory_model);
|
||||
// $this->_data['view_model']->set_heading('Inventory');
|
||||
// $this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
// return $this->render('Admin/InventoryView', $this->_data);
|
||||
// }
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->inventory_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/inventory/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Inventory_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Inventory_admin_view_view_model($this->inventory_model);
|
||||
$this->_data['view_model']->set_heading('Inventory');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
//get all school data
|
||||
$this->_data['school_data'] = array_column($this->school_model->get_all(['status' => 1]),'name','id');
|
||||
//get all professor data
|
||||
$this->_data['professor_data'] = array_column($this->professor_model->get_all(['status' => 1]),'name','id');
|
||||
//get all classes data
|
||||
$this->_data['classes_data'] = array_column($this->classes_model->get_all(['status' => 1]),'name','id');
|
||||
//get all textbook data
|
||||
$this->_data['textbook_data'] = array_column($this->textbook_model->get_all(['status' => 1]),'isbn','id');
|
||||
|
||||
$this->_data['view_model']->set_school_id( $this->_data['school_data'][$this->_data['view_model']->get_school_id()]);
|
||||
$this->_data['view_model']->set_professor_id( $this->_data['professor_data'][$this->_data['view_model']->get_professor_id()]);
|
||||
$this->_data['view_model']->set_class_id( $this->_data['classes_data'][$this->_data['view_model']->get_class_id()]);
|
||||
// $this->_data['view_model']->set_textbook_id( $this->_data['textbook_data'][$this->_data['view_model']->get_textbook_id()]);
|
||||
// print_r($this->_data);
|
||||
// exit;
|
||||
|
||||
return $this->render('Admin/InventoryView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->inventory_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->inventory_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Inventory_gallery_image_list Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_inventory_gallery_image_list_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'inventory_gallery_image_list_model';
|
||||
public $_page_name = 'Inventory_gallery_image_list';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Inventory_gallery_image_list_admin_list_paginate_view_model.php';
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
$session = $this->get_session();
|
||||
$where = [];
|
||||
$this->_data['view_model'] = new Inventory_gallery_image_list_admin_list_paginate_view_model(
|
||||
$this->inventory_gallery_image_list_model,
|
||||
$this->pagination,
|
||||
'/admin/inventory_gallery_image_list/0');
|
||||
$this->_data['view_model']->set_heading('Inventory_gallery_image_list');
|
||||
$this->_data['view_model']->set_total_rows($this->inventory_gallery_image_list_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/inventory_gallery_image_list/0');
|
||||
$this->_data['view_model']->set_list($this->inventory_gallery_image_list_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Inventory_gallery_image_list', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Inventory_gallery_image_list_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->inventory_gallery_image_list_model->set_form_validation(
|
||||
$this->form_validation, $this->inventory_gallery_image_list_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Inventory_gallery_image_list_admin_add_view_model($this->inventory_gallery_image_list_model);
|
||||
$this->_data['view_model']->set_heading('Inventory_gallery_image_list');
|
||||
|
||||
$this->load->model('image_model');
|
||||
$gallery_images = $this->image_model->get_all();
|
||||
foreach ($gallery_images as $key => $image) {
|
||||
if($image->type == 4){
|
||||
$image->show_url = base_url().$image->url;
|
||||
}else
|
||||
{
|
||||
$image->show_url = $image->url;
|
||||
}$image->type = $this->image_model->type_mapping()[$image->type];
|
||||
}
|
||||
$this->_data['gallery_images'] = $gallery_images;
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/Inventory_gallery_image_listAdd', $this->_data);
|
||||
}
|
||||
|
||||
$inventory_id = $this->input->post('inventory_id', TRUE);
|
||||
$gallery_image = $this->input->post('gallery_image', TRUE);
|
||||
$gallery_image_id = $this->input->post('gallery_image_id', TRUE);
|
||||
$gallery_image_id = $this->input->post('gallery_image_id', TRUE);
|
||||
$gallery_image_id_id = $this->input->post('gallery_image_id_id', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->inventory_gallery_image_list_model->create([
|
||||
'inventory_id' => $inventory_id,
|
||||
'gallery_image' => $gallery_image,
|
||||
'gallery_image_id' => $gallery_image_id,
|
||||
'gallery_image_id' => $gallery_image_id,
|
||||
'gallery_image_id_id' => $gallery_image_id_id,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/inventory_gallery_image_list/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/Inventory_gallery_image_listAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->inventory_gallery_image_list_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/inventory_gallery_image_list/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Inventory_gallery_image_list_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->inventory_gallery_image_list_model->set_form_validation(
|
||||
$this->form_validation, $this->inventory_gallery_image_list_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Inventory_gallery_image_list_admin_edit_view_model($this->inventory_gallery_image_list_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Inventory_gallery_image_list');
|
||||
|
||||
$this->load->model('image_model');
|
||||
$gallery_images = $this->image_model->get_all();
|
||||
foreach ($gallery_images as $key => $image) {
|
||||
if($image->type == 4){
|
||||
$image->show_url = base_url().$image->url;
|
||||
}else
|
||||
{
|
||||
$image->show_url = $image->url;
|
||||
}$image->type = $this->image_model->type_mapping()[$image->type];
|
||||
}
|
||||
$this->_data['gallery_images'] = $gallery_images;
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/Inventory_gallery_image_listEdit', $this->_data);
|
||||
}
|
||||
|
||||
$inventory_id = $this->input->post('inventory_id', TRUE);
|
||||
$gallery_image = $this->input->post('gallery_image', TRUE);
|
||||
$gallery_image_id = $this->input->post('gallery_image_id', TRUE);
|
||||
$gallery_image_id = $this->input->post('gallery_image_id', TRUE);
|
||||
$gallery_image_id_id = $this->input->post('gallery_image_id_id', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->inventory_gallery_image_list_model->edit([
|
||||
'inventory_id' => $inventory_id,
|
||||
'gallery_image' => $gallery_image,
|
||||
'gallery_image_id' => $gallery_image_id,
|
||||
'gallery_image_id' => $gallery_image_id,
|
||||
'gallery_image_id_id' => $gallery_image_id_id,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/inventory_gallery_image_list/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/Inventory_gallery_image_listEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->inventory_gallery_image_list_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/inventory_gallery_image_list/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Inventory_gallery_image_list_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Inventory_gallery_image_list_admin_view_view_model($this->inventory_gallery_image_list_model);
|
||||
$this->_data['view_model']->set_heading('Inventory_gallery_image_list');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/Inventory_gallery_image_listView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$model = $this->inventory_gallery_image_list_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/inventory_gallery_image_list/0');
|
||||
}
|
||||
|
||||
$result = $this->inventory_gallery_image_list_model->delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
return $this->redirect('/admin/inventory_gallery_image_list/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->error('Error');
|
||||
return redirect('/admin/inventory_gallery_image_list/0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once __DIR__ . '/../../services/User_service.php';
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Login Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_login_controller extends Manaknight_Controller
|
||||
{
|
||||
protected $_redirect = '/admin/dashboard';
|
||||
|
||||
public $_valid_roles = [2];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index ()
|
||||
{
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('user_model');
|
||||
$this->load->helper('cookie');
|
||||
|
||||
$service = new User_service($this->credential_model);
|
||||
if($this->input->cookie('admin_remember_me_token', TRUE) !== null && $this->input->cookie('admin_remember_me_token', TRUE) !== '')
|
||||
{
|
||||
$this->_remember_me_login();
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
|
||||
$this->form_validation->set_rules('password', 'Password', 'required');
|
||||
$this->_data['portal'] = 'admin';
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
echo $this->load->view('Admin/Login', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
$redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect);
|
||||
$role = $this->_valid_roles[0];
|
||||
$authenticated_user = $service->login_by_role($email, $password, $role);
|
||||
|
||||
if ($authenticated_user)
|
||||
{
|
||||
delete_cookie('redirect');
|
||||
$user_id = $authenticated_user->user_id;
|
||||
|
||||
if(!empty($this->input->post("remember_me"))) {
|
||||
$this->load->helper('string');
|
||||
$remember_cookie = [
|
||||
'user_id' => $user_id,
|
||||
'name' => 'admin_remember_me_token',
|
||||
'value' => random_string('alnum', 16),
|
||||
'expire' => time()+$this->config->item('cookie_expire'),
|
||||
'domain' => base_url()
|
||||
];
|
||||
$this->load->model('cookies_model');
|
||||
$check_cookie = $this->cookies_model->get_by_field('user_id', $user_id);
|
||||
if($check_cookie)
|
||||
{
|
||||
$cookie = $this->cookies_model->edit($remember_cookie, $check_cookie->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cookie = $this->cookies_model->create($remember_cookie);
|
||||
}
|
||||
if($cookie)
|
||||
{
|
||||
setcookie($remember_cookie['name'], $remember_cookie['value'], $remember_cookie['expire'], $remember_cookie['domain']);
|
||||
}
|
||||
}
|
||||
$this->set_session('credential_id', (int) $authenticated_user->id);
|
||||
$this->set_session('user_id', (int) $user_id);
|
||||
$this->set_session('email', (string) $authenticated_user->email);
|
||||
$this->set_session('role', (string) $authenticated_user->role_id);
|
||||
return $this->redirect($redirect);
|
||||
}
|
||||
|
||||
$this->error('Wrong email or password.');
|
||||
return $this->redirect('admin/login');
|
||||
}
|
||||
|
||||
|
||||
public function _remember_me_login()
|
||||
{
|
||||
$this->load->helper('string');
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('cookies_model');
|
||||
$token_value = $this->input->cookie('admin_remember_me_token', TRUE);
|
||||
$cookie = $this->cookies_model->get_by_fields(['value' => $token_value]);
|
||||
$service = new User_service($this->credential_model, $this->user_model);
|
||||
$redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect);
|
||||
if($cookie)
|
||||
{
|
||||
$user_id = $cookie->user_id;
|
||||
$credential = $this->credential_model->get_by_field('user_id', $user_id);
|
||||
$role = $this->_valid_roles[0];
|
||||
if($credential->role_id != $role)
|
||||
{
|
||||
setcookie('admin_remember_me_token', '', 1, base_url());
|
||||
return $this->redirect('admin/login');
|
||||
}
|
||||
$random_string = random_string('alnum', 30);
|
||||
$this->cookies_model->edit(['value' => $random_string, 'expire' => time()+$this->config->item('cookie_expire')], $cookie->id);
|
||||
setcookie('admin_remember_me_token', $random_string, time()+$this->config->item('cookie_expire'), base_url());
|
||||
$this->set_session('credential_id', (int) $credential->id);
|
||||
$this->set_session('user_id', (int) $user_id);
|
||||
$this->set_session('email', (string) $credential->email);
|
||||
$this->set_session('role', (string) $credential->role_id);
|
||||
return $this->redirect($redirect);
|
||||
}
|
||||
else
|
||||
{
|
||||
setcookie('admin_remember_me_token', '', 1, base_url());
|
||||
return $this->redirect('admin/login');
|
||||
}
|
||||
|
||||
$this->error('Wrong email or password.');
|
||||
return $this->redirect('admin/login');
|
||||
}
|
||||
|
||||
public function logout ()
|
||||
{
|
||||
$this->load->helper('cookie');
|
||||
setcookie('admin_remember_me_token', '', 1, base_url());
|
||||
$this->destroy_session();
|
||||
return $this->redirect('admin/login');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Marketing Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_marketing_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'marketing_model';
|
||||
public $_page_name = 'Marketing';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Marketing_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Marketing_admin_list_paginate_view_model(
|
||||
$this->marketing_model,
|
||||
$this->pagination,
|
||||
'/admin/marketing/0');
|
||||
$this->_data['view_model']->set_heading('Marketing');
|
||||
$this->_data['view_model']->set_publish_date(($this->input->get('publish_date', TRUE) != NULL) ? $this->input->get('publish_date', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_title(($this->input->get('title', TRUE) != NULL) ? $this->input->get('title', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'publish_date' => $this->_data['view_model']->get_publish_date(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
'user_id' => $this->_data['view_model']->get_user_id(),
|
||||
'title' => $this->_data['view_model']->get_title(),
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->marketing_model->count($where));
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/marketing/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->marketing_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Marketing', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Marketing_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->marketing_model->set_form_validation(
|
||||
$this->form_validation, $this->marketing_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Marketing_admin_add_view_model($this->marketing_model);
|
||||
$this->_data['view_model']->set_heading('Marketing');
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/MarketingAdd', $this->_data);
|
||||
}
|
||||
|
||||
$title = $this->input->post('title', TRUE);
|
||||
$seo_title = $this->input->post('seo_title', TRUE);
|
||||
$seo_description = $this->input->post('seo_description', TRUE);
|
||||
$content = $this->input->post('content', TRUE);
|
||||
$slug = $this->input->post('slug', TRUE);
|
||||
$password_protect = $this->input->post('password_protect', TRUE);
|
||||
$header_template_path = $this->input->post('header_template_path', TRUE);
|
||||
$content_template_path = $this->input->post('content_template_path', TRUE);
|
||||
$footer_template_path = $this->input->post('footer_template_path', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
$publish_date = date('y-m-d');
|
||||
$slug_path = $this->_data['view_model']->marketing_slug_url();
|
||||
$result = $this->marketing_model->create([
|
||||
'title' => $title,
|
||||
'seo_title' => $seo_title,
|
||||
'seo_description' => $seo_description,
|
||||
'content' => $content,
|
||||
'slug' => $slug_path.$slug,
|
||||
'password_protect' => $password_protect,
|
||||
'header_template_path' => $header_template_path,
|
||||
'content_template_path' => $content_template_path,
|
||||
'footer_template_path' => $footer_template_path,
|
||||
'status' => $status,
|
||||
'publish_date' => $publish_date,
|
||||
'user_id' => $session['user_id']
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Page added successfully');
|
||||
|
||||
return $this->redirect('/admin/marketing/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/MarketingAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->marketing_model->get($id);
|
||||
$session = $this->get_session();
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/marketing/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Marketing_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->marketing_model->set_form_validation(
|
||||
$this->form_validation, $this->marketing_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Marketing_admin_edit_view_model($this->marketing_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Marketing');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/MarketingEdit', $this->_data);
|
||||
}
|
||||
|
||||
$title = $this->input->post('title', TRUE);
|
||||
$seo_title = $this->input->post('seo_title', TRUE);
|
||||
$seo_description = $this->input->post('seo_description', TRUE);
|
||||
$content = $this->input->post('content', TRUE);
|
||||
$slug = $this->input->post('slug', TRUE);
|
||||
$password_protect = $this->input->post('password_protect', TRUE);
|
||||
$header_template_path = $this->input->post('header_template_path', TRUE);
|
||||
$content_template_path = $this->input->post('content_template_path', TRUE);
|
||||
$footer_template_path = $this->input->post('footer_template_path', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$publish_date = date('y-m-d');
|
||||
$slug_path = $this->_data['view_model']->marketing_slug_url();
|
||||
|
||||
$result = $this->marketing_model->edit([
|
||||
'title' => $title,
|
||||
'seo_title' => $seo_title,
|
||||
'seo_description' => $seo_description,
|
||||
'content' => $content,
|
||||
'slug' => $slug_path.$slug,
|
||||
'password_protect' => $password_protect,
|
||||
'header_template_path' => $header_template_path,
|
||||
'content_template_path' => $content_template_path,
|
||||
'footer_template_path' => $footer_template_path,
|
||||
'status' => $status,
|
||||
'publish_date' => $publish_date,
|
||||
'user_id' => $session['user_id']
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Page Edited successfully');
|
||||
|
||||
return $this->redirect('/admin/marketing/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/MarketingEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->marketing_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/marketing/0');
|
||||
}
|
||||
|
||||
return $this->redirect($model->slug);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$model = $this->marketing_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/marketing/0');
|
||||
}
|
||||
|
||||
|
||||
$result = $this->marketing_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Page Deleted successfully');
|
||||
return $this->redirect('/admin/marketing/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->error('Error');
|
||||
return redirect('/admin/marketing/0');
|
||||
}
|
||||
|
||||
public function bulk_delete()
|
||||
{
|
||||
|
||||
$bulk_items = $this->input->post('bulk_items');
|
||||
foreach ($bulk_items as $key => $id) {
|
||||
$this->marketing_model->real_delete($id);
|
||||
}
|
||||
echo 'success';
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Credential Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_me_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'credential_model';
|
||||
public $_page_name = 'Change Password';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function me()
|
||||
{
|
||||
$session = $this->get_session();
|
||||
$model = $this->credential_model->get($session['credential_id']);
|
||||
$this->_data['email'] = $model->email;
|
||||
$this->_data['password'] = '';
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
|
||||
$this->form_validation->set_rules('password', 'Password', '');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/Mes', $this->_data);
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
|
||||
$payload = [
|
||||
'email' => $email,
|
||||
];
|
||||
|
||||
if (strlen($password) > 1)
|
||||
{
|
||||
$payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
$result = $this->credential_model->edit($payload, $session['credential_id']);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Saved');
|
||||
return $this->redirect('/admin/me', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/Mes', $this->_data);
|
||||
}
|
||||
}
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Order Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_order_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'order_model';
|
||||
public $_page_name = 'Order';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('school_model');
|
||||
$this->load->model('professor_model');
|
||||
$this->load->model('textbook_model');
|
||||
$this->load->model('classes_model');
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('payout_model');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Order_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Order_admin_list_paginate_view_model(
|
||||
$this->order_model,
|
||||
$this->pagination,
|
||||
'/admin/order/0');
|
||||
$this->_data['view_model']->set_heading('Order');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_purchase_user_id(($this->input->get('purchase_user_id', TRUE) != NULL) ? $this->input->get('purchase_user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_sale_user_id(($this->input->get('sale_user_id', TRUE) != NULL) ? $this->input->get('sale_user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_inventory_id(($this->input->get('inventory_id', TRUE) != NULL) ? $this->input->get('inventory_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_date(($this->input->get('order_date', TRUE) != NULL) ? $this->input->get('order_date', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_time(($this->input->get('order_time', TRUE) != NULL) ? $this->input->get('order_time', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_subtotal(($this->input->get('subtotal', TRUE) != NULL) ? $this->input->get('subtotal', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_tax(($this->input->get('tax', TRUE) != NULL) ? $this->input->get('tax', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_discount(($this->input->get('discount', TRUE) != NULL) ? $this->input->get('discount', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_total(($this->input->get('total', TRUE) != NULL) ? $this->input->get('total', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'purchase_user_id' => $this->_data['view_model']->get_purchase_user_id(),
|
||||
'sale_user_id' => $this->_data['view_model']->get_sale_user_id(),
|
||||
'inventory_id' => $this->_data['view_model']->get_inventory_id(),
|
||||
'order_date' => $this->_data['view_model']->get_order_date(),
|
||||
'order_time' => $this->_data['view_model']->get_order_time(),
|
||||
'subtotal' => $this->_data['view_model']->get_subtotal(),
|
||||
'tax' => $this->_data['view_model']->get_tax(),
|
||||
'discount' => $this->_data['view_model']->get_discount(),
|
||||
'total' => $this->_data['view_model']->get_total(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->order_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/order/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->order_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
// load data
|
||||
$schools = $this->school_model->get_all(['status' => 1]);
|
||||
$professors = $this->professor_model->get_all(['status' => 1]);
|
||||
$textbooks = $this->db->select('isbn')->from('inventory')->get()->result_array();
|
||||
$classes = $this->classes_model->get_all(['status' => 1]);
|
||||
|
||||
$inventory_data = $this->db->select('i.*,p.name as professor,s.name as school')->from('inventory i')
|
||||
->join('school s','s.id=i.school_id')
|
||||
->join('professor p','p.id=i.professor_id')
|
||||
->get()->result_array();
|
||||
|
||||
$user_id_array = $this->user_model->get_all();
|
||||
$this->_data['users'] = $user_id_array;
|
||||
if($user_id_array){
|
||||
$user_id_array = array_column($user_id_array,'first_name','id');
|
||||
}
|
||||
|
||||
|
||||
if( $this->_data['view_model']->get_list()){
|
||||
|
||||
foreach ( $this->_data['view_model']->get_list() as $key => &$value) {
|
||||
$value->school_id = '';
|
||||
$value->professor_id = '';
|
||||
$value->isbn = '';
|
||||
$value->purchase_user_id = $user_id_array[$value->purchase_user_id] ?? '';
|
||||
foreach ($inventory_data as $ke=> $v) {
|
||||
# code...
|
||||
if($v['id']==$value->inventory_id){
|
||||
$value->school_id = $v['school'];
|
||||
$value->professor_id = $v['professor'];
|
||||
$value->isbn = $v['isbn'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Order', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->order_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/order/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Order_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Order_admin_view_view_model($this->order_model);
|
||||
$this->_data['view_model']->set_heading('Order');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/OrderView', $this->_data);
|
||||
}
|
||||
public function refund($id){
|
||||
|
||||
$this->order_model->update('order', [ 'status' => 2 ],['id' => $id ]);
|
||||
$this->payout_model->update('payout',[ 'status'=>3 ],['order_id' => $id ] );
|
||||
$order_data = $this->db->select('*')->from('order')->where('id',$id)->get()->row_array();
|
||||
|
||||
//create setup intent
|
||||
$stripe = new \Stripe\StripeClient(
|
||||
$this->config->item('stripe_secret_key')
|
||||
);
|
||||
|
||||
$refund = $stripe->refunds->create([
|
||||
'charge' => $order_data['stripe_charge_id'],
|
||||
]);
|
||||
|
||||
if ($refund)
|
||||
{
|
||||
$this->success('Order Refunded successfully.');
|
||||
}
|
||||
|
||||
return redirect('admin/order/0','refresh');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Payout Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_payout_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'payout_model';
|
||||
public $_page_name = 'Payout';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('user_model');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Payout_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Payout_admin_list_paginate_view_model(
|
||||
$this->payout_model,
|
||||
$this->pagination,
|
||||
'/admin/payout/0');
|
||||
$this->_data['view_model']->set_heading('Payout');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_amount(($this->input->get('amount', TRUE) != NULL) ? $this->input->get('amount', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'user_id' => $this->_data['view_model']->get_user_id(),
|
||||
'amount' => $this->_data['view_model']->get_amount(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->payout_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/payout/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->payout_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
$user_data = $this->user_model->get_all();
|
||||
$this->_data['users'] = $user_data;
|
||||
$user_id_array = [];
|
||||
$user_email_array = [];
|
||||
if($user_data){
|
||||
$user_id_array = array_column($user_data,'first_name','id');
|
||||
$user_email_array = array_column($user_data,'paypal_email','id');
|
||||
}
|
||||
// print_r($user_id_array);exit;
|
||||
if($this->_data['view_model']->get_list() ){
|
||||
|
||||
foreach ( $this->_data['view_model']->get_list() as $key => &$value) {
|
||||
$value->paypal_email = $user_email_array[$value->user_id] ?? '';
|
||||
$value->user_id = $user_id_array[$value->user_id] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Payout', $this->_data);
|
||||
}
|
||||
public function paid($id){
|
||||
$this->payout_model->update('payout',['status'=>1],['id'=>$id]);
|
||||
|
||||
$this->success('User paid successfully');
|
||||
return redirect('admin/payout/0','refresh');
|
||||
}
|
||||
public function mark_all_paid(){
|
||||
|
||||
if($_GET['id']){
|
||||
|
||||
foreach ($_GET['id'] as $key => $value) {
|
||||
$this->payout_model->update('payout',['status'=>1],['id'=>$value]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->success('Bulk paid successfully');
|
||||
return redirect('admin/payout/0','refresh');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Professor Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_professor_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'professor_model';
|
||||
public $_page_name = 'Professor';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Professor_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Professor_admin_list_paginate_view_model(
|
||||
$this->professor_model,
|
||||
$this->pagination,
|
||||
'/admin/professor/0');
|
||||
$this->_data['view_model']->set_heading('Professor');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'name' => $this->_data['view_model']->get_name(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->professor_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/professor/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->professor_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Professor', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Professor_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->professor_model->set_form_validation(
|
||||
$this->form_validation, $this->professor_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Professor_admin_add_view_model($this->professor_model);
|
||||
$this->_data['view_model']->set_heading('Professor');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/ProfessorAdd', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->professor_model->create([
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Professor added.');
|
||||
|
||||
return $this->redirect('/admin/professor/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/ProfessorAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->professor_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/professor/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Professor_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->professor_model->set_form_validation(
|
||||
$this->form_validation, $this->professor_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Professor_admin_edit_view_model($this->professor_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Professor');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/ProfessorEdit', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->professor_model->edit([
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Professor updated.');
|
||||
|
||||
return $this->redirect('/admin/professor/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/ProfessorEdit', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->professor_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->professor_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
|
||||
/**
|
||||
* Admin Profile Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_profile_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'user_model';
|
||||
public $_page_name = 'Profile';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->model('credential_model');
|
||||
$session = $this->get_session();
|
||||
$model = $this->user_model->get($session['user_id']);
|
||||
$id = $session['user_id'];
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/dashboard');
|
||||
}
|
||||
|
||||
$credential = $this->credential_model->get($session['credential_id']);
|
||||
$email_validation_rules = 'required|valid_email';
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Admin_profile_view_model.php';
|
||||
|
||||
if ($this->input->post('email') != $credential->email)
|
||||
{
|
||||
$email_validation_rules .= '|is_unique[credential.email]';
|
||||
}
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', $email_validation_rules);
|
||||
$this->form_validation->set_rules('first_name', 'First Name', 'required');
|
||||
$this->form_validation->set_rules('last_name', 'Last Name', 'required');
|
||||
|
||||
$this->_data['view_model'] = new Admin_profile_view_model($this->user_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_email($credential->email);
|
||||
$this->_data['view_model']->set_heading('Admin');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/Profile', $this->_data);
|
||||
}
|
||||
|
||||
$first_name = $this->input->post('first_name');
|
||||
$last_name = $this->input->post('last_name');
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
|
||||
$payload = [
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name
|
||||
];
|
||||
|
||||
$result = $this->user_model->edit_raw($payload, $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$credential_payload = [
|
||||
'email' => $email
|
||||
];
|
||||
|
||||
if (strlen($password) > 0)
|
||||
{
|
||||
$credential_payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
$result = $this->credential_model->edit_raw($credential_payload, $session['credential_id']);
|
||||
$this->success('Saved');
|
||||
return $this->redirect('/admin/profile', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/Profile', $this->_data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
|
||||
/**
|
||||
* Admin Profile Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_profile_credential_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'credential_model';
|
||||
public $_page_name = 'Credentials';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
$session = $this->get_session();
|
||||
$user_obj = $this->user_model->get($session['user_id']);
|
||||
$session = $this->get_session();
|
||||
$this->load->model($this->_model_file);
|
||||
$model = $this->credential_model->get($user_obj->credential_id ?? 0);
|
||||
$id = $user_obj->credential_id ?? 0;
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
die();
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Admin_profile_credential_view_model.php';
|
||||
$email_validation_rules = 'required|valid_email';
|
||||
|
||||
if ($this->input->post('email') != $session['email'])
|
||||
{
|
||||
$email_validation_rules .= '|is_unique[credential.email]';
|
||||
}
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', $email_validation_rules);
|
||||
|
||||
$this->_data['view_model'] = new Admin_profile_credential_view_model($model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Admin');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/Credential', $this->_data);
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
|
||||
$payload = [
|
||||
'email' => $email,
|
||||
];
|
||||
|
||||
if (strlen($password) > 0)
|
||||
{
|
||||
$payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
$result = $this->credential_model->edit_raw($payload, $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Saved');
|
||||
return $this->redirect('/admin/credential?layout_clean_mode=1', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/Credential', $this->_data);
|
||||
}
|
||||
}
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Refund Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_refund_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'refund_model';
|
||||
public $_page_name = 'Refund';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Refund_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Refund_admin_list_paginate_view_model(
|
||||
$this->refund_model,
|
||||
$this->pagination,
|
||||
'/admin/refund/0');
|
||||
$this->_data['view_model']->set_heading('Refund');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_amount(($this->input->get('amount', TRUE) != NULL) ? $this->input->get('amount', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_reason(($this->input->get('reason', TRUE) != NULL) ? $this->input->get('reason', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_stripe_charge_id(($this->input->get('stripe_charge_id', TRUE) != NULL) ? $this->input->get('stripe_charge_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_stripe_invoice_id(($this->input->get('stripe_invoice_id', TRUE) != NULL) ? $this->input->get('stripe_invoice_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'user_id' => $this->_data['view_model']->get_user_id(),
|
||||
'amount' => $this->_data['view_model']->get_amount(),
|
||||
'reason' => $this->_data['view_model']->get_reason(),
|
||||
'stripe_charge_id' => $this->_data['view_model']->get_stripe_charge_id(),
|
||||
'stripe_invoice_id' => $this->_data['view_model']->get_stripe_invoice_id(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->refund_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/refund/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->refund_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Refund', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Refund_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->refund_model->set_form_validation(
|
||||
$this->form_validation, $this->refund_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Refund_admin_add_view_model($this->refund_model);
|
||||
$this->_data['view_model']->set_heading('Refund');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/RefundAdd', $this->_data);
|
||||
}
|
||||
|
||||
$order_id = $this->input->post('order_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$amount = $this->input->post('amount', TRUE);
|
||||
$reason = $this->input->post('reason', TRUE);
|
||||
$explanation = $this->input->post('explanation', TRUE);
|
||||
$receipt_url = $this->input->post('receipt_url', TRUE);
|
||||
$stripe_charge_id = $this->input->post('stripe_charge_id', TRUE);
|
||||
$stripe_invoice_id = $this->input->post('stripe_invoice_id', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->refund_model->create([
|
||||
'order_id' => $order_id,
|
||||
'user_id' => $user_id,
|
||||
'amount' => $amount,
|
||||
'reason' => $reason,
|
||||
'explanation' => $explanation,
|
||||
'receipt_url' => $receipt_url,
|
||||
'stripe_charge_id' => $stripe_charge_id,
|
||||
'stripe_invoice_id' => $stripe_invoice_id,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/refund/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/RefundAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->refund_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/refund/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Refund_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->refund_model->set_form_validation(
|
||||
$this->form_validation, $this->refund_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Refund_admin_edit_view_model($this->refund_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Refund');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/RefundEdit', $this->_data);
|
||||
}
|
||||
|
||||
$order_id = $this->input->post('order_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$amount = $this->input->post('amount', TRUE);
|
||||
$reason = $this->input->post('reason', TRUE);
|
||||
$explanation = $this->input->post('explanation', TRUE);
|
||||
$receipt_url = $this->input->post('receipt_url', TRUE);
|
||||
$stripe_charge_id = $this->input->post('stripe_charge_id', TRUE);
|
||||
$stripe_invoice_id = $this->input->post('stripe_invoice_id', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->refund_model->edit([
|
||||
'order_id' => $order_id,
|
||||
'user_id' => $user_id,
|
||||
'amount' => $amount,
|
||||
'reason' => $reason,
|
||||
'explanation' => $explanation,
|
||||
'receipt_url' => $receipt_url,
|
||||
'stripe_charge_id' => $stripe_charge_id,
|
||||
'stripe_invoice_id' => $stripe_invoice_id,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/refund/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/RefundEdit', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Review Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_review_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'review_model';
|
||||
public $_page_name = 'Review';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('user_model');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Review_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Review_admin_list_paginate_view_model(
|
||||
$this->review_model,
|
||||
$this->pagination,
|
||||
'/admin/review/0');
|
||||
$this->_data['view_model']->set_heading('Review');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_comment(($this->input->get('comment', TRUE) != NULL) ? $this->input->get('comment', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_rating(($this->input->get('rating', TRUE) != NULL) ? $this->input->get('rating', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'user_id' => $this->_data['view_model']->get_user_id(),
|
||||
'comment' => $this->_data['view_model']->get_comment(),
|
||||
'rating' => $this->_data['view_model']->get_rating(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->review_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/review/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->review_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
$user_id_array = $this->user_model->get_all();
|
||||
$this->_data['users'] = $user_id_array;
|
||||
if($user_id_array){
|
||||
$user_id_array = array_column($user_id_array,'first_name','id');
|
||||
}
|
||||
// print_r($user_id_array);exit;
|
||||
if($this->_data['view_model']->get_list() ){
|
||||
|
||||
foreach ( $this->_data['view_model']->get_list() as $key => &$value) {
|
||||
$value->user_id = $user_id_array[$value->user_id] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Review', $this->_data);
|
||||
}
|
||||
|
||||
public function reject($id){
|
||||
$this->review_model->update('review',['status'=>0],['id'=>$id]);
|
||||
|
||||
$this->success('Review Rejected successfully');
|
||||
return redirect('admin/review/0','refresh');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* School Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_school_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'school_model';
|
||||
public $_page_name = 'School';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/School_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new School_admin_list_paginate_view_model(
|
||||
$this->school_model,
|
||||
$this->pagination,
|
||||
'/admin/school/0');
|
||||
$this->_data['view_model']->set_heading('School');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'name' => $this->_data['view_model']->get_name(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->school_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/school/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->school_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/School', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/School_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->school_model->set_form_validation(
|
||||
$this->form_validation, $this->school_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new School_admin_add_view_model($this->school_model);
|
||||
$this->_data['view_model']->set_heading('School');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/SchoolAdd', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->school_model->create([
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('School added.');
|
||||
|
||||
return $this->redirect('/admin/school/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/SchoolAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->school_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/school/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/School_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->school_model->set_form_validation(
|
||||
$this->form_validation, $this->school_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new School_admin_edit_view_model($this->school_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('School');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/SchoolEdit', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->school_model->edit([
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('School updated.');
|
||||
|
||||
return $this->redirect('/admin/school/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/SchoolEdit', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->school_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->school_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Setting Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_setting_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'setting_model';
|
||||
public $_page_name = 'Setting';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Setting_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Setting_admin_list_paginate_view_model(
|
||||
$this->setting_model,
|
||||
$this->pagination,
|
||||
'/admin/setting/0');
|
||||
$this->_data['view_model']->set_heading('Setting');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_key(($this->input->get('key', TRUE) != NULL) ? $this->input->get('key', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_value(($this->input->get('value', TRUE) != NULL) ? $this->input->get('value', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'key' => $this->_data['view_model']->get_key(),
|
||||
'value' => $this->_data['view_model']->get_value(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->setting_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/setting/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->setting_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Setting', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->setting_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/setting/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Setting_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->setting_model->set_form_validation(
|
||||
$this->form_validation, $this->setting_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Setting_admin_edit_view_model($this->setting_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Setting');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/SettingEdit', $this->_data);
|
||||
}
|
||||
|
||||
$value = $this->input->post('value', TRUE);
|
||||
|
||||
$result = $this->setting_model->edit([
|
||||
'value' => $value,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/setting/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/SettingEdit', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_api_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Sms API Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_sms_api_controller extends Admin_api_controller
|
||||
{
|
||||
protected $_model_file = 'sms_model';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Sms_admin_list_view_model.php';
|
||||
$this->_data['view_model'] = new Sms_admin_list_view_model($this->sms_model);
|
||||
$this->_data['view_model']->set_list($this->sms_model->get_all());
|
||||
$this->_data['view_model']->set_heading('Sms');
|
||||
return $this->success($this->_data['view_model']->to_json(), 200);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$this->form_validation = $this->sms_model->set_form_validation(
|
||||
$this->form_validation, $this->sms_model->get_all_validation_rule());
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->_render_validation_error();
|
||||
}
|
||||
|
||||
$slug = $this->input->post('slug', TRUE);
|
||||
$content = $this->input->post('content', TRUE);
|
||||
$tag = $this->input->post('tag', TRUE);
|
||||
|
||||
$result = $this->sms_model->create([
|
||||
'slug' => $slug,
|
||||
'content' => $content,
|
||||
'tag' => $tag,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->success([], 200);
|
||||
}
|
||||
|
||||
return $this->_render_custom_error([
|
||||
'error' => 'Error'
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->sms_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
return $this->_render_custom_error([
|
||||
'error' => 'Error'
|
||||
]);
|
||||
}
|
||||
|
||||
$this->form_validation = $this->sms_model->set_form_validation(
|
||||
$this->form_validation, $this->sms_model->get_all_edit_validation_rule());
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->_render_validation_error();
|
||||
}
|
||||
|
||||
$content = $this->input->post('content', TRUE);
|
||||
$tag = $this->input->post('tag', TRUE);
|
||||
$slug = $this->input->post('slug', TRUE);
|
||||
|
||||
$result = $this->sms_model->edit([
|
||||
'content' => $content,
|
||||
'tag' => $tag,
|
||||
'slug' => $slug,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->success([], 200);
|
||||
}
|
||||
|
||||
return $this->_render_custom_error([
|
||||
'error' => 'Error'
|
||||
]);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->sms_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
return $this->_render_custom_error([
|
||||
'error' => 'Error'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Sms_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Sms_admin_view_view_model($this->sms_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
return $this->success(['data' => $this->_data['view_model']->to_json()], 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Sms Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_sms_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'sms_model';
|
||||
public $_page_name = 'SMS';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
$session = $this->get_session();
|
||||
include_once __DIR__ . '/../../view_models/Sms_admin_list_view_model.php';
|
||||
$this->_data['view_model'] = new Sms_admin_list_view_model($this->sms_model);
|
||||
$this->_data['view_model']->set_list($this->sms_model->get_all());
|
||||
$this->_data['view_model']->set_heading('SMS');
|
||||
|
||||
|
||||
return $this->render('Admin/Sms', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Sms_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->sms_model->set_form_validation(
|
||||
$this->form_validation, $this->sms_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Sms_admin_add_view_model($this->sms_model);
|
||||
$this->_data['view_model']->set_heading('SMS');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/SmsAdd', $this->_data);
|
||||
}
|
||||
|
||||
$slug = $this->input->post('slug', TRUE);
|
||||
$content = $this->input->post('content', TRUE);
|
||||
$tag = $this->input->post('tag', TRUE);
|
||||
|
||||
$result = $this->sms_model->create([
|
||||
'slug' => $slug,
|
||||
'content' => $content,
|
||||
'tag' => $tag,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/sms', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/SmsAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->sms_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/sms');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Sms_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->sms_model->set_form_validation(
|
||||
$this->form_validation, $this->sms_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Sms_admin_edit_view_model($this->sms_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('SMS');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/SmsEdit', $this->_data);
|
||||
}
|
||||
|
||||
$content = $this->input->post('content', TRUE);
|
||||
$tag = $this->input->post('tag', TRUE);
|
||||
$slug = $this->input->post('slug', TRUE);
|
||||
|
||||
$result = $this->sms_model->edit([
|
||||
'content' => $content,
|
||||
'tag' => $tag,
|
||||
'slug' => $slug,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/sms', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/SmsEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->sms_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/sms');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Sms_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Sms_admin_view_view_model($this->sms_model);
|
||||
$this->_data['view_model']->set_heading('SMS');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/SmsView', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_api_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Spreadsheet API Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_spreadsheet_api_controller extends Admin_api_controller
|
||||
{
|
||||
protected $_model_file = 'spreadsheet_model';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Spreadsheet_admin_list_paginate_view_model.php';
|
||||
|
||||
$this->_data['view_model'] = new Spreadsheet_admin_list_paginate_view_model(
|
||||
$this->spreadsheet_model,
|
||||
$this->pagination,
|
||||
'/admin/spreadsheet/0');
|
||||
$this->_data['view_model']->set_heading('{{{page_name}}}');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'name' => $this->_data['view_model']->get_name(),
|
||||
'user_id' => $this->_data['view_model']->get_user_id(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
'created_at' => $this->_data['view_model']->get_created_at(),
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->spreadsheet_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page(10);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->spreadsheet_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where));
|
||||
return $this->success($this->_data['view_model']->to_json(), 200);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$this->form_validation = $this->spreadsheet_model->set_form_validation(
|
||||
$this->form_validation, $this->spreadsheet_model->get_all_validation_rule());
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->_render_validation_error();
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$value = $this->input->post('value', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->spreadsheet_model->create([
|
||||
'name' => $name,
|
||||
'value' => $value,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Spreadsheet added.');
|
||||
|
||||
return $this->success([], 200);
|
||||
}
|
||||
|
||||
return $this->_render_custom_error([
|
||||
'error' => 'Error'
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->spreadsheet_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
return $this->_render_custom_error([
|
||||
'error' => 'Error'
|
||||
]);
|
||||
}
|
||||
|
||||
$this->form_validation = $this->spreadsheet_model->set_form_validation(
|
||||
$this->form_validation, $this->spreadsheet_model->get_all_edit_validation_rule());
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->_render_validation_error();
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$value = $this->input->post('value', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->spreadsheet_model->edit([
|
||||
'name' => $name,
|
||||
'value' => $value,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Spreadsheet updated.');
|
||||
|
||||
return $this->success([], 200);
|
||||
}
|
||||
|
||||
return $this->_render_custom_error([
|
||||
'error' => 'Error'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,433 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Spreadsheet Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_spreadsheet_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'spreadsheet_model';
|
||||
public $_page_name = 'Spreadsheet';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Spreadsheet_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Spreadsheet_admin_list_paginate_view_model(
|
||||
$this->spreadsheet_model,
|
||||
$this->pagination,
|
||||
'/admin/spreadsheet/0');
|
||||
$this->_data['view_model']->set_heading('Spreadsheet');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'name' => $this->_data['view_model']->get_name(),
|
||||
'user_id' => $this->_data['view_model']->get_user_id(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
'created_at' => $this->_data['view_model']->get_created_at(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->spreadsheet_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/spreadsheet/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->spreadsheet_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Spreadsheet', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Spreadsheet_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->spreadsheet_model->set_form_validation(
|
||||
$this->form_validation, $this->spreadsheet_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Spreadsheet_admin_add_view_model($this->spreadsheet_model);
|
||||
$this->_data['view_model']->set_heading('Spreadsheet');
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/SpreadsheetAdd', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$value = $this->input->post('value', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$final_value = "";
|
||||
$luckysheet_order = "";
|
||||
|
||||
$file_name = $_FILES['value']['name'];
|
||||
|
||||
if($file_name != "")
|
||||
{
|
||||
|
||||
$original_name = "";
|
||||
$original_name = explode('.' , $file_name);
|
||||
if(is_array($original_name) && count($original_name) > 1)
|
||||
{
|
||||
$original_name = $original_name[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$value_file = fopen($_FILES['value']['tmp_name'], "r");
|
||||
if($_FILES['value']['type'] == 'text/csv')
|
||||
{
|
||||
$default_delimeter = ";";
|
||||
$headers = fgetcsv($value_file, 10000, $default_delimeter);
|
||||
/**
|
||||
* Condition for checking and setting up the delimeter for the csv
|
||||
*/
|
||||
if(is_array($headers) && count($headers) <= 1)
|
||||
{
|
||||
$headers = fgetcsv($value_file, 10000, ',');
|
||||
if(is_array($headers) && count($headers)>1)
|
||||
{
|
||||
$default_delimeter = ",";
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($headers) && is_array($headers))
|
||||
{
|
||||
|
||||
$temp_array[] = array();
|
||||
for( $x = 0 ; $x < count($headers); $x++)
|
||||
{
|
||||
$header_array = array(
|
||||
'r' => 0,
|
||||
'c' => $x,
|
||||
'v' => array(
|
||||
'ct' => array(
|
||||
'fa' => 'General',
|
||||
't' => 'g'
|
||||
),
|
||||
'm' => $headers[$x],
|
||||
'v' => $headers[$x]
|
||||
)
|
||||
);
|
||||
$temp_array[$x] = $header_array;
|
||||
}
|
||||
$ro = 1 ; //count of rows
|
||||
while (($data = fgetcsv($value_file, 1000,$default_delimeter)) !== FALSE)
|
||||
{
|
||||
|
||||
if(!empty($data) && is_array($data))
|
||||
{
|
||||
foreach($data as $data_key => $values)
|
||||
{
|
||||
|
||||
$body_data = array(
|
||||
'r' => $ro,
|
||||
'c' => $data_key,
|
||||
'v' => array(
|
||||
'ct' => array(
|
||||
'fa' => 'General',
|
||||
't' => 'g'
|
||||
),
|
||||
'm' => $values,
|
||||
'v' => $values
|
||||
)
|
||||
);
|
||||
$temp_array[] = $body_data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$ro++;
|
||||
}
|
||||
|
||||
|
||||
$luckysheet_format =
|
||||
array(
|
||||
array(
|
||||
'name' => $original_name, //Worksheet name
|
||||
'color' => '', //Worksheet color
|
||||
'index' => '0', //Worksheet index
|
||||
'status' => 1, //Worksheet active status
|
||||
'order' => 0, //The order of the worksheet
|
||||
'hide' => 0,//Whether worksheet hide
|
||||
'row' => 100, //the number of rows in a sheet
|
||||
'column' => 36, //the number of columns in a sheet
|
||||
'defaultRowHeight' => 19, //Customized default row height
|
||||
'defaultColWidth' => 73, //Customized default column width
|
||||
'celldata' => $temp_array,//Initial the cell data
|
||||
'config' => array(
|
||||
'merge' => new ArrayObject(), //merged cells
|
||||
'rowlen' => new ArrayObject(), //Table row height
|
||||
'columnlen' => new ArrayObject(), //Table column width
|
||||
'rowhidden' => new ArrayObject(), //hidden rows
|
||||
'colhidden' => new ArrayObject(), //hidden columns
|
||||
'borderInfo'=> new ArrayObject(), //borders
|
||||
'authority' => new ArrayObject(), //Worksheet protection
|
||||
),
|
||||
'scrollLeft' => 0, //Left and right scroll bar position
|
||||
'scrollTop' => 315, //Up and down scroll bar position
|
||||
'luckysheet_select_save' => [], //selected area
|
||||
'calcChain' => [],//Formula chain
|
||||
'isPivotTable' => false,//Whether is pivot table
|
||||
'pivotTable' => new ArrayObject(),//Pivot table settings
|
||||
'filter_select' => new ArrayObject(),//Filter range
|
||||
'filter' => null,//Filter configuration
|
||||
'luckysheet_alternateformat_save' => array(), //Alternate colors
|
||||
'luckysheet_alternateformat_save_modelCustom' => [], //Customize alternate colors
|
||||
'luckysheet_conditionformat_save' => new ArrayObject(),//condition format
|
||||
'frozen' => new ArrayObject(), //freeze row and column configuration
|
||||
'chart' => [], //Chart configuration
|
||||
'zoomRatio' => 1, // zoom ratio
|
||||
'image' => [], //image
|
||||
'showGridLines' => 1, //Whether to show grid lines
|
||||
)
|
||||
);
|
||||
|
||||
$luckysheet_order = json_encode($luckysheet_format);
|
||||
|
||||
}
|
||||
fclose($value_file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$luckysheet_format =
|
||||
array(
|
||||
array(
|
||||
'name' => $name, //Worksheet name
|
||||
'color' => '', //Worksheet color
|
||||
'index' => '0', //Worksheet index
|
||||
'status' => 1, //Worksheet active status
|
||||
'order' => 0, //The order of the worksheet
|
||||
'hide' => 0,//Whether worksheet hide
|
||||
'row' => 100, //the number of rows in a sheet
|
||||
'column' => 36, //the number of columns in a sheet
|
||||
'defaultRowHeight' => 19, //Customized default row height
|
||||
'defaultColWidth' => 73, //Customized default column width
|
||||
'celldata' => [],//Initial the cell data
|
||||
'config' => array(
|
||||
'merge' => new ArrayObject(), //merged cells
|
||||
'rowlen' => new ArrayObject(), //Table row height
|
||||
'columnlen' => new ArrayObject(), //Table column width
|
||||
'rowhidden' => new ArrayObject(), //hidden rows
|
||||
'colhidden' => new ArrayObject(), //hidden columns
|
||||
'borderInfo'=> new ArrayObject(), //borders
|
||||
'authority' => new ArrayObject(), //Worksheet protection
|
||||
),
|
||||
'scrollLeft' => 0, //Left and right scroll bar position
|
||||
'scrollTop' => 315, //Up and down scroll bar position
|
||||
'luckysheet_select_save' => [], //selected area
|
||||
'calcChain' => [],//Formula chain
|
||||
'isPivotTable' => false,//Whether is pivot table
|
||||
'pivotTable' => new ArrayObject(),//Pivot table settings
|
||||
'filter_select' => new ArrayObject(),//Filter range
|
||||
'filter' => null,//Filter configuration
|
||||
'luckysheet_alternateformat_save' => array(), //Alternate colors
|
||||
'luckysheet_alternateformat_save_modelCustom' => [], //Customize alternate colors
|
||||
'luckysheet_conditionformat_save' => new ArrayObject(),//condition format
|
||||
'frozen' => new ArrayObject(), //freeze row and column configuration
|
||||
'chart' => [], //Chart configuration
|
||||
'zoomRatio' => 1, // zoom ratio
|
||||
'image' => [], //image
|
||||
'showGridLines' => 1, //Whether to show grid lines
|
||||
)
|
||||
);
|
||||
|
||||
$luckysheet_order = json_encode($luckysheet_format);
|
||||
|
||||
}
|
||||
|
||||
$result = $this->spreadsheet_model->create([
|
||||
'name' => $name,
|
||||
'value' => $luckysheet_order,
|
||||
'status' => $status,
|
||||
'user_id' => $session['user_id']
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Spreadsheet added.');
|
||||
|
||||
return $this->redirect('/admin/spreadsheet/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/SpreadsheetAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->spreadsheet_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/spreadsheet/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Spreadsheet_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->spreadsheet_model->set_form_validation(
|
||||
$this->form_validation, $this->spreadsheet_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Spreadsheet_admin_edit_view_model($this->spreadsheet_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Spreadsheet');
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/SpreadsheetEdit', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->spreadsheet_model->edit([
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Spreadsheet updated.');
|
||||
|
||||
return $this->redirect('/admin/spreadsheet/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/SpreadsheetEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function bulk_delete()
|
||||
{
|
||||
|
||||
$bulk_items = $this->input->post('bulk_items');
|
||||
foreach ($bulk_items as $key => $id) {
|
||||
$this->spreadsheet_model->real_delete($id);
|
||||
}
|
||||
echo 'success';
|
||||
exit();
|
||||
}
|
||||
/**
|
||||
* Function to return spreadsheet data only
|
||||
*/
|
||||
public function spreadsheet_data($id)
|
||||
{
|
||||
$model = $this->spreadsheet_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/spreadsheet/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Spreadsheet_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->spreadsheet_model->set_form_validation(
|
||||
$this->form_validation, $this->spreadsheet_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Spreadsheet_admin_edit_view_model($this->spreadsheet_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Spreadsheet');
|
||||
|
||||
return $this->render('Admin/Spreadsheet_view_only', $this->_data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* function to update the sheet
|
||||
*/
|
||||
|
||||
public function update_sheet($id)
|
||||
{
|
||||
$model = $this->spreadsheet_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
echo json_encode(['error'=> 'error']);
|
||||
exit();
|
||||
}
|
||||
$data = file_get_contents("php://input",TRUE);
|
||||
if($data)
|
||||
{
|
||||
$result = $this->spreadsheet_model->edit([
|
||||
'value' => $data,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Spreadsheet Updated Successfully.');
|
||||
echo json_encode(['success'=> 'updated']);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$this->error('Error');
|
||||
echo json_encode(['error'=> 'error']);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Suggestion Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_suggestion_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'suggestion_model';
|
||||
public $_page_name = 'Suggestion';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Suggestion_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Suggestion_admin_list_paginate_view_model(
|
||||
$this->suggestion_model,
|
||||
$this->pagination,
|
||||
'/admin/suggestion/0');
|
||||
$this->_data['view_model']->set_heading('Suggestion');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_email(($this->input->get('email', TRUE) != NULL) ? $this->input->get('email', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_suggestion_type(($this->input->get('suggestion_type', TRUE) != NULL) ? $this->input->get('suggestion_type', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_additional_notes(($this->input->get('additional_notes', TRUE) != NULL) ? $this->input->get('additional_notes', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'name' => $this->_data['view_model']->get_name(),
|
||||
'email' => $this->_data['view_model']->get_email(),
|
||||
'suggestion_type' => $this->_data['view_model']->get_suggestion_type(),
|
||||
'additional_notes' => $this->_data['view_model']->get_additional_notes(),
|
||||
'created_at' => $this->_data['view_model']->get_created_at(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->suggestion_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/suggestion/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->suggestion_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Suggestion', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->suggestion_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/suggestion/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Suggestion_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Suggestion_admin_view_view_model($this->suggestion_model);
|
||||
$this->_data['view_model']->set_heading('Suggestion');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/SuggestionView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$model = $this->suggestion_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
// $this->error('Error');
|
||||
// return redirect('/admin/suggestion/0');
|
||||
}
|
||||
|
||||
$result = $this->suggestion_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
return $this->redirect('/admin/suggestion/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->error('Error');
|
||||
return redirect('/admin/suggestion/0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Tax Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_tax_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'tax_model';
|
||||
public $_page_name = 'Tax';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Tax_admin_list_paginate_view_model.php';
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
$session = $this->get_session();
|
||||
$where = [];
|
||||
$this->_data['view_model'] = new Tax_admin_list_paginate_view_model(
|
||||
$this->tax_model,
|
||||
$this->pagination,
|
||||
'/admin/tax/0');
|
||||
$this->_data['view_model']->set_heading('Tax');
|
||||
$this->_data['view_model']->set_total_rows($this->tax_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/tax/0');
|
||||
$this->_data['view_model']->set_list($this->tax_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Tax', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Tax_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->tax_model->set_form_validation(
|
||||
$this->form_validation, $this->tax_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Tax_admin_add_view_model($this->tax_model);
|
||||
$this->_data['view_model']->set_heading('Tax');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/TaxAdd', $this->_data);
|
||||
}
|
||||
|
||||
$tax = $this->input->post('tax', TRUE);
|
||||
|
||||
$result = $this->tax_model->create([
|
||||
'tax' => $tax,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/tax/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/TaxAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->tax_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/tax/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Tax_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->tax_model->set_form_validation(
|
||||
$this->form_validation, $this->tax_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Tax_admin_edit_view_model($this->tax_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Tax');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/TaxEdit', $this->_data);
|
||||
}
|
||||
|
||||
$tax = $this->input->post('tax', TRUE);
|
||||
|
||||
$result = $this->tax_model->edit([
|
||||
'tax' => $tax,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/tax/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/TaxEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->tax_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/tax/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Tax_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Tax_admin_view_view_model($this->tax_model);
|
||||
$this->_data['view_model']->set_heading('Tax');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/TaxView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->tax_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->tax_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Test_image Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_test_image_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'test_image_model';
|
||||
public $_page_name = 'Test image';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Test_image_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Test_image_admin_list_paginate_view_model(
|
||||
$this->test_image_model,
|
||||
$this->pagination,
|
||||
'/admin/test_image/0');
|
||||
$this->_data['view_model']->set_heading('Test image');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'created_at' => $this->_data['view_model']->get_created_at(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->test_image_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/test_image/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->test_image_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Test_image', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Test_image_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->test_image_model->set_form_validation(
|
||||
$this->form_validation, $this->test_image_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Test_image_admin_add_view_model($this->test_image_model);
|
||||
$this->_data['view_model']->set_heading('Test image');
|
||||
|
||||
$this->load->model('image_model');
|
||||
$gallery_images = $this->image_model->get_all();
|
||||
foreach ($gallery_images as $key => $image) {
|
||||
if($image->type == 4){
|
||||
$image->show_url = base_url().$image->url;
|
||||
}else
|
||||
{
|
||||
$image->show_url = $image->url;
|
||||
}$image->type = $this->image_model->type_mapping()[$image->type];
|
||||
}
|
||||
$this->_data['gallery_images'] = $gallery_images;
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/Test_imageAdd', $this->_data);
|
||||
}
|
||||
|
||||
$image = $this->input->post('image', TRUE);
|
||||
$image_id = $this->input->post('image_id', TRUE);
|
||||
|
||||
$result = $this->test_image_model->create([
|
||||
'image' => $image,
|
||||
'image_id' => $image_id,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('image added.');
|
||||
|
||||
return $this->redirect('/admin/test_image/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/Test_imageAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->test_image_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/test_image/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Test_image_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->test_image_model->set_form_validation(
|
||||
$this->form_validation, $this->test_image_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Test_image_admin_edit_view_model($this->test_image_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Test image');
|
||||
|
||||
$this->load->model('image_model');
|
||||
$gallery_images = $this->image_model->get_all();
|
||||
foreach ($gallery_images as $key => $image) {
|
||||
if($image->type == 4){
|
||||
$image->show_url = base_url().$image->url;
|
||||
}else
|
||||
{
|
||||
$image->show_url = $image->url;
|
||||
}$image->type = $this->image_model->type_mapping()[$image->type];
|
||||
}
|
||||
$this->_data['gallery_images'] = $gallery_images;
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/Test_imageEdit', $this->_data);
|
||||
}
|
||||
|
||||
$image = $this->input->post('image', TRUE);
|
||||
$image_id = $this->input->post('image_id', TRUE);
|
||||
|
||||
$result = $this->test_image_model->edit([
|
||||
'image' => $image,
|
||||
'image_id' => $image_id,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('image updated.');
|
||||
|
||||
return $this->redirect('/admin/test_image/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/Test_imageEdit', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function bulk_delete()
|
||||
{
|
||||
|
||||
$bulk_items = $this->input->post('bulk_items');
|
||||
foreach ($bulk_items as $key => $id) {
|
||||
$this->test_image_model->real_delete($id);
|
||||
}
|
||||
echo 'success';
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Textbook Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_textbook_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'textbook_model';
|
||||
public $_page_name = 'Textbook';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Textbook_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Textbook_admin_list_paginate_view_model(
|
||||
$this->textbook_model,
|
||||
$this->pagination,
|
||||
'/admin/textbook/0');
|
||||
$this->_data['view_model']->set_heading('Textbook');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'name' => $this->_data['view_model']->get_name(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->textbook_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/textbook/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->textbook_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Textbook', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Textbook_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->textbook_model->set_form_validation(
|
||||
$this->form_validation, $this->textbook_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Textbook_admin_add_view_model($this->textbook_model);
|
||||
$this->_data['view_model']->set_heading('Textbook');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/TextbookAdd', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$isbn = $this->input->post('isbn', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->textbook_model->create([
|
||||
'name' => $name,
|
||||
'isbn' => $isbn,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Textbook added.');
|
||||
|
||||
return $this->redirect('/admin/textbook/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/TextbookAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->textbook_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/textbook/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Textbook_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->textbook_model->set_form_validation(
|
||||
$this->form_validation, $this->textbook_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Textbook_admin_edit_view_model($this->textbook_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Textbook');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/TextbookEdit', $this->_data);
|
||||
}
|
||||
|
||||
$name = $this->input->post('name', TRUE);
|
||||
$isbn = $this->input->post('isbn', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->textbook_model->edit([
|
||||
'name' => $name,
|
||||
'isbn' => $isbn,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Textbook updated.');
|
||||
|
||||
return $this->redirect('/admin/textbook/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/TextbookEdit', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->textbook_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->textbook_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Ticket Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_ticket_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'ticket_model';
|
||||
public $_page_name = 'Ticket';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('user_model');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Ticket_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Ticket_admin_list_paginate_view_model(
|
||||
$this->ticket_model,
|
||||
$this->pagination,
|
||||
'/admin/ticket/0');
|
||||
$this->_data['view_model']->set_heading('Ticket');
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_message(($this->input->get('message', TRUE) != NULL) ? $this->input->get('message', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'message' => $this->_data['view_model']->get_message(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->ticket_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/ticket/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->ticket_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
$user_id_array = $this->user_model->get_all();
|
||||
if($user_id_array){
|
||||
$user_id_array = array_column($user_id_array,'first_name','id');
|
||||
}
|
||||
// print_r($user_id_array);exit;
|
||||
if($this->_data['view_model']->get_list() ){
|
||||
|
||||
foreach ( $this->_data['view_model']->get_list() as $key => &$value) {
|
||||
$value->user_id = $user_id_array[$value->user_id] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Ticket', $this->_data);
|
||||
}
|
||||
|
||||
public function resolve($id){
|
||||
$this->ticket_model->update('ticket',['status'=>1],['id'=>$id]);
|
||||
|
||||
$this->success('Resolved successfully');
|
||||
return redirect('admin/ticket/0','refresh');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Transaction Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_transaction_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'transaction_model';
|
||||
public $_page_name = 'Transaction';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Transaction_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Transaction_admin_list_paginate_view_model(
|
||||
$this->transaction_model,
|
||||
$this->pagination,
|
||||
'/admin/transaction/0');
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_payment_method(($this->input->get('payment_method', TRUE) != NULL) ? $this->input->get('payment_method', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_transaction_date(($this->input->get('transaction_date', TRUE) != NULL) ? $this->input->get('transaction_date', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_transaction_time(($this->input->get('transaction_time', TRUE) != NULL) ? $this->input->get('transaction_time', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_tax(($this->input->get('tax', TRUE) != NULL) ? $this->input->get('tax', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_discount(($this->input->get('discount', TRUE) != NULL) ? $this->input->get('discount', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_subtotal(($this->input->get('subtotal', TRUE) != NULL) ? $this->input->get('subtotal', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_total(($this->input->get('total', TRUE) != NULL) ? $this->input->get('total', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'payment_method' => $this->_data['view_model']->get_payment_method(),
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'transaction_date' => $this->_data['view_model']->get_transaction_date(),
|
||||
'transaction_time' => $this->_data['view_model']->get_transaction_time(),
|
||||
'user_id' => $this->_data['view_model']->get_user_id(),
|
||||
'tax' => $this->_data['view_model']->get_tax(),
|
||||
'discount' => $this->_data['view_model']->get_discount(),
|
||||
'subtotal' => $this->_data['view_model']->get_subtotal(),
|
||||
'total' => $this->_data['view_model']->get_total(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->transaction_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/transaction/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->transaction_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/Transaction', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Transaction_admin_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->transaction_model->set_form_validation(
|
||||
$this->form_validation, $this->transaction_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Transaction_admin_add_view_model($this->transaction_model);
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/TransactionAdd', $this->_data);
|
||||
}
|
||||
|
||||
$payment_method = $this->input->post('payment_method', TRUE);
|
||||
$order_id = $this->input->post('order_id', TRUE);
|
||||
$transaction_date = $this->input->post('transaction_date', TRUE);
|
||||
$transaction_time = $this->input->post('transaction_time', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$tax = $this->input->post('tax', TRUE);
|
||||
$discount = $this->input->post('discount', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->transaction_model->create([
|
||||
'payment_method' => $payment_method,
|
||||
'order_id' => $order_id,
|
||||
'transaction_date' => $transaction_date,
|
||||
'transaction_time' => $transaction_time,
|
||||
'user_id' => $user_id,
|
||||
'tax' => $tax,
|
||||
'discount' => $discount,
|
||||
'subtotal' => $subtotal,
|
||||
'total' => $total,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/transaction/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/TransactionAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->transaction_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/transaction/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Transaction_admin_edit_view_model.php';
|
||||
$this->form_validation = $this->transaction_model->set_form_validation(
|
||||
$this->form_validation, $this->transaction_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Transaction_admin_edit_view_model($this->transaction_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Admin/TransactionEdit', $this->_data);
|
||||
}
|
||||
|
||||
$payment_method = $this->input->post('payment_method', TRUE);
|
||||
$order_id = $this->input->post('order_id', TRUE);
|
||||
$transaction_date = $this->input->post('transaction_date', TRUE);
|
||||
$transaction_time = $this->input->post('transaction_time', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$tax = $this->input->post('tax', TRUE);
|
||||
$discount = $this->input->post('discount', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->transaction_model->edit([
|
||||
'payment_method' => $payment_method,
|
||||
'order_id' => $order_id,
|
||||
'transaction_date' => $transaction_date,
|
||||
'transaction_time' => $transaction_time,
|
||||
'user_id' => $user_id,
|
||||
'tax' => $tax,
|
||||
'discount' => $discount,
|
||||
'subtotal' => $subtotal,
|
||||
'total' => $total,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/admin/transaction/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Admin/TransactionEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->transaction_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/admin/transaction/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Transaction_admin_view_view_model.php';
|
||||
$this->_data['view_model'] = new Transaction_admin_view_view_model($this->transaction_model);
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Admin/TransactionView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->input->post('id', TRUE);
|
||||
|
||||
if (!empty($id))
|
||||
{
|
||||
$model = $this->transaction_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 404;
|
||||
$output['msg'] = 'Error! Data not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->transaction_model->real_delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 500;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! ID not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function bulk_delete()
|
||||
{
|
||||
|
||||
$bulk_items = $this->input->post('bulk_items');
|
||||
foreach ($bulk_items as $key => $id) {
|
||||
$this->transaction_model->real_delete($id);
|
||||
}
|
||||
echo 'success';
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Admin_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* User_card Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Admin_user_card_controller extends Admin_controller
|
||||
{
|
||||
protected $_model_file = 'user_card_model';
|
||||
public $_page_name = 'User Card';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/User_card_admin_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new User_card_admin_list_paginate_view_model(
|
||||
$this->user_card_model,
|
||||
$this->pagination,
|
||||
'/admin/user_card/0');
|
||||
$this->_data['view_model']->set_heading('User Card');
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_last4(($this->input->get('last4', TRUE) != NULL) ? $this->input->get('last4', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_is_default(($this->input->get('is_default', TRUE) != NULL) ? $this->input->get('is_default', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'user_id' => $this->_data['view_model']->get_user_id(),
|
||||
'last4' => $this->_data['view_model']->get_last4(),
|
||||
'is_default' => $this->_data['view_model']->get_is_default(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->user_card_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/admin/user_card/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->user_card_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Admin/User_card', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+264
@@ -0,0 +1,264 @@
|
||||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Marketing Controller
|
||||
*
|
||||
* @copyright 2021 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Marketing_controller extends Manaknight_Controller
|
||||
{
|
||||
public $_data = [
|
||||
'error' => '',
|
||||
'success' => ''
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
$this->load->model('marketing_model');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dl($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : <pre>' . print_r($data, TRUE) . '</pre>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug json Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dj($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : ' . json_encode($data));
|
||||
}
|
||||
}
|
||||
|
||||
public function get_session()
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
return $_SESSION;
|
||||
}
|
||||
|
||||
$session = $this->config->item('session_test');
|
||||
|
||||
if (!$session)
|
||||
{
|
||||
$session = [];
|
||||
}
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
public function set_session($field, $value)
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
$_SESSION[$field] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$session = $this->config->item('session_test');
|
||||
if (!$session)
|
||||
{
|
||||
$session = [];
|
||||
}
|
||||
$session[$field] = $value;
|
||||
$this->config->set_item('session_test', $session);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy_session()
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
unset($_SESSION);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->config->set_item('session_test', []);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_setting()
|
||||
{
|
||||
return $this->_setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate a slug
|
||||
*/
|
||||
public function generate_marketing_slug($str)
|
||||
{
|
||||
|
||||
$delimiter = '-';
|
||||
$slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter));
|
||||
$full_path = base_url() . 'a/';
|
||||
|
||||
$row = $this->marketing_model->get_by_field('slug', $full_path . $slug);
|
||||
|
||||
if (empty($row))
|
||||
{
|
||||
$output['slug'] = $slug;
|
||||
echo json_encode($output);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$i = 1;
|
||||
$check_me_again = TRUE;
|
||||
while ($check_me_again)
|
||||
{
|
||||
$slug = $slug . '-' . $i;
|
||||
$row = $this->marketing_model->get_by_field('slug', $full_path . $slug);
|
||||
|
||||
if (empty($row))
|
||||
{
|
||||
$check_me_again = FALSE;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$output['slug'] = $slug;
|
||||
echo json_encode($output);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to return the generated page
|
||||
*/
|
||||
public function generate_custom_marketing_page($slug)
|
||||
{
|
||||
$slug_url = base_url() . 'a/';
|
||||
$slug = $slug_url.$slug;
|
||||
$marketing_data = $this->marketing_model->get_by_field('slug',$slug);
|
||||
$this->_data['header'] = '';
|
||||
$this->_data['footer'] = '';
|
||||
$this->_data['content_template'] = '';
|
||||
$this->_data['content'] = '';
|
||||
$this->_data['success'] = '';
|
||||
$this->_data['error'] = '';
|
||||
$this->_data['layout_clean_mode'] = TRUE;
|
||||
$this->_data['reuse_query_string'] = TRUE;
|
||||
$this->_data['base_url'] = base_url();
|
||||
$this->_data['total_rows'] = 25;
|
||||
$this->_data['per_page'] = 25;
|
||||
$this->_data['num_links'] = '';
|
||||
$this->_data['full_tag_open'] = '<ul class="pagination justify-content-end">';
|
||||
$this->_data['full_tag_close'] = '</ul>';
|
||||
$this->_data['attributes'] = ['class' => 'page-link'];
|
||||
$this->_data['first_link'] = FALSE ;
|
||||
$this->_data['last_link'] = FALSE;
|
||||
$this->_data['first_tag_open'] = '<li class="page-item">';
|
||||
$this->_data['first_tag_close'] = '</li>';
|
||||
$this->_data['prev_link'] = '«';
|
||||
$this->_data['setting'] = $this->get_setting();
|
||||
$this->_data['list'] = [];
|
||||
|
||||
if($marketing_data)
|
||||
{
|
||||
if($marketing_data->header_template_path != '')
|
||||
{
|
||||
$this->_data['header'] = $marketing_data->header_template_path ? $marketing_data->header_template_path : '';
|
||||
}
|
||||
|
||||
if($marketing_data->footer_template_path != '')
|
||||
{
|
||||
$this->_data['footer'] = $marketing_data->footer_template_path ? $marketing_data->footer_template_path : '';
|
||||
}
|
||||
|
||||
$this->_data['content'] = $marketing_data->content ? $marketing_data->content : '';
|
||||
$this->_data['content_template'] = $marketing_data->content_template_path ? $marketing_data->content_template_path : '';
|
||||
|
||||
if($marketing_data->status == 0)
|
||||
{
|
||||
if ($marketing_data->password_protect == '')
|
||||
{
|
||||
return $this->generate_marketing_template($this->_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$valid_passwords = [
|
||||
'guest' => $marketing_data->password_protect
|
||||
];
|
||||
$valid_users = array_keys($valid_passwords);
|
||||
|
||||
$user = $_SERVER['PHP_AUTH_USER'];
|
||||
$pass = $_SERVER['PHP_AUTH_PW'];
|
||||
|
||||
$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
|
||||
|
||||
if (!$validated)
|
||||
{
|
||||
header('WWW-Authenticate: Basic realm="My Realm"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
die ('Not authorized');
|
||||
}
|
||||
|
||||
return $this->generate_marketing_template($this->_data);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->output->set_status_header('404');
|
||||
$data['heading'] = '404 Page Not Found';
|
||||
$data['message'] = 'The page you requested was not found';
|
||||
$this->load->view('errors/html/error_404',$data);
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
$this->output->set_status_header('404');
|
||||
$data['heading'] = '404 Page Not Found';
|
||||
$data['message'] = 'The page you requested was not found';
|
||||
$this->load->view('errors/html/error_404', $data);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate marketing template
|
||||
*/
|
||||
|
||||
public function generate_marketing_template($marketing_data)
|
||||
{
|
||||
if($marketing_data['header'] != '')
|
||||
{
|
||||
$this->load->view($marketing_data['header'], $marketing_data);
|
||||
}
|
||||
|
||||
if($marketing_data['content_template'] == '')
|
||||
{
|
||||
echo $marketing_data['content_template'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->load->view('Guest/Template_page', $marketing_data);
|
||||
}
|
||||
|
||||
if($marketing_data['footer'] != '')
|
||||
{
|
||||
$this->load->view($marketing_data['footer'], $marketing_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,580 @@
|
||||
<?php if (!defined('BASEPATH'))
|
||||
{
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2019*/
|
||||
/**
|
||||
* Stripe Webhooks Api Controller
|
||||
*
|
||||
* @copyright 2021 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
*
|
||||
*/
|
||||
|
||||
use \Stripe\Stripe;
|
||||
use \Stripe\Webhook;
|
||||
|
||||
class Stripe_webhooks_api_controller extends CI_Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$stripe_config = [
|
||||
'stripe_api_version' => ($this->config->item('stripe_api_version') ?? ''),
|
||||
'stripe_publish_key' => ($this->config->item('stripe_publish_key') ?? ''),
|
||||
'stripe_secret_key' => ($this->config->item('stripe_secret_key') ?? '')
|
||||
];
|
||||
$this->load->library('payment_service', $stripe_config);
|
||||
$this->load->database();
|
||||
}
|
||||
|
||||
/**
|
||||
* handle stripe events
|
||||
* @see https://stripe.com/docs/api/events/types
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$payload = @file_get_contents('php://input');
|
||||
$event = null;
|
||||
|
||||
try
|
||||
{
|
||||
$event = $this->payment_service->get_stripe_event($payload);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
|
||||
$args = $event->data->object;
|
||||
|
||||
switch ($event->type)
|
||||
{
|
||||
case 'payment_intent.succeeded':
|
||||
// $this->handle_payment_intent_succeeded($args);
|
||||
break;
|
||||
|
||||
case 'payment_method.attached':
|
||||
// $this->handle_payment_method($args);
|
||||
break;
|
||||
|
||||
case 'invoice.created':
|
||||
// $this->handle_invoice_created($args);
|
||||
break;
|
||||
|
||||
case 'invoice.finalized':
|
||||
// $this->handle_invoice_finalized($args);
|
||||
break;
|
||||
|
||||
case 'invoice.payment_failed':
|
||||
// $this->handle_invoice_payment_failed($args);
|
||||
break;
|
||||
|
||||
case 'invoice.payment_succeeded':
|
||||
// $this->handle_invoice_payment_succeeded($args);
|
||||
break;
|
||||
|
||||
case 'invoice.upcoming':
|
||||
// $this->handle_invoice_upcoming($args);
|
||||
break;
|
||||
|
||||
case 'charge.dispute.created':
|
||||
$this->handle_dispute_created($args);
|
||||
error_log(print_r($args), true);
|
||||
break;
|
||||
|
||||
case 'charge.dispute.funds_reinstated':
|
||||
$this->handle_dispute_funds_reinstated($args);
|
||||
break;
|
||||
|
||||
case 'charge.dispute.funds_withdrawn':
|
||||
$this->handle_dispute_funds_withdrawn($args);
|
||||
break;
|
||||
|
||||
case 'charge.dispute.updated':
|
||||
$this->handle_dispute_updated($args);
|
||||
error_log(print_r($args, true));
|
||||
break;
|
||||
|
||||
case 'charge.succeeded':
|
||||
error_log(print_r($args, true));
|
||||
// $this->handle_charge_succeeded($args);
|
||||
break;
|
||||
|
||||
case 'charge.refunded':
|
||||
$this->handle_charge_refunded($args);
|
||||
break;
|
||||
|
||||
case 'charge.refund.updated':
|
||||
$this->handle_refund_updated($args);
|
||||
break;
|
||||
|
||||
case 'checkout.session.completed':
|
||||
// $this->handle_checkout_session_completed($args);
|
||||
break;
|
||||
|
||||
case 'customer.source.expiring':
|
||||
http_response_code(200);
|
||||
break;
|
||||
|
||||
case 'customer.subscription.updated':
|
||||
http_response_code(200);
|
||||
break;
|
||||
|
||||
case 'customer.subscription.deleted':
|
||||
// $this->handle_subscription_deleted($args);
|
||||
break;
|
||||
|
||||
case 'subscription_schedule.aborted':
|
||||
// $this->handle_subscription_schedule_aborted($args);
|
||||
break;
|
||||
|
||||
case 'subscription_schedule.canceled':
|
||||
// $this->handle_subscription_schedule_canceled($args);
|
||||
break;
|
||||
|
||||
case 'subscription_schedule.completed':
|
||||
// $this->handle_subscription_schedule_completed($args);
|
||||
break;
|
||||
|
||||
case 'subscription_schedule.expiring':
|
||||
// $this->handle_subscription_schedule_expiring($args);
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispute:
|
||||
* https://stripe.com/docs/api/disputes/object
|
||||
*/
|
||||
public function handle_dispute_created($args)
|
||||
{
|
||||
$this->load->model('dispute_model');
|
||||
$this->load->model('order_model');
|
||||
$this->load->model('order_notes_model');
|
||||
|
||||
if (isset($args['id']))
|
||||
{
|
||||
// get order_id and user_id
|
||||
$order_data = $this->order_model->get_by_field('stripe_charge_id', $args['charge']);
|
||||
|
||||
// if (!empty($order_data))
|
||||
// {
|
||||
$payload = [
|
||||
'order_id' => $order_data->id ?? 0,
|
||||
'user_id' => $order_data->user_id ?? 0,
|
||||
'amount' => $args['amount'] ?? "",
|
||||
'reason' => $args['reason'] ?? "",
|
||||
'explanation' => $args['explanation'] ?? "",
|
||||
'stripe_charge_id' => $args['charge'] ?? "",
|
||||
'stripe_dispute_id' => $args['id'] ?? "",
|
||||
'status' => $args['status'] ?? ""
|
||||
];
|
||||
|
||||
$result = $this->dispute_model->create($payload);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$order_notes_payload = [
|
||||
'order_id' => $order_data->id ?? 0,
|
||||
'description' => 'Dispute created.'
|
||||
];
|
||||
|
||||
$this->order_notes_model->create($order_notes_payload);
|
||||
|
||||
echo json_encode(["success" => true, "message" => "dispute created succeeded captured"]);
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode(["success" => false, "message" => "dispute created failed"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// echo json_encode(["success" => false, "message" => "order data not found"]);
|
||||
// http_response_code(400);
|
||||
// exit();
|
||||
// }
|
||||
// }
|
||||
echo json_encode(["success" => false, "message" => "invalid dispute received"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurs when funds are reinstated to your account after a dispute is closed.
|
||||
* This includes partially refunded payments.
|
||||
*/
|
||||
public function handle_dispute_funds_reinstated($args)
|
||||
{
|
||||
$this->load->model('dispute_model');
|
||||
$this->load->model('order_model');
|
||||
$this->load->model('order_notes_model');
|
||||
|
||||
if (isset($args['id']))
|
||||
{
|
||||
// get order_id and user_id
|
||||
$order_data = $this->order_model->get_by_field('stripe_charge_id', $args['charge']);
|
||||
|
||||
if (!empty($order_data))
|
||||
{
|
||||
$dispute_data = $this->dispute_model->get_by_field('stripe_dispute_id', $args['id']);
|
||||
|
||||
$payload = [
|
||||
'amount' => $args['amount'] ?? "",
|
||||
'reason' => $args['reason'] ?? "",
|
||||
'explanation' => $args['explanation'] ?? "",
|
||||
'status' => $args['status']
|
||||
];
|
||||
|
||||
$result = $this->dispute_model->edit($payload, $dispute_data->id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$order_notes_payload = [
|
||||
'order_id' => $order_data->id,
|
||||
'description' => 'Dispute reinstated. Partial dispute. Amount ' . $args['amount'] / 100
|
||||
];
|
||||
|
||||
$this->order_notes_model->create($order_notes_payload);
|
||||
|
||||
if (!empty($order_data))
|
||||
{
|
||||
$order_payload = ['status' => 6];
|
||||
$this->order_model->edit($order_payload, $order_data->id);
|
||||
}
|
||||
|
||||
echo json_encode(["success" => true, "message" => "dispute reinstate succeeded"]);
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode(["success" => false, "message" => "dispute reinstate failed"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode(["success" => false, "message" => "order data not found"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
echo json_encode(["success" => false, "message" => "invalid dispute received"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurs when funds are removed from your account due to a dispute.
|
||||
*/
|
||||
public function handle_dispute_funds_withdrawn($args)
|
||||
{
|
||||
$this->load->model('dispute_model');
|
||||
$this->load->model('order_model');
|
||||
$this->load->model('order_notes_model');
|
||||
|
||||
if (isset($args['id']))
|
||||
{
|
||||
// get order_id and user_id
|
||||
$order_data = $this->order_model->get_by_field('stripe_charge_id', $args['charge']);
|
||||
|
||||
if (!empty($order_data))
|
||||
{
|
||||
$dispute_data = $this->dispute_model->get_by_field('stripe_dispute_id', $args['id']);
|
||||
|
||||
$payload = [
|
||||
'amount' => $args['amount'] ?? "",
|
||||
'reason' => $args['reason'] ?? "",
|
||||
'explanation' => $args['explanation'] ?? "",
|
||||
'status' => $args['status']
|
||||
];
|
||||
|
||||
$result = $this->dispute_model->edit($payload, $dispute_data->id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$order_notes_payload = [
|
||||
'order_id' => $order_data->id,
|
||||
'description' => 'Dispute funds_withdrawn'
|
||||
];
|
||||
|
||||
$this->order_notes_model->create($order_notes_payload);
|
||||
|
||||
if (!empty($order_data))
|
||||
{
|
||||
$order_payload = ['status' => 6];
|
||||
$this->order_model->edit($order_payload, $order_data->id);
|
||||
}
|
||||
|
||||
echo json_encode(["success" => true, "message" => "dispute funds_withdrawn succeeded"]);
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode(["success" => false, "message" => "dispute funds_withdrawn failed"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode(["success" => false, "message" => "order data not found"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
echo json_encode(["success" => false, "message" => "invalid dispute received"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurs when the dispute is updated (usually with evidence).
|
||||
*/
|
||||
public function handle_dispute_updated($args)
|
||||
{
|
||||
$this->load->model('dispute_model');
|
||||
$this->load->model('order_model');
|
||||
$this->load->model('order_notes_model');
|
||||
|
||||
if (isset($args['id']))
|
||||
{
|
||||
// get order_id and user_id
|
||||
$order_data = $this->order_model->get_by_field('stripe_charge_id', $args['charge']);
|
||||
|
||||
if (!empty($order_data))
|
||||
{
|
||||
$dispute_data = $this->dispute_model->get_by_field('stripe_dispute_id', $args['id']);
|
||||
|
||||
$payload = [
|
||||
'amount' => $args['amount'] ?? "",
|
||||
'reason' => $args['reason'] ?? "",
|
||||
'explanation' => $args['explanation'] ?? "",
|
||||
'status' => $args['status']
|
||||
];
|
||||
|
||||
$result = $this->dispute_model->edit($payload, $dispute_data->id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$order_notes_payload = [
|
||||
'order_id' => $order_data->id,
|
||||
'description' => 'Dispute dispute updated. Evidence: ' . $args['evidence'] ?? ""
|
||||
];
|
||||
|
||||
$this->order_notes_model->create($order_notes_payload);
|
||||
|
||||
echo json_encode(["success" => true, "message" => "dispute update succeeded"]);
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode(["success" => false, "message" => "dispute update failed"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode(["success" => false, "message" => "order data not found"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
echo json_encode(["success" => false, "message" => "invalid dispute received"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refund:
|
||||
*
|
||||
*/
|
||||
public function handle_charge_refunded($args)
|
||||
{
|
||||
$this->load->model('order_model');
|
||||
$this->load->model('order_notes_model');
|
||||
$this->load->model('refund_model');
|
||||
|
||||
if (isset($args['id']))
|
||||
{
|
||||
// get order_id and user_id
|
||||
$order_data = $this->order_model->get_by_field('stripe_charge_id', $args['id']);
|
||||
|
||||
$refund_params = [
|
||||
'order_id' => $order_data->id ?? 0,
|
||||
'user_id' => $order_data->user_id ?? 0,
|
||||
'amount' => $args['amount_refunded'] ?? 0,
|
||||
'reason' => $args['refunds']['data'][0]['reason'] ?? "null",
|
||||
'explanation' => $args['refunds']['data'][0]['explanation'] ?? "",
|
||||
'stripe_charge_id' => $args['id'],
|
||||
'stripe_invoice_id' => $args['invoice'] ?? "",
|
||||
'receipt_url' => $args['receipt_url'] ?? "",
|
||||
'status' => $args['refunds']['data'][0]['status'] ?? ""
|
||||
];
|
||||
|
||||
$result = $this->refund_model->create($refund_params);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$order_notes_payload = [
|
||||
'order_id' => $order_data->id ?? 0,
|
||||
'description' => 'Refund completed.'
|
||||
];
|
||||
|
||||
$this->order_notes_model->create($order_notes_payload);
|
||||
|
||||
if (!empty($order_data))
|
||||
{
|
||||
$order_payload = ['status' => 5];
|
||||
$this->order_model->edit($order_payload, $order_data->id);
|
||||
}
|
||||
|
||||
echo json_encode(["success" => true, "message" => "refund captured"]);
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode(["success" => true, "message" => "charge refund add failed on db"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
echo json_encode(["success" => true, "message" => "charge refunded captured"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
|
||||
public function handle_refund_updated($args)
|
||||
{
|
||||
$this->load->model('order_model');
|
||||
$this->load->model('order_notes_model');
|
||||
$this->load->model('refund_model');
|
||||
|
||||
if (isset($args['id']))
|
||||
{
|
||||
// get order_id and user_id
|
||||
$order_data = $this->order_model->get_by_field('stripe_charge_id', $args['id']);
|
||||
$refund_data = $this->order_model->get_by_field('stripe_charge_id', $args['id']);
|
||||
|
||||
if ($refund_data)
|
||||
{
|
||||
$refund_params = [
|
||||
'amount' => $args['amount_refunded'] ?? 0,
|
||||
'reason' => $args['refunds']['data'][0]['reason'] ?? "null",
|
||||
'explanation' => $args['refunds']['data'][0]['explanation'] ?? "",
|
||||
'stripe_charge_id' => $args['id'],
|
||||
'stripe_invoice_id' => $args['invoice'] ?? "",
|
||||
'receipt_url' => $args['receipt_url'] ?? "",
|
||||
'status' => $args['refunds']['data'][0]['status'] ?? ""
|
||||
];
|
||||
|
||||
$result = $this->refund_model->edit($refund_params, $refund_data->id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$order_notes_payload = [
|
||||
'order_id' => $order_data->id ?? 0,
|
||||
'description' => 'Refund updated.'
|
||||
];
|
||||
|
||||
$this->order_notes_model->create($order_notes_payload);
|
||||
|
||||
if (!empty($order_data))
|
||||
{
|
||||
$order_payload = ['status' => 5];
|
||||
$this->order_model->edit($order_payload, $order_data->id);
|
||||
}
|
||||
|
||||
echo json_encode(["success" => true, "message" => "refund updated"]);
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode(["success" => false, "message" => "refund update failed"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode(["success" => false, "message" => "refund update failed. data not found on db."]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
echo json_encode(["success" => false, "message" => "refund update capture failed"]);
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* handle stripe ach events
|
||||
* @see https://stripe.com/docs/api/events/types
|
||||
*/
|
||||
public function stripe_events()
|
||||
{
|
||||
$endpoint_secret = $this->config->item('stripe_endpoint_secret');
|
||||
|
||||
$stripe_secret_key = $this->config->item('stripe_secret_key');
|
||||
Stripe::setApiKey($stripe_secret_key);
|
||||
|
||||
$payload = @file_get_contents('php://input');
|
||||
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
|
||||
$event = null;
|
||||
|
||||
try {
|
||||
$event = Webhook::constructEvent(
|
||||
$payload, $sig_header, $endpoint_secret
|
||||
);
|
||||
}
|
||||
catch (\UnexpectedValueException $e)
|
||||
{
|
||||
// Invalid payload
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
catch (\Stripe\Exception\SignatureVerificationException $e)
|
||||
{
|
||||
// Invalid signature
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Handle the event
|
||||
switch ($event->type)
|
||||
{
|
||||
case 'invoice.paid':
|
||||
$payment_intent = $event->data->object;
|
||||
// write your stripe webhook code here
|
||||
// contains a StripePaymentIntent
|
||||
// $this->handle_invoice_paid_method($payment_intent);
|
||||
break;
|
||||
default:
|
||||
echo 'Received unknown event type ' . $event->type;
|
||||
}
|
||||
|
||||
http_response_code(200);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Cronjob_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Backup Code Cronjob Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Backup_code_cronjob_controller extends CI_Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index ()
|
||||
{
|
||||
$date = date('Y-m-d');
|
||||
$this->project_backup($date);
|
||||
// $this->send_backup($date);
|
||||
}
|
||||
|
||||
private function project_backup($date)
|
||||
{
|
||||
$this->load->library('zip');
|
||||
$this->zip->read_dir(FCPATH, FALSE);
|
||||
$this->zip->archive("project_backup_{$date}.zip");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Cronjob_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Backup Database Cronjob Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Backup_db_cronjob_controller extends CI_Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index ()
|
||||
{
|
||||
$date = date('Y-m-d');
|
||||
$this->database_backup($date);
|
||||
// $this->send_backup($date);
|
||||
}
|
||||
|
||||
private function database_backup($date)
|
||||
{
|
||||
$this->load->helper('file');
|
||||
$this->load->dbutil();
|
||||
@$backup = $this->dbutil->backup();
|
||||
write_file("database_backup_{$date}.zip", $backup);
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Cronjob Abstract Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Cronjob_controller extends CI_Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Debug Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dl($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : <pre>' . print_r($data, TRUE) . '</pre>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug json Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dj($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : ' . json_encode($data));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to send Emails given slug, payload and email
|
||||
*
|
||||
* @param string $slug
|
||||
* @param mixed $payload
|
||||
* @param string $email
|
||||
* @return void
|
||||
*/
|
||||
protected function _send_email_notification($slug, $payload, $email)
|
||||
{
|
||||
$this->load->model('email_model');
|
||||
$this->load->library('mail_service');
|
||||
$this->mail_service->set_adapter('smtp');
|
||||
$email_template = $this->email_model->get_template($slug, $payload);
|
||||
|
||||
if ($email_template)
|
||||
{
|
||||
$from = $this->config->item('from_email');
|
||||
return $this->mail_service->send($from, $email, $email_template->subject, $email_template->html);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to send Sms given slug, payload and phone #
|
||||
*
|
||||
* @param string $slug
|
||||
* @param mixed $payload
|
||||
* @param string $to
|
||||
* @return void
|
||||
*/
|
||||
protected function _send_sms_notification($slug, $payload, $to)
|
||||
{
|
||||
$this->load->model('sms_model');
|
||||
$this->load->library('sms_service');
|
||||
$this->sms_service->set_adapter('sms');
|
||||
$sms_template = $this->sms_model->get_template($slug, $payload);
|
||||
|
||||
if ($sms_template)
|
||||
{
|
||||
return $this->sms_service->send($to, $sms_template->content);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to send Push notification
|
||||
*
|
||||
* @param string $slug
|
||||
* @param mixed $payload
|
||||
* @param string $to
|
||||
* @return void
|
||||
*/
|
||||
protected function _send_push_notification($device_type, $device_id, $title, $message, $image)
|
||||
{
|
||||
$this->load->library('push_notification_service');
|
||||
$this->push_notification_service->init();
|
||||
return $this->push_notification_service->send($device_type, $device_id, $title, $message, $image);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Abstract Controller
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Migration_cron_controller extends CI_Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->library('migration');
|
||||
|
||||
if ($this->migration->current() === FALSE)
|
||||
{
|
||||
print_r($this->migration->error_string());
|
||||
} else {
|
||||
echo 'Complete';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Cronjob_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Token Cronjob Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Token_cronjob_controller extends CI_Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index ()
|
||||
{
|
||||
$this->load->database();
|
||||
$this->load->model('token_model');
|
||||
$reset_token_status = $this->token_model->raw_query("UPDATE `token` SET status=0 WHERE `expire_at` < NOW();");
|
||||
$remove_expired_tokens = $this->token_model->raw_query("DELETE FROM `token` WHERE status=0");
|
||||
}
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Health Check Controller
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Custom404 extends CI_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->helper('url');
|
||||
$this->load->database();
|
||||
|
||||
$this->load->library('redirect_custom_service');
|
||||
$this->load->model('url_redirect_model');
|
||||
$this->redirect_custom_service->set_url_redirect_model( $this->url_redirect_model );
|
||||
if($this->redirect_custom_service->set_url_redirect_model($this->url_redirect_model))
|
||||
{
|
||||
|
||||
$this->redirect_custom_service->check_redirect();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->output->set_status_header('404');
|
||||
$data["heading"] = "404 Page Not Found";
|
||||
$data["message"] = "The page you requested was not found ";
|
||||
|
||||
$this->load->view('errors/html/error_404',$data);
|
||||
}
|
||||
}
|
||||
?>
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||
// include_once 'Manaknight_controller.php';
|
||||
|
||||
/**
|
||||
* Frontend Controller to Manage all Frontend pages
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Api_controller extends Manaknight_controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
|
||||
|
||||
$this->load->model('school_model');
|
||||
$this->load->model('professor_model');
|
||||
$this->load->model('textbook_model');
|
||||
$this->load->model('classes_model');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// select2 customer search
|
||||
public function get_schools()
|
||||
{
|
||||
|
||||
$custom_query = '';
|
||||
if( $this->input->POST('term') )
|
||||
{
|
||||
$custom_query = ' `name` LIKE "%'. $this->input->POST('term',true) .'%" ';
|
||||
$data_list = $this->school_model->get_all_custom_where($custom_query, ['status' => 1]);
|
||||
|
||||
$response_list = array();
|
||||
foreach($data_list as $d_key => $_data)
|
||||
{
|
||||
array_push($response_list, array('text' => $_data->name, 'id' => $_data->id));
|
||||
}
|
||||
|
||||
$output['results'] = $response_list;
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// select2 customer search
|
||||
public function get_professors()
|
||||
{
|
||||
|
||||
$custom_query = '';
|
||||
if( $this->input->get('term') )
|
||||
{
|
||||
$custom_query = ' `name` LIKE "%'. $this->input->get('term',true) .'%" ';
|
||||
$data_list = $this->professor_model->get_all_custom_where($custom_query, ['status' => 1]);
|
||||
|
||||
$response_list = array();
|
||||
foreach($data_list as $d_key => $_data)
|
||||
{
|
||||
array_push($response_list, array('text' => $_data->name, 'id' => $_data->id));
|
||||
}
|
||||
|
||||
$output['results'] = $response_list;
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// select2 customer search
|
||||
public function get_courses()
|
||||
{
|
||||
|
||||
$custom_query = '';
|
||||
if( $this->input->get('term') )
|
||||
{
|
||||
$custom_query = ' `name` LIKE "%'. $this->input->get('term',true) .'%" ';
|
||||
$data_list = $this->classes_model->get_all_custom_where($custom_query, ['status' => 1]);
|
||||
|
||||
$response_list = array();
|
||||
foreach($data_list as $d_key => $_data)
|
||||
{
|
||||
array_push($response_list, array('text' => $_data->name, 'id' => $_data->id));
|
||||
}
|
||||
|
||||
$output['results'] = $response_list;
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// select2 customer search
|
||||
public function get_textbooks()
|
||||
{
|
||||
if( $this->input->get('term') )
|
||||
{
|
||||
$custom_query = ' `isbn` LIKE "%'. $this->input->get('term',true) .'%" ';
|
||||
$data_list = $this->db->select('distinct(isbn)')->from('inventory')->where($custom_query)->get()->result_array();
|
||||
|
||||
|
||||
$response_list = array();
|
||||
foreach($data_list as $d_key => $_data)
|
||||
{
|
||||
array_push($response_list, array('text' => $_data['isbn'], 'id' => $_data['isbn']));
|
||||
}
|
||||
|
||||
$output['results'] = $response_list;
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// select2 customer search
|
||||
public function update_old_orders_if_refunded()
|
||||
{
|
||||
$this->load->model('order_model');
|
||||
$this->load->model('payout_model');
|
||||
|
||||
|
||||
$all_order = $this->order_model->get_all(['status' => 2]);
|
||||
foreach($all_order as $_key => $_value)
|
||||
{
|
||||
$this->payout_model->update('payout',[ 'status'=> 3 ],['order_id' => $_value->id ] );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
+221
@@ -0,0 +1,221 @@
|
||||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
include_once __DIR__ . '/../../middlewares/Auth_middleware.php';
|
||||
include_once __DIR__ . '/../../middlewares/Acl_middleware.php';
|
||||
include_once __DIR__ . '/../../middlewares/Maintenance_middleware.php';
|
||||
include_once __DIR__ . '/../../middlewares/Affilate_middleware.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Guest Abstract Controller
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Guest_controller extends CI_Controller
|
||||
{
|
||||
public $_data = [
|
||||
'error' => '',
|
||||
'success' => ''
|
||||
];
|
||||
|
||||
//testMode flag
|
||||
protected $_test_mode = FALSE;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->config->load('setting');
|
||||
$this->_setting = $this->config->item('setting');
|
||||
|
||||
$this->_run_middlewares();
|
||||
|
||||
}
|
||||
|
||||
protected function _middleware()
|
||||
{
|
||||
return [
|
||||
'affilate',
|
||||
'maintenance'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dl($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : <pre>' . print_r($data, TRUE) . '</pre>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug json Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dj($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : ' . json_encode($data));
|
||||
}
|
||||
}
|
||||
|
||||
public function get_session()
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
return $_SESSION;
|
||||
}
|
||||
|
||||
$session = $this->config->item('session_test');
|
||||
|
||||
if (!$session)
|
||||
{
|
||||
$session = [];
|
||||
}
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
public function set_session($field, $value)
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
$_SESSION[$field] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$session = $this->config->item('session_test');
|
||||
if (!$session)
|
||||
{
|
||||
$session = [];
|
||||
}
|
||||
$session[$field] = $value;
|
||||
$this->config->set_item('session_test', $session);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy_session()
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
unset($_SESSION);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->config->set_item('session_test', []);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to send Emails given slug, payload and email
|
||||
*
|
||||
* @param string $slug
|
||||
* @param mixed $payload
|
||||
* @param string $email
|
||||
* @return void
|
||||
*/
|
||||
protected function _send_email_notification($slug, $payload, $email)
|
||||
{
|
||||
$this->load->model('email_model');
|
||||
$this->load->library('mail_service');
|
||||
$this->mail_service->set_adapter('smtp');
|
||||
$email_template = $this->email_model->get_template($slug, $payload);
|
||||
|
||||
if ($email_template)
|
||||
{
|
||||
$from = $this->config->item('from_email');
|
||||
return $this->mail_service->send($from, $email, $email_template->subject, $email_template->html);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to send Sms given slug, payload and phone #
|
||||
*
|
||||
* @param string $slug
|
||||
* @param mixed $payload
|
||||
* @param string $to
|
||||
* @return void
|
||||
*/
|
||||
protected function _send_sms_notification($slug, $payload, $to)
|
||||
{
|
||||
$this->load->model('sms_model');
|
||||
$this->load->library('sms_service');
|
||||
$this->sms_service->set_adapter('sms');
|
||||
$sms_template = $this->sms_model->get_template($slug, $payload);
|
||||
|
||||
if ($sms_template)
|
||||
{
|
||||
return $this->sms_service->send($to, $sms_template->content);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to send Push notification
|
||||
*
|
||||
* @param string $slug
|
||||
* @param mixed $payload
|
||||
* @param string $to
|
||||
* @return void
|
||||
*/
|
||||
protected function _send_push_notification($device_type, $device_id, $title, $message, $image)
|
||||
{
|
||||
$this->load->library('push_notification_service');
|
||||
$this->push_notification_service->init();
|
||||
return $this->push_notification_service->send($device_type, $device_id, $title, $message, $image);
|
||||
}
|
||||
|
||||
protected function _run_middlewares ()
|
||||
{
|
||||
|
||||
$middlewares = [
|
||||
'affilate' => new Affilate_middleware($this, $this->config),
|
||||
'auth' => new Auth_middleware($this, $this->config),
|
||||
'acl' => new Acl_middleware($this, $this->config),
|
||||
'maintenance' => new Maintenance_middleware($this, $this->config)
|
||||
];
|
||||
|
||||
foreach ($this->_middleware() as $middleware_key)
|
||||
{
|
||||
if (isset($middlewares[$middleware_key]))
|
||||
{
|
||||
$result = $middlewares[$middleware_key]->run();
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get_setting()
|
||||
{
|
||||
return $this->_setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to URL
|
||||
*
|
||||
* @param string $template
|
||||
* @param array $data
|
||||
*/
|
||||
public function redirect($url, $option = [])
|
||||
{
|
||||
return ($option) ? redirect($url, $option) : redirect($url);
|
||||
}
|
||||
}
|
||||
+591
@@ -0,0 +1,591 @@
|
||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||
// include_once 'Manaknight_controller.php';
|
||||
|
||||
/**
|
||||
* Frontend Controller to Manage all Frontend pages
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Home_controller extends Manaknight_controller
|
||||
{
|
||||
|
||||
public $_data = [
|
||||
'error' => '',
|
||||
'success' => ''
|
||||
];
|
||||
|
||||
|
||||
protected $_flash_error = [
|
||||
'error' => '',
|
||||
'success' => ''
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
|
||||
// load services
|
||||
$this->load->library('helpers_service');
|
||||
$this->load->library('stripe_helper_service');
|
||||
// $this->load->library('stevesie_api_helper_service');
|
||||
// $this->load->library('sale_detail_api_service');
|
||||
|
||||
|
||||
$this->load->model('school_model');
|
||||
$this->load->model('content_model');
|
||||
$this->load->model('professor_model');
|
||||
$this->load->model('textbook_model');
|
||||
$this->load->model('classes_model');
|
||||
|
||||
$this->load->model('inventory_model');
|
||||
|
||||
// $this->load->library('helpers_service');
|
||||
|
||||
$this->_data['layout_clean_mode'] = FALSE;
|
||||
|
||||
/**
|
||||
* social links
|
||||
*/
|
||||
$facebook_link = '#';
|
||||
$twitter_link = '#';
|
||||
$instagram_link = '#';
|
||||
|
||||
$this->_data['facebook_link'] = $facebook_link;
|
||||
$this->_data['twitter_link'] = $twitter_link;
|
||||
$this->_data['instagram_link'] = $instagram_link;
|
||||
}
|
||||
|
||||
public function index($offset = 0)
|
||||
{
|
||||
|
||||
$content = $this->content_model->get_all(['status'=>1]);
|
||||
$this->_data['content'] = [];
|
||||
if($content ){
|
||||
$data = [];
|
||||
foreach ($content as $key => $value) {
|
||||
$data[$value->content_name]= $value;
|
||||
}
|
||||
$this->_data['content'] = $data;
|
||||
}
|
||||
$meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','home_page_meta_title')
|
||||
->or_where('content_name','home_page_meta_description')->get()->result_array();
|
||||
if($meta_data){
|
||||
$meta_data = array_column($meta_data,'content','content_name');
|
||||
$this->_data['meta']['title']= $meta_data['home_page_meta_title'];
|
||||
$this->_data['meta']['desc']= $meta_data['home_page_meta_description'];
|
||||
}
|
||||
$this->_data['active'] = 'home';
|
||||
$this->_render('Guest/Home', $this->_data);
|
||||
}
|
||||
|
||||
public function get_all_categories()
|
||||
{
|
||||
$data = $this->school_model->get_all(['status' => 1]);
|
||||
|
||||
if ($data)
|
||||
{
|
||||
echo json_encode($data);
|
||||
exit();
|
||||
}
|
||||
echo json_encode(FALSE);
|
||||
exit();
|
||||
}
|
||||
|
||||
public function load_items_by_school_select()
|
||||
{
|
||||
$school_id = $this->input->get('school_id');
|
||||
|
||||
if ($school_id == 0)
|
||||
{
|
||||
$output = [
|
||||
'error' => TRUE,
|
||||
'status' => 0,
|
||||
'msg' => 'all'
|
||||
];
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
|
||||
$items = $this->inventory_model->get_all(['school_id' => $school_id]);
|
||||
|
||||
$school_data = $this->school_model->get($school_id);
|
||||
|
||||
if (!empty($items))
|
||||
{
|
||||
$output = [
|
||||
'success' => TRUE,
|
||||
'status' => 200,
|
||||
'data' => $items,
|
||||
'school_name' => $school_data->name
|
||||
];
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = [
|
||||
'error' => TRUE,
|
||||
'status' => 0,
|
||||
'msg' => 'No items found for: ' . $school_data->name . ' school.'
|
||||
];
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function item_details($id)
|
||||
{
|
||||
$item_details = $this->inventory_model->get_item_details_fe($id);
|
||||
|
||||
if (!empty($item_details))
|
||||
{
|
||||
$this->_data['item_details'] = $item_details;
|
||||
}
|
||||
|
||||
$school_id = $item_details->school_id;
|
||||
|
||||
$related_items = $this->inventory_model->get_all(['school_id' => $school_id]);
|
||||
|
||||
if (!empty($related_items))
|
||||
{
|
||||
$this->_data['related_items'] = $related_items;
|
||||
}
|
||||
|
||||
// echo '<pre>';print_r($related_items);die();
|
||||
|
||||
$this->_data['active'] = 'item_details';
|
||||
$this->_render('Guest/Item_details', $this->_data);
|
||||
}
|
||||
|
||||
public function about()
|
||||
{
|
||||
$this->_data['active'] = 'about';
|
||||
$this->_render('Guest/About', $this->_data);
|
||||
}
|
||||
|
||||
public function contact()
|
||||
{
|
||||
if($this->input->post('submit_btn')){
|
||||
|
||||
if($this->input->post('email') && $this->input->post('message') ){
|
||||
|
||||
$email = htmlentities($this->input->post('email'));
|
||||
// $name = htmlentities($this->input->post('name'));
|
||||
$message = htmlentities($this->input->post('message'));
|
||||
|
||||
|
||||
$regex = '/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/';
|
||||
if (!preg_match($regex, $email)) {
|
||||
$this->_data['status_'] = 'error';
|
||||
$this->_data['status_msg'] = 'Invalid Email';
|
||||
}else{
|
||||
|
||||
$data = array(
|
||||
'name'=>'',
|
||||
'email'=>$email,
|
||||
'message'=>$message,
|
||||
'created_at'=>date('Y-m-d')
|
||||
);
|
||||
|
||||
$this->db->insert('contact_us',$data);
|
||||
|
||||
$this->load->model('email_model');
|
||||
$this->load->library('mail_service');
|
||||
$this->mail_service->set_adapter('smtp');
|
||||
$from_email = $this->config->item('from_email');
|
||||
|
||||
$this->mail_service->send($from_email, $from_email, "Contact Us", $message, $email);
|
||||
|
||||
$this->_data['status_'] = 'success';
|
||||
$this->_data['status_msg'] = 'Form submitted successfully.';
|
||||
}
|
||||
|
||||
}else{
|
||||
$this->_data['status_'] = 'error';
|
||||
$this->_data['status_msg'] = 'Fill All required Fields';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->_data['meta'] = [
|
||||
'title'=>'',
|
||||
'desc'=>'',
|
||||
];
|
||||
|
||||
$meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','contact_page_meta_title')
|
||||
->or_where('content_name','contact_page_meta_description')->get()->result_array();
|
||||
if($meta_data){
|
||||
$meta_data = array_column($meta_data,'content','content_name');
|
||||
$this->_data['meta']['title']= $meta_data['contact_page_meta_title'];
|
||||
$this->_data['meta']['desc']= $meta_data['contact_page_meta_description'];
|
||||
}
|
||||
|
||||
$this->_data['active'] = 'contact';
|
||||
$this->_render('Guest/Contact', $this->_data);
|
||||
}
|
||||
public function privacy_policy()
|
||||
{
|
||||
$this->_data['active'] = 'privacy_policy';
|
||||
$this->_data['data'] = $this->db->select('*')->from('content')->where('content_name','privacy_policy')->get()->row_array();
|
||||
$this->_render('Guest/Privacy_policy', $this->_data);
|
||||
}
|
||||
public function buy($offset = 0)
|
||||
{
|
||||
// if($this->session->userdata('user_id'))
|
||||
// {
|
||||
// //create setup intent used in js
|
||||
// $stripe = new \Stripe\StripeClient(
|
||||
// $this->config->item('stripe_secret_key')
|
||||
// );
|
||||
// $this->_data['clientSecret'] = $stripe->setupIntents->create([
|
||||
// 'payment_method_types' => ['card'],
|
||||
// ])->client_secret;
|
||||
// }
|
||||
|
||||
$this->_data['stripe_client'] = $this->config->item('stripe_publish_key');
|
||||
//get all school data
|
||||
|
||||
if ($this->input->get('school_id', TRUE))
|
||||
{
|
||||
$this->_data['school_data'] = $this->school_model->get_all(['status' => 1, 'id' => $this->input->get('school_id') ]);
|
||||
}
|
||||
|
||||
|
||||
if ($this->input->get('professor_id', TRUE))
|
||||
{
|
||||
$this->_data['professor_data'] = $this->professor_model->get_all(['status' => 1, 'id' => $this->input->get('professor_id') ]);
|
||||
}
|
||||
|
||||
|
||||
if ($this->input->get('class_id', TRUE))
|
||||
{
|
||||
$this->_data['classes_data'] = $this->classes_model->get_all(['status' => 1, 'id' => $this->input->get('class_id') ]);
|
||||
}
|
||||
|
||||
|
||||
if ($this->input->get('isbn', TRUE))
|
||||
{
|
||||
$this->_data['textbook_data'] = $this->db->select('distinct(isbn)')->from('inventory')->where('isbn', $this->input->get('isbn', TRUE))->get()->result_array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$search_term = $this->input->get('search_term', TRUE);
|
||||
$school_id = $this->input->get('school_id', TRUE);
|
||||
$professor_id = $this->input->get('professor_id', TRUE);
|
||||
$textbook_id = $this->input->get('textbook_id', TRUE);
|
||||
$isbn = $this->input->get('isbn', TRUE);
|
||||
$class_id = $this->input->get('class_id', TRUE);
|
||||
$order_by = $this->input->get('order_by', TRUE);
|
||||
$direction = $this->input->get('direction', TRUE);
|
||||
|
||||
|
||||
// if($school_id || $professor_id || $textbook_id || $class_id || $search_term)
|
||||
// {
|
||||
// for pagination
|
||||
$this->load->library('pagination');
|
||||
|
||||
$rows_data = $this->inventory_model->get_all_active_items_list_fe($search_term, $school_id, $professor_id, $textbook_id, $class_id,$isbn,$order_by,$direction);
|
||||
|
||||
$total_rows = 0;
|
||||
if (!empty($rows_data))
|
||||
{
|
||||
$total_rows = count($rows_data);
|
||||
}
|
||||
$limit = 10;
|
||||
|
||||
// $offset = $offset * $limit ;
|
||||
|
||||
if ($offset != 0 OR $offset != "")
|
||||
{
|
||||
$offset = ($offset - 1) * $limit;
|
||||
}
|
||||
|
||||
|
||||
$this->pagination->initialize([
|
||||
'reuse_query_string' => TRUE,
|
||||
'base_url' => base_url().'/buy',
|
||||
'total_rows' => $total_rows,
|
||||
'per_page' => $limit,
|
||||
'num_links' => 2,
|
||||
'full_tag_open' => '<ul class="pagination pagination-lg justify-content-center">',
|
||||
'full_tag_close' => '</ul>',
|
||||
'attributes' => ['class' => 'page-link'],
|
||||
'first_link' => FALSE,
|
||||
'last_link' => FALSE,
|
||||
'use_page_numbers' => TRUE,
|
||||
'first_tag_open' => '<li class="page-item">',
|
||||
'first_tag_close' => '</li>',
|
||||
'prev_link' => '«',
|
||||
'prev_tag_open' => '<li class="page-item">',
|
||||
'prev_tag_close' => '</li>',
|
||||
'next_link' => '»',
|
||||
'next_tag_open' => '<li class="page-item">',
|
||||
'next_tag_close' => '</li>',
|
||||
'last_tag_open' => '<li class="page-item">',
|
||||
'last_tag_close' => '</li>',
|
||||
'cur_tag_open' => '<li class="page-item active"><a href="#" class="page-link">',
|
||||
'cur_tag_close' => '<span class="sr-only">(current)</span></a></li>',
|
||||
'num_tag_open' => '<li class="page-item">',
|
||||
'num_tag_close' => '</li>'
|
||||
]);
|
||||
|
||||
$items = $this->inventory_model->get_all_active_items_list_fe($search_term, $school_id, $professor_id, $textbook_id, $class_id,$isbn,$order_by,$direction, $offset, $limit);
|
||||
|
||||
if (!empty($items))
|
||||
{
|
||||
$this->_data['links'] = $this->pagination->create_links();
|
||||
$this->_data['items'] = $items;
|
||||
}
|
||||
|
||||
// }
|
||||
//notes amount
|
||||
$notes_amount = $this->db->select('value')->from('setting')->where('key','fixed_paper_amount')->get()->row_array();
|
||||
if( $notes_amount){
|
||||
$this->_data['notes_amount'] = $notes_amount['value'];
|
||||
}else{
|
||||
$this->_data['notes_amount'] = 50;
|
||||
}
|
||||
|
||||
$this->_data['user_downloaded_files'] = [];
|
||||
if($this->session->userdata('user_id'))
|
||||
{
|
||||
$this->_data['user_downloaded_files'] = $this->db->select('inventory_id')->from('order')->where('purchase_user_id',$this->session->userdata('user_id'))->get()->result_array();
|
||||
if($this->_data['user_downloaded_files'] )
|
||||
{
|
||||
$this->_data['user_downloaded_files'] = array_column($this->_data['user_downloaded_files'],'inventory_id');
|
||||
}
|
||||
}
|
||||
|
||||
$this->_data['meta'] = [
|
||||
'title' => '',
|
||||
'desc' => '',
|
||||
];
|
||||
|
||||
$meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','buy_page_meta_title')->or_where('content_name','buy_page_meta_description')->get()->result_array();
|
||||
if($meta_data)
|
||||
{
|
||||
$meta_data = array_column($meta_data,'content','content_name');
|
||||
$this->_data['meta']['title'] = $meta_data['buy_page_meta_title'];
|
||||
$this->_data['meta']['desc'] = $meta_data['buy_page_meta_description'];
|
||||
}
|
||||
|
||||
$this->_data['active'] = 'buy';
|
||||
$this->_render('Guest/Buy', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function sell()
|
||||
{
|
||||
$content = $this->content_model->get_all(['status'=>1]);
|
||||
$this->_data['content'] = [];
|
||||
if($content )
|
||||
{
|
||||
$data = [];
|
||||
foreach ($content as $key => $value) {
|
||||
$data[$value->content_name]= $value;
|
||||
}
|
||||
$this->_data['content'] = $data;
|
||||
}
|
||||
|
||||
// //get all school data
|
||||
// $this->_data['school_data'] = $this->school_model->get_all(['status' => 1]);
|
||||
// $this->_data['professor_data'] = $this->professor_model->get_all(['status' => 1]);
|
||||
// $this->_data['classes_data'] = $this->classes_model->get_all(['status' => 1]);
|
||||
// $this->_data['textbook_data'] = $this->textbook_model->get_all(['status' => 1]);
|
||||
|
||||
|
||||
|
||||
$data = $this->db->select('paypal_email')->from('user')->where('id',$this->session->userdata('user_id'))->get()->row_array();
|
||||
|
||||
if (isset($data['paypal_email']))
|
||||
{
|
||||
$this->_data['paypal_email'] = $data['paypal_email'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->_data['meta'] = [
|
||||
'title'=>'',
|
||||
'desc'=>'',
|
||||
];
|
||||
|
||||
$meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','sell_page_meta_title')->or_where('content_name','sell_page_meta_description')->get()->result_array();
|
||||
|
||||
if($meta_data)
|
||||
{
|
||||
$meta_data = array_column($meta_data,'content','content_name');
|
||||
$this->_data['meta']['title']= $meta_data['sell_page_meta_title'];
|
||||
$this->_data['meta']['desc']= $meta_data['sell_page_meta_description'];
|
||||
}
|
||||
|
||||
$this->_data['active'] = 'sell';
|
||||
|
||||
$this->_render('Guest/Sell', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
public function checkout()
|
||||
{
|
||||
|
||||
if(!$this->session->userdata('user_id')){
|
||||
|
||||
echo json_encode(['status'=>'error','message'=>'You Have to Login First']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
// stripe_helper_service
|
||||
$card_number = $this->input->post('card_number', TRUE);
|
||||
$exp_month = $this->input->post('exp_month', TRUE);
|
||||
$exp_year = $this->input->post('exp_year', TRUE);
|
||||
$cvc = $this->input->post('cvc', TRUE);
|
||||
$inv_id = $this->input->post('inv_id', TRUE);
|
||||
|
||||
$new_card_last4 = substr($card_number, 12);
|
||||
|
||||
// add card
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$response = $this->stripe_helper_service->create_stripe_token($card_number, $exp_month, $exp_year, $cvc);
|
||||
|
||||
if (isset($response['success']))
|
||||
{
|
||||
$stripe_token_id = $response['token']->id;
|
||||
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$this->stripe_helper_service->set_user_model($this->user_model);
|
||||
// pass token_id to assign card to user
|
||||
$res_card_data = $this->stripe_helper_service->add_new_card($stripe_token_id, $user_id);
|
||||
|
||||
if (isset($res_card_data['success']))
|
||||
{
|
||||
$stripe_card_id = $res_card_data['card_data']->id;
|
||||
$stripe_brand = $res_card_data['card_data']->brand;
|
||||
$stripe_exp_month = $res_card_data['card_data']->exp_month;
|
||||
$stripe_exp_year = $res_card_data['card_data']->exp_year;
|
||||
$stripe_last4 = $res_card_data['card_data']->last4;
|
||||
|
||||
// store the card id with the associated user
|
||||
$check_new_card = $this->user_card_model->create([
|
||||
'is_default' => 0,
|
||||
'user_id' => $user_id,
|
||||
'stripe_card_id' => $stripe_card_id,
|
||||
'brand' => $stripe_brand,
|
||||
'exp_month' => $stripe_exp_month,
|
||||
'exp_year' => $stripe_exp_year,
|
||||
'last4' => $stripe_last4,
|
||||
'cvc' => $cvc,
|
||||
'status' => 1
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// when user do not have the user->stripe_id
|
||||
echo json_encode(['status'=>'error','message'=>'Error']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// when new card validation failed
|
||||
echo json_encode(['status'=>'error','message'=>'Error You card is invalid']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
$html = '';
|
||||
if($this->input->post('keyword'))
|
||||
{
|
||||
|
||||
$result = $this->db->query("
|
||||
SELECT name FROM school WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%'
|
||||
UNION ALL
|
||||
SELECT name FROM classes WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%'
|
||||
UNION ALL
|
||||
SELECT name FROM professor WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%'
|
||||
UNION ALL
|
||||
SELECT name FROM textbook WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%'
|
||||
UNION ALL
|
||||
SELECT title as name FROM inventory WHERE title LIKE '%".htmlentities($this->input->post('keyword'))."%'
|
||||
")->result_array();
|
||||
|
||||
|
||||
|
||||
|
||||
if(!empty($result)) {
|
||||
$html .='<ul id="country-list" style="z-index:1000;width:91%;max-height:200px;overflow-y:scroll;">';
|
||||
foreach($result as $key =>$value) {
|
||||
$html .= '<li onClick="selectCountry(`'.$value["name"].'`);">'.$value["name"].'</li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
}
|
||||
}
|
||||
echo json_encode(['html'=>$html]);
|
||||
exit();
|
||||
}
|
||||
public function preview($id)
|
||||
{
|
||||
|
||||
$this->_data['active'] = 'Preview';
|
||||
$this->_data['data'] = $this->inventory_model->get_by_fields(['status'=>1,'id'=>$id]);
|
||||
$this->_render('Guest/Preview', $this->_data);
|
||||
}
|
||||
public function terms_and_conditions()
|
||||
{
|
||||
// $terms = $this->terms_and_conditions_model->get(1);
|
||||
|
||||
// if (!empty($terms))
|
||||
// {
|
||||
// $this->_data['terms'] = $terms;
|
||||
// }
|
||||
$this->_data['data'] = $this->db->select('*')->from('content')->where('content_name','terms_conditon')->get()->row_array();
|
||||
$this->_data['active'] = 'terms_and_conditions';
|
||||
$this->_render('Guest/Terms_and_conditions', $this->_data);
|
||||
}
|
||||
|
||||
protected function _render($template, $_data)
|
||||
{
|
||||
$this->_data['page_section'] = $template;
|
||||
|
||||
$this->load->view('Guest/Header', $this->_data);
|
||||
$this->load->view($template, $this->_data);
|
||||
$this->load->view('Guest/Footer', $this->_data);
|
||||
}
|
||||
|
||||
public function dd()
|
||||
{
|
||||
$output = '';
|
||||
|
||||
echo "<pre>";
|
||||
print_r($output);
|
||||
die();
|
||||
}
|
||||
|
||||
public function get_review(){
|
||||
if( isset($_POST['id']) )
|
||||
{
|
||||
|
||||
$data = $this->db->select('r.*,u.image,u.first_name')->from('review r')->join('user u','r.user_id=u.id')->where('inventory_id',$_POST['id'])->where('r.status',1)->order_by('r.created_at')->get()->result_array();
|
||||
echo json_encode(['status'=>true,'data'=>$data]);
|
||||
exit;
|
||||
}
|
||||
echo json_encode(['status'=>false]);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
+473
@@ -0,0 +1,473 @@
|
||||
<?php
|
||||
use Aws\S3\S3Client;
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Image Abstract Controller
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Image_controller extends CI_Controller
|
||||
{
|
||||
public $_data = [
|
||||
'error' => '',
|
||||
'success' => ''
|
||||
];
|
||||
|
||||
//testMode flag
|
||||
protected $_test_mode = FALSE;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
}
|
||||
|
||||
public function index ()
|
||||
{
|
||||
$image_upload_type = $this->config->item('image_upload');
|
||||
|
||||
if ($image_upload_type == 's3')
|
||||
{
|
||||
return $this->s3_upload();
|
||||
}
|
||||
|
||||
$this->load->model('image_model');
|
||||
$data_uri = $this->input->post('image');
|
||||
$base_url = $this->config->item('base_url');
|
||||
$image_path = __DIR__ . '/../../../uploads/';
|
||||
$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data_uri));
|
||||
$filename = md5(uniqid() . time()) . '.png';
|
||||
file_put_contents($image_path . $filename, $data);
|
||||
list($width, $height) = @getimagesize( $image_path .$filename );
|
||||
$session = $this->get_session();
|
||||
$user_id = isset($session['user_id']) ? $session['user_id'] : 0;
|
||||
|
||||
$image_id = $this->image_model->create([
|
||||
'url' => '/uploads/' . $filename,
|
||||
'type' => 0,
|
||||
'user_id' => $user_id,
|
||||
'width' => $width,
|
||||
'caption' => '',
|
||||
'height' => $height
|
||||
]);
|
||||
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode([
|
||||
'id' => $image_id,
|
||||
'image' => $base_url . '/uploads/' . $filename,
|
||||
'width' => $width,
|
||||
'height' => $height
|
||||
]));
|
||||
}
|
||||
|
||||
public function s3_upload ()
|
||||
{
|
||||
$s3 = new S3Client([
|
||||
'version' => $this->config->item('aws_version'),
|
||||
'region' => $this->config->item('aws_region'),
|
||||
'endpoint' => $this->config->item('aws_endpoint'),
|
||||
'use_path_style_endpoint' => true,
|
||||
'credentials' => [
|
||||
'key' => $this->config->item('aws_key'),
|
||||
'secret' => $this->config->item('aws_secret'),
|
||||
]
|
||||
]);
|
||||
|
||||
$this->load->model('image_model');
|
||||
$data_uri = $this->input->post('image');
|
||||
$image_path = __DIR__ . '/../../../uploads/';
|
||||
$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data_uri));
|
||||
$filename = md5(uniqid() . time()) . '.png';
|
||||
file_put_contents($image_path . $filename, $data);
|
||||
list($width, $height) = getimagesize( $image_path . $filename );
|
||||
$session = $this->get_session();
|
||||
$user_id = isset($session['user_id']) ? $session['user_id'] : 0;
|
||||
|
||||
try
|
||||
{
|
||||
$result = $s3->putObject([
|
||||
'Bucket' => $this->config->item('aws_bucket'),
|
||||
'Key' => $filename,
|
||||
'Body' => fopen($image_path . $filename, 'r'),
|
||||
'ACL' => 'public-read',
|
||||
]);
|
||||
|
||||
$image_id = $this->image_model->create([
|
||||
'url' => $result->get('ObjectURL'),
|
||||
'type' => 0,
|
||||
'user_id' => $user_id,
|
||||
'width' => $width,
|
||||
'caption' => '',
|
||||
'height' => $height
|
||||
]);
|
||||
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode([
|
||||
'id' => $image_id,
|
||||
'image' => $result->get('ObjectURL'),
|
||||
'width' => $width,
|
||||
'height' => $height
|
||||
]));
|
||||
}
|
||||
catch (Aws\S3\Exception\S3Exception $e)
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Upload to S3 Failed'
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
public function file_upload ()
|
||||
{
|
||||
$file_upload_type = $this->config->item('file_upload');
|
||||
$this->load->library('mime_service');
|
||||
if ($file_upload_type == 's3')
|
||||
{
|
||||
return $this->s3_file_upload();
|
||||
}
|
||||
|
||||
$this->load->model('image_model');
|
||||
|
||||
if (!(isset($_FILES) && count($_FILES) > 0 && isset($_FILES['file'])))
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Upload file missing'
|
||||
]));
|
||||
}
|
||||
|
||||
$file = $_FILES['file'];
|
||||
$size = $file['size'];
|
||||
$path = $file['tmp_name'];
|
||||
$type = $file['type'];
|
||||
$extension = $this->mime_service->get_extension($type);
|
||||
|
||||
if ($size > $this->config->item('upload_byte_size_limit'))
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Upload file size too big'
|
||||
]));
|
||||
}
|
||||
|
||||
$filename = md5(uniqid() . time()) . $extension;
|
||||
$width = 0;
|
||||
$height = 0;
|
||||
$session = $this->get_session();
|
||||
$user_id = isset($session['user_id']) ? $session['user_id'] : 0;
|
||||
$image_path = __DIR__ . '/../../../uploads/';
|
||||
|
||||
if (!move_uploaded_file($path, $image_path . $filename))
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Upload file failed'
|
||||
]));
|
||||
}
|
||||
|
||||
$image_id = $this->image_model->create([
|
||||
'url' => '/uploads/' . $filename,
|
||||
'type' => 4,
|
||||
'user_id' => $user_id,
|
||||
'width' => $width,
|
||||
'caption' => '',
|
||||
'height' => $height
|
||||
]);
|
||||
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode([
|
||||
'id' => $image_id,
|
||||
'file' => '/uploads/' . $filename,
|
||||
'width' => $width,
|
||||
'height' => $height
|
||||
]));
|
||||
}
|
||||
|
||||
public function s3_file_upload ()
|
||||
{
|
||||
$this->load->model('image_model');
|
||||
$this->load->library('mime_service');
|
||||
|
||||
$s3 = new S3Client([
|
||||
'version' => $this->config->item('aws_version'),
|
||||
'region' => $this->config->item('aws_region'),
|
||||
'endpoint' => $this->config->item('aws_endpoint'),
|
||||
'use_path_style_endpoint' => true,
|
||||
'credentials' => [
|
||||
'key' => $this->config->item('aws_key'),
|
||||
'secret' => $this->config->item('aws_secret'),
|
||||
]
|
||||
]);
|
||||
|
||||
if (!(isset($_FILES) && count($_FILES) > 0 && isset($_FILES['file'])))
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Upload file failed'
|
||||
]));
|
||||
}
|
||||
|
||||
$file = $_FILES['file'];
|
||||
$size = $file['size'];
|
||||
$path = $file['tmp_name'];
|
||||
$type = $file['type'];
|
||||
$extension = $this->mime_service->get_extension($type);
|
||||
|
||||
if ($size > $this->config->item('upload_byte_size_limit'))
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Upload file size too big'
|
||||
]));
|
||||
}
|
||||
|
||||
$filename = md5(uniqid() . time()) . $extension;
|
||||
$width = 0;
|
||||
$height = 0;
|
||||
$session = $this->get_session();
|
||||
$user_id = isset($session['user_id']) ? $session['user_id'] : 0;
|
||||
|
||||
try
|
||||
{
|
||||
$result = $s3->putObject([
|
||||
'Bucket' => $this->config->item('aws_bucket'),
|
||||
'Key' => $filename,
|
||||
'Body' => fopen($path, 'r'),
|
||||
'ACL' => 'public-read',
|
||||
]);
|
||||
|
||||
$image_id = $this->image_model->create([
|
||||
'url' => $result->get('ObjectURL'),
|
||||
'type' => 5,
|
||||
'user_id' => $user_id,
|
||||
'width' => $width,
|
||||
'caption' => '',
|
||||
'height' => $height
|
||||
]);
|
||||
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode([
|
||||
'id' => $image_id,
|
||||
'file' => $result->get('ObjectURL'),
|
||||
'width' => $width,
|
||||
'height' => $height
|
||||
]));
|
||||
}
|
||||
catch (Aws\S3\Exception\S3Exception $e)
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Upload to S3 Failed'
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
public function paginate($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
$this->load->model('image_model');
|
||||
include_once __DIR__ . '/../../view_models/Image_asset_paginate_view_model.php';
|
||||
$where = [];
|
||||
$this->_data['view_model'] = new Image_asset_paginate_view_model(
|
||||
$this->image_model,
|
||||
$this->pagination,
|
||||
'/v1/api/assets/0');
|
||||
|
||||
$this->_data['view_model']->set_heading('Images');
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->image_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page(10);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->image_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where));
|
||||
|
||||
return $this->success($this->_data['view_model']->to_json(), 200);
|
||||
}
|
||||
|
||||
public function file_import ($model)
|
||||
{
|
||||
$model_name = $model . '_model';
|
||||
$this->load->library('mime_service');
|
||||
$this->load->library('csv_import_service');
|
||||
$this->load->model($model_name);
|
||||
|
||||
$this->csv_import_service->set_model($this->$model_name, $model);
|
||||
|
||||
/* if ($this->csv_import_service->csv_file_exist($_FILES))
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Upload CSV File missing'
|
||||
]));
|
||||
}*/
|
||||
|
||||
$file = $_FILES['file'];
|
||||
$size = $file['size'];
|
||||
$path = $file['tmp_name'];
|
||||
$type = $file['type'];
|
||||
$extension = $this->mime_service->get_extension($type);
|
||||
//$extension = ucfirst(str_replace('.', '', $this->mime_service->get_extension($type)));
|
||||
$save_as = FCPATH . 'uploads/' . $file["name"];
|
||||
|
||||
if ($size > $this->config->item('upload_byte_size_limit'))
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Upload file size too big'
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
$save_as = FCPATH . 'uploads/temp' . $extension;
|
||||
|
||||
if ($size > $this->config->item('upload_byte_size_limit'))
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Upload file size too big'
|
||||
]));
|
||||
}
|
||||
|
||||
if (move_uploaded_file($path, $save_as))
|
||||
{
|
||||
$data = $this->csv_import_service->_import_data( $save_as );
|
||||
|
||||
if($data)
|
||||
{
|
||||
unlink($save_as);
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode([
|
||||
'status' => TRUE
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Generating SQL worked but insert error to the database'
|
||||
]));
|
||||
}
|
||||
|
||||
public function preview_csv()
|
||||
{
|
||||
$this->load->library('mime_service');
|
||||
$this->load->library('csv_import_service');
|
||||
|
||||
$file = $_FILES['file'];
|
||||
$size = $file['size'];
|
||||
$path = $file['tmp_name'];
|
||||
$type = $file['type'];
|
||||
$save_as = FCPATH . 'uploads/' . $file["name"];
|
||||
|
||||
if ($size > $this->config->item('upload_byte_size_limit'))
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode([
|
||||
'message' => 'Upload file size too big'
|
||||
]));
|
||||
}
|
||||
|
||||
if (move_uploaded_file($path, $save_as))
|
||||
{
|
||||
$data = $this->csv_import_service->_get_file_data( $save_as );
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode([
|
||||
'message' => 'xyzFile loaded',
|
||||
'data' => $data,
|
||||
'preview' => TRUE
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dl($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : <pre>' . print_r($data, TRUE) . '</pre>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug json Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dj($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : ' . json_encode($data));
|
||||
}
|
||||
}
|
||||
|
||||
public function get_session()
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
return $_SESSION;
|
||||
}
|
||||
|
||||
$session = $this->config->item('session_test');
|
||||
|
||||
if (!$session)
|
||||
{
|
||||
$session = [];
|
||||
}
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Success API Call
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function success($success)
|
||||
{
|
||||
$success['code'] = 200;
|
||||
$success['success'] = TRUE;
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($success));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+264
@@ -0,0 +1,264 @@
|
||||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Marketing Controller
|
||||
*
|
||||
* @copyright 2021 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Marketing_controller extends Manaknight_Controller
|
||||
{
|
||||
public $_data = [
|
||||
'error' => '',
|
||||
'success' => ''
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
$this->load->model('marketing_model');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dl($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : <pre>' . print_r($data, TRUE) . '</pre>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug json Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dj($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : ' . json_encode($data));
|
||||
}
|
||||
}
|
||||
|
||||
public function get_session()
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
return $_SESSION;
|
||||
}
|
||||
|
||||
$session = $this->config->item('session_test');
|
||||
|
||||
if (!$session)
|
||||
{
|
||||
$session = [];
|
||||
}
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
public function set_session($field, $value)
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
$_SESSION[$field] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$session = $this->config->item('session_test');
|
||||
if (!$session)
|
||||
{
|
||||
$session = [];
|
||||
}
|
||||
$session[$field] = $value;
|
||||
$this->config->set_item('session_test', $session);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy_session()
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
unset($_SESSION);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->config->set_item('session_test', []);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_setting()
|
||||
{
|
||||
return $this->_setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate a slug
|
||||
*/
|
||||
public function generate_marketing_slug($str)
|
||||
{
|
||||
|
||||
$delimiter = '-';
|
||||
$slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter));
|
||||
$full_path = base_url() . 'a/';
|
||||
|
||||
$row = $this->marketing_model->get_by_field('slug', $full_path . $slug);
|
||||
|
||||
if (empty($row))
|
||||
{
|
||||
$output['slug'] = $slug;
|
||||
echo json_encode($output);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$i = 1;
|
||||
$check_me_again = TRUE;
|
||||
while ($check_me_again)
|
||||
{
|
||||
$slug = $slug . '-' . $i;
|
||||
$row = $this->marketing_model->get_by_field('slug', $full_path . $slug);
|
||||
|
||||
if (empty($row))
|
||||
{
|
||||
$check_me_again = FALSE;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$output['slug'] = $slug;
|
||||
echo json_encode($output);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to return the generated page
|
||||
*/
|
||||
public function generate_custom_marketing_page($slug)
|
||||
{
|
||||
$slug_url = base_url() . 'a/';
|
||||
$slug = $slug_url.$slug;
|
||||
$marketing_data = $this->marketing_model->get_by_field('slug',$slug);
|
||||
$this->_data['header'] = '';
|
||||
$this->_data['footer'] = '';
|
||||
$this->_data['content_template'] = '';
|
||||
$this->_data['content'] = '';
|
||||
$this->_data['success'] = '';
|
||||
$this->_data['error'] = '';
|
||||
$this->_data['layout_clean_mode'] = TRUE;
|
||||
$this->_data['reuse_query_string'] = TRUE;
|
||||
$this->_data['base_url'] = base_url();
|
||||
$this->_data['total_rows'] = 25;
|
||||
$this->_data['per_page'] = 25;
|
||||
$this->_data['num_links'] = '';
|
||||
$this->_data['full_tag_open'] = '<ul class="pagination justify-content-end">';
|
||||
$this->_data['full_tag_close'] = '</ul>';
|
||||
$this->_data['attributes'] = ['class' => 'page-link'];
|
||||
$this->_data['first_link'] = FALSE ;
|
||||
$this->_data['last_link'] = FALSE;
|
||||
$this->_data['first_tag_open'] = '<li class="page-item">';
|
||||
$this->_data['first_tag_close'] = '</li>';
|
||||
$this->_data['prev_link'] = '«';
|
||||
$this->_data['setting'] = $this->get_setting();
|
||||
$this->_data['list'] = [];
|
||||
|
||||
if($marketing_data)
|
||||
{
|
||||
if($marketing_data->header_template_path != '')
|
||||
{
|
||||
$this->_data['header'] = $marketing_data->header_template_path ? $marketing_data->header_template_path : '';
|
||||
}
|
||||
|
||||
if($marketing_data->footer_template_path != '')
|
||||
{
|
||||
$this->_data['footer'] = $marketing_data->footer_template_path ? $marketing_data->footer_template_path : '';
|
||||
}
|
||||
|
||||
$this->_data['content'] = $marketing_data->content ? $marketing_data->content : '';
|
||||
$this->_data['content_template'] = $marketing_data->content_template_path ? $marketing_data->content_template_path : '';
|
||||
|
||||
if($marketing_data->status == 0)
|
||||
{
|
||||
if ($marketing_data->password_protect == '')
|
||||
{
|
||||
return $this->generate_marketing_template($this->_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$valid_passwords = [
|
||||
'guest' => $marketing_data->password_protect
|
||||
];
|
||||
$valid_users = array_keys($valid_passwords);
|
||||
|
||||
$user = $_SERVER['PHP_AUTH_USER'];
|
||||
$pass = $_SERVER['PHP_AUTH_PW'];
|
||||
|
||||
$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
|
||||
|
||||
if (!$validated)
|
||||
{
|
||||
header('WWW-Authenticate: Basic realm="My Realm"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
die ('Not authorized');
|
||||
}
|
||||
|
||||
return $this->generate_marketing_template($this->_data);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->output->set_status_header('404');
|
||||
$data['heading'] = '404 Page Not Found';
|
||||
$data['message'] = 'The page you requested was not found';
|
||||
$this->load->view('errors/html/error_404',$data);
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
$this->output->set_status_header('404');
|
||||
$data['heading'] = '404 Page Not Found';
|
||||
$data['message'] = 'The page you requested was not found';
|
||||
$this->load->view('errors/html/error_404', $data);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate marketing template
|
||||
*/
|
||||
|
||||
public function generate_marketing_template($marketing_data)
|
||||
{
|
||||
if($marketing_data['header'] != '')
|
||||
{
|
||||
$this->load->view($marketing_data['header'], $marketing_data);
|
||||
}
|
||||
|
||||
if($marketing_data['content_template'] == '')
|
||||
{
|
||||
echo $marketing_data['content_template'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->load->view('Guest/Template_page', $marketing_data);
|
||||
}
|
||||
|
||||
if($marketing_data['footer'] != '')
|
||||
{
|
||||
$this->load->view($marketing_data['footer'], $marketing_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Voice Controller
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Spreadsheet_controller extends Manaknight_Controller
|
||||
{
|
||||
public $_data = [
|
||||
'error' => '',
|
||||
'success' => ''
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
$this->load->model('spreadsheet_model');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dl($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : <pre>' . print_r($data, TRUE) . '</pre>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug json Controller to error_log and turn off in production
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function dj($key, $data)
|
||||
{
|
||||
if (ENVIRONMENT == 'development')
|
||||
{
|
||||
error_log($key . ' CONTROLLER : ' . json_encode($data));
|
||||
}
|
||||
}
|
||||
|
||||
public function get_session()
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
return $_SESSION;
|
||||
}
|
||||
|
||||
$session = $this->config->item('session_test');
|
||||
|
||||
if (!$session)
|
||||
{
|
||||
$session = [];
|
||||
}
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
public function set_session($field, $value)
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
$_SESSION[$field] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$session = $this->config->item('session_test');
|
||||
if (!$session)
|
||||
{
|
||||
$session = [];
|
||||
}
|
||||
$session[$field] = $value;
|
||||
$this->config->set_item('session_test', $session);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy_session()
|
||||
{
|
||||
if (!$this->_test_mode)
|
||||
{
|
||||
unset($_SESSION);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->config->set_item('session_test', []);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_setting()
|
||||
{
|
||||
return $this->_setting;
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Health Check Controller
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Health_check_controller extends CI_Controller
|
||||
{
|
||||
public function index ()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->load->database();
|
||||
$error = get_instance()->db->error();
|
||||
|
||||
if (!empty($error) && $error['code'] > 0)
|
||||
{
|
||||
throw new Exception('Database Connection Failed');
|
||||
}
|
||||
|
||||
return $this->output
|
||||
->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode(array(
|
||||
'status' => 200,
|
||||
'date' => date('Y-m-j H:i:s', time())
|
||||
)));
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return $this->output
|
||||
->set_content_type('application/json')
|
||||
->set_status_header(500)
|
||||
->set_output(json_encode(array(
|
||||
'status' => 500,
|
||||
'date' => date('Y-m-j H:i:s', time())
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Cart Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_cart_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'cart_model';
|
||||
public $_page_name = 'Cart';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Cart_member_list_paginate_view_model.php';
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
$session = $this->get_session();
|
||||
$where = [];
|
||||
$this->_data['view_model'] = new Cart_member_list_paginate_view_model(
|
||||
$this->cart_model,
|
||||
$this->pagination,
|
||||
'/member/cart/0');
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
$this->_data['view_model']->set_total_rows($this->cart_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/cart/0');
|
||||
$this->_data['view_model']->set_list($this->cart_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Cart', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Cart_member_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->cart_model->set_form_validation(
|
||||
$this->form_validation, $this->cart_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Cart_member_add_view_model($this->cart_model);
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/CartAdd', $this->_data);
|
||||
}
|
||||
|
||||
$product_id = $this->input->post('product_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$session_id = $this->input->post('session_id', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$quantity = $this->input->post('quantity', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
|
||||
$result = $this->cart_model->create([
|
||||
'product_id' => $product_id,
|
||||
'user_id' => $user_id,
|
||||
'session_id' => $session_id,
|
||||
'subtotal' => $subtotal,
|
||||
'quantity' => $quantity,
|
||||
'total' => $total,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/member/cart/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/CartAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->cart_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/cart/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Cart_member_edit_view_model.php';
|
||||
$this->form_validation = $this->cart_model->set_form_validation(
|
||||
$this->form_validation, $this->cart_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Cart_member_edit_view_model($this->cart_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/CartEdit', $this->_data);
|
||||
}
|
||||
|
||||
$product_id = $this->input->post('product_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$session_id = $this->input->post('session_id', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$quantity = $this->input->post('quantity', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
|
||||
$result = $this->cart_model->edit([
|
||||
'product_id' => $product_id,
|
||||
'user_id' => $user_id,
|
||||
'session_id' => $session_id,
|
||||
'subtotal' => $subtotal,
|
||||
'quantity' => $quantity,
|
||||
'total' => $total,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/member/cart/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/CartEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->cart_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/cart/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Cart_member_view_view_model.php';
|
||||
$this->_data['view_model'] = new Cart_member_view_view_model($this->cart_model);
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Member/CartView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$model = $this->cart_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/cart/0');
|
||||
}
|
||||
|
||||
$result = $this->cart_model->delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
return $this->redirect('/member/cart/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->error('Error');
|
||||
return redirect('/member/cart/0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/**
|
||||
* Member Controller
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_controller extends Manaknight_Controller
|
||||
{
|
||||
|
||||
public $_page_name ='dashboard';
|
||||
|
||||
public $_valid_roles = [1];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->_data['page_name'] = $this->_page_name;
|
||||
$this->_data['setting'] = $this->_setting;
|
||||
$this->_data['layout_clean_mode'] = FALSE;
|
||||
$this->_run_middlewares();
|
||||
$layout_mode = $this->input->get('layout_clean_mode', TRUE);
|
||||
if (isset($layout_mode) && $layout_mode === '1')
|
||||
{
|
||||
$this->_data['layout_clean_mode'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
protected function _middleware()
|
||||
{
|
||||
return [
|
||||
'affilate', 'auth', 'acl', 'maintenance'
|
||||
];
|
||||
}
|
||||
|
||||
public function render($template, $data)
|
||||
{
|
||||
return (!$this->_test_mode) ? $this->_render($template, $data) : $this->_render_test($template, $data);
|
||||
}
|
||||
|
||||
protected function _render_test($template, $data)
|
||||
{
|
||||
return [
|
||||
'header' => $this->load->view('Layout/MemberHeader', $data, TRUE),
|
||||
'body' => $this->load->view($template, $data, TRUE),
|
||||
'footer' => $this->load->view('Layout/MemberFooter', $data, TRUE),
|
||||
'data' => $data,
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Function to return the images for media gallery
|
||||
*/
|
||||
public function get_all_images()
|
||||
{
|
||||
$this->load->model('image_model');
|
||||
$images = $this->image_model->get_all();
|
||||
return $images;
|
||||
}
|
||||
|
||||
protected function _render($template, $data)
|
||||
{
|
||||
$data['images'] = $this->get_all_images();
|
||||
$data['page_section'] = $template;
|
||||
$this->load->view('Layout/MemberHeader', $data);
|
||||
$this->load->view($template, $data);
|
||||
$this->load->view('Layout/MemberFooter',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* User token invalid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function unauthorize_error_message()
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(401)
|
||||
->set_output(json_encode([
|
||||
'code' => 401,
|
||||
'success' => FALSE,
|
||||
'message' => 'invalid credentials'
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* User Role invalid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function unauthorize_resource_error_message()
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(406)
|
||||
->set_output(json_encode([
|
||||
'code' => 406,
|
||||
'success' => FALSE,
|
||||
'message' => 'cannot access resource'
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Success API Call
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function success2($success)
|
||||
{
|
||||
$success['code'] = 200;
|
||||
$success['success'] = TRUE;
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($success));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid form input
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _render_validation_error ()
|
||||
{
|
||||
$data = [];
|
||||
$data['code'] = 403;
|
||||
$data['success'] = FALSE;
|
||||
$data['error'] = $this->form_validation->error_array();
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render Custom Error
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _render_custom_error ($errors)
|
||||
{
|
||||
$data = [];
|
||||
$data['code'] = 403;
|
||||
$data['success'] = FALSE;
|
||||
$data['error'] = $errors;
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode($data));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
|
||||
/**
|
||||
* Member Dashboard Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_dashboard_controller extends Member_controller
|
||||
{
|
||||
public $_page_name = 'Dashboard';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index ()
|
||||
{
|
||||
return $this->render('Member/Dashboard', $this->_data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Dispute Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_dispute_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'dispute_model';
|
||||
public $_page_name = 'Dispute';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Dispute_member_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Dispute_member_list_paginate_view_model(
|
||||
$this->dispute_model,
|
||||
$this->pagination,
|
||||
'/member/dispute/0');
|
||||
$this->_data['view_model']->set_heading('Dispute');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_reason(($this->input->get('reason', TRUE) != NULL) ? $this->input->get('reason', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_stripe_charge_id(($this->input->get('stripe_charge_id', TRUE) != NULL) ? $this->input->get('stripe_charge_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_stripe_dispute_id(($this->input->get('stripe_dispute_id', TRUE) != NULL) ? $this->input->get('stripe_dispute_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'user_id' => $this->_data['view_model']->get_user_id(),
|
||||
'reason' => $this->_data['view_model']->get_reason(),
|
||||
'stripe_charge_id' => $this->_data['view_model']->get_stripe_charge_id(),
|
||||
'stripe_dispute_id' => $this->_data['view_model']->get_stripe_dispute_id(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->dispute_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/dispute/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->dispute_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Dispute', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->dispute_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/dispute/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Dispute_member_view_view_model.php';
|
||||
$this->_data['view_model'] = new Dispute_member_view_view_model($this->dispute_model);
|
||||
$this->_data['view_model']->set_heading('Dispute');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Member/DisputeView', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once __DIR__ . '/../../services/User_service.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Forgot Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_forgot_controller extends Manaknight_Controller
|
||||
{
|
||||
public function index ()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('email_model');
|
||||
$this->load->model('token_model');
|
||||
$this->load->library('mail_service');
|
||||
|
||||
$service = new User_service($this->credential_model);
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
echo $this->load->view('Member/Forgot', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$from_email = $this->config->item('from_email');
|
||||
$base_url = $this->config->item('base_url');
|
||||
|
||||
$this->mail_service->set_adapter('smtp');
|
||||
$service->set_email_model($this->email_model);
|
||||
$service->set_token_model($this->token_model);
|
||||
$service->set_email_service($this->mail_service);
|
||||
|
||||
$reset = $service->forgot_password($email, $from_email, $base_url . '/member/reset', 1);
|
||||
|
||||
if ($reset)
|
||||
{
|
||||
$this->success('Your Reset email was sent. Check your email.');
|
||||
return $this->redirect('/member/login');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Email does not exist in our system.';
|
||||
echo $this->load->view('Member/Forgot', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
+1657
File diff suppressed because it is too large
Load Diff
+145
@@ -0,0 +1,145 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once __DIR__ . '/../../services/User_service.php';
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Login Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_login_controller extends Manaknight_Controller
|
||||
{
|
||||
protected $_redirect = '/sell';
|
||||
|
||||
public $_valid_roles = [1];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index ()
|
||||
{
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('user_model');
|
||||
$this->load->helper('cookie');
|
||||
|
||||
$service = new User_service($this->credential_model, $this->user_model);
|
||||
if($this->input->cookie('member_remember_me_token', TRUE) !== null && $this->input->cookie('member_remember_me_token', TRUE) !== '')
|
||||
{
|
||||
$this->_remember_me_login();
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
|
||||
$this->form_validation->set_rules('password', 'Password', 'required');
|
||||
$this->_data['portal'] = 'member';
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
echo $this->load->view('Member/Login', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
$redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect);
|
||||
|
||||
$role = $this->_valid_roles[0];
|
||||
$authenticated_user = $service->login_by_role($email, $password, $role);
|
||||
|
||||
if ($authenticated_user)
|
||||
{
|
||||
delete_cookie('redirect');
|
||||
$user_id = $authenticated_user->user_id;
|
||||
|
||||
if(!empty($this->input->post("remember_me"))) {
|
||||
$this->load->helper('string');
|
||||
$remember_cookie = [
|
||||
'user_id' => $user_id,
|
||||
'name' => 'member_remember_me_token',
|
||||
'value' => random_string('alnum', 16),
|
||||
'expire' => time()+$this->config->item('cookie_expire'),
|
||||
'domain' => base_url()
|
||||
];
|
||||
$this->load->model('cookies_model');
|
||||
$check_cookie = $this->cookies_model->get_by_field('user_id', $user_id);
|
||||
if($check_cookie)
|
||||
{
|
||||
$cookie = $this->cookies_model->edit($remember_cookie, $check_cookie->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cookie = $this->cookies_model->create($remember_cookie);
|
||||
}
|
||||
if($cookie)
|
||||
{
|
||||
setcookie($remember_cookie['name'], $remember_cookie['value'], $remember_cookie['expire'], $remember_cookie['domain']);
|
||||
}
|
||||
}
|
||||
$this->set_session('credential_id', (int) $authenticated_user->id);
|
||||
$this->set_session('user_id', (int) $user_id);
|
||||
$this->set_session('email', (string) $authenticated_user->email);
|
||||
$this->set_session('role', (string) $authenticated_user->role_id);
|
||||
|
||||
if( isset($_POST['return_url']) && $_POST['return_url'] =='buy')
|
||||
{
|
||||
return $this->redirect('buy');
|
||||
}
|
||||
return $this->redirect($redirect);
|
||||
}
|
||||
|
||||
$this->error('Wrong email or password.');
|
||||
return $this->redirect('member/login');
|
||||
}
|
||||
|
||||
|
||||
public function _remember_me_login()
|
||||
{
|
||||
$this->load->helper('string');
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('cookies_model');
|
||||
$token_value = $this->input->cookie('member_remember_me_token', TRUE);
|
||||
$cookie = $this->cookies_model->get_by_fields(['value' => $token_value]);
|
||||
$service = new User_service($this->credential_model, $this->user_model);
|
||||
$redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect);
|
||||
if($cookie)
|
||||
{
|
||||
$user_id = $cookie->user_id;
|
||||
$credential = $this->credential_model->get_by_field('user_id', $user_id);
|
||||
$role = $this->_valid_roles[0];
|
||||
if($credential->role_id != $role)
|
||||
{
|
||||
setcookie('member_remember_me_token', '', 1, base_url());
|
||||
return $this->redirect('admin/login');
|
||||
}
|
||||
$random_string = random_string('alnum', 30);
|
||||
$this->cookies_model->edit(['value' => $random_string, 'expire' => time()+$this->config->item('cookie_expire')], $cookie->id);
|
||||
setcookie('member_remember_me_token', $random_string, time()+$this->config->item('cookie_expire'), base_url());
|
||||
$this->set_session('credential_id', (int) $credential->id);
|
||||
$this->set_session('user_id', (int) $user_id);
|
||||
$this->set_session('email', (string) $credential->email);
|
||||
$this->set_session('role', (string) $credential->role_id);
|
||||
return $this->redirect($redirect);
|
||||
}
|
||||
else
|
||||
{
|
||||
setcookie('member_remember_me_token', '', 1, base_url());
|
||||
return $this->redirect('admin/login');
|
||||
}
|
||||
|
||||
$this->error('Wrong email or password.');
|
||||
return $this->redirect('member/login');
|
||||
}
|
||||
|
||||
public function logout ()
|
||||
{
|
||||
$this->load->helper('cookie');
|
||||
setcookie('member_remember_me_token', '', 1, base_url());
|
||||
$this->destroy_session();
|
||||
return $this->redirect('member/login');
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Credential Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_me_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'credential_model';
|
||||
public $_page_name = 'Change Password';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function me()
|
||||
{
|
||||
$session = $this->get_session();
|
||||
$model = $this->credential_model->get($session['credential_id']);
|
||||
$this->_data['email'] = $model->email;
|
||||
$this->_data['password'] = '';
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
|
||||
$this->form_validation->set_rules('password', 'Password', '');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/Mes', $this->_data);
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
|
||||
$payload = [
|
||||
'email' => $email,
|
||||
];
|
||||
|
||||
if (strlen($password) > 1)
|
||||
{
|
||||
$payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
$result = $this->credential_model->edit($payload, $session['credential_id']);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Saved');
|
||||
return $this->redirect('/member/me', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/Mes', $this->_data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
|
||||
/**
|
||||
* Member Profile Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_profile_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'user_model';
|
||||
public $_page_name = 'Profile';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('member_profile_model');
|
||||
$this->load->model('school_model');
|
||||
$session = $this->get_session();
|
||||
$model = $this->user_model->get($session['user_id']);
|
||||
$id = $session['user_id'];
|
||||
|
||||
// load data
|
||||
$schools = $this->school_model->get_all();
|
||||
|
||||
|
||||
if (!empty($schools))
|
||||
{
|
||||
$this->_data['schools'] = $schools;
|
||||
}
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/dashboard');
|
||||
}
|
||||
|
||||
$credential = $this->credential_model->get($session['credential_id']);
|
||||
$email_validation_rules = 'required|valid_email';
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Member_profile_view_model.php';
|
||||
|
||||
if ($this->input->post('email') != $credential->email)
|
||||
{
|
||||
$email_validation_rules .= '|is_unique[credential.email]';
|
||||
}
|
||||
|
||||
$member_profile_data = $this->db->select('*')->from('member_profile')->where('user_id',$id)->get()->row_array();
|
||||
$user_data = $this->db->select('*')->from('user')->where('id',$id)->get()->row_array();
|
||||
|
||||
$this->_data['phone'] = $user_data['phone'];
|
||||
$this->_data['username'] = $member_profile_data['username'];
|
||||
$this->_data['school_id'] = $member_profile_data['school_id'];
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', $email_validation_rules);
|
||||
$this->form_validation->set_rules('first_name', 'First Name', 'required');
|
||||
$this->form_validation->set_rules('last_name', 'Last Name', 'required');
|
||||
|
||||
$this->_data['view_model'] = new Member_profile_view_model($this->user_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_email($credential->email);
|
||||
$this->_data['view_model']->set_heading('Member');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/Profile', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$first_name = $this->input->post('first_name');
|
||||
$last_name = $this->input->post('last_name');
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
|
||||
// $username = $this->input->post('username');
|
||||
$school_id = $this->input->post('school_id');
|
||||
|
||||
$payload = [
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name
|
||||
];
|
||||
|
||||
$payload_2 = [
|
||||
// 'username' => $username,
|
||||
'school_id' => $school_id
|
||||
];
|
||||
|
||||
$result = $this->user_model->edit_raw($payload, $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->db->set($payload_2)->where('id',$member_profile_data['id'])->update('member_profile');
|
||||
$this->db->set(['phone'=>$this->input->post('phone')])->where('id',$id)->update('user');
|
||||
$credential_payload = [
|
||||
'email' => $email
|
||||
];
|
||||
|
||||
if (strlen($password) > 0)
|
||||
{
|
||||
$credential_payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
$result = $this->credential_model->edit_raw($credential_payload, $session['credential_id']);
|
||||
$this->success('Saved');
|
||||
return $this->redirect('/member/profile', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/Profile', $this->_data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
|
||||
/**
|
||||
* Member Profile Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_profile_credential_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'credential_model';
|
||||
public $_page_name = 'Credentials';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
$session = $this->get_session();
|
||||
$user_obj = $this->user_model->get($session['user_id']);
|
||||
$session = $this->get_session();
|
||||
$this->load->model($this->_model_file);
|
||||
$model = $this->credential_model->get($user_obj->credential_id ?? 0);
|
||||
$id = $user_obj->credential_id ?? 0;
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
die();
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Member_profile_credential_view_model.php';
|
||||
$email_validation_rules = 'required|valid_email';
|
||||
|
||||
if ($this->input->post('email') != $session['email'])
|
||||
{
|
||||
$email_validation_rules .= '|is_unique[credential.email]';
|
||||
}
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', $email_validation_rules);
|
||||
|
||||
$this->_data['view_model'] = new Member_profile_credential_view_model($model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Member');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/Credential', $this->_data);
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
|
||||
$payload = [
|
||||
'email' => $email,
|
||||
];
|
||||
|
||||
if (strlen($password) > 0)
|
||||
{
|
||||
$payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
$result = $this->credential_model->edit_raw($payload, $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Saved');
|
||||
return $this->redirect('/member/credential?layout_clean_mode=1', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/Credential', $this->_data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Purchases Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_purchases_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'order_model';
|
||||
public $_page_name = 'Purchases';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('school_model');
|
||||
$this->load->model('professor_model');
|
||||
$this->load->model('classes_model');
|
||||
$this->load->model('textbook_model');
|
||||
|
||||
$this->load->model('inventory_model');
|
||||
|
||||
$this->load->library('helpers_service');
|
||||
$this->load->library('names_helper_service');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
|
||||
// load data
|
||||
$schools = $this->school_model->get_all(['status' => 1]);
|
||||
$professors = $this->professor_model->get_all(['status' => 1]);
|
||||
|
||||
if (!empty($schools))
|
||||
{
|
||||
$this->_data['schools'] = $schools;
|
||||
}
|
||||
|
||||
if (!empty($professors))
|
||||
{
|
||||
$this->_data['professors'] = $professors;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Purchases_member_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Purchases_member_list_paginate_view_model(
|
||||
$this->order_model,
|
||||
$this->pagination,
|
||||
'/member/purchases/0');
|
||||
$this->_data['view_model']->set_heading('Purchases');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_purchase_user_id(($this->input->get('purchase_user_id', TRUE) != NULL) ? $this->input->get('purchase_user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_sale_user_id(($this->input->get('sale_user_id', TRUE) != NULL) ? $this->input->get('sale_user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_inventory_id(($this->input->get('inventory_id', TRUE) != NULL) ? $this->input->get('inventory_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_date(($this->input->get('order_date', TRUE) != NULL) ? $this->input->get('order_date', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = ['purchase_user_id' => $this->session->userdata('user_id')];
|
||||
|
||||
if (!empty($_GET['school_id']))
|
||||
{
|
||||
$inventory = $this->inventory_model->get_all(['school_id' => $_GET['school_id']]);
|
||||
|
||||
if ($inventory)
|
||||
{
|
||||
$where[] = "inventory_id in (" . implode(',',array_column($inventory,'id')) . " ) ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = "inventory_id = 0";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_GET['professor_id']))
|
||||
{
|
||||
$inventory = $this->inventory_model->get_all(['professor_id' => $_GET['professor_id']]);
|
||||
if ($inventory)
|
||||
{
|
||||
$where[] = "inventory_id in (" . implode(',',array_column($inventory,'id')) . " ) ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = "inventory_id = 0";
|
||||
}
|
||||
|
||||
}
|
||||
if (!empty($_GET['year']))
|
||||
{
|
||||
$inventory = $this->inventory_model->get_all(['year' => $_GET['year']]);
|
||||
if ($inventory)
|
||||
{
|
||||
$where[] = "inventory_id in (" . implode(',',array_column($inventory,'id')) . " ) ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = "inventory_id = 0";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($this->_data['view_model']->get_id())
|
||||
{
|
||||
$where[] = "id = " . $this->_data['view_model']->get_id();
|
||||
}
|
||||
|
||||
if ($this->_data['view_model']->get_inventory_id())
|
||||
{
|
||||
$where[] = "inventory_id = " . $this->_data['view_model']->get_inventory_id();
|
||||
}
|
||||
|
||||
if ($this->_data['view_model']->get_order_date())
|
||||
{
|
||||
$where[] = "order_date = " . $this->_data['view_model']->get_order_date();
|
||||
}
|
||||
|
||||
if ($this->_data['view_model']->get_status() || $this->_data['view_model']->get_status() == '0')
|
||||
{
|
||||
$where[] = "status = " . $this->_data['view_model']->get_status();
|
||||
}
|
||||
|
||||
// $where = [
|
||||
// 'id' => $this->_data['view_model']->get_id(),
|
||||
// 'purchase_user_id' => $this->_data['view_model']->get_purchase_user_id(),
|
||||
// 'sale_user_id' => $this->_data['view_model']->get_sale_user_id(),
|
||||
// 'inventory_id' => $this->_data['view_model']->get_inventory_id(),
|
||||
// 'order_date' => $this->_data['view_model']->get_order_date(),
|
||||
// 'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
// ];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->order_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/purchases/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->order_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
if( $this->_data['view_model']->get_list())
|
||||
{
|
||||
|
||||
$invetory_ids = array_column($this->_data['view_model']->get_list(),'inventory_id');
|
||||
if($invetory_ids)
|
||||
{
|
||||
$inventory_data = $this->db->select('i.*,s.name as school,p.name as professor')->from('inventory i')->join('school s','s.id=i.school_id')->join('professor p','p.id=i.professor_id')->where_in('i.id',$invetory_ids,true)->get()->result_array();
|
||||
|
||||
$review_given = $this->db->select('*')->from('review')->where('user_id',$this->session->userdata('user_id'))->get()->result_array();
|
||||
if($review_given)
|
||||
{
|
||||
$review_given = array_column($review_given,'inventory_id');
|
||||
}
|
||||
|
||||
$dispute_given = $this->db->select('*')->from('ticket')->where('user_id',$this->session->userdata('user_id'))->get()->result_array();
|
||||
if($dispute_given){
|
||||
$dispute_given = array_column($dispute_given,'order_id');
|
||||
}
|
||||
foreach ($this->_data['view_model']->get_list() as $data)
|
||||
{
|
||||
|
||||
$data->review_given = 0;
|
||||
if(in_array($data->inventory_id,$review_given))
|
||||
{
|
||||
$data->review_given = 1;
|
||||
}
|
||||
$data->dispute_given = 0;
|
||||
if(in_array($data->id,$dispute_given))
|
||||
{
|
||||
$data->dispute_given = 1;
|
||||
}
|
||||
|
||||
|
||||
foreach ($inventory_data as $key => $value)
|
||||
{
|
||||
if($data->inventory_id == $value['id'])
|
||||
{
|
||||
$data->school = $value['school'];
|
||||
$data->year = $value['year'];
|
||||
$data->file_src = base_url().$value['file'];
|
||||
$data->professor = $value['professor'];
|
||||
$data->word_count = $value['word_count'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($data->school))
|
||||
{
|
||||
$data->school = "";
|
||||
$data->year = "";
|
||||
$data->file_src = "";
|
||||
$data->professor = "";
|
||||
$data->word_count = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Purchases', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->order_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/purchases/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Purchases_member_view_view_model.php';
|
||||
$this->_data['view_model'] = new Purchases_member_view_view_model($this->order_model);
|
||||
$this->_data['view_model']->set_heading('Purchases');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Member/PurchasesView', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||
include_once __DIR__ . '/../../services/User_service.php';
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Register Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_register_controller extends Manaknight_Controller
|
||||
{
|
||||
protected $_redirect = '/sell';
|
||||
|
||||
public $_valid_roles = [1];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_run_middlewares();
|
||||
}
|
||||
|
||||
protected function _middleware()
|
||||
{
|
||||
return [
|
||||
'affilate',
|
||||
'maintenance'
|
||||
];
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('refer_log_model');
|
||||
$this->load->helper('cookie');
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('member_profile_model');
|
||||
|
||||
$service = new User_service($this->credential_model, $this->user_model, $this->member_profile_model);
|
||||
$service->set_refer_log_model($this->refer_log_model);
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[credential.email]');
|
||||
$this->form_validation->set_rules('password', 'Password', 'trim|required');
|
||||
$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|matches[password]');
|
||||
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
|
||||
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
|
||||
|
||||
// $this->form_validation->set_rules('username', 'Username', 'trim|required|is_unique[member_profile.username]');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
echo $this->load->view('Member/Register', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
$first_name = $this->input->post('first_name');
|
||||
$last_name = $this->input->post('last_name');
|
||||
// $username = $this->input->post('username');
|
||||
$username = $first_name;
|
||||
// if($email == $username){
|
||||
// $this->_data['error'] = 'Can not Use Email as Username';
|
||||
// echo $this->load->view('Member/Register', $this->_data, TRUE);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
|
||||
$redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect);
|
||||
$session = $this->get_session();
|
||||
$refer = (isset($session['refer']) && strlen($session['refer']) > 0) ? $session['refer'] : '';
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$created_user = $service->create($email, $password, $first_name, $last_name, $username, 1, $refer);
|
||||
|
||||
if (!$created_user)
|
||||
{
|
||||
$this->db->trans_rollback();
|
||||
$this->_data['error'] = 'User creation failed. Please try again.';
|
||||
echo $this->load->view('Member/Register', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
|
||||
delete_cookie('redirect');
|
||||
$credential = $this->credential_model->get_by_fields([
|
||||
'email' => $email,
|
||||
'type' => 'n'
|
||||
]);
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$this->set_session('credential_id', (int) $credential->id);
|
||||
$this->set_session('user_id', (int) $created_user->id);
|
||||
$this->set_session('email', (string) $created_user->email);
|
||||
$this->set_session('role', (string) $created_user->role_id);
|
||||
if(isset($_POST['return_url'] ) && $_POST['return_url'] =='buy'){
|
||||
return $this->redirect('buy');
|
||||
|
||||
}
|
||||
return $this->redirect($redirect);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once __DIR__ . '/../../services/User_service.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Reset Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_reset_controller extends Manaknight_Controller
|
||||
{
|
||||
public function index ($reset_token)
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('token_model');
|
||||
$this->load->model('credential_model');
|
||||
|
||||
$service = new User_service($this->credential_model);
|
||||
$service->set_token_model($this->token_model);
|
||||
|
||||
$valid_user = $service->valid_reset_token($reset_token);
|
||||
|
||||
if (!$valid_user)
|
||||
{
|
||||
$this->error('Email does not exist in our system.');
|
||||
return $this->redirect('/member/login');
|
||||
}
|
||||
|
||||
$this->_data['reset_token'] = $reset_token;
|
||||
|
||||
$this->form_validation->set_rules('password', 'Password', 'trim|required');
|
||||
$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|matches[password]');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
echo $this->load->view('Member/Reset', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$password = $this->input->post('password');
|
||||
$password_reseted = $service->reset_password($valid_user->id, $password);
|
||||
|
||||
if ($password_reseted)
|
||||
{
|
||||
$service->invalidate_token($reset_token, $valid_user->id);
|
||||
$credential = $this->credential_model->get_by_field('user_id', $valid_user->id);
|
||||
$this->credential_model->edit(['verify' => '1'], $credential->id);
|
||||
$this->set_session('credential_id', (int) $credential->id);
|
||||
$this->set_session('user_id', (int) $credential->user_id);
|
||||
$this->set_session('email', (string) $credential->email);
|
||||
$this->set_session('role', (string) $credential->role_id);
|
||||
$this->success('Success! You can start using your account now.');
|
||||
return $this->redirect('/member/dashboard');
|
||||
}
|
||||
|
||||
$this->error('Invalid reset token to reset password.');
|
||||
return $this->redirect('/member/login');
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Sales Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_sales_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'payout_model';
|
||||
public $_page_name = 'Sales';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Sales_member_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Sales_member_list_paginate_view_model(
|
||||
$this->payout_model,
|
||||
$this->pagination,
|
||||
'/member/sales/0');
|
||||
$this->_data['view_model']->set_heading('Sales');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_amount(($this->input->get('amount', TRUE) != NULL) ? $this->input->get('amount', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'user_id' => $this->session->userdata('user_id'),
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'amount' => $this->_data['view_model']->get_amount(),
|
||||
'created_at' => $this->_data['view_model']->get_created_at(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->payout_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/sales/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->payout_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
$invetory_data = $this->db->select('i.*,p.name as professor,c.name as class,s.name as school')->from('inventory i ')
|
||||
->join('school s','s.id=i.school_id')
|
||||
->join('professor p','p.id=i.professor_id')
|
||||
->join('classes c','c.id=i.class_id')
|
||||
->get()->result_array();
|
||||
|
||||
foreach ( $this->_data['view_model']->get_list() as $key => &$value) {
|
||||
$value->school = '';
|
||||
$value->professor = '';
|
||||
$value->class = '';
|
||||
$value->isbn = '';
|
||||
foreach ($invetory_data as $k => $v) {
|
||||
if($value->inventory_id==$v['id']){
|
||||
$value->school = $v['school'];
|
||||
$value->professor = $v['professor'];
|
||||
$value->class = $v['class'];
|
||||
$value->isbn = $v['isbn'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Sales', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Ticket Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_ticket_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'ticket_model';
|
||||
public $_page_name = 'Ticket';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Ticket_member_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Ticket_member_list_paginate_view_model(
|
||||
$this->ticket_model,
|
||||
$this->pagination,
|
||||
'/member/ticket/0');
|
||||
$this->_data['view_model']->set_heading('Ticket');
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_message(($this->input->get('message', TRUE) != NULL) ? $this->input->get('message', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_receive_status(($this->input->get('receive_status', TRUE) != NULL) ? $this->input->get('receive_status', TRUE) : NULL);
|
||||
|
||||
|
||||
$where = [
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'message' => $this->_data['view_model']->get_message(),
|
||||
'receive_status' => $this->_data['view_model']->get_receive_status(),
|
||||
'user_id' => $this->session->userdata('user_id'),
|
||||
];
|
||||
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->ticket_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/ticket/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->ticket_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Ticket', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Transaction Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_transaction_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'transaction_model';
|
||||
public $_page_name = 'Transaction';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Transaction_member_list_paginate_view_model.php';
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
$session = $this->get_session();
|
||||
$where = [];
|
||||
$this->_data['view_model'] = new Transaction_member_list_paginate_view_model(
|
||||
$this->transaction_model,
|
||||
$this->pagination,
|
||||
'/member/transaction/0');
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
$this->_data['view_model']->set_total_rows($this->transaction_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/transaction/0');
|
||||
$this->_data['view_model']->set_list($this->transaction_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Transaction', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Transaction_member_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->transaction_model->set_form_validation(
|
||||
$this->form_validation, $this->transaction_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Transaction_member_add_view_model($this->transaction_model);
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/TransactionAdd', $this->_data);
|
||||
}
|
||||
|
||||
$order_id = $this->input->post('order_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$transaction_date = $this->input->post('transaction_date', TRUE);
|
||||
$transaction_time = $this->input->post('transaction_time', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$tax = $this->input->post('tax', TRUE);
|
||||
$discount = $this->input->post('discount', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
$stripe_charge_id = $this->input->post('stripe_charge_id', TRUE);
|
||||
$payment_method = $this->input->post('payment_method', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->transaction_model->create([
|
||||
'order_id' => $order_id,
|
||||
'user_id' => $user_id,
|
||||
'transaction_date' => $transaction_date,
|
||||
'transaction_time' => $transaction_time,
|
||||
'subtotal' => $subtotal,
|
||||
'tax' => $tax,
|
||||
'discount' => $discount,
|
||||
'total' => $total,
|
||||
'stripe_charge_id' => $stripe_charge_id,
|
||||
'payment_method' => $payment_method,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/member/transaction/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/TransactionAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->transaction_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/transaction/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Transaction_member_edit_view_model.php';
|
||||
$this->form_validation = $this->transaction_model->set_form_validation(
|
||||
$this->form_validation, $this->transaction_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Transaction_member_edit_view_model($this->transaction_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/TransactionEdit', $this->_data);
|
||||
}
|
||||
|
||||
$order_id = $this->input->post('order_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$transaction_date = $this->input->post('transaction_date', TRUE);
|
||||
$transaction_time = $this->input->post('transaction_time', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$tax = $this->input->post('tax', TRUE);
|
||||
$discount = $this->input->post('discount', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
$stripe_charge_id = $this->input->post('stripe_charge_id', TRUE);
|
||||
$payment_method = $this->input->post('payment_method', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->transaction_model->edit([
|
||||
'order_id' => $order_id,
|
||||
'user_id' => $user_id,
|
||||
'transaction_date' => $transaction_date,
|
||||
'transaction_time' => $transaction_time,
|
||||
'subtotal' => $subtotal,
|
||||
'tax' => $tax,
|
||||
'discount' => $discount,
|
||||
'total' => $total,
|
||||
'stripe_charge_id' => $stripe_charge_id,
|
||||
'payment_method' => $payment_method,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/member/transaction/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/TransactionEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->transaction_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/transaction/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Transaction_member_view_view_model.php';
|
||||
$this->_data['view_model'] = new Transaction_member_view_view_model($this->transaction_model);
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Member/TransactionView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$model = $this->transaction_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/transaction/0');
|
||||
}
|
||||
|
||||
$result = $this->transaction_model->delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
return $this->redirect('/member/transaction/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->error('Error');
|
||||
return redirect('/member/transaction/0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,415 @@
|
||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* User_card Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_user_card_controller extends Member_controller
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_model_file = 'user_card_model';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $_page_name = 'User Card';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('user_model');
|
||||
|
||||
$this->load->library('stripe_helper_service');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $page
|
||||
* @return mixed
|
||||
*/
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/User_card_member_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new User_card_member_list_paginate_view_model(
|
||||
$this->user_card_model,
|
||||
$this->pagination,
|
||||
'/member/user_card/0');
|
||||
$this->_data['view_model']->set_heading('User Card');
|
||||
$this->_data['view_model']->set_is_default(($this->input->get('is_default', TRUE) != NULL) ? $this->input->get('is_default', TRUE) : NULL);
|
||||
// $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_last4(($this->input->get('last4', TRUE) != NULL) ? $this->input->get('last4', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'is_default' => $this->_data['view_model']->get_is_default(),
|
||||
'user_id' => $user_id,
|
||||
'last4' => $this->_data['view_model']->get_last4()
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->user_card_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/user_card/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->user_card_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/User_card', $this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/User_card_member_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
|
||||
$this->form_validation = $this->user_card_model->set_form_validation(
|
||||
$this->form_validation, $this->user_card_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new User_card_member_add_view_model($this->user_card_model);
|
||||
$this->_data['view_model']->set_heading('User Card');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/User_cardAdd', $this->_data);
|
||||
}
|
||||
|
||||
$user_all_card_data = $this->user_card_model->get_all(['user_id' => $user_id]);
|
||||
// $user_card_data = $this->user_card_model->get_by_field('user_id', $user_id);
|
||||
|
||||
$is_default = $this->input->post('is_default', TRUE);
|
||||
$card_name = $this->input->post('card_name', TRUE);
|
||||
$card_number = $this->input->post('card_number', TRUE);
|
||||
$exp_month = $this->input->post('exp_month', TRUE);
|
||||
$exp_year = $this->input->post('exp_year', TRUE);
|
||||
$cvc = $this->input->post('cvc', TRUE);
|
||||
|
||||
$new_card_last4 = substr($card_number, 12);
|
||||
|
||||
if (!empty($user_all_card_data))
|
||||
{
|
||||
if (!empty($card_number) && !empty($exp_month) && !empty($exp_year) && !empty($cvc))
|
||||
{
|
||||
// use for each
|
||||
foreach ($user_all_card_data as $key1 => $res1)
|
||||
{
|
||||
if ($res1->last4 == $new_card_last4)
|
||||
{
|
||||
// throw error
|
||||
$this->error('This card last4->(...' . $new_card_last4 . ') is already added. Try again with a new card.');
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
// add card
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$response = $this->stripe_helper_service->create_stripe_token($card_number, $exp_month, $exp_year, $cvc);
|
||||
|
||||
if (isset($response['success']))
|
||||
{
|
||||
$stripe_token_id = $response['token']->id;
|
||||
|
||||
$this->stripe_helper_service->set_user_model($this->user_model);
|
||||
// pass token_id to assign card to user
|
||||
$res_card_data = $this->stripe_helper_service->add_new_card($stripe_token_id, $user_id);
|
||||
|
||||
if (isset($res_card_data['success']))
|
||||
{
|
||||
$stripe_card_id = $res_card_data['card_data']->id;
|
||||
$stripe_brand = $res_card_data['card_data']->brand;
|
||||
$stripe_exp_month = $res_card_data['card_data']->exp_month;
|
||||
$stripe_exp_year = $res_card_data['card_data']->exp_year;
|
||||
$stripe_last4 = $res_card_data['card_data']->last4;
|
||||
|
||||
// store the card id with the associated user
|
||||
$check_new_card = $this->user_card_model->create([
|
||||
'is_default' => 0,
|
||||
'user_id' => $user_id,
|
||||
'stripe_card_id' => $stripe_card_id,
|
||||
'last4' => $stripe_last4,
|
||||
'brand' => $stripe_brand,
|
||||
'exp_month' => $stripe_exp_month,
|
||||
'exp_year' => $stripe_exp_year
|
||||
]);
|
||||
|
||||
if ($check_new_card)
|
||||
{
|
||||
$this->success('Card added successfully.');
|
||||
return $this->redirect('/member/user_card/0', 'refresh');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error('Card add failed. Try Again.');
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// when user do not have the user->stripe_id
|
||||
$this->error($res_card_data['error_msg']);
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// when new card validation failed
|
||||
$this->error($response['error_msg']);
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error('Empty Field');
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// create stripe_customer_id and add the new card
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$response = $this->stripe_helper_service->create_stripe_token($card_number, $exp_month, $exp_year, $cvc);
|
||||
|
||||
if (isset($response['success']))
|
||||
{
|
||||
$stripe_token_id = $response['token']->id;
|
||||
// var_dump($stripe_token_id);
|
||||
// die();
|
||||
|
||||
// get user email from credential model
|
||||
$customer_email = $this->credential_model->get_by_field('user_id', $user_id);
|
||||
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$res_customer = $this->stripe_helper_service->create_stripe_customer_with_card($customer_email, $stripe_token_id);
|
||||
|
||||
if (isset($res_customer['success']))
|
||||
{
|
||||
$stripe_customer_id = $res_customer['card']->customer;
|
||||
$stripe_card_id = $res_customer['card']->id;
|
||||
$stripe_brand = $res_customer['card']->brand;
|
||||
$stripe_exp_month = $res_customer['card']->exp_month;
|
||||
$stripe_exp_year = $res_customer['card']->exp_year;
|
||||
$stripe_last4 = $res_customer['card']->last4;
|
||||
|
||||
// update user->stripe_id
|
||||
$update_stripe_id = $this->user_model->edit([
|
||||
'stripe_id' => $stripe_customer_id
|
||||
], $user_id);
|
||||
|
||||
// add card on user_card
|
||||
if ($update_stripe_id)
|
||||
{
|
||||
// store the card id with the associated user
|
||||
$check_new_card = $this->user_card_model->create([
|
||||
'is_default' => 1,
|
||||
'user_id' => $user_id,
|
||||
'stripe_card_id' => $stripe_card_id,
|
||||
'last4' => $stripe_last4,
|
||||
'brand' => $stripe_brand,
|
||||
'exp_month' => $stripe_exp_month,
|
||||
'exp_year' => $stripe_exp_year
|
||||
]);
|
||||
|
||||
if ($check_new_card)
|
||||
{
|
||||
$this->success('Card added successfully and set to default.');
|
||||
return $this->redirect('/member/user_card/0', 'refresh');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error('Card add failed. Try Again.');
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error($res_customer['error_msg']);
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// when new card validation failed
|
||||
$this->error($response['error_msg']);
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/User_cardAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function set_default()
|
||||
{
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
|
||||
$user_card_id = $this->input->post('user_card_id');
|
||||
|
||||
if (!empty($user_card_id))
|
||||
{
|
||||
$user_card_data = $this->user_card_model->get($user_card_id);
|
||||
|
||||
if (!empty($user_card_data))
|
||||
{
|
||||
if ($user_card_data->is_default == 1)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'This card is already set to default.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$this->stripe_helper_service->set_user_model($this->user_model);
|
||||
$response = $this->stripe_helper_service->update_default_card($user_card_data->stripe_card_id, $user_id);
|
||||
|
||||
if (isset($response['success']))
|
||||
{
|
||||
// make other cards is_default to = 0
|
||||
$all_card_data = $this->user_card_model->get_all(['user_id' => $user_id]);
|
||||
if (!empty($all_card_data))
|
||||
{
|
||||
foreach ($all_card_data as $key1 => $res1)
|
||||
{
|
||||
$this->user_card_model->edit(['is_default' => 0], $res1->id);
|
||||
}
|
||||
}
|
||||
|
||||
// then only set is_default 1 to the default card
|
||||
$result = $this->user_card_model->edit([
|
||||
'is_default' => 1
|
||||
], $user_card_id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Card set to default.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = $response['error_msg'];
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! User card not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
|
||||
$user_card_id = $this->input->post('user_card_id');
|
||||
|
||||
if (!empty($user_card_id))
|
||||
{
|
||||
$user_card_data = $this->user_card_model->get($user_card_id);
|
||||
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$this->stripe_helper_service->set_user_model($this->user_model);
|
||||
$response = $this->stripe_helper_service->delete_card_from_customer($user_id, $user_card_data->stripe_card_id);
|
||||
|
||||
if (isset($response['success']))
|
||||
{
|
||||
$result = $this->user_card_model->real_delete($user_card_id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'User card deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = $response['error_msg'];
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! User card not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once dirname(__FILE__) . '/Guest/Home_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
class Welcome extends Home_controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user