Esempio n. 1
0
 /**
  * Create a new company
  *
  * @return void
  */
 public function create_new_company()
 {
     if (!wp_verify_nonce($_POST['_wpnonce'], 'erp-new-company')) {
         wp_die(__('Cheating?', 'wp-erp'));
     }
     $posted = array_map('strip_tags_deep', $_POST);
     $posted = array_map('trim_deep', $posted);
     $errors = [];
     $required = ['name' => __('Company name', 'wp-erp'), 'address' => ['country' => __('Country', 'wp-erp')]];
     if (!$this->is_valid_input($posted, 'name')) {
         $errors[] = __('Company name is required', 'wp-erp');
     }
     if (!$this->is_valid_input($posted['address'], 'country')) {
         $errors[] = __('Country is required', 'wp-erp');
     }
     if ($errors) {
         var_dump($errors);
         die;
     }
     $args = ['logo' => isset($posted['company_logo_id']) ? absint($posted['company_logo_id']) : 0, 'name' => $posted['name'], 'address' => ['address_1' => $posted['address']['address_1'], 'address_2' => $posted['address']['address_2'], 'city' => $posted['address']['city'], 'state' => $posted['address']['state'], 'zip' => $posted['address']['zip'], 'country' => $posted['address']['country']], 'phone' => $posted['phone'], 'fax' => $posted['fax'], 'mobile' => $posted['mobile'], 'website' => $posted['website'], 'currency' => $posted['currency']];
     $company = new Company();
     $company->update($args);
     $redirect_to = admin_url('admin.php?page=erp-company&action=edit&msg=updated');
     wp_redirect($redirect_to);
     exit;
 }
Esempio n. 2
0
 /**
  * Create a new company location
  *
  * @return void
  */
 public function location_create()
 {
     $this->verify_nonce('erp-company-location');
     $location_name = isset($_POST['location_name']) ? sanitize_text_field($_POST['location_name']) : '';
     $address_1 = isset($_POST['address_1']) ? sanitize_text_field($_POST['address_1']) : '';
     $address_2 = isset($_POST['address_2']) ? sanitize_text_field($_POST['address_2']) : '';
     $city = isset($_POST['city']) ? sanitize_text_field($_POST['city']) : '';
     $state = isset($_POST['state']) ? sanitize_text_field($_POST['state']) : '';
     $zip = isset($_POST['zip']) ? intval($_POST['zip']) : '';
     $country = isset($_POST['country']) ? sanitize_text_field($_POST['country']) : '';
     $location_id = isset($_POST['location_id']) ? intval($_POST['location_id']) : 0;
     $args = ['id' => $location_id, 'name' => $location_name, 'address_1' => $address_1, 'address_2' => $address_2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country];
     $company = new Company();
     $location_id = $company->create_location($args);
     if (is_wp_error($location_id)) {
         $this->send_error($location_id->get_error_message());
     }
     $this->send_success();
 }