first commit
This commit is contained in:
+228
@@ -0,0 +1,228 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Cart Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_cart_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'cart_model';
|
||||
public $_page_name = 'Cart';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Cart_member_list_paginate_view_model.php';
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
$session = $this->get_session();
|
||||
$where = [];
|
||||
$this->_data['view_model'] = new Cart_member_list_paginate_view_model(
|
||||
$this->cart_model,
|
||||
$this->pagination,
|
||||
'/member/cart/0');
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
$this->_data['view_model']->set_total_rows($this->cart_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/cart/0');
|
||||
$this->_data['view_model']->set_list($this->cart_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Cart', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Cart_member_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->cart_model->set_form_validation(
|
||||
$this->form_validation, $this->cart_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Cart_member_add_view_model($this->cart_model);
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/CartAdd', $this->_data);
|
||||
}
|
||||
|
||||
$product_id = $this->input->post('product_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$session_id = $this->input->post('session_id', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$quantity = $this->input->post('quantity', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
|
||||
$result = $this->cart_model->create([
|
||||
'product_id' => $product_id,
|
||||
'user_id' => $user_id,
|
||||
'session_id' => $session_id,
|
||||
'subtotal' => $subtotal,
|
||||
'quantity' => $quantity,
|
||||
'total' => $total,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/member/cart/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/CartAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->cart_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/cart/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Cart_member_edit_view_model.php';
|
||||
$this->form_validation = $this->cart_model->set_form_validation(
|
||||
$this->form_validation, $this->cart_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Cart_member_edit_view_model($this->cart_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/CartEdit', $this->_data);
|
||||
}
|
||||
|
||||
$product_id = $this->input->post('product_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$session_id = $this->input->post('session_id', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$quantity = $this->input->post('quantity', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
|
||||
$result = $this->cart_model->edit([
|
||||
'product_id' => $product_id,
|
||||
'user_id' => $user_id,
|
||||
'session_id' => $session_id,
|
||||
'subtotal' => $subtotal,
|
||||
'quantity' => $quantity,
|
||||
'total' => $total,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/member/cart/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/CartEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->cart_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/cart/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Cart_member_view_view_model.php';
|
||||
$this->_data['view_model'] = new Cart_member_view_view_model($this->cart_model);
|
||||
$this->_data['view_model']->set_heading('Cart');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Member/CartView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$model = $this->cart_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/cart/0');
|
||||
}
|
||||
|
||||
$result = $this->cart_model->delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
return $this->redirect('/member/cart/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->error('Error');
|
||||
return redirect('/member/cart/0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/**
|
||||
* Member Controller
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_controller extends Manaknight_Controller
|
||||
{
|
||||
|
||||
public $_page_name ='dashboard';
|
||||
|
||||
public $_valid_roles = [1];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->_data['page_name'] = $this->_page_name;
|
||||
$this->_data['setting'] = $this->_setting;
|
||||
$this->_data['layout_clean_mode'] = FALSE;
|
||||
$this->_run_middlewares();
|
||||
$layout_mode = $this->input->get('layout_clean_mode', TRUE);
|
||||
if (isset($layout_mode) && $layout_mode === '1')
|
||||
{
|
||||
$this->_data['layout_clean_mode'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
protected function _middleware()
|
||||
{
|
||||
return [
|
||||
'affilate', 'auth', 'acl', 'maintenance'
|
||||
];
|
||||
}
|
||||
|
||||
public function render($template, $data)
|
||||
{
|
||||
return (!$this->_test_mode) ? $this->_render($template, $data) : $this->_render_test($template, $data);
|
||||
}
|
||||
|
||||
protected function _render_test($template, $data)
|
||||
{
|
||||
return [
|
||||
'header' => $this->load->view('Layout/MemberHeader', $data, TRUE),
|
||||
'body' => $this->load->view($template, $data, TRUE),
|
||||
'footer' => $this->load->view('Layout/MemberFooter', $data, TRUE),
|
||||
'data' => $data,
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Function to return the images for media gallery
|
||||
*/
|
||||
public function get_all_images()
|
||||
{
|
||||
$this->load->model('image_model');
|
||||
$images = $this->image_model->get_all();
|
||||
return $images;
|
||||
}
|
||||
|
||||
protected function _render($template, $data)
|
||||
{
|
||||
$data['images'] = $this->get_all_images();
|
||||
$data['page_section'] = $template;
|
||||
$this->load->view('Layout/MemberHeader', $data);
|
||||
$this->load->view($template, $data);
|
||||
$this->load->view('Layout/MemberFooter',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* User token invalid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function unauthorize_error_message()
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(401)
|
||||
->set_output(json_encode([
|
||||
'code' => 401,
|
||||
'success' => FALSE,
|
||||
'message' => 'invalid credentials'
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* User Role invalid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function unauthorize_resource_error_message()
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(406)
|
||||
->set_output(json_encode([
|
||||
'code' => 406,
|
||||
'success' => FALSE,
|
||||
'message' => 'cannot access resource'
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Success API Call
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function success2($success)
|
||||
{
|
||||
$success['code'] = 200;
|
||||
$success['success'] = TRUE;
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($success));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid form input
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _render_validation_error ()
|
||||
{
|
||||
$data = [];
|
||||
$data['code'] = 403;
|
||||
$data['success'] = FALSE;
|
||||
$data['error'] = $this->form_validation->error_array();
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render Custom Error
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _render_custom_error ($errors)
|
||||
{
|
||||
$data = [];
|
||||
$data['code'] = 403;
|
||||
$data['success'] = FALSE;
|
||||
$data['error'] = $errors;
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(403)
|
||||
->set_output(json_encode($data));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
|
||||
/**
|
||||
* Member Dashboard Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_dashboard_controller extends Member_controller
|
||||
{
|
||||
public $_page_name = 'Dashboard';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index ()
|
||||
{
|
||||
return $this->render('Member/Dashboard', $this->_data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Dispute Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_dispute_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'dispute_model';
|
||||
public $_page_name = 'Dispute';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Dispute_member_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Dispute_member_list_paginate_view_model(
|
||||
$this->dispute_model,
|
||||
$this->pagination,
|
||||
'/member/dispute/0');
|
||||
$this->_data['view_model']->set_heading('Dispute');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_reason(($this->input->get('reason', TRUE) != NULL) ? $this->input->get('reason', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_stripe_charge_id(($this->input->get('stripe_charge_id', TRUE) != NULL) ? $this->input->get('stripe_charge_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_stripe_dispute_id(($this->input->get('stripe_dispute_id', TRUE) != NULL) ? $this->input->get('stripe_dispute_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'user_id' => $this->_data['view_model']->get_user_id(),
|
||||
'reason' => $this->_data['view_model']->get_reason(),
|
||||
'stripe_charge_id' => $this->_data['view_model']->get_stripe_charge_id(),
|
||||
'stripe_dispute_id' => $this->_data['view_model']->get_stripe_dispute_id(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->dispute_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/dispute/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->dispute_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Dispute', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->dispute_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/dispute/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Dispute_member_view_view_model.php';
|
||||
$this->_data['view_model'] = new Dispute_member_view_view_model($this->dispute_model);
|
||||
$this->_data['view_model']->set_heading('Dispute');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Member/DisputeView', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once __DIR__ . '/../../services/User_service.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Forgot Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_forgot_controller extends Manaknight_Controller
|
||||
{
|
||||
public function index ()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('email_model');
|
||||
$this->load->model('token_model');
|
||||
$this->load->library('mail_service');
|
||||
|
||||
$service = new User_service($this->credential_model);
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
echo $this->load->view('Member/Forgot', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$from_email = $this->config->item('from_email');
|
||||
$base_url = $this->config->item('base_url');
|
||||
|
||||
$this->mail_service->set_adapter('smtp');
|
||||
$service->set_email_model($this->email_model);
|
||||
$service->set_token_model($this->token_model);
|
||||
$service->set_email_service($this->mail_service);
|
||||
|
||||
$reset = $service->forgot_password($email, $from_email, $base_url . '/member/reset', 1);
|
||||
|
||||
if ($reset)
|
||||
{
|
||||
$this->success('Your Reset email was sent. Check your email.');
|
||||
return $this->redirect('/member/login');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Email does not exist in our system.';
|
||||
echo $this->load->view('Member/Forgot', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
+1657
File diff suppressed because it is too large
Load Diff
+145
@@ -0,0 +1,145 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once __DIR__ . '/../../services/User_service.php';
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Login Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_login_controller extends Manaknight_Controller
|
||||
{
|
||||
protected $_redirect = '/sell';
|
||||
|
||||
public $_valid_roles = [1];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index ()
|
||||
{
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('user_model');
|
||||
$this->load->helper('cookie');
|
||||
|
||||
$service = new User_service($this->credential_model, $this->user_model);
|
||||
if($this->input->cookie('member_remember_me_token', TRUE) !== null && $this->input->cookie('member_remember_me_token', TRUE) !== '')
|
||||
{
|
||||
$this->_remember_me_login();
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
|
||||
$this->form_validation->set_rules('password', 'Password', 'required');
|
||||
$this->_data['portal'] = 'member';
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
echo $this->load->view('Member/Login', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
$redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect);
|
||||
|
||||
$role = $this->_valid_roles[0];
|
||||
$authenticated_user = $service->login_by_role($email, $password, $role);
|
||||
|
||||
if ($authenticated_user)
|
||||
{
|
||||
delete_cookie('redirect');
|
||||
$user_id = $authenticated_user->user_id;
|
||||
|
||||
if(!empty($this->input->post("remember_me"))) {
|
||||
$this->load->helper('string');
|
||||
$remember_cookie = [
|
||||
'user_id' => $user_id,
|
||||
'name' => 'member_remember_me_token',
|
||||
'value' => random_string('alnum', 16),
|
||||
'expire' => time()+$this->config->item('cookie_expire'),
|
||||
'domain' => base_url()
|
||||
];
|
||||
$this->load->model('cookies_model');
|
||||
$check_cookie = $this->cookies_model->get_by_field('user_id', $user_id);
|
||||
if($check_cookie)
|
||||
{
|
||||
$cookie = $this->cookies_model->edit($remember_cookie, $check_cookie->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cookie = $this->cookies_model->create($remember_cookie);
|
||||
}
|
||||
if($cookie)
|
||||
{
|
||||
setcookie($remember_cookie['name'], $remember_cookie['value'], $remember_cookie['expire'], $remember_cookie['domain']);
|
||||
}
|
||||
}
|
||||
$this->set_session('credential_id', (int) $authenticated_user->id);
|
||||
$this->set_session('user_id', (int) $user_id);
|
||||
$this->set_session('email', (string) $authenticated_user->email);
|
||||
$this->set_session('role', (string) $authenticated_user->role_id);
|
||||
|
||||
if( isset($_POST['return_url']) && $_POST['return_url'] =='buy')
|
||||
{
|
||||
return $this->redirect('buy');
|
||||
}
|
||||
return $this->redirect($redirect);
|
||||
}
|
||||
|
||||
$this->error('Wrong email or password.');
|
||||
return $this->redirect('member/login');
|
||||
}
|
||||
|
||||
|
||||
public function _remember_me_login()
|
||||
{
|
||||
$this->load->helper('string');
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('cookies_model');
|
||||
$token_value = $this->input->cookie('member_remember_me_token', TRUE);
|
||||
$cookie = $this->cookies_model->get_by_fields(['value' => $token_value]);
|
||||
$service = new User_service($this->credential_model, $this->user_model);
|
||||
$redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect);
|
||||
if($cookie)
|
||||
{
|
||||
$user_id = $cookie->user_id;
|
||||
$credential = $this->credential_model->get_by_field('user_id', $user_id);
|
||||
$role = $this->_valid_roles[0];
|
||||
if($credential->role_id != $role)
|
||||
{
|
||||
setcookie('member_remember_me_token', '', 1, base_url());
|
||||
return $this->redirect('admin/login');
|
||||
}
|
||||
$random_string = random_string('alnum', 30);
|
||||
$this->cookies_model->edit(['value' => $random_string, 'expire' => time()+$this->config->item('cookie_expire')], $cookie->id);
|
||||
setcookie('member_remember_me_token', $random_string, time()+$this->config->item('cookie_expire'), base_url());
|
||||
$this->set_session('credential_id', (int) $credential->id);
|
||||
$this->set_session('user_id', (int) $user_id);
|
||||
$this->set_session('email', (string) $credential->email);
|
||||
$this->set_session('role', (string) $credential->role_id);
|
||||
return $this->redirect($redirect);
|
||||
}
|
||||
else
|
||||
{
|
||||
setcookie('member_remember_me_token', '', 1, base_url());
|
||||
return $this->redirect('admin/login');
|
||||
}
|
||||
|
||||
$this->error('Wrong email or password.');
|
||||
return $this->redirect('member/login');
|
||||
}
|
||||
|
||||
public function logout ()
|
||||
{
|
||||
$this->load->helper('cookie');
|
||||
setcookie('member_remember_me_token', '', 1, base_url());
|
||||
$this->destroy_session();
|
||||
return $this->redirect('member/login');
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Credential Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_me_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'credential_model';
|
||||
public $_page_name = 'Change Password';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function me()
|
||||
{
|
||||
$session = $this->get_session();
|
||||
$model = $this->credential_model->get($session['credential_id']);
|
||||
$this->_data['email'] = $model->email;
|
||||
$this->_data['password'] = '';
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
|
||||
$this->form_validation->set_rules('password', 'Password', '');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/Mes', $this->_data);
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
|
||||
$payload = [
|
||||
'email' => $email,
|
||||
];
|
||||
|
||||
if (strlen($password) > 1)
|
||||
{
|
||||
$payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
$result = $this->credential_model->edit($payload, $session['credential_id']);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Saved');
|
||||
return $this->redirect('/member/me', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/Mes', $this->_data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
|
||||
/**
|
||||
* Member Profile Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_profile_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'user_model';
|
||||
public $_page_name = 'Profile';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('member_profile_model');
|
||||
$this->load->model('school_model');
|
||||
$session = $this->get_session();
|
||||
$model = $this->user_model->get($session['user_id']);
|
||||
$id = $session['user_id'];
|
||||
|
||||
// load data
|
||||
$schools = $this->school_model->get_all();
|
||||
|
||||
|
||||
if (!empty($schools))
|
||||
{
|
||||
$this->_data['schools'] = $schools;
|
||||
}
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/dashboard');
|
||||
}
|
||||
|
||||
$credential = $this->credential_model->get($session['credential_id']);
|
||||
$email_validation_rules = 'required|valid_email';
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Member_profile_view_model.php';
|
||||
|
||||
if ($this->input->post('email') != $credential->email)
|
||||
{
|
||||
$email_validation_rules .= '|is_unique[credential.email]';
|
||||
}
|
||||
|
||||
$member_profile_data = $this->db->select('*')->from('member_profile')->where('user_id',$id)->get()->row_array();
|
||||
$user_data = $this->db->select('*')->from('user')->where('id',$id)->get()->row_array();
|
||||
|
||||
$this->_data['phone'] = $user_data['phone'];
|
||||
$this->_data['username'] = $member_profile_data['username'];
|
||||
$this->_data['school_id'] = $member_profile_data['school_id'];
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', $email_validation_rules);
|
||||
$this->form_validation->set_rules('first_name', 'First Name', 'required');
|
||||
$this->form_validation->set_rules('last_name', 'Last Name', 'required');
|
||||
|
||||
$this->_data['view_model'] = new Member_profile_view_model($this->user_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_email($credential->email);
|
||||
$this->_data['view_model']->set_heading('Member');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/Profile', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$first_name = $this->input->post('first_name');
|
||||
$last_name = $this->input->post('last_name');
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
|
||||
// $username = $this->input->post('username');
|
||||
$school_id = $this->input->post('school_id');
|
||||
|
||||
$payload = [
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name
|
||||
];
|
||||
|
||||
$payload_2 = [
|
||||
// 'username' => $username,
|
||||
'school_id' => $school_id
|
||||
];
|
||||
|
||||
$result = $this->user_model->edit_raw($payload, $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->db->set($payload_2)->where('id',$member_profile_data['id'])->update('member_profile');
|
||||
$this->db->set(['phone'=>$this->input->post('phone')])->where('id',$id)->update('user');
|
||||
$credential_payload = [
|
||||
'email' => $email
|
||||
];
|
||||
|
||||
if (strlen($password) > 0)
|
||||
{
|
||||
$credential_payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
$result = $this->credential_model->edit_raw($credential_payload, $session['credential_id']);
|
||||
$this->success('Saved');
|
||||
return $this->redirect('/member/profile', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/Profile', $this->_data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
|
||||
/**
|
||||
* Member Profile Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_profile_credential_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'credential_model';
|
||||
public $_page_name = 'Credentials';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
$session = $this->get_session();
|
||||
$user_obj = $this->user_model->get($session['user_id']);
|
||||
$session = $this->get_session();
|
||||
$this->load->model($this->_model_file);
|
||||
$model = $this->credential_model->get($user_obj->credential_id ?? 0);
|
||||
$id = $user_obj->credential_id ?? 0;
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
die();
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Member_profile_credential_view_model.php';
|
||||
$email_validation_rules = 'required|valid_email';
|
||||
|
||||
if ($this->input->post('email') != $session['email'])
|
||||
{
|
||||
$email_validation_rules .= '|is_unique[credential.email]';
|
||||
}
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', $email_validation_rules);
|
||||
|
||||
$this->_data['view_model'] = new Member_profile_credential_view_model($model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Member');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/Credential', $this->_data);
|
||||
}
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
|
||||
$payload = [
|
||||
'email' => $email,
|
||||
];
|
||||
|
||||
if (strlen($password) > 0)
|
||||
{
|
||||
$payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
$result = $this->credential_model->edit_raw($payload, $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->success('Saved');
|
||||
return $this->redirect('/member/credential?layout_clean_mode=1', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/Credential', $this->_data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Purchases Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_purchases_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'order_model';
|
||||
public $_page_name = 'Purchases';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('school_model');
|
||||
$this->load->model('professor_model');
|
||||
$this->load->model('classes_model');
|
||||
$this->load->model('textbook_model');
|
||||
|
||||
$this->load->model('inventory_model');
|
||||
|
||||
$this->load->library('helpers_service');
|
||||
$this->load->library('names_helper_service');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
|
||||
// load data
|
||||
$schools = $this->school_model->get_all(['status' => 1]);
|
||||
$professors = $this->professor_model->get_all(['status' => 1]);
|
||||
|
||||
if (!empty($schools))
|
||||
{
|
||||
$this->_data['schools'] = $schools;
|
||||
}
|
||||
|
||||
if (!empty($professors))
|
||||
{
|
||||
$this->_data['professors'] = $professors;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Purchases_member_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Purchases_member_list_paginate_view_model(
|
||||
$this->order_model,
|
||||
$this->pagination,
|
||||
'/member/purchases/0');
|
||||
$this->_data['view_model']->set_heading('Purchases');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_purchase_user_id(($this->input->get('purchase_user_id', TRUE) != NULL) ? $this->input->get('purchase_user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_sale_user_id(($this->input->get('sale_user_id', TRUE) != NULL) ? $this->input->get('sale_user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_inventory_id(($this->input->get('inventory_id', TRUE) != NULL) ? $this->input->get('inventory_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_date(($this->input->get('order_date', TRUE) != NULL) ? $this->input->get('order_date', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = ['purchase_user_id' => $this->session->userdata('user_id')];
|
||||
|
||||
if (!empty($_GET['school_id']))
|
||||
{
|
||||
$inventory = $this->inventory_model->get_all(['school_id' => $_GET['school_id']]);
|
||||
|
||||
if ($inventory)
|
||||
{
|
||||
$where[] = "inventory_id in (" . implode(',',array_column($inventory,'id')) . " ) ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = "inventory_id = 0";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_GET['professor_id']))
|
||||
{
|
||||
$inventory = $this->inventory_model->get_all(['professor_id' => $_GET['professor_id']]);
|
||||
if ($inventory)
|
||||
{
|
||||
$where[] = "inventory_id in (" . implode(',',array_column($inventory,'id')) . " ) ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = "inventory_id = 0";
|
||||
}
|
||||
|
||||
}
|
||||
if (!empty($_GET['year']))
|
||||
{
|
||||
$inventory = $this->inventory_model->get_all(['year' => $_GET['year']]);
|
||||
if ($inventory)
|
||||
{
|
||||
$where[] = "inventory_id in (" . implode(',',array_column($inventory,'id')) . " ) ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = "inventory_id = 0";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($this->_data['view_model']->get_id())
|
||||
{
|
||||
$where[] = "id = " . $this->_data['view_model']->get_id();
|
||||
}
|
||||
|
||||
if ($this->_data['view_model']->get_inventory_id())
|
||||
{
|
||||
$where[] = "inventory_id = " . $this->_data['view_model']->get_inventory_id();
|
||||
}
|
||||
|
||||
if ($this->_data['view_model']->get_order_date())
|
||||
{
|
||||
$where[] = "order_date = " . $this->_data['view_model']->get_order_date();
|
||||
}
|
||||
|
||||
if ($this->_data['view_model']->get_status() || $this->_data['view_model']->get_status() == '0')
|
||||
{
|
||||
$where[] = "status = " . $this->_data['view_model']->get_status();
|
||||
}
|
||||
|
||||
// $where = [
|
||||
// 'id' => $this->_data['view_model']->get_id(),
|
||||
// 'purchase_user_id' => $this->_data['view_model']->get_purchase_user_id(),
|
||||
// 'sale_user_id' => $this->_data['view_model']->get_sale_user_id(),
|
||||
// 'inventory_id' => $this->_data['view_model']->get_inventory_id(),
|
||||
// 'order_date' => $this->_data['view_model']->get_order_date(),
|
||||
// 'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
// ];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->order_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/purchases/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->order_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
if( $this->_data['view_model']->get_list())
|
||||
{
|
||||
|
||||
$invetory_ids = array_column($this->_data['view_model']->get_list(),'inventory_id');
|
||||
if($invetory_ids)
|
||||
{
|
||||
$inventory_data = $this->db->select('i.*,s.name as school,p.name as professor')->from('inventory i')->join('school s','s.id=i.school_id')->join('professor p','p.id=i.professor_id')->where_in('i.id',$invetory_ids,true)->get()->result_array();
|
||||
|
||||
$review_given = $this->db->select('*')->from('review')->where('user_id',$this->session->userdata('user_id'))->get()->result_array();
|
||||
if($review_given)
|
||||
{
|
||||
$review_given = array_column($review_given,'inventory_id');
|
||||
}
|
||||
|
||||
$dispute_given = $this->db->select('*')->from('ticket')->where('user_id',$this->session->userdata('user_id'))->get()->result_array();
|
||||
if($dispute_given){
|
||||
$dispute_given = array_column($dispute_given,'order_id');
|
||||
}
|
||||
foreach ($this->_data['view_model']->get_list() as $data)
|
||||
{
|
||||
|
||||
$data->review_given = 0;
|
||||
if(in_array($data->inventory_id,$review_given))
|
||||
{
|
||||
$data->review_given = 1;
|
||||
}
|
||||
$data->dispute_given = 0;
|
||||
if(in_array($data->id,$dispute_given))
|
||||
{
|
||||
$data->dispute_given = 1;
|
||||
}
|
||||
|
||||
|
||||
foreach ($inventory_data as $key => $value)
|
||||
{
|
||||
if($data->inventory_id == $value['id'])
|
||||
{
|
||||
$data->school = $value['school'];
|
||||
$data->year = $value['year'];
|
||||
$data->file_src = base_url().$value['file'];
|
||||
$data->professor = $value['professor'];
|
||||
$data->word_count = $value['word_count'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($data->school))
|
||||
{
|
||||
$data->school = "";
|
||||
$data->year = "";
|
||||
$data->file_src = "";
|
||||
$data->professor = "";
|
||||
$data->word_count = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Purchases', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->order_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/purchases/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Purchases_member_view_view_model.php';
|
||||
$this->_data['view_model'] = new Purchases_member_view_view_model($this->order_model);
|
||||
$this->_data['view_model']->set_heading('Purchases');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Member/PurchasesView', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||
include_once __DIR__ . '/../../services/User_service.php';
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Register Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_register_controller extends Manaknight_Controller
|
||||
{
|
||||
protected $_redirect = '/sell';
|
||||
|
||||
public $_valid_roles = [1];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_run_middlewares();
|
||||
}
|
||||
|
||||
protected function _middleware()
|
||||
{
|
||||
return [
|
||||
'affilate',
|
||||
'maintenance'
|
||||
];
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('refer_log_model');
|
||||
$this->load->helper('cookie');
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('member_profile_model');
|
||||
|
||||
$service = new User_service($this->credential_model, $this->user_model, $this->member_profile_model);
|
||||
$service->set_refer_log_model($this->refer_log_model);
|
||||
|
||||
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[credential.email]');
|
||||
$this->form_validation->set_rules('password', 'Password', 'trim|required');
|
||||
$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|matches[password]');
|
||||
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
|
||||
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
|
||||
|
||||
// $this->form_validation->set_rules('username', 'Username', 'trim|required|is_unique[member_profile.username]');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
echo $this->load->view('Member/Register', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
$first_name = $this->input->post('first_name');
|
||||
$last_name = $this->input->post('last_name');
|
||||
// $username = $this->input->post('username');
|
||||
$username = $first_name;
|
||||
// if($email == $username){
|
||||
// $this->_data['error'] = 'Can not Use Email as Username';
|
||||
// echo $this->load->view('Member/Register', $this->_data, TRUE);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
|
||||
$redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect);
|
||||
$session = $this->get_session();
|
||||
$refer = (isset($session['refer']) && strlen($session['refer']) > 0) ? $session['refer'] : '';
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$created_user = $service->create($email, $password, $first_name, $last_name, $username, 1, $refer);
|
||||
|
||||
if (!$created_user)
|
||||
{
|
||||
$this->db->trans_rollback();
|
||||
$this->_data['error'] = 'User creation failed. Please try again.';
|
||||
echo $this->load->view('Member/Register', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
|
||||
delete_cookie('redirect');
|
||||
$credential = $this->credential_model->get_by_fields([
|
||||
'email' => $email,
|
||||
'type' => 'n'
|
||||
]);
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$this->set_session('credential_id', (int) $credential->id);
|
||||
$this->set_session('user_id', (int) $created_user->id);
|
||||
$this->set_session('email', (string) $created_user->email);
|
||||
$this->set_session('role', (string) $created_user->role_id);
|
||||
if(isset($_POST['return_url'] ) && $_POST['return_url'] =='buy'){
|
||||
return $this->redirect('buy');
|
||||
|
||||
}
|
||||
return $this->redirect($redirect);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once __DIR__ . '/../../services/User_service.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Reset Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_reset_controller extends Manaknight_Controller
|
||||
{
|
||||
public function index ($reset_token)
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('token_model');
|
||||
$this->load->model('credential_model');
|
||||
|
||||
$service = new User_service($this->credential_model);
|
||||
$service->set_token_model($this->token_model);
|
||||
|
||||
$valid_user = $service->valid_reset_token($reset_token);
|
||||
|
||||
if (!$valid_user)
|
||||
{
|
||||
$this->error('Email does not exist in our system.');
|
||||
return $this->redirect('/member/login');
|
||||
}
|
||||
|
||||
$this->_data['reset_token'] = $reset_token;
|
||||
|
||||
$this->form_validation->set_rules('password', 'Password', 'trim|required');
|
||||
$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|matches[password]');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
echo $this->load->view('Member/Reset', $this->_data, TRUE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$password = $this->input->post('password');
|
||||
$password_reseted = $service->reset_password($valid_user->id, $password);
|
||||
|
||||
if ($password_reseted)
|
||||
{
|
||||
$service->invalidate_token($reset_token, $valid_user->id);
|
||||
$credential = $this->credential_model->get_by_field('user_id', $valid_user->id);
|
||||
$this->credential_model->edit(['verify' => '1'], $credential->id);
|
||||
$this->set_session('credential_id', (int) $credential->id);
|
||||
$this->set_session('user_id', (int) $credential->user_id);
|
||||
$this->set_session('email', (string) $credential->email);
|
||||
$this->set_session('role', (string) $credential->role_id);
|
||||
$this->success('Success! You can start using your account now.');
|
||||
return $this->redirect('/member/dashboard');
|
||||
}
|
||||
|
||||
$this->error('Invalid reset token to reset password.');
|
||||
return $this->redirect('/member/login');
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Sales Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_sales_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'payout_model';
|
||||
public $_page_name = 'Sales';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Sales_member_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Sales_member_list_paginate_view_model(
|
||||
$this->payout_model,
|
||||
$this->pagination,
|
||||
'/member/sales/0');
|
||||
$this->_data['view_model']->set_heading('Sales');
|
||||
$this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_amount(($this->input->get('amount', TRUE) != NULL) ? $this->input->get('amount', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'id' => $this->_data['view_model']->get_id(),
|
||||
'user_id' => $this->session->userdata('user_id'),
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'amount' => $this->_data['view_model']->get_amount(),
|
||||
'created_at' => $this->_data['view_model']->get_created_at(),
|
||||
'status' => $this->_data['view_model']->get_status(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->payout_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/sales/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->payout_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
$invetory_data = $this->db->select('i.*,p.name as professor,c.name as class,s.name as school')->from('inventory i ')
|
||||
->join('school s','s.id=i.school_id')
|
||||
->join('professor p','p.id=i.professor_id')
|
||||
->join('classes c','c.id=i.class_id')
|
||||
->get()->result_array();
|
||||
|
||||
foreach ( $this->_data['view_model']->get_list() as $key => &$value) {
|
||||
$value->school = '';
|
||||
$value->professor = '';
|
||||
$value->class = '';
|
||||
$value->isbn = '';
|
||||
foreach ($invetory_data as $k => $v) {
|
||||
if($value->inventory_id==$v['id']){
|
||||
$value->school = $v['school'];
|
||||
$value->professor = $v['professor'];
|
||||
$value->class = $v['class'];
|
||||
$value->isbn = $v['isbn'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Sales', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Ticket Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_ticket_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'ticket_model';
|
||||
public $_page_name = 'Ticket';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Ticket_member_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new Ticket_member_list_paginate_view_model(
|
||||
$this->ticket_model,
|
||||
$this->pagination,
|
||||
'/member/ticket/0');
|
||||
$this->_data['view_model']->set_heading('Ticket');
|
||||
$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_message(($this->input->get('message', TRUE) != NULL) ? $this->input->get('message', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_receive_status(($this->input->get('receive_status', TRUE) != NULL) ? $this->input->get('receive_status', TRUE) : NULL);
|
||||
|
||||
|
||||
$where = [
|
||||
'order_id' => $this->_data['view_model']->get_order_id(),
|
||||
'message' => $this->_data['view_model']->get_message(),
|
||||
'receive_status' => $this->_data['view_model']->get_receive_status(),
|
||||
'user_id' => $this->session->userdata('user_id'),
|
||||
];
|
||||
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->ticket_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/ticket/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->ticket_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Ticket', $this->_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Transaction Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_transaction_controller extends Member_controller
|
||||
{
|
||||
protected $_model_file = 'transaction_model';
|
||||
public $_page_name = 'Transaction';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/Transaction_member_list_paginate_view_model.php';
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
$session = $this->get_session();
|
||||
$where = [];
|
||||
$this->_data['view_model'] = new Transaction_member_list_paginate_view_model(
|
||||
$this->transaction_model,
|
||||
$this->pagination,
|
||||
'/member/transaction/0');
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
$this->_data['view_model']->set_total_rows($this->transaction_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/transaction/0');
|
||||
$this->_data['view_model']->set_list($this->transaction_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/Transaction', $this->_data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/Transaction_member_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$this->form_validation = $this->transaction_model->set_form_validation(
|
||||
$this->form_validation, $this->transaction_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new Transaction_member_add_view_model($this->transaction_model);
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/TransactionAdd', $this->_data);
|
||||
}
|
||||
|
||||
$order_id = $this->input->post('order_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$transaction_date = $this->input->post('transaction_date', TRUE);
|
||||
$transaction_time = $this->input->post('transaction_time', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$tax = $this->input->post('tax', TRUE);
|
||||
$discount = $this->input->post('discount', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
$stripe_charge_id = $this->input->post('stripe_charge_id', TRUE);
|
||||
$payment_method = $this->input->post('payment_method', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->transaction_model->create([
|
||||
'order_id' => $order_id,
|
||||
'user_id' => $user_id,
|
||||
'transaction_date' => $transaction_date,
|
||||
'transaction_time' => $transaction_time,
|
||||
'subtotal' => $subtotal,
|
||||
'tax' => $tax,
|
||||
'discount' => $discount,
|
||||
'total' => $total,
|
||||
'stripe_charge_id' => $stripe_charge_id,
|
||||
'payment_method' => $payment_method,
|
||||
'status' => $status,
|
||||
|
||||
]);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/member/transaction/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/TransactionAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$model = $this->transaction_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/transaction/0');
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Transaction_member_edit_view_model.php';
|
||||
$this->form_validation = $this->transaction_model->set_form_validation(
|
||||
$this->form_validation, $this->transaction_model->get_all_edit_validation_rule());
|
||||
$this->_data['view_model'] = new Transaction_member_edit_view_model($this->transaction_model);
|
||||
$this->_data['view_model']->set_model($model);
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/TransactionEdit', $this->_data);
|
||||
}
|
||||
|
||||
$order_id = $this->input->post('order_id', TRUE);
|
||||
$user_id = $this->input->post('user_id', TRUE);
|
||||
$transaction_date = $this->input->post('transaction_date', TRUE);
|
||||
$transaction_time = $this->input->post('transaction_time', TRUE);
|
||||
$subtotal = $this->input->post('subtotal', TRUE);
|
||||
$tax = $this->input->post('tax', TRUE);
|
||||
$discount = $this->input->post('discount', TRUE);
|
||||
$total = $this->input->post('total', TRUE);
|
||||
$stripe_charge_id = $this->input->post('stripe_charge_id', TRUE);
|
||||
$payment_method = $this->input->post('payment_method', TRUE);
|
||||
$status = $this->input->post('status', TRUE);
|
||||
|
||||
$result = $this->transaction_model->edit([
|
||||
'order_id' => $order_id,
|
||||
'user_id' => $user_id,
|
||||
'transaction_date' => $transaction_date,
|
||||
'transaction_time' => $transaction_time,
|
||||
'subtotal' => $subtotal,
|
||||
'tax' => $tax,
|
||||
'discount' => $discount,
|
||||
'total' => $total,
|
||||
'stripe_charge_id' => $stripe_charge_id,
|
||||
'payment_method' => $payment_method,
|
||||
'status' => $status,
|
||||
|
||||
], $id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
|
||||
return $this->redirect('/member/transaction/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/TransactionEdit', $this->_data);
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$model = $this->transaction_model->get($id);
|
||||
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/transaction/0');
|
||||
}
|
||||
|
||||
|
||||
include_once __DIR__ . '/../../view_models/Transaction_member_view_view_model.php';
|
||||
$this->_data['view_model'] = new Transaction_member_view_view_model($this->transaction_model);
|
||||
$this->_data['view_model']->set_heading('Transaction');
|
||||
$this->_data['view_model']->set_model($model);
|
||||
|
||||
|
||||
return $this->render('Member/TransactionView', $this->_data);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$model = $this->transaction_model->get($id);
|
||||
$session = $this->get_session();
|
||||
if (!$model)
|
||||
{
|
||||
$this->error('Error');
|
||||
return redirect('/member/transaction/0');
|
||||
}
|
||||
|
||||
$result = $this->transaction_model->delete($id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
|
||||
return $this->redirect('/member/transaction/0', 'refresh');
|
||||
}
|
||||
|
||||
$this->error('Error');
|
||||
return redirect('/member/transaction/0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,415 @@
|
||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||
include_once 'Member_controller.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* User_card Controller
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Member_user_card_controller extends Member_controller
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_model_file = 'user_card_model';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $_page_name = 'User Card';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('credential_model');
|
||||
$this->load->model('user_model');
|
||||
|
||||
$this->load->library('stripe_helper_service');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $page
|
||||
* @return mixed
|
||||
*/
|
||||
public function index($page)
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
include_once __DIR__ . '/../../view_models/User_card_member_list_paginate_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
|
||||
$format = $this->input->get('format', TRUE) ?? 'view';
|
||||
$order_by = $this->input->get('order_by', TRUE) ?? '';
|
||||
$direction = $this->input->get('direction', TRUE) ?? 'ASC';
|
||||
$per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
|
||||
|
||||
$this->_data['view_model'] = new User_card_member_list_paginate_view_model(
|
||||
$this->user_card_model,
|
||||
$this->pagination,
|
||||
'/member/user_card/0');
|
||||
$this->_data['view_model']->set_heading('User Card');
|
||||
$this->_data['view_model']->set_is_default(($this->input->get('is_default', TRUE) != NULL) ? $this->input->get('is_default', TRUE) : NULL);
|
||||
// $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
|
||||
$this->_data['view_model']->set_last4(($this->input->get('last4', TRUE) != NULL) ? $this->input->get('last4', TRUE) : NULL);
|
||||
|
||||
$where = [
|
||||
'is_default' => $this->_data['view_model']->get_is_default(),
|
||||
'user_id' => $user_id,
|
||||
'last4' => $this->_data['view_model']->get_last4()
|
||||
];
|
||||
|
||||
$this->_data['view_model']->set_total_rows($this->user_card_model->count($where));
|
||||
|
||||
$this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
|
||||
$this->_data['view_model']->set_per_page($per_page_sort);
|
||||
$this->_data['view_model']->set_order_by($order_by);
|
||||
$this->_data['view_model']->set_sort($direction);
|
||||
$this->_data['view_model']->set_sort_base_url('/member/user_card/0');
|
||||
$this->_data['view_model']->set_page($page);
|
||||
$this->_data['view_model']->set_list($this->user_card_model->get_paginated(
|
||||
$this->_data['view_model']->get_page(),
|
||||
$this->_data['view_model']->get_per_page(),
|
||||
$where,
|
||||
$order_by,
|
||||
$direction));
|
||||
|
||||
if ($format == 'csv')
|
||||
{
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="export.csv"');
|
||||
|
||||
echo $this->_data['view_model']->to_csv();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($format != 'view')
|
||||
{
|
||||
return $this->output->set_content_type('application/json')
|
||||
->set_status_header(200)
|
||||
->set_output(json_encode($this->_data['view_model']->to_json()));
|
||||
}
|
||||
|
||||
return $this->render('Member/User_card', $this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
include_once __DIR__ . '/../../view_models/User_card_member_add_view_model.php';
|
||||
$session = $this->get_session();
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
|
||||
$this->form_validation = $this->user_card_model->set_form_validation(
|
||||
$this->form_validation, $this->user_card_model->get_all_validation_rule());
|
||||
$this->_data['view_model'] = new User_card_member_add_view_model($this->user_card_model);
|
||||
$this->_data['view_model']->set_heading('User Card');
|
||||
|
||||
if ($this->form_validation->run() === FALSE)
|
||||
{
|
||||
return $this->render('Member/User_cardAdd', $this->_data);
|
||||
}
|
||||
|
||||
$user_all_card_data = $this->user_card_model->get_all(['user_id' => $user_id]);
|
||||
// $user_card_data = $this->user_card_model->get_by_field('user_id', $user_id);
|
||||
|
||||
$is_default = $this->input->post('is_default', TRUE);
|
||||
$card_name = $this->input->post('card_name', TRUE);
|
||||
$card_number = $this->input->post('card_number', TRUE);
|
||||
$exp_month = $this->input->post('exp_month', TRUE);
|
||||
$exp_year = $this->input->post('exp_year', TRUE);
|
||||
$cvc = $this->input->post('cvc', TRUE);
|
||||
|
||||
$new_card_last4 = substr($card_number, 12);
|
||||
|
||||
if (!empty($user_all_card_data))
|
||||
{
|
||||
if (!empty($card_number) && !empty($exp_month) && !empty($exp_year) && !empty($cvc))
|
||||
{
|
||||
// use for each
|
||||
foreach ($user_all_card_data as $key1 => $res1)
|
||||
{
|
||||
if ($res1->last4 == $new_card_last4)
|
||||
{
|
||||
// throw error
|
||||
$this->error('This card last4->(...' . $new_card_last4 . ') is already added. Try again with a new card.');
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
// add card
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$response = $this->stripe_helper_service->create_stripe_token($card_number, $exp_month, $exp_year, $cvc);
|
||||
|
||||
if (isset($response['success']))
|
||||
{
|
||||
$stripe_token_id = $response['token']->id;
|
||||
|
||||
$this->stripe_helper_service->set_user_model($this->user_model);
|
||||
// pass token_id to assign card to user
|
||||
$res_card_data = $this->stripe_helper_service->add_new_card($stripe_token_id, $user_id);
|
||||
|
||||
if (isset($res_card_data['success']))
|
||||
{
|
||||
$stripe_card_id = $res_card_data['card_data']->id;
|
||||
$stripe_brand = $res_card_data['card_data']->brand;
|
||||
$stripe_exp_month = $res_card_data['card_data']->exp_month;
|
||||
$stripe_exp_year = $res_card_data['card_data']->exp_year;
|
||||
$stripe_last4 = $res_card_data['card_data']->last4;
|
||||
|
||||
// store the card id with the associated user
|
||||
$check_new_card = $this->user_card_model->create([
|
||||
'is_default' => 0,
|
||||
'user_id' => $user_id,
|
||||
'stripe_card_id' => $stripe_card_id,
|
||||
'last4' => $stripe_last4,
|
||||
'brand' => $stripe_brand,
|
||||
'exp_month' => $stripe_exp_month,
|
||||
'exp_year' => $stripe_exp_year
|
||||
]);
|
||||
|
||||
if ($check_new_card)
|
||||
{
|
||||
$this->success('Card added successfully.');
|
||||
return $this->redirect('/member/user_card/0', 'refresh');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error('Card add failed. Try Again.');
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// when user do not have the user->stripe_id
|
||||
$this->error($res_card_data['error_msg']);
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// when new card validation failed
|
||||
$this->error($response['error_msg']);
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error('Empty Field');
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// create stripe_customer_id and add the new card
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$response = $this->stripe_helper_service->create_stripe_token($card_number, $exp_month, $exp_year, $cvc);
|
||||
|
||||
if (isset($response['success']))
|
||||
{
|
||||
$stripe_token_id = $response['token']->id;
|
||||
// var_dump($stripe_token_id);
|
||||
// die();
|
||||
|
||||
// get user email from credential model
|
||||
$customer_email = $this->credential_model->get_by_field('user_id', $user_id);
|
||||
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$res_customer = $this->stripe_helper_service->create_stripe_customer_with_card($customer_email, $stripe_token_id);
|
||||
|
||||
if (isset($res_customer['success']))
|
||||
{
|
||||
$stripe_customer_id = $res_customer['card']->customer;
|
||||
$stripe_card_id = $res_customer['card']->id;
|
||||
$stripe_brand = $res_customer['card']->brand;
|
||||
$stripe_exp_month = $res_customer['card']->exp_month;
|
||||
$stripe_exp_year = $res_customer['card']->exp_year;
|
||||
$stripe_last4 = $res_customer['card']->last4;
|
||||
|
||||
// update user->stripe_id
|
||||
$update_stripe_id = $this->user_model->edit([
|
||||
'stripe_id' => $stripe_customer_id
|
||||
], $user_id);
|
||||
|
||||
// add card on user_card
|
||||
if ($update_stripe_id)
|
||||
{
|
||||
// store the card id with the associated user
|
||||
$check_new_card = $this->user_card_model->create([
|
||||
'is_default' => 1,
|
||||
'user_id' => $user_id,
|
||||
'stripe_card_id' => $stripe_card_id,
|
||||
'last4' => $stripe_last4,
|
||||
'brand' => $stripe_brand,
|
||||
'exp_month' => $stripe_exp_month,
|
||||
'exp_year' => $stripe_exp_year
|
||||
]);
|
||||
|
||||
if ($check_new_card)
|
||||
{
|
||||
$this->success('Card added successfully and set to default.');
|
||||
return $this->redirect('/member/user_card/0', 'refresh');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error('Card add failed. Try Again.');
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error($res_customer['error_msg']);
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// when new card validation failed
|
||||
$this->error($response['error_msg']);
|
||||
return redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_data['error'] = 'Error';
|
||||
return $this->render('Member/User_cardAdd', $this->_data);
|
||||
}
|
||||
|
||||
public function set_default()
|
||||
{
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
|
||||
$user_card_id = $this->input->post('user_card_id');
|
||||
|
||||
if (!empty($user_card_id))
|
||||
{
|
||||
$user_card_data = $this->user_card_model->get($user_card_id);
|
||||
|
||||
if (!empty($user_card_data))
|
||||
{
|
||||
if ($user_card_data->is_default == 1)
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'This card is already set to default.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$this->stripe_helper_service->set_user_model($this->user_model);
|
||||
$response = $this->stripe_helper_service->update_default_card($user_card_data->stripe_card_id, $user_id);
|
||||
|
||||
if (isset($response['success']))
|
||||
{
|
||||
// make other cards is_default to = 0
|
||||
$all_card_data = $this->user_card_model->get_all(['user_id' => $user_id]);
|
||||
if (!empty($all_card_data))
|
||||
{
|
||||
foreach ($all_card_data as $key1 => $res1)
|
||||
{
|
||||
$this->user_card_model->edit(['is_default' => 0], $res1->id);
|
||||
}
|
||||
}
|
||||
|
||||
// then only set is_default 1 to the default card
|
||||
$result = $this->user_card_model->edit([
|
||||
'is_default' => 1
|
||||
], $user_card_id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'Card set to default.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = $response['error_msg'];
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! User card not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
|
||||
$user_card_id = $this->input->post('user_card_id');
|
||||
|
||||
if (!empty($user_card_id))
|
||||
{
|
||||
$user_card_data = $this->user_card_model->get($user_card_id);
|
||||
|
||||
$this->stripe_helper_service->set_config($this->config);
|
||||
$this->stripe_helper_service->set_user_model($this->user_model);
|
||||
$response = $this->stripe_helper_service->delete_card_from_customer($user_id, $user_card_data->stripe_card_id);
|
||||
|
||||
if (isset($response['success']))
|
||||
{
|
||||
$result = $this->user_card_model->real_delete($user_card_id);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$output['success'] = TRUE;
|
||||
$output['status'] = 200;
|
||||
$output['msg'] = 'User card deleted successfully.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! Please try again later.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = $response['error_msg'];
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output['error'] = TRUE;
|
||||
$output['status'] = 0;
|
||||
$output['msg'] = 'Error! User card not found.';
|
||||
echo json_encode($output);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user