function edit($product_id, $id = 0) { if ($id == 0) { $id = $this->input->post('commentId'); } $productcomments = new Productcomment($id); if ($_SERVER['REQUEST_METHOD'] == 'GET') { $result = array(); if (!$productcomments->exists()) { $result['status'] = false; } else { $result['status'] = true; $result['name'] = $productcomments->name; $result['title'] = $productcomments->title; $result['email'] = $productcomments->email; $result['content'] = $productcomments->content; $result['creationDate'] = $productcomments->creationDate; $result['id'] = $productcomments->id; } } else { $productcomments->title = $this->input->post('title'); $productcomments->product_id = $product_id; $productcomments->name = $this->input->post('name'); $productcomments->email = $this->input->post('email'); $productcomments->content = $this->input->post('content'); $productcomments->creationDate = $this->input->post('creationDate'); if ($productcomments->creationdate == "") { $productcomments->creationDate = date("Y-m-d H:i:s"); } if ($productcomments->save()) { $result = array('status' => "true"); } else { $result = array('status' => "false"); } } echo json_encode($result); exit; }
function addComment($id) { $this->load->library("securimage"); $comment = new Productcomment(); $comment->title = $this->input->post('title'); $comment->content = $this->input->post('content'); $comment->email = $this->input->post('commentEmail'); $comment->name = $this->input->post('name'); $comment->creationDate = date("Y-m-d H:i:s"); $comment->likes = 0; $comment->dislikes = 0; $comment->product_id = $id; $dis['status'] = true; if ($this->securimage->check($_POST['captcha_code']) == false) { $dis['status'] = false; $dis['message'] = "Vui lòng nhập hình ảnh xác nhận"; } else { $comment->save(); } header('Content-Type: application/json'); echo json_encode($dis); //$this->firephp->log( json_encode($dis)); exit; }