Ejemplo n.º 1
0
 public function init($formID)
 {
     switch ($formID) {
         case 'vote':
             $key = key($_POST[$formID]);
             $id = $_POST[$formID][$key];
             if (check_in_ses('vote_set', $id)) {
             }
             Redirect($base . '#review-' . $id);
             exit;
             break;
         case 'review':
             $validation = crud_validation($reviews->form_map(), 'review');
             $data = $reviews->post = $validation['post'];
             if ($validation['error']) {
                 foreach ($validation['error'] as $e => $v) {
                     $reviews->map[$e]['error'] = $v;
                 }
             } else {
                 $crud->insert(REVIEWS_TABLE, $data);
                 $rating = $reviews->get_rating($data['productID']);
                 $customers_rating = round($rating['avg'] * 2) / 2;
                 $crud->update(PRODUCTS_TABLE, array('customers_rating' => number_format($customers_rating, 2, '.', ''), 'customer_votes' => (int) $rating['amt']), 'productID=' . $productID);
             }
             Redirect($base . '#review-' . $id);
             exit;
             break;
     }
 }
Ejemplo n.º 2
0
 public function __construct($set, $map, $data)
 {
     parent::__construct();
     parent::rqst();
     $this->set = $set;
     $this->map = $map;
     $this->data = $data[0];
     if (isset($_POST['crud'])) {
         $validation = crud_validation($this->map);
         $post = $validation['post'];
         $error = $validation['error'];
         $this->data = array_merge($this->data, $post);
         if ($error) {
             foreach ($error as $e => $v) {
                 $this->map[$e]['error'] = $v;
             }
         } else {
             switch ($post['method']) {
                 case 'edit':
                     $data = array_intersect_key($post, array_flip($this->set['cols']));
                     $this->update($this->set['tbl'], $data, $this->set['actionID'] . '=' . $post[$this->set['actionID']]);
                     break;
                     //                    case 'add':
                     //                        $this->update(REVIEWS_TABLE, $data, 'id=' . $data['id']);
                     //                        break;
             }
             $hook = $this->set['hook'];
             if ($hook) {
                 call_user_func($hook['func'], $this->data[$hook['param']]);
             }
             Redirect($this->build_url('delete'));
         }
     }
 }
Ejemplo n.º 3
0
 private function form()
 {
     $data = array_intersect_key($this->map, array_flip($this->set['cols']));
     $data = REQ::parse_set($data);
     if (isset($_POST['review'])) {
         $validation = crud_validation($data, 'review');
         $post = $validation['post'];
         $error = $validation['error'];
         if ($error) {
             function _av($n)
             {
                 return array('val' => $n);
             }
             function _ae($n)
             {
                 return array('error' => $n);
             }
             $data = array_merge_recursive($data, array_map('_av', $post));
             $data = array_merge_recursive($data, array_map('_ae', $error));
         } else {
             $this->insert($this->set['tbl'], $post);
             $this->update_rating_product($this->set['productID']);
             $successes['successes'] = 'Спасибо за Ваш комментарий, после проверки администратором он будет опубликован.';
         }
     }
     $form['data'] = $data;
     $form['hidden'] = array('productID' => $this->set['productID']);
     if (isset($_POST['ajx'])) {
         $response = $successes ? $successes : $form;
         echo json_encode($response);
         //fb(json_encode($response));
         exit;
     }
     if ($successes) {
         Redirect($_SERVER['REQUEST_URI'] . '#reviews');
     }
     return $form;
 }