Пример #1
0
 public function validate($group, $fields = array())
 {
     if (empty($group) || !is_array($fields)) {
         return false;
     }
     $this->load->language('setting/setting');
     $error = null;
     foreach ($fields as $field_name => $field_value) {
         switch ($group) {
             case 'details':
                 if ($field_name == 'store_name' && !$field_value) {
                     $error['name'] = $this->language->get('error_name');
                 }
                 if ($field_name == 'config_title' && !$field_value) {
                     $error['title'] = $this->language->get('error_title');
                 }
                 if ($field_name == 'config_url' && !$field_value) {
                     $error['url'] = $this->language->get('error_url');
                 }
                 if ($field_name == 'config_ssl_url' && !$field_value && $this->request->get['config_ssl']) {
                     $error['ssl_url'] = $this->language->get('error_ssl_url');
                 }
                 if (sizeof($fields) > 1) {
                     if (mb_strlen($fields['config_owner']) < 2 || mb_strlen($fields['config_owner']) > 64) {
                         $error['owner'] = $this->language->get('error_owner');
                     }
                     if (mb_strlen($fields['config_address']) < 2 || mb_strlen($fields['config_address']) > 256) {
                         $error['address'] = $this->language->get('error_address');
                     }
                     if (mb_strlen($fields['store_main_email']) > 96 || !preg_match(EMAIL_REGEX_PATTERN, $fields['store_main_email'])) {
                         $error['email'] = $this->language->get('error_email');
                     }
                     if (mb_strlen($fields['config_telephone']) > 32) {
                         $error['telephone'] = $this->language->get('error_telephone');
                     }
                 }
                 break;
             case 'general':
                 if ($field_name == 'config_catalog_limit' && !$field_value) {
                     $error['catalog_limit'] = $this->language->get('error_limit');
                 }
                 if ($field_name == 'config_bestseller_limit' && !$field_value) {
                     $error['bestseller_limit'] = $this->language->get('error_limit');
                 }
                 if ($field_name == 'config_featured_limit' && !$field_value) {
                     $error['featured_limit'] = $this->language->get('error_limit');
                 }
                 if ($field_name == 'config_latest_limit' && !$field_value) {
                     $error['latest_limit'] = $this->language->get('error_limit');
                 }
                 if ($field_name == 'config_special_limit' && !$field_value) {
                     $error['special_limit'] = $this->language->get('error_limit');
                 }
                 break;
             case 'appearance':
                 if ($field_name == 'config_image_thumb_width' && !$field_value || $field_name == 'config_image_thumb_height' && !$field_value) {
                     $error['image_thumb_width'] = $error['image_thumb_height'] = $this->language->get('error_image_thumb');
                 }
                 if ($field_name == 'config_image_popup_width' && !$field_value || $field_name == 'config_image_popup_height' && !$field_value) {
                     $error['image_popup_height'] = $error['image_popup_width'] = $this->language->get('error_image_popup');
                 }
                 if ($field_name == 'config_image_category_width' && !$field_value || $field_name == 'config_image_category_height' && !$field_value) {
                     $error['image_category_height'] = $this->language->get('error_image_category');
                 }
                 if ($field_name == 'config_image_manufacturer_width' && !$field_value || $field_name == 'config_image_manufacturer_height' && !$field_value) {
                     $error['image_manufacturer_height'] = $this->language->get('error_image_manufacturer');
                 }
                 if ($field_name == 'config_image_product_width' && !$field_value || $field_name == 'config_image_product_height' && !$field_value) {
                     $error['image_product_height'] = $this->language->get('error_image_product');
                 }
                 if ($field_name == 'config_image_additional_width' && !$field_value || $field_name == 'config_image_additional_height' && !$field_value) {
                     $error['image_additional_height'] = $this->language->get('error_image_additional');
                 }
                 if ($field_name == 'config_image_related_width' && !$field_value || $field_name == 'config_image_related_height' && !$field_value) {
                     $error['image_related_height'] = $this->language->get('error_image_related');
                 }
                 if ($field_name == 'config_image_cart_width' && !$field_value || $field_name == 'config_image_cart_height' && !$field_value) {
                     $error['image_cart_height'] = $this->language->get('error_image_cart');
                 }
                 if ($field_name == 'config_image_grid_width' && !$field_value || $field_name == 'config_image_grid_height' && !$field_value) {
                     $error['image_grid_height'] = $this->language->get('error_image_grid');
                 }
                 break;
             case 'checkout':
                 if ($field_name == 'config_start_order_id' && $field_value && !(int) $field_value) {
                     $error['start_order_id'] = $this->language->get('error_start_order_id');
                 }
                 if ($field_name == 'starting_invoice_id' && $field_value && !(int) $field_value) {
                     $error['starting_invoice_id'] = $this->language->get('error_starting_invoice_id');
                 }
                 if ($field_name == 'config_expire_order_days' && $field_value && !(int) $field_value) {
                     $error['expire_order_days'] = $this->language->get('error_expire_order_days');
                 }
                 break;
             case 'api':
                 break;
             case 'mail':
                 if ($fields['config_mail_protocol'] == 'smtp' && ($field_name == 'config_smtp_host' && !$field_value || $field_name == 'config_smtp_port' && !$field_value || $field_name == 'config_smtp_timeout' && !$field_value)) {
                     $error['mail'] = $this->language->get('error_mail');
                 }
                 break;
             case 'system':
                 if ($field_name == 'config_error_filename' && !$field_value) {
                     $error['error_filename'] = $this->language->get('error_error_filename');
                 }
                 if ($field_name == 'config_upload_max_size') {
                     $fields[$field_value] = preformatInteger($field_value);
                 }
                 break;
             default:
         }
     }
     return array('error' => $error, 'validated' => $fields);
 }
Пример #2
0
 /**
  * @param int $product_id
  * @param array $data
  * @return int
  */
 public function addProductDiscount($product_id, $data)
 {
     $data['price'] = str_replace(" ", "", $data['price']);
     if (!empty($data['date_start'])) {
         $data['date_start'] = dateDisplay2ISO($data['date_start'], $this->language->get('date_format_short'));
     }
     if (!empty($data['date_end'])) {
         $data['date_end'] = dateDisplay2ISO($data['date_end'], $this->language->get('date_format_short'));
     }
     $this->db->query("INSERT INTO " . $this->db->table("product_discounts") . "\n\t\t\t\tSET product_id = '" . (int) $product_id . "',\n\t\t\t\t\tcustomer_group_id = '" . (int) $data['customer_group_id'] . "',\n\t\t\t\t\tquantity = '" . preformatInteger($data['quantity']) . "',\n\t\t\t\t\tpriority = '" . (int) $data['priority'] . "',\n\t\t\t\t\tprice = '" . preformatFloat($data['price']) . "',\n\t\t\t\t\tdate_start = '" . $this->db->escape($data['date_start']) . "',\n\t\t\t\t\tdate_end = '" . $this->db->escape($data['date_end']) . "'");
     $id = $this->db->getLastId();
     $this->cache->remove('product');
     return $id;
 }
Пример #3
0
 public function validate($group, $fields = array())
 {
     if (empty($group) || !is_array($fields)) {
         return false;
     }
     $this->load->language('setting/setting');
     foreach ($fields as $field_name => $field_value) {
         switch ($group) {
             case 'details':
                 if ($field_name == 'store_name' && !$field_value) {
                     $error['name'] = $this->language->get('error_name');
                 }
                 if ($field_name == 'config_title' && !$field_value) {
                     $error['title'] = $this->language->get('error_title');
                 }
                 if ($field_name == 'config_url' && !$field_value) {
                     $error['url'] = $this->language->get('error_url');
                 }
                 if ($field_name == 'config_ssl_url' && !$field_value && $this->request->get['config_ssl']) {
                     $error['ssl_url'] = $this->language->get('error_ssl_url');
                 }
                 if (sizeof($fields) > 1) {
                     if (strlen(utf8_decode($fields['config_owner'])) < 2 || strlen(utf8_decode($fields['config_owner'])) > 64) {
                         $error['owner'] = $this->language->get('error_owner');
                     }
                     if (strlen(utf8_decode($fields['config_address'])) < 2 || strlen(utf8_decode($fields['config_address'])) > 256) {
                         $error['address'] = $this->language->get('error_address');
                     }
                     $pattern = '/^[A-Z0-9._%-]+@[A-Z0-9][A-Z0-9.-]{0,61}\\.[A-Z]{2,6}$/i';
                     if (strlen(utf8_decode($fields['store_main_email'])) > 96 || !preg_match($pattern, $fields['store_main_email'])) {
                         $error['email'] = $this->language->get('error_email');
                     }
                     if (strlen(utf8_decode($fields['config_telephone'])) < 2 || strlen(utf8_decode($fields['config_telephone'])) > 32) {
                         $error['telephone'] = $this->language->get('error_telephone');
                     }
                 }
                 break;
             case 'general':
                 //if ($field == 'config_admin_limit' &&  !$value) {
                 //$error['admin_limit'] = $this->language->get('error_limit');
                 //}
                 if ($field_name == 'config_catalog_limit' && !$field_value) {
                     $error['catalog_limit'] = $this->language->get('error_limit');
                 }
                 if ($field_name == 'config_bestseller_limit' && !$field_value) {
                     $error['bestseller_limit'] = $this->language->get('error_limit');
                 }
                 if ($field_name == 'config_featured_limit' && !$field_value) {
                     $error['featured_limit'] = $this->language->get('error_limit');
                 }
                 if ($field_name == 'config_latest_limit' && !$field_value) {
                     $error['latest_limit'] = $this->language->get('error_limit');
                 }
                 if ($field_name == 'config_special_limit' && !$field_value) {
                     $error['special_limit'] = $this->language->get('error_limit');
                 }
                 break;
             case 'appearance':
                 if ($field_name == 'config_image_thumb_width' && !$field_value || $field_name == 'config_image_thumb_height' && !$field_value) {
                     $error['image_thumb_width'] = $error['image_thumb_height'] = $this->language->get('error_image_thumb');
                 }
                 if ($field_name == 'config_image_popup_width' && !$field_value || $field_name == 'config_image_popup_height' && !$field_value) {
                     $error['image_popup_height'] = $error['image_popup_width'] = $this->language->get('error_image_popup');
                 }
                 if ($field_name == 'config_image_category_width' && !$field_value || $field_name == 'config_image_category_height' && !$field_value) {
                     $error['image_category_height'] = $this->language->get('error_image_category');
                 }
                 if ($field_name == 'config_image_product_width' && !$field_value || $field_name == 'config_image_product_height' && !$field_value) {
                     $error['image_product_height'] = $this->language->get('error_image_product');
                 }
                 if ($field_name == 'config_image_additional_width' && !$field_value || $field_name == 'config_image_additional_height' && !$field_value) {
                     $error['image_additional_height'] = $this->language->get('error_image_additional');
                 }
                 if ($field_name == 'config_image_related_width' && !$field_value || $field_name == 'config_image_related_height' && !$field_value) {
                     $error['image_related_height'] = $this->language->get('error_image_related');
                 }
                 if ($field_name == 'config_image_cart_width' && !$field_value || $field_name == 'config_image_cart_height' && !$field_value) {
                     $error['image_cart_height'] = $this->language->get('error_image_cart');
                 }
                 if ($field_name == 'config_image_grid_width' && !$field_value || $field_name == 'config_image_grid_height' && !$field_value) {
                     $error['image_grid_height'] = $this->language->get('error_image_grid');
                 }
                 break;
             case 'checkout':
                 break;
             case 'api':
                 break;
             case 'mail':
                 if ($fields['config_mail_protocol'] == 'smtp' && ($field_name == 'config_smtp_host' && !$field_value || $field_name == 'config_smtp_port' && !$field_value || $field_name == 'config_smtp_timeout' && !$field_value)) {
                     $error['mail'] = $this->language->get('error_mail');
                 }
                 break;
             case 'system':
                 if ($field_name == 'config_error_filename' && !$field_value) {
                     $error['error_filename'] = $this->language->get('error_error_filename');
                 }
                 if ($field_name == 'config_upload_max_size') {
                     $fields[$field_value] = preformatInteger($field_value);
                 }
                 break;
             default:
         }
     }
     return array('error' => $error, 'validated' => $fields);
 }