first commit

This commit is contained in:
ryanwong
2022-06-30 05:46:02 -04:00
commit a96eaec33b
859 changed files with 199842 additions and 0 deletions
+139
View File
@@ -0,0 +1,139 @@
<?php defined('BASEPATH') || exit('No direct script access allowed');
// include_once 'Manaknight_controller.php';
/**
* Frontend Controller to Manage all Frontend pages
* @copyright 2019 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
class Api_controller extends Manaknight_controller
{
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model('school_model');
$this->load->model('professor_model');
$this->load->model('textbook_model');
$this->load->model('classes_model');
}
// select2 customer search
public function get_schools()
{
$custom_query = '';
if( $this->input->POST('term') )
{
$custom_query = ' `name` LIKE "%'. $this->input->POST('term',true) .'%" ';
$data_list = $this->school_model->get_all_custom_where($custom_query, ['status' => 1]);
$response_list = array();
foreach($data_list as $d_key => $_data)
{
array_push($response_list, array('text' => $_data->name, 'id' => $_data->id));
}
$output['results'] = $response_list;
echo json_encode($output);
exit();
}
}
// select2 customer search
public function get_professors()
{
$custom_query = '';
if( $this->input->get('term') )
{
$custom_query = ' `name` LIKE "%'. $this->input->get('term',true) .'%" ';
$data_list = $this->professor_model->get_all_custom_where($custom_query, ['status' => 1]);
$response_list = array();
foreach($data_list as $d_key => $_data)
{
array_push($response_list, array('text' => $_data->name, 'id' => $_data->id));
}
$output['results'] = $response_list;
echo json_encode($output);
exit();
}
}
// select2 customer search
public function get_courses()
{
$custom_query = '';
if( $this->input->get('term') )
{
$custom_query = ' `name` LIKE "%'. $this->input->get('term',true) .'%" ';
$data_list = $this->classes_model->get_all_custom_where($custom_query, ['status' => 1]);
$response_list = array();
foreach($data_list as $d_key => $_data)
{
array_push($response_list, array('text' => $_data->name, 'id' => $_data->id));
}
$output['results'] = $response_list;
echo json_encode($output);
exit();
}
}
// select2 customer search
public function get_textbooks()
{
if( $this->input->get('term') )
{
$custom_query = ' `isbn` LIKE "%'. $this->input->get('term',true) .'%" ';
$data_list = $this->db->select('distinct(isbn)')->from('inventory')->where($custom_query)->get()->result_array();
$response_list = array();
foreach($data_list as $d_key => $_data)
{
array_push($response_list, array('text' => $_data['isbn'], 'id' => $_data['isbn']));
}
$output['results'] = $response_list;
echo json_encode($output);
exit();
}
}
// select2 customer search
public function update_old_orders_if_refunded()
{
$this->load->model('order_model');
$this->load->model('payout_model');
$all_order = $this->order_model->get_all(['status' => 2]);
foreach($all_order as $_key => $_value)
{
$this->payout_model->update('payout',[ 'status'=> 3 ],['order_id' => $_value->id ] );
}
}
}
?>
+221
View File
@@ -0,0 +1,221 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once __DIR__ . '/../../middlewares/Auth_middleware.php';
include_once __DIR__ . '/../../middlewares/Acl_middleware.php';
include_once __DIR__ . '/../../middlewares/Maintenance_middleware.php';
include_once __DIR__ . '/../../middlewares/Affilate_middleware.php';
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* Guest Abstract Controller
*
* @copyright 2019 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
class Guest_controller extends CI_Controller
{
public $_data = [
'error' => '',
'success' => ''
];
//testMode flag
protected $_test_mode = FALSE;
public function __construct()
{
parent::__construct();
$this->config->load('setting');
$this->_setting = $this->config->item('setting');
$this->_run_middlewares();
}
protected function _middleware()
{
return [
'affilate',
'maintenance'
];
}
/**
* Debug Controller to error_log and turn off in production
*
* @param mixed $data
* @return void
*/
public function dl($key, $data)
{
if (ENVIRONMENT == 'development')
{
error_log($key . ' CONTROLLER : <pre>' . print_r($data, TRUE) . '</pre>');
}
}
/**
* Debug json Controller to error_log and turn off in production
*
* @param mixed $data
* @return void
*/
public function dj($key, $data)
{
if (ENVIRONMENT == 'development')
{
error_log($key . ' CONTROLLER : ' . json_encode($data));
}
}
public function get_session()
{
if (!$this->_test_mode)
{
return $_SESSION;
}
$session = $this->config->item('session_test');
if (!$session)
{
$session = [];
}
return $session;
}
public function set_session($field, $value)
{
if (!$this->_test_mode)
{
$_SESSION[$field] = $value;
}
else
{
$session = $this->config->item('session_test');
if (!$session)
{
$session = [];
}
$session[$field] = $value;
$this->config->set_item('session_test', $session);
}
}
public function destroy_session()
{
if (!$this->_test_mode)
{
unset($_SESSION);
}
else
{
$this->config->set_item('session_test', []);
}
}
/**
* Function to send Emails given slug, payload and email
*
* @param string $slug
* @param mixed $payload
* @param string $email
* @return void
*/
protected function _send_email_notification($slug, $payload, $email)
{
$this->load->model('email_model');
$this->load->library('mail_service');
$this->mail_service->set_adapter('smtp');
$email_template = $this->email_model->get_template($slug, $payload);
if ($email_template)
{
$from = $this->config->item('from_email');
return $this->mail_service->send($from, $email, $email_template->subject, $email_template->html);
}
return FALSE;
}
/**
* Function to send Sms given slug, payload and phone #
*
* @param string $slug
* @param mixed $payload
* @param string $to
* @return void
*/
protected function _send_sms_notification($slug, $payload, $to)
{
$this->load->model('sms_model');
$this->load->library('sms_service');
$this->sms_service->set_adapter('sms');
$sms_template = $this->sms_model->get_template($slug, $payload);
if ($sms_template)
{
return $this->sms_service->send($to, $sms_template->content);
}
return FALSE;
}
/**
* Function to send Push notification
*
* @param string $slug
* @param mixed $payload
* @param string $to
* @return void
*/
protected function _send_push_notification($device_type, $device_id, $title, $message, $image)
{
$this->load->library('push_notification_service');
$this->push_notification_service->init();
return $this->push_notification_service->send($device_type, $device_id, $title, $message, $image);
}
protected function _run_middlewares ()
{
$middlewares = [
'affilate' => new Affilate_middleware($this, $this->config),
'auth' => new Auth_middleware($this, $this->config),
'acl' => new Acl_middleware($this, $this->config),
'maintenance' => new Maintenance_middleware($this, $this->config)
];
foreach ($this->_middleware() as $middleware_key)
{
if (isset($middlewares[$middleware_key]))
{
$result = $middlewares[$middleware_key]->run();
if (!$result)
{
return FALSE;
}
}
}
}
public function get_setting()
{
return $this->_setting;
}
/**
* Redirect to URL
*
* @param string $template
* @param array $data
*/
public function redirect($url, $option = [])
{
return ($option) ? redirect($url, $option) : redirect($url);
}
}
+591
View File
@@ -0,0 +1,591 @@
<?php defined('BASEPATH') || exit('No direct script access allowed');
// include_once 'Manaknight_controller.php';
/**
* Frontend Controller to Manage all Frontend pages
* @copyright 2019 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
class Home_controller extends Manaknight_controller
{
public $_data = [
'error' => '',
'success' => ''
];
protected $_flash_error = [
'error' => '',
'success' => ''
];
public function __construct()
{
parent::__construct();
$this->load->database();
// load services
$this->load->library('helpers_service');
$this->load->library('stripe_helper_service');
// $this->load->library('stevesie_api_helper_service');
// $this->load->library('sale_detail_api_service');
$this->load->model('school_model');
$this->load->model('content_model');
$this->load->model('professor_model');
$this->load->model('textbook_model');
$this->load->model('classes_model');
$this->load->model('inventory_model');
// $this->load->library('helpers_service');
$this->_data['layout_clean_mode'] = FALSE;
/**
* social links
*/
$facebook_link = '#';
$twitter_link = '#';
$instagram_link = '#';
$this->_data['facebook_link'] = $facebook_link;
$this->_data['twitter_link'] = $twitter_link;
$this->_data['instagram_link'] = $instagram_link;
}
public function index($offset = 0)
{
$content = $this->content_model->get_all(['status'=>1]);
$this->_data['content'] = [];
if($content ){
$data = [];
foreach ($content as $key => $value) {
$data[$value->content_name]= $value;
}
$this->_data['content'] = $data;
}
$meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','home_page_meta_title')
->or_where('content_name','home_page_meta_description')->get()->result_array();
if($meta_data){
$meta_data = array_column($meta_data,'content','content_name');
$this->_data['meta']['title']= $meta_data['home_page_meta_title'];
$this->_data['meta']['desc']= $meta_data['home_page_meta_description'];
}
$this->_data['active'] = 'home';
$this->_render('Guest/Home', $this->_data);
}
public function get_all_categories()
{
$data = $this->school_model->get_all(['status' => 1]);
if ($data)
{
echo json_encode($data);
exit();
}
echo json_encode(FALSE);
exit();
}
public function load_items_by_school_select()
{
$school_id = $this->input->get('school_id');
if ($school_id == 0)
{
$output = [
'error' => TRUE,
'status' => 0,
'msg' => 'all'
];
echo json_encode($output);
exit();
}
$items = $this->inventory_model->get_all(['school_id' => $school_id]);
$school_data = $this->school_model->get($school_id);
if (!empty($items))
{
$output = [
'success' => TRUE,
'status' => 200,
'data' => $items,
'school_name' => $school_data->name
];
echo json_encode($output);
exit();
}
else
{
$output = [
'error' => TRUE,
'status' => 0,
'msg' => 'No items found for: ' . $school_data->name . ' school.'
];
echo json_encode($output);
exit();
}
}
public function item_details($id)
{
$item_details = $this->inventory_model->get_item_details_fe($id);
if (!empty($item_details))
{
$this->_data['item_details'] = $item_details;
}
$school_id = $item_details->school_id;
$related_items = $this->inventory_model->get_all(['school_id' => $school_id]);
if (!empty($related_items))
{
$this->_data['related_items'] = $related_items;
}
// echo '<pre>';print_r($related_items);die();
$this->_data['active'] = 'item_details';
$this->_render('Guest/Item_details', $this->_data);
}
public function about()
{
$this->_data['active'] = 'about';
$this->_render('Guest/About', $this->_data);
}
public function contact()
{
if($this->input->post('submit_btn')){
if($this->input->post('email') && $this->input->post('message') ){
$email = htmlentities($this->input->post('email'));
// $name = htmlentities($this->input->post('name'));
$message = htmlentities($this->input->post('message'));
$regex = '/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/';
if (!preg_match($regex, $email)) {
$this->_data['status_'] = 'error';
$this->_data['status_msg'] = 'Invalid Email';
}else{
$data = array(
'name'=>'',
'email'=>$email,
'message'=>$message,
'created_at'=>date('Y-m-d')
);
$this->db->insert('contact_us',$data);
$this->load->model('email_model');
$this->load->library('mail_service');
$this->mail_service->set_adapter('smtp');
$from_email = $this->config->item('from_email');
$this->mail_service->send($from_email, $from_email, "Contact Us", $message, $email);
$this->_data['status_'] = 'success';
$this->_data['status_msg'] = 'Form submitted successfully.';
}
}else{
$this->_data['status_'] = 'error';
$this->_data['status_msg'] = 'Fill All required Fields';
}
}
$this->_data['meta'] = [
'title'=>'',
'desc'=>'',
];
$meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','contact_page_meta_title')
->or_where('content_name','contact_page_meta_description')->get()->result_array();
if($meta_data){
$meta_data = array_column($meta_data,'content','content_name');
$this->_data['meta']['title']= $meta_data['contact_page_meta_title'];
$this->_data['meta']['desc']= $meta_data['contact_page_meta_description'];
}
$this->_data['active'] = 'contact';
$this->_render('Guest/Contact', $this->_data);
}
public function privacy_policy()
{
$this->_data['active'] = 'privacy_policy';
$this->_data['data'] = $this->db->select('*')->from('content')->where('content_name','privacy_policy')->get()->row_array();
$this->_render('Guest/Privacy_policy', $this->_data);
}
public function buy($offset = 0)
{
// if($this->session->userdata('user_id'))
// {
// //create setup intent used in js
// $stripe = new \Stripe\StripeClient(
// $this->config->item('stripe_secret_key')
// );
// $this->_data['clientSecret'] = $stripe->setupIntents->create([
// 'payment_method_types' => ['card'],
// ])->client_secret;
// }
$this->_data['stripe_client'] = $this->config->item('stripe_publish_key');
//get all school data
if ($this->input->get('school_id', TRUE))
{
$this->_data['school_data'] = $this->school_model->get_all(['status' => 1, 'id' => $this->input->get('school_id') ]);
}
if ($this->input->get('professor_id', TRUE))
{
$this->_data['professor_data'] = $this->professor_model->get_all(['status' => 1, 'id' => $this->input->get('professor_id') ]);
}
if ($this->input->get('class_id', TRUE))
{
$this->_data['classes_data'] = $this->classes_model->get_all(['status' => 1, 'id' => $this->input->get('class_id') ]);
}
if ($this->input->get('isbn', TRUE))
{
$this->_data['textbook_data'] = $this->db->select('distinct(isbn)')->from('inventory')->where('isbn', $this->input->get('isbn', TRUE))->get()->result_array();
}
$search_term = $this->input->get('search_term', TRUE);
$school_id = $this->input->get('school_id', TRUE);
$professor_id = $this->input->get('professor_id', TRUE);
$textbook_id = $this->input->get('textbook_id', TRUE);
$isbn = $this->input->get('isbn', TRUE);
$class_id = $this->input->get('class_id', TRUE);
$order_by = $this->input->get('order_by', TRUE);
$direction = $this->input->get('direction', TRUE);
// if($school_id || $professor_id || $textbook_id || $class_id || $search_term)
// {
// for pagination
$this->load->library('pagination');
$rows_data = $this->inventory_model->get_all_active_items_list_fe($search_term, $school_id, $professor_id, $textbook_id, $class_id,$isbn,$order_by,$direction);
$total_rows = 0;
if (!empty($rows_data))
{
$total_rows = count($rows_data);
}
$limit = 10;
// $offset = $offset * $limit ;
if ($offset != 0 OR $offset != "")
{
$offset = ($offset - 1) * $limit;
}
$this->pagination->initialize([
'reuse_query_string' => TRUE,
'base_url' => base_url().'/buy',
'total_rows' => $total_rows,
'per_page' => $limit,
'num_links' => 2,
'full_tag_open' => '<ul class="pagination pagination-lg justify-content-center">',
'full_tag_close' => '</ul>',
'attributes' => ['class' => 'page-link'],
'first_link' => FALSE,
'last_link' => FALSE,
'use_page_numbers' => TRUE,
'first_tag_open' => '<li class="page-item">',
'first_tag_close' => '</li>',
'prev_link' => '&laquo',
'prev_tag_open' => '<li class="page-item">',
'prev_tag_close' => '</li>',
'next_link' => '&raquo',
'next_tag_open' => '<li class="page-item">',
'next_tag_close' => '</li>',
'last_tag_open' => '<li class="page-item">',
'last_tag_close' => '</li>',
'cur_tag_open' => '<li class="page-item active"><a href="#" class="page-link">',
'cur_tag_close' => '<span class="sr-only">(current)</span></a></li>',
'num_tag_open' => '<li class="page-item">',
'num_tag_close' => '</li>'
]);
$items = $this->inventory_model->get_all_active_items_list_fe($search_term, $school_id, $professor_id, $textbook_id, $class_id,$isbn,$order_by,$direction, $offset, $limit);
if (!empty($items))
{
$this->_data['links'] = $this->pagination->create_links();
$this->_data['items'] = $items;
}
// }
//notes amount
$notes_amount = $this->db->select('value')->from('setting')->where('key','fixed_paper_amount')->get()->row_array();
if( $notes_amount){
$this->_data['notes_amount'] = $notes_amount['value'];
}else{
$this->_data['notes_amount'] = 50;
}
$this->_data['user_downloaded_files'] = [];
if($this->session->userdata('user_id'))
{
$this->_data['user_downloaded_files'] = $this->db->select('inventory_id')->from('order')->where('purchase_user_id',$this->session->userdata('user_id'))->get()->result_array();
if($this->_data['user_downloaded_files'] )
{
$this->_data['user_downloaded_files'] = array_column($this->_data['user_downloaded_files'],'inventory_id');
}
}
$this->_data['meta'] = [
'title' => '',
'desc' => '',
];
$meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','buy_page_meta_title')->or_where('content_name','buy_page_meta_description')->get()->result_array();
if($meta_data)
{
$meta_data = array_column($meta_data,'content','content_name');
$this->_data['meta']['title'] = $meta_data['buy_page_meta_title'];
$this->_data['meta']['desc'] = $meta_data['buy_page_meta_description'];
}
$this->_data['active'] = 'buy';
$this->_render('Guest/Buy', $this->_data);
}
public function sell()
{
$content = $this->content_model->get_all(['status'=>1]);
$this->_data['content'] = [];
if($content )
{
$data = [];
foreach ($content as $key => $value) {
$data[$value->content_name]= $value;
}
$this->_data['content'] = $data;
}
// //get all school data
// $this->_data['school_data'] = $this->school_model->get_all(['status' => 1]);
// $this->_data['professor_data'] = $this->professor_model->get_all(['status' => 1]);
// $this->_data['classes_data'] = $this->classes_model->get_all(['status' => 1]);
// $this->_data['textbook_data'] = $this->textbook_model->get_all(['status' => 1]);
$data = $this->db->select('paypal_email')->from('user')->where('id',$this->session->userdata('user_id'))->get()->row_array();
if (isset($data['paypal_email']))
{
$this->_data['paypal_email'] = $data['paypal_email'];
}
$this->_data['meta'] = [
'title'=>'',
'desc'=>'',
];
$meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','sell_page_meta_title')->or_where('content_name','sell_page_meta_description')->get()->result_array();
if($meta_data)
{
$meta_data = array_column($meta_data,'content','content_name');
$this->_data['meta']['title']= $meta_data['sell_page_meta_title'];
$this->_data['meta']['desc']= $meta_data['sell_page_meta_description'];
}
$this->_data['active'] = 'sell';
$this->_render('Guest/Sell', $this->_data);
}
public function checkout()
{
if(!$this->session->userdata('user_id')){
echo json_encode(['status'=>'error','message'=>'You Have to Login First']);
exit;
}
$user_id = $this->session->userdata('user_id');
// stripe_helper_service
$card_number = $this->input->post('card_number', TRUE);
$exp_month = $this->input->post('exp_month', TRUE);
$exp_year = $this->input->post('exp_year', TRUE);
$cvc = $this->input->post('cvc', TRUE);
$inv_id = $this->input->post('inv_id', TRUE);
$new_card_last4 = substr($card_number, 12);
// add card
$this->stripe_helper_service->set_config($this->config);
$response = $this->stripe_helper_service->create_stripe_token($card_number, $exp_month, $exp_year, $cvc);
if (isset($response['success']))
{
$stripe_token_id = $response['token']->id;
$this->stripe_helper_service->set_config($this->config);
$this->stripe_helper_service->set_user_model($this->user_model);
// pass token_id to assign card to user
$res_card_data = $this->stripe_helper_service->add_new_card($stripe_token_id, $user_id);
if (isset($res_card_data['success']))
{
$stripe_card_id = $res_card_data['card_data']->id;
$stripe_brand = $res_card_data['card_data']->brand;
$stripe_exp_month = $res_card_data['card_data']->exp_month;
$stripe_exp_year = $res_card_data['card_data']->exp_year;
$stripe_last4 = $res_card_data['card_data']->last4;
// store the card id with the associated user
$check_new_card = $this->user_card_model->create([
'is_default' => 0,
'user_id' => $user_id,
'stripe_card_id' => $stripe_card_id,
'brand' => $stripe_brand,
'exp_month' => $stripe_exp_month,
'exp_year' => $stripe_exp_year,
'last4' => $stripe_last4,
'cvc' => $cvc,
'status' => 1
]);
}
else
{
// when user do not have the user->stripe_id
echo json_encode(['status'=>'error','message'=>'Error']);
exit;
}
}
else
{
// when new card validation failed
echo json_encode(['status'=>'error','message'=>'Error You card is invalid']);
exit;
}
}
public function autocomplete()
{
$html = '';
if($this->input->post('keyword'))
{
$result = $this->db->query("
SELECT name FROM school WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%'
UNION ALL
SELECT name FROM classes WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%'
UNION ALL
SELECT name FROM professor WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%'
UNION ALL
SELECT name FROM textbook WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%'
UNION ALL
SELECT title as name FROM inventory WHERE title LIKE '%".htmlentities($this->input->post('keyword'))."%'
")->result_array();
if(!empty($result)) {
$html .='<ul id="country-list" style="z-index:1000;width:91%;max-height:200px;overflow-y:scroll;">';
foreach($result as $key =>$value) {
$html .= '<li onClick="selectCountry(`'.$value["name"].'`);">'.$value["name"].'</li>';
}
$html .= '</ul>';
}
}
echo json_encode(['html'=>$html]);
exit();
}
public function preview($id)
{
$this->_data['active'] = 'Preview';
$this->_data['data'] = $this->inventory_model->get_by_fields(['status'=>1,'id'=>$id]);
$this->_render('Guest/Preview', $this->_data);
}
public function terms_and_conditions()
{
// $terms = $this->terms_and_conditions_model->get(1);
// if (!empty($terms))
// {
// $this->_data['terms'] = $terms;
// }
$this->_data['data'] = $this->db->select('*')->from('content')->where('content_name','terms_conditon')->get()->row_array();
$this->_data['active'] = 'terms_and_conditions';
$this->_render('Guest/Terms_and_conditions', $this->_data);
}
protected function _render($template, $_data)
{
$this->_data['page_section'] = $template;
$this->load->view('Guest/Header', $this->_data);
$this->load->view($template, $this->_data);
$this->load->view('Guest/Footer', $this->_data);
}
public function dd()
{
$output = '';
echo "<pre>";
print_r($output);
die();
}
public function get_review(){
if( isset($_POST['id']) )
{
$data = $this->db->select('r.*,u.image,u.first_name')->from('review r')->join('user u','r.user_id=u.id')->where('inventory_id',$_POST['id'])->where('r.status',1)->order_by('r.created_at')->get()->result_array();
echo json_encode(['status'=>true,'data'=>$data]);
exit;
}
echo json_encode(['status'=>false]);
exit;
}
}
+473
View File
@@ -0,0 +1,473 @@
<?php
use Aws\S3\S3Client;
if (!defined('BASEPATH')) exit('No direct script access allowed');
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* Image Abstract Controller
*
* @copyright 2019 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
class Image_controller extends CI_Controller
{
public $_data = [
'error' => '',
'success' => ''
];
//testMode flag
protected $_test_mode = FALSE;
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function index ()
{
$image_upload_type = $this->config->item('image_upload');
if ($image_upload_type == 's3')
{
return $this->s3_upload();
}
$this->load->model('image_model');
$data_uri = $this->input->post('image');
$base_url = $this->config->item('base_url');
$image_path = __DIR__ . '/../../../uploads/';
$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data_uri));
$filename = md5(uniqid() . time()) . '.png';
file_put_contents($image_path . $filename, $data);
list($width, $height) = @getimagesize( $image_path .$filename );
$session = $this->get_session();
$user_id = isset($session['user_id']) ? $session['user_id'] : 0;
$image_id = $this->image_model->create([
'url' => '/uploads/' . $filename,
'type' => 0,
'user_id' => $user_id,
'width' => $width,
'caption' => '',
'height' => $height
]);
return $this->output->set_content_type('application/json')
->set_status_header(200)
->set_output(json_encode([
'id' => $image_id,
'image' => $base_url . '/uploads/' . $filename,
'width' => $width,
'height' => $height
]));
}
public function s3_upload ()
{
$s3 = new S3Client([
'version' => $this->config->item('aws_version'),
'region' => $this->config->item('aws_region'),
'endpoint' => $this->config->item('aws_endpoint'),
'use_path_style_endpoint' => true,
'credentials' => [
'key' => $this->config->item('aws_key'),
'secret' => $this->config->item('aws_secret'),
]
]);
$this->load->model('image_model');
$data_uri = $this->input->post('image');
$image_path = __DIR__ . '/../../../uploads/';
$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data_uri));
$filename = md5(uniqid() . time()) . '.png';
file_put_contents($image_path . $filename, $data);
list($width, $height) = getimagesize( $image_path . $filename );
$session = $this->get_session();
$user_id = isset($session['user_id']) ? $session['user_id'] : 0;
try
{
$result = $s3->putObject([
'Bucket' => $this->config->item('aws_bucket'),
'Key' => $filename,
'Body' => fopen($image_path . $filename, 'r'),
'ACL' => 'public-read',
]);
$image_id = $this->image_model->create([
'url' => $result->get('ObjectURL'),
'type' => 0,
'user_id' => $user_id,
'width' => $width,
'caption' => '',
'height' => $height
]);
return $this->output->set_content_type('application/json')
->set_status_header(200)
->set_output(json_encode([
'id' => $image_id,
'image' => $result->get('ObjectURL'),
'width' => $width,
'height' => $height
]));
}
catch (Aws\S3\Exception\S3Exception $e)
{
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Upload to S3 Failed'
]));
}
}
public function file_upload ()
{
$file_upload_type = $this->config->item('file_upload');
$this->load->library('mime_service');
if ($file_upload_type == 's3')
{
return $this->s3_file_upload();
}
$this->load->model('image_model');
if (!(isset($_FILES) && count($_FILES) > 0 && isset($_FILES['file'])))
{
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Upload file missing'
]));
}
$file = $_FILES['file'];
$size = $file['size'];
$path = $file['tmp_name'];
$type = $file['type'];
$extension = $this->mime_service->get_extension($type);
if ($size > $this->config->item('upload_byte_size_limit'))
{
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Upload file size too big'
]));
}
$filename = md5(uniqid() . time()) . $extension;
$width = 0;
$height = 0;
$session = $this->get_session();
$user_id = isset($session['user_id']) ? $session['user_id'] : 0;
$image_path = __DIR__ . '/../../../uploads/';
if (!move_uploaded_file($path, $image_path . $filename))
{
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Upload file failed'
]));
}
$image_id = $this->image_model->create([
'url' => '/uploads/' . $filename,
'type' => 4,
'user_id' => $user_id,
'width' => $width,
'caption' => '',
'height' => $height
]);
return $this->output->set_content_type('application/json')
->set_status_header(200)
->set_output(json_encode([
'id' => $image_id,
'file' => '/uploads/' . $filename,
'width' => $width,
'height' => $height
]));
}
public function s3_file_upload ()
{
$this->load->model('image_model');
$this->load->library('mime_service');
$s3 = new S3Client([
'version' => $this->config->item('aws_version'),
'region' => $this->config->item('aws_region'),
'endpoint' => $this->config->item('aws_endpoint'),
'use_path_style_endpoint' => true,
'credentials' => [
'key' => $this->config->item('aws_key'),
'secret' => $this->config->item('aws_secret'),
]
]);
if (!(isset($_FILES) && count($_FILES) > 0 && isset($_FILES['file'])))
{
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Upload file failed'
]));
}
$file = $_FILES['file'];
$size = $file['size'];
$path = $file['tmp_name'];
$type = $file['type'];
$extension = $this->mime_service->get_extension($type);
if ($size > $this->config->item('upload_byte_size_limit'))
{
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Upload file size too big'
]));
}
$filename = md5(uniqid() . time()) . $extension;
$width = 0;
$height = 0;
$session = $this->get_session();
$user_id = isset($session['user_id']) ? $session['user_id'] : 0;
try
{
$result = $s3->putObject([
'Bucket' => $this->config->item('aws_bucket'),
'Key' => $filename,
'Body' => fopen($path, 'r'),
'ACL' => 'public-read',
]);
$image_id = $this->image_model->create([
'url' => $result->get('ObjectURL'),
'type' => 5,
'user_id' => $user_id,
'width' => $width,
'caption' => '',
'height' => $height
]);
return $this->output->set_content_type('application/json')
->set_status_header(200)
->set_output(json_encode([
'id' => $image_id,
'file' => $result->get('ObjectURL'),
'width' => $width,
'height' => $height
]));
}
catch (Aws\S3\Exception\S3Exception $e)
{
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Upload to S3 Failed'
]));
}
}
public function paginate($page)
{
$this->load->library('pagination');
$this->load->model('image_model');
include_once __DIR__ . '/../../view_models/Image_asset_paginate_view_model.php';
$where = [];
$this->_data['view_model'] = new Image_asset_paginate_view_model(
$this->image_model,
$this->pagination,
'/v1/api/assets/0');
$this->_data['view_model']->set_heading('Images');
$this->_data['view_model']->set_total_rows($this->image_model->count($where));
$this->_data['view_model']->set_per_page(10);
$this->_data['view_model']->set_page($page);
$this->_data['view_model']->set_list($this->image_model->get_paginated(
$this->_data['view_model']->get_page(),
$this->_data['view_model']->get_per_page(),
$where));
return $this->success($this->_data['view_model']->to_json(), 200);
}
public function file_import ($model)
{
$model_name = $model . '_model';
$this->load->library('mime_service');
$this->load->library('csv_import_service');
$this->load->model($model_name);
$this->csv_import_service->set_model($this->$model_name, $model);
/* if ($this->csv_import_service->csv_file_exist($_FILES))
{
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Upload CSV File missing'
]));
}*/
$file = $_FILES['file'];
$size = $file['size'];
$path = $file['tmp_name'];
$type = $file['type'];
$extension = $this->mime_service->get_extension($type);
//$extension = ucfirst(str_replace('.', '', $this->mime_service->get_extension($type)));
$save_as = FCPATH . 'uploads/' . $file["name"];
if ($size > $this->config->item('upload_byte_size_limit'))
{
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Upload file size too big'
]));
}
$save_as = FCPATH . 'uploads/temp' . $extension;
if ($size > $this->config->item('upload_byte_size_limit'))
{
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Upload file size too big'
]));
}
if (move_uploaded_file($path, $save_as))
{
$data = $this->csv_import_service->_import_data( $save_as );
if($data)
{
unlink($save_as);
return $this->output->set_content_type('application/json')
->set_status_header(200)
->set_output(json_encode([
'status' => TRUE
]));
}
}
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Generating SQL worked but insert error to the database'
]));
}
public function preview_csv()
{
$this->load->library('mime_service');
$this->load->library('csv_import_service');
$file = $_FILES['file'];
$size = $file['size'];
$path = $file['tmp_name'];
$type = $file['type'];
$save_as = FCPATH . 'uploads/' . $file["name"];
if ($size > $this->config->item('upload_byte_size_limit'))
{
return $this->output->set_content_type('application/json')
->set_status_header(403)
->set_output(json_encode([
'message' => 'Upload file size too big'
]));
}
if (move_uploaded_file($path, $save_as))
{
$data = $this->csv_import_service->_get_file_data( $save_as );
return $this->output->set_content_type('application/json')
->set_status_header(200)
->set_output(json_encode([
'message' => 'xyzFile loaded',
'data' => $data,
'preview' => TRUE
]));
}
}
/**
* Debug Controller to error_log and turn off in production
*
* @param mixed $data
* @return void
*/
public function dl($key, $data)
{
if (ENVIRONMENT == 'development')
{
error_log($key . ' CONTROLLER : <pre>' . print_r($data, TRUE) . '</pre>');
}
}
/**
* Debug json Controller to error_log and turn off in production
*
* @param mixed $data
* @return void
*/
public function dj($key, $data)
{
if (ENVIRONMENT == 'development')
{
error_log($key . ' CONTROLLER : ' . json_encode($data));
}
}
public function get_session()
{
if (!$this->_test_mode)
{
return $_SESSION;
}
$session = $this->config->item('session_test');
if (!$session)
{
$session = [];
}
return $session;
}
/**
* Success API Call
*
* @return string
*/
public function success($success)
{
$success['code'] = 200;
$success['success'] = TRUE;
return $this->output->set_content_type('application/json')
->set_status_header(200)
->set_output(json_encode($success));
}
}
+264
View File
@@ -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'] = '&laquo';
$this->_data['setting'] = $this->get_setting();
$this->_data['list'] = [];
if($marketing_data)
{
if($marketing_data->header_template_path != '')
{
$this->_data['header'] = $marketing_data->header_template_path ? $marketing_data->header_template_path : '';
}
if($marketing_data->footer_template_path != '')
{
$this->_data['footer'] = $marketing_data->footer_template_path ? $marketing_data->footer_template_path : '';
}
$this->_data['content'] = $marketing_data->content ? $marketing_data->content : '';
$this->_data['content_template'] = $marketing_data->content_template_path ? $marketing_data->content_template_path : '';
if($marketing_data->status == 0)
{
if ($marketing_data->password_protect == '')
{
return $this->generate_marketing_template($this->_data);
}
else
{
$valid_passwords = [
'guest' => $marketing_data->password_protect
];
$valid_users = array_keys($valid_passwords);
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
if (!$validated)
{
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
die ('Not authorized');
}
return $this->generate_marketing_template($this->_data);
}
}
else
{
$this->output->set_status_header('404');
$data['heading'] = '404 Page Not Found';
$data['message'] = 'The page you requested was not found';
$this->load->view('errors/html/error_404',$data);
exit();
}
}
$this->output->set_status_header('404');
$data['heading'] = '404 Page Not Found';
$data['message'] = 'The page you requested was not found';
$this->load->view('errors/html/error_404', $data);
exit();
}
/**
* Function to generate marketing template
*/
public function generate_marketing_template($marketing_data)
{
if($marketing_data['header'] != '')
{
$this->load->view($marketing_data['header'], $marketing_data);
}
if($marketing_data['content_template'] == '')
{
echo $marketing_data['content_template'];
}
else
{
$this->load->view('Guest/Template_page', $marketing_data);
}
if($marketing_data['footer'] != '')
{
$this->load->view($marketing_data['footer'], $marketing_data);
}
}
}
+107
View File
@@ -0,0 +1,107 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* Voice Controller
*
* @copyright 2019 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
class Spreadsheet_controller extends Manaknight_Controller
{
public $_data = [
'error' => '',
'success' => ''
];
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model('spreadsheet_model');
}
/**
* Debug Controller to error_log and turn off in production
*
* @param mixed $data
* @return void
*/
public function dl($key, $data)
{
if (ENVIRONMENT == 'development')
{
error_log($key . ' CONTROLLER : <pre>' . print_r($data, TRUE) . '</pre>');
}
}
/**
* Debug json Controller to error_log and turn off in production
*
* @param mixed $data
* @return void
*/
public function dj($key, $data)
{
if (ENVIRONMENT == 'development')
{
error_log($key . ' CONTROLLER : ' . json_encode($data));
}
}
public function get_session()
{
if (!$this->_test_mode)
{
return $_SESSION;
}
$session = $this->config->item('session_test');
if (!$session)
{
$session = [];
}
return $session;
}
public function set_session($field, $value)
{
if (!$this->_test_mode)
{
$_SESSION[$field] = $value;
}
else
{
$session = $this->config->item('session_test');
if (!$session)
{
$session = [];
}
$session[$field] = $value;
$this->config->set_item('session_test', $session);
}
}
public function destroy_session()
{
if (!$this->_test_mode)
{
unset($_SESSION);
}
else
{
$this->config->set_item('session_test', []);
}
}
public function get_setting()
{
return $this->_setting;
}
}
+11
View File
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>