first commit
This commit is contained in:
+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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user