示例#1
0
 function editAds_post()
 {
     if (count($this->post()) > 0) {
         $input = $this->inputCleaner($this->post());
     }
     // clean input variables
     if (isset($input['user_id']) && isset($input['ads_id']) && isset($input['salt'])) {
         //check salt key
         $this->load->model('user_model');
         $this->load->model('ads_model');
         $this->load->model('webservice_api_model');
         $this->load->helper('wall_type');
         $salt = $this->post()['salt'];
         $isSalt = $this->user_model->check_salt($input['user_id'], $salt);
         //
         $data = $this->ads_model->get_adsOwner($input['ads_id']);
         // get real ads owner
         $owner = $data['user_'];
         if ($isSalt && $owner == $input['user_id']) {
             $catFields = $this->ads_model->get_catFields($input['cat']);
             $this->ads_model->delete_customFields($input['ads_id']);
             $input['id'] = $input['ads_id'];
             // for ali standard
             // ads category pic
             $input['cat_pic'] = get_cat_pic($input['cat']);
             $this->webservice_api_model->update_ads($input);
             // get custom fields of ads and insert to db
             $offset = 0;
             $data = array();
             foreach ($catFields as $field) {
                 $data[$offset]['ads_'] = $input['ads_id'];
                 $data[$offset]['value'] = $this->security->xss_clean($input['custom_' . $field['field_']]);
                 $data[$offset]['field_'] = $field['field_'];
                 $offset++;
             }
             //print_r($data);
             if (count($data) > 0) {
                 $this->ads_model->add_fields($data);
             }
             $re = array("status" => 1000, "data" => true);
             $this->response($re, 200);
             // successful : edited text field
         } else {
             $re = array("status" => 1004, "data" => "some error happend , check error number in error list.");
             $this->response($re, 200);
             // Faild
         }
     } else {
         $re = array("status" => 1002, "data" => "some error happend , check error number in error list.");
         $this->response($re, 200);
         // Faild
     }
 }
示例#2
0
文件: Ads.php 项目: padideIt/wall
 public function edit_action()
 {
     if ($this->ion_auth->logged_in()) {
         $this->load->library('form_validation');
         $this->load->model('ads_model');
         $this->load->helper('wall_mapdb');
         $this->load->helper('wall_type');
         $uid = $this->get_uid();
         $owner = $this->get_adsOwner($_POST['id']);
         $admin = ($this->ion_auth->is_admin() or $this->ion_auth->in_group(3) && $this->permission(2));
         $ads_id = $_POST['id'];
         if ($owner == $uid or $admin) {
             $this->form_validation->set_rules('title', 'Title', 'required');
             $this->form_validation->set_rules('cat', 'cat', 'callback_checkCat|required');
             $this->form_validation->set_rules('state', 'state', 'callback_checkState|required');
             $this->form_validation->set_rules('city', 'city', 'callback_checkCity|required');
             $this->form_validation->set_rules('street', 'street', 'required');
             $this->form_validation->set_rules('description', 'description', 'required');
             $this->form_validation->set_rules('price', 'price', 'required');
             $this->form_validation->set_rules('name', 'name', 'required');
             $this->form_validation->set_rules('phone', 'phone', 'required');
             $catFields = $this->ads_model->get_catFields($_POST['cat']);
             foreach ($catFields as $field) {
                 $this->form_validation->set_rules("custom_" . $field['field_'], 'custom field', 'required');
             }
             // check form validation
             if ($this->form_validation->run()) {
                 $this->ads_model->delete_customFields($ads_id);
                 // get cat pic info
                 $_POST['cat_pic'] = get_cat_pic($_POST['cat']);
                 $this->ads_model->update($_POST);
                 // get custom fields of ads and insert to db
                 if ($ads_id != 0 && $ads_id !== false) {
                     $offset = 0;
                     foreach ($catFields as $field) {
                         $customs[$offset]['ads_'] = $ads_id;
                         $customs[$offset]['value'] = $this->security->xss_clean($_POST['custom_' . $field['field_']]);
                         $customs[$offset]['field_'] = $field['field_'];
                         $offset++;
                     }
                     if ($offset != 0) {
                         $this->ads_model->add_fields($customs);
                     }
                 }
                 // upload ads pics and add pics names to db
                 $this->load->helper('wall_upload');
                 $pics = upload_pic($_FILES['userfile'], $ads_id, "adspic", 10, true);
                 $ctr = 0;
                 foreach ($pics as $key => $pic) {
                     $ctr++;
                     $ads_pic[$key]['ads_'] = $ads_id;
                     $ads_pic[$key]['pic'] = $pic;
                 }
                 if ($ctr != 0) {
                     $this->ads_model->add_pics($ads_pic);
                 }
                 $msg = "آگهی با موفقیت ویرایش شد.";
                 $this->session->set_userdata('msg', $msg);
                 if ($admin) {
                     redirect(site_url('admin/manage_ads'));
                     exit;
                 } else {
                     redirect(site_url('dashboard/myads'));
                     exit;
                 }
             } else {
                 // form validation failed and reset ads edit page
                 redirect(site_url("ads/edit/{$ads_id}"));
             }
         } else {
             $msg = "عدم دسترسی، لطفا وارد شوید.";
             $this->session->set_userdata('error', $msg);
             $this->session->set_userdata('redirect', "ads/edit/{$ads_id}");
             redirect(site_url('user/login'));
             exit;
         }
     } else {
         $msg = "عدم دسترسی، لطفا وارد شوید.";
         $this->session->set_userdata('error', $msg);
         $this->session->set_userdata('redirect', "ads/edit/{$ads_id}");
         redirect(site_url('user/login'));
         exit;
     }
 }