Beispiel #1
0
 /**
  * Handle form submission of add store (brand) form.
  * 
  * @author unknown, Christophe
  */
 public function add_brand()
 {
     $this->load->library('Vision_users');
     $rules = array(array('field' => 'store_name', 'label' => 'Store Name', 'rules' => 'trim|required'), array('field' => 'man_id', 'label' => 'Manufacturer ID', 'rules' => 'trim|numeric|min_length[5]|max_length[9]'));
     $this->form_validation->set_rules($rules);
     $this->form_validation->set_fields();
     $store_name = $this->input->post('store_name');
     $man_id = $this->input->post('man_id');
     // this is to handle failed file uploads so as not to duplicated the store name
     $new_store_id = $this->input->post('new_store_id');
     if ($this->form_validation->run()) {
         $store_info['user_id'] = $this->user_id;
         $store_info['store_name'] = $store_name;
         $store_info['store_enable'] = '1';
         $store_info['created_at'] = date("Y-m-d H:i:s");
         $store_info['man_id'] = $man_id;
         if (!empty($new_store_id)) {
             // if store already exists, then connect user to store
             $store_info['id'] = $new_store_id;
             $this->store_id = $new_store_id;
             $this->Store->update_store_info($store_info);
             // send notification to TrackStreet staff about store being added
             $email = $this->config->item('environment') == 'production' ? 'christophe@trackstreet.com, chris@trackstreet.com' : '*****@*****.**';
             $subject = '[TrackStreet] New Store Added: ' . $store_name;
             $html_message = "<p>A new store (brand) has been added: {$store_name} (ID: {$this->store_id})</p>";
             $html_message .= "<p>User who added store: {$this->user['first_name']} {$this->user['last_name']} (ID: {$this->user_id})</p>";
             $text_message = strip_tags($html_message);
             $this->vision_users->sendSESEmail($email, $subject, $html_message, $text_message);
         } else {
             // create new store
             $this->store_id = $this->Store->add_store($store_info);
             $this->User->add_team_member($this->store_id, $this->user_id);
             // send notification to TrackStreet staff about new store being added
             $email = $this->config->item('environment') == 'production' ? 'christophe@trackstreet.com, chris@trackstreet.com' : '*****@*****.**';
             $subject = '[TrackStreet] New Store Added: ' . $store_name;
             $html_message = "<p>A new store (brand) has been added: {$store_name} (ID: {$this->store_id})</p>";
             $html_message .= "<p>User who added store: {$this->user['first_name']} {$this->user['last_name']} (ID: {$this->user_id})</p>";
             $text_message = strip_tags($html_message);
             $this->vision_users->sendSESEmail($email, $subject, $html_message, $text_message);
             parent::_switch_brand($this->store_id);
         }
         $this->store_id = $this->data->new_store_id = $this->store_id;
         if ($_FILES['brand_logo']['error'] != 4) {
             $upload = $this->upload_logo();
             if (!$upload) {
                 $this->data->store_name = $store_name;
                 $this->data->man_id = $man_id;
                 $this->data->message = $this->file_upload_error;
                 $this->session->set_flashdata('error_msg', 'Error: Logo could not be uploaded. Please try again, or contact support for help.');
                 redirect('/settings/add_store');
                 exit;
             } else {
                 $this->db->where('id', $this->store_id);
                 $this->db->update($this->_table_store, array('brand_logo' => $this->uploaded_file));
                 redirect(base_url() . 'settings/products');
             }
         } else {
             redirect(base_url() . 'settings/products');
         }
     } else {
         $this->data->store_name = $store_name;
         $this->data->man_id = $man_id;
         $this->data->new_store_id = '';
         $this->data->message = validation_errors();
     }
     $this->javascript('views/settings.js.php');
     $this->_view = $this->_controller . '/index';
 }