|
Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/laciasmara.com/public_html/shop/application/controllers/admin/ |
Upload File : |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class review_reminders extends Admin_Controller
{
private $image_filename = NULL;
function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>'); //above is to add class to form validation error, to be styled
if ($this->data['membership_type'] == "starter") {
redirect('admin/promotion');
}
}
//this is to list all sizes
public function index()
{
// Pagination in action. 100 results per page
$this->load->helper('pagination_helper');
add_pagination(base_url() . 'admin/review_reminders/index', count($this->db->get('orders')->result()), 100, 4, 'tab1_pagination');
// Get the current date
$current_date = date('Y-m-d');
// Get the date 2 weeks ago from the current date
$two_weeks_ago = date('Y-m-d', strtotime('-2 weeks', strtotime($current_date)));
$this->db->select('id_orders, order_date, recipient_name, email, order_language, email_review')
->from('orders')
->where('payment_status', 5)
->where('email_review IS NULL')
->where('order_date <=', $two_weeks_ago); // Filter orders that are 2 weeks old or older
$this->data['orders'] = $this->db->get()->result();
// Loop through the orders and send the review reminder email
foreach ($this->data['orders'] as $order) {
// Send Mail
$email_data['id_orders'] = $order->id_orders;
$email_data['order_date'] = $order->order_date;
$email_data['customer_name'] = $order->recipient_name;
$email_data['email'] = $order->email;
if ($order->order_language == 'english') {
$email_data['subject'] = 'Review the product you purchased and Get 500 Points.';
} else {
$email_data['subject'] = 'Ulas Produk yang kamu beli dan Dapatkan 500 Points';
}
if ($order->order_language == 'english') {
$view_file = 'email/english/review';
} else {
$view_file = 'email/indonesian/review';
}
$this->send_email($view_file, $email_data);
// Update the 'email_review' field to mark that the review reminder has been sent
$this->db->where('id_orders', $order->id_orders);
$this->db->update('orders', array('email_review' => '1'));
}
$this->db->select('id_orders, order_date, recipient_name, email, email_review')
->from('orders')
->where('payment_status', 5)
->where('email_review IS NULL');
$this->data['orders1'] = $this->db->get()->result();
$this->db->select('id_orders, order_date, recipient_name, email, email_review')
->from('orders')
->where('payment_status', 5)
->where('email_review', 1)
->order_by('id_orders', 'desc');
$this->data['orders2'] = $this->db->get()->result();
$this->db->select('id_orders, order_date, recipient_name, email, email_review')
->from('orders')
->where('payment_status', 5)
->where('email_review', 2);
$this->data['orders3'] = $this->db->get()->result();
// Load view
$this->data['subview'] = 'admin/review_reminders/index';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
public function add()
{
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$selectedOrders = $this->input->post('orders');
if (!empty($selectedOrders)) {
$this->db->set('email_review', 1)
->where_in('id_orders', $selectedOrders)
->update('orders');
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Emails sent and orders updated successfully.</p>');
} else {
$this->session->set_flashdata('result', '<br><p style="background:red; color:white; padding:5px; font-weight:bold;">No orders selected.</p>');
}
}
$this->db->select('id_orders, order_date, recipient_name, email, email_review')
->from('orders')
->where('payment_status', 5)
->where('email_review IS NULL');
$this->data['orders1'] = $this->db->get()->result();
$this->data['subview'] = 'admin/review_reminders/edit';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
//to edit size in admin
public function edit($id = NULL)
{
//check if id exist. If not exist, show 404.
$this->db->select('id')->from('flashsale')->where('id', $id);
$count = $this->db->get()->num_rows();
if ($count == 0) {
show_404();
}
//get flashsale data
$this->db->select('*')->from('flashsale')->where('id', $id);
$this->data['flashsale'] = $this->db->get()->row();
//get flashsale product items
$this->db->select('*')->from('flashsale_products')->where('flashsale_id', $id);
$this->data['flashsale_products'] = $this->db->get()->result_array();
//validation check in action
//validation in action
$config = array(
array(
'field' => 'time_start',
'label' => 'Time Start',
'rules' => 'required'
),
array(
'field' => 'time_end',
'label' => 'Time End',
'rules' => 'required'
),
array(
'field' => 'userfile',
'label' => 'Banner',
'rules' => 'callback__cek_banner'
),
array(
'field' => 'search_product1',
'label' => 'Product 1',
'rules' => 'required'
),
array(
'field' => 'search_product1',
'label' => 'Product 1',
'rules' => 'required'
),
);
for ($i = 1; $i <= 100; $i++) {
$config[]['field'] = "discounted_price{$i}";
$config[]['label'] = "discounted_price{$i}";
$config[]['rules'] = "trim";
$config[]['field'] = "quota_per_user{$i}";
$config[]['label'] = "quota_per_user{$i}";
$config[]['rules'] = "trim";
$config[]['field'] = "counter{$i}";
$config[]['label'] = "counter{$i}";
$config[]['rules'] = "trim";
}
for ($i = 2; $i <= 100; $i++) {
$config[]['field'] = "search_product{$i}";
$config[]['label'] = "search_product{$i}";
$config[]['rules'] = "trim";
}
$this->form_validation->set_rules($config);
if ($this->form_validation->run($this) == TRUE) {
$data_flashsale = array(
'time_start' => $this->security->xss_clean($this->input->post('time_start')),
'time_end' => $this->security->xss_clean($this->input->post('time_end'))
);
if ($this->image_filename != NULL) {
$data_flashsale['banner'] = $this->image_filename;
}
$this->db->where('id', $id);
$this->db->update('flashsale', $data_flashsale);
//edit flashsale products item..
//first, delete all flashsale products items..
/* $this->db->where('flashsale_id', $id);
$this->db->delete('flashsale_products'); */
$counter_array_i = -1;
for ($i = 1; $i <= 100; $i++) {
$counter_array_i++;
@$product_sku = preg_replace('/[^0-9]+/', '', $this->input->post("product_sku")[$counter_array_i]);
if (!empty($this->input->post("search_product{$i}"))) {
$data['flashsale_id'] = $id;
//get product_id
$this->db->select('id_products')->from('products')->where('title', $this->input->post("search_product{$i}"));
$product_id = $this->db->get()->row();
if (count($product_id) > 0) {
//this product id is exist..
//check if this producct already exist in flashsale product table
$this->db->select('product_id')->from('flashsale_products')->where('product_id', $product_id->id_products)->where('flashsale_id', $id);
$count_product = $this->db->get()->num_rows();
if ($count_product > 0) {
//this product exist in flashsale product table, then update it
if (empty($this->input->post("discounted_price{$i}"))) {
$data['discounted_price'] = 0;
} else {
$data['discounted_price'] = $this->input->post("discounted_price{$i}");
}
if (empty($this->input->post("quota_per_user{$i}"))) {
$data['max_per_user'] = 9999;
} else {
$data['max_per_user'] = $this->input->post("quota_per_user{$i}");
}
if (empty($this->input->post("counter{$i}"))) {
$data['counter'] = 1;
} else {
$data['counter'] = $this->input->post("counter{$i}");
}
$data['product_details_id'] = $product_sku;
$this->db->where('flashsale_id', $id);
$this->db->where('product_id', $product_id->id_products);
$this->db->update('flashsale_products', $data);
} else {
//this product not yet exist...then insert...
$data['product_id'] = $product_id->id_products;
$data['product_name'] = $this->input->post("search_product{$i}");
$data['product_details_id'] = $product_sku;
if (empty($this->input->post("discounted_price{$i}"))) {
$data['discounted_price'] = 0;
} else {
$data['discounted_price'] = $this->input->post("discounted_price{$i}");
}
if (empty($this->input->post("quota_per_user{$i}"))) {
$data['max_per_user'] = 9999;
} else {
$data['max_per_user'] = $this->input->post("quota_per_user{$i}");
}
if (empty($this->input->post("counter{$i}"))) {
$data['counter'] = 1;
} else {
$data['counter'] = $this->input->post("counter{$i}");
}
$this->db->insert('flashsale_products', $data);
}
}
}
}
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Flashdata Edit Successful</p>');
redirect('admin/flashsale/edit/' . $id);
}
$this->data['subview'] = 'admin/flashsale/edit';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
public function _cek_banner()
{
//get max image width and height from configuration table
$this->db->select('category_image_width, category_image_height')->from('configuration')->where('id_configuration', 1);
$image_dimension = $this->db->get()->row();
//check & processing image banner upload files
if ($_FILES['userfile']['size'] !== 0) {
$config['upload_path'] = './uploads/banners/';
$config['allowed_types'] = 'jpg|png|jpeg';
$config['max_size'] = '300';
$config['max_width'] = $image_dimension->category_image_width;
$config['max_height'] = $image_dimension->category_image_height;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('userfile')) {
$this->form_validation->set_message('_cek_banner', 'Image size/dimension not correct.');
return FALSE;
} else {
$image = $this->upload->data();
$this->image_filename = $image['file_name'];
return TRUE;
}
}
}
}