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 : /proc/self/root/var/www/laciasmara.com/public_html/shop/application/controllers/ |
Upload File : |
<?php defined('BASEPATH') or exit('No direct script access allowed'); class Product_review extends Public_Controller { public function __construct() { parent::__construct(); } public function add_review() { if (!isset($_POST['submit_review'])) { show_404(); } if ($this->session->userdata('customer')['customer_id'] != NULL) { $product_id = $this->input->post('product_id'); $customer_id = $this->session->userdata('customer')['customer_id']; // Check if this product_id and customer_id already reviewed... $this->db->select('product_id, customer_id') ->from('product_review') ->where('Product_id', $product_id) ->where('customer_id', $customer_id); $count_review = $this->db->get()->num_rows(); if ($count_review == 0) { // Check if the customer has purchased the product with payment_status = 5 $this->db->from('orders o'); $this->db->join('orders_detail od', 'o.id_orders = od.orders_id'); $this->db->where('o.customer_id', $customer_id); $this->db->where('od.product_id', $product_id); $this->db->where('o.payment_status', 5); $query = $this->db->get(); if ($query->num_rows() > 0) { // Review not yet...can proceed.. $data = array( 'product_id' => $product_id, 'customer_id' => $customer_id, 'rating' => $this->input->post('rating'), 'review' => $this->security->xss_clean($this->input->post('review')), 'subject' => $this->security->xss_clean($this->input->post('subject')), 'display_name' => $this->security->xss_clean($this->input->post('display_name')) ); $insert = $this->db->insert('product_review', $data); if ($insert) { $jumdata = $this->db->select('*')->from('product_review')->where('product_id', $product_id)->get()->num_rows(); if ($jumdata > 0) { $start = $this->db->select('sum(rating) as jumrating')->from('product_review')->where('product_id', $product_id)->get()->row(); $tstart = $jumdata . ' Review'; $jstar = floor($start->jumrating / $jumdata); } else { $tstart = '0 Review'; $jstar = 0; } $data_rating = array( 'rating' => $jstar ); $this->db->where('id_products', $product_id); $this->db->update('products', $data_rating); // Add 500 points to current_pointreward column in customers table $this->db->set('current_pointreward', 'current_pointreward+500', FALSE); $this->db->where('id_customers', $customer_id); $this->db->update('customers'); $this->session->set_flashdata('product_review', '<p style="color:green"><strong>ULASAN BERHASIL DITAMBAHKAN, Anda Mendapatkan +500 Points</strong><br><br></p>'); } else { $this->session->set_flashdata('product_review', '<p style="color:red"><strong>ULASAN GAGAL DITAMBAHKAN</strong><br><br></p>'); } } else { $this->session->set_flashdata('product_review', '<p style="color:red"><strong>ANDA BELUM PERNAH MEMBELI PRODUK INI</strong><br><br></p>'); } } else { // Review already exists... $this->session->set_flashdata('product_review', '<p style="color:red"><strong>ANDA SUDAH PERNAH MENGULAS PRODUK INI</strong><br><br></p>'); } redirect('product/' . $this->input->post('product_alias')); } } public function add_reviews() { // Get form data $product_id = $this->input->post('product_id'); $product_alias = $this->input->post('product_alias'); $customer_id = $this->session->userdata('customer')['customer_id'] ?? null; $display_name = $this->input->post('display_name'); $rating = $this->input->post('rating'); $subject = $this->input->post('subject'); $review = $this->input->post('review'); if (!$rating || !$subject || !$review) { $this->session->set_flashdata('error', 'Mohon lengkapi semua kolom sebelum mengirim ulasan.'); redirect('product/' . $product_alias); return; } // Prepare data for insertion $reviewData = array( 'product_id' => $product_id, 'review_date' => date('Y-m-d H:i:s'), 'customer_id' => $customer_id, 'rating' => $rating, 'subject' => $subject, 'review' => $review, 'status' => 'pending', 'display_name' => $display_name ); // Insert review into the database $insert = $this->db->insert('product_review', $reviewData); if ($insert) { if ($customer_id) { $this->session->set_flashdata('message', 'Ulasanmu berhasil dikirim! ✨ Poin akan diberikan ke akunmu setelah ulasan disetujui oleh tim kami.'); } else { $this->session->set_flashdata('message', 'Terima kasih! Ulasanmu berhasil dikirim dan sedang menunggu moderasi. ✨'); } } else { $this->session->set_flashdata('error', 'Oops! Gagal mengirim ulasan. Silakan coba lagi dalam beberapa saat.'); } redirect('product/' . $product_alias); } public function hitungreview() { $product = $this->db->select('*')->from('product_review')->group_by('product_id')->get()->result(); foreach ($product as $value) { $jumdata = $this->db->select('*')->from('product_review')->where('product_id', $value->product_id)->get()->num_rows(); if ($jumdata > 0) { $start = $this->db->select('sum(rating) as jumrating')->from('product_review')->where('product_id', $value->product_id)->get()->row(); $tstart = $jumdata . ' Review'; $jstar = floor($start->jumrating / $jumdata); } else { $tstart = '0 Review'; $jstar = 0; } $data_rating = array( 'rating' => $jstar ); $this->db->where('id_products', $value->product_id); $this->db->update('products', $data_rating); echo $value->product_id . ' *' . $jstar . ' / ' . $jumdata . ' Review - DONE<br>'; } } }