Example #1
0
        function process_posts()
        {
            if (!($fp = fopen($this->file, "r"))) {
                echo '<p><strong>' . __('Failed to open file.', 'wc2') . '</strong></p>';
                wp_import_cleanup($this->id);
                return false;
            }
            global $wpdb;
            $wc2_item = WC2_DB_Item::get_instance();
            //all delete
            //$wc2_item->delete_all_item_data();
            //die();
            $err = new WP_Error();
            $sp = ",";
            $lines = array();
            $buf = '';
            while (!feof($fp)) {
                $temp = fgets($fp, 10240);
                if (0 == strlen($temp)) {
                    continue;
                }
                $num = substr_count($temp, '"');
                if (0 == $num % 2 && '' == $buf) {
                    $lines[] = $temp;
                } elseif (1 == $num % 2 && '' == $buf) {
                    $buf .= $temp;
                } elseif (0 == $num % 2 && '' != $buf) {
                    $buf .= $temp;
                } elseif (1 == $num % 2 && '' != $buf) {
                    $buf .= $temp;
                    $lines[] = $buf;
                    $buf = '';
                }
            }
            fclose($fp);
            //Post data - fixed
            define('COL_POST_ID', 0);
            define('COL_POST_AUTHOR', 1);
            define('COL_POST_CONTENT', 2);
            define('COL_POST_TITLE', 3);
            define('COL_POST_EXCERPT', 4);
            define('COL_POST_STATUS', 5);
            define('COL_POST_COMMENT_STATUS', 6);
            define('COL_POST_PASSWORD', 7);
            define('COL_POST_NAME', 8);
            define('COL_POST_MODIFIED', 9);
            define('COL_POST_CATEGORY', 10);
            define('COL_POST_TAG', 11);
            define('COL_POST_CUSTOM_FIELD', 12);
            define('COL_ITEM_CODE', 13);
            define('COL_ITEM_NAME', 14);
            $item_base_column = $wc2_item->get_item_base_column();
            $item_meta_column = $wc2_item->get_item_meta_column();
            $item_sku_column = $wc2_item->get_item_sku_column();
            $item_sku_meta_column = $wc2_item->get_item_sku_meta_column();
            $system = wc2_get_option('system');
            $this->encode_type = isset($system['csv_encode_type']) ? $system['csv_encode_type'] : 0;
            $start_col = 13;
            $sku_start_col = $start_col;
            foreach ((array) $item_base_column as $key => $column) {
                if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                    $sku_start_col++;
                }
            }
            foreach ((array) $item_meta_column as $key => $column) {
                if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                    $sku_start_col++;
                }
            }
            $post_status = array('publish', 'future', 'draft', 'pending', 'private');
            $pre_item_code = '';
            $item_id = 0;
            $sku_id = 1;
            $this->data_rows = count($lines);
            $this->success = 0;
            $this->false = 0;
            //Progressbar 処理件数SET
            echo '<script type="text/javascript">PG_Set_Max(' . $this->data_rows . ');</script>' . "\r\n";
            ob_flush();
            flush();
            foreach ($lines as $row => $line) {
                $datas = array();
                $datas = explode($sp, trim($line));
                $this->values = array();
                $buf = '';
                foreach ($datas as $data) {
                    $num = substr_count($data, '"');
                    if (0 == $num % 2 && '' == $buf) {
                        if ('"' == substr($data, 0, 1)) {
                            $data = substr($data, 1);
                        }
                        if ('"' == substr($data, -1)) {
                            $data = substr($data, 0, -1);
                        }
                        $data = str_replace(array('""'), '"', $data);
                        $this->values[] = false !== $data ? $data : '';
                    } elseif (1 == $num % 2 && '' == $buf) {
                        $buf .= $data;
                    } elseif (0 == $num % 2 && '' != $buf) {
                        $buf .= $sp . $data;
                    } elseif (1 == $num % 2 && '' != $buf) {
                        $buf .= $sp . $data;
                        if ('"' == substr($buf, 0, 1)) {
                            $buf = substr($buf, 1);
                        }
                        if ('"' == substr($buf, -1)) {
                            $buf = substr($buf, 0, -1);
                        }
                        $buf = str_replace(array('""'), '"', $buf);
                        $this->values[] = false !== $buf ? $buf : '';
                        $buf = '';
                    }
                }
                if ('Post ID' == $this->values[COL_POST_ID]) {
                    $this->data_rows -= 1;
                    $this->progress_add();
                    continue;
                }
                if ($pre_item_code == $this->values[COL_ITEM_CODE] && WC2_Utils::is_blank($this->values[COL_POST_ID])) {
                    $mode = 'add';
                    $post_id = '';
                } else {
                    $post_id = !WC2_Utils::is_blank($this->values[COL_POST_ID]) ? (int) $this->values[COL_POST_ID] : '';
                    if ($post_id) {
                        $post_ob = get_post($post_id);
                        if (!isset($post_ob->ID) || empty($post_ob)) {
                            $this->error_log($row, __("Post-ID {$post_id} does not exist.", 'wc2'));
                            $this->create_log();
                            $this->progress_add();
                            continue;
                        }
                        $mode = 'upd';
                    } else {
                        $mode = 'add';
                    }
                }
                $wc2_item->set_the_post_id($post_id);
                //data_check
                foreach ($this->values as $key => $val) {
                    $value = trim($val);
                    switch ($key) {
                        case COL_POST_ID:
                            if (!preg_match("/^[0-9]+\$/", $value) && 0 != strlen($value)) {
                                $this->error_log($row, __('A value of the Post-ID is abnormal.', 'wc2'));
                            }
                            break;
                        case COL_POST_AUTHOR:
                        case COL_POST_COMMENT_STATUS:
                        case COL_POST_PASSWORD:
                        case COL_POST_NAME:
                        case COL_POST_TITLE:
                        case COL_POST_CONTENT:
                        case COL_POST_EXCERPT:
                            break;
                        case COL_POST_STATUS:
                            if (0 == strlen($value) || !in_array($value, $post_status)) {
                                $this->error_log($row, __('A value of the display status is abnormal.', 'wc2'));
                            }
                            break;
                        case COL_POST_MODIFIED:
                            if ('future' == $this->values[COL_POST_STATUS] && (0 == strlen($value) || '0000-00-00 00:00:00' == $value)) {
                                if (preg_match($date_pattern, $value, $match)) {
                                    if (checkdate($match[2], $match[3], $match[1]) && (0 < $match[4] && 24 > $match[4]) && (0 < $match[5] && 60 > $match[5]) && (0 < $match[6] && 60 > $match[6])) {
                                    } else {
                                        $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2'));
                                    }
                                } else {
                                    $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2'));
                                }
                            } else {
                                if (0 != strlen($value) && '0000-00-00 00:00:00' != $value) {
                                    if (preg_match("/^[0-9]+\$/", substr($value, 0, 4))) {
                                        if (strtotime($value) === false) {
                                            $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2'));
                                        }
                                    } else {
                                        $datetime = explode(' ', $value);
                                        $date_str = $this->dates_interconv($datetime[0]) . ' ' . $datetime[1];
                                        if (strtotime($date_str) === false) {
                                            $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2'));
                                        }
                                    }
                                }
                            }
                            break;
                        case COL_POST_CATEGORY:
                            if (0 == strlen($value)) {
                                $this->error_log($row, __('A category is non-input.', 'wc2'));
                            }
                            break;
                        case COL_POST_TAG:
                        case COL_POST_CUSTOM_FIELD:
                            break;
                        case COL_ITEM_CODE:
                            if (0 == strlen($value)) {
                                $this->error_log($row, __('An item code is non-input.', 'wc2'));
                            } else {
                                $post_ids = $wc2_item->get_some_post_ids_by_item_code($value);
                                if ('upd' == $mode) {
                                    if (1 < count($post_ids)) {
                                        $this->error_log($row, __('This Item-Code has been duplicated.', 'wc2'));
                                        foreach ($post_ids as $res_val) {
                                            $this->error_log($row, "item_code=" . $value . ", post_id=" . $res_val['item_post_id']);
                                        }
                                    } elseif (1 === count($post_ids)) {
                                        if ($post_ids[0]['item_post_id'] != $post_id) {
                                            $this->error_log($row, __('This Item-Code has already been used.', 'wc2'));
                                            $this->error_log($row, "item_code=" . $value . ", post_id=" . $post_ids[0]['item_post_id']);
                                        }
                                    }
                                } else {
                                    if ('add' == $mode) {
                                        if ($value != $pre_item_code) {
                                            if (0 < count($post_ids)) {
                                                $this->error_log($row, __('This Item-Code has already been used.', 'wc2'));
                                                foreach ($post_ids as $res_val) {
                                                    $this->error_log($row, "item_code=" . $value . ", post_id=" . $res_val['item_post_id']);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        case COL_ITEM_NAME:
                            if (0 == strlen($value)) {
                                $this->error_log($row, __('An item name is non-input.', 'wc2'));
                            }
                            break;
                    }
                }
                //表示する Item column をエラーチェック
                $check_num = $start_col;
                foreach ($item_base_column as $key => $column) {
                    if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                        $check_column[$key] = $check_num;
                        $check_num++;
                    }
                }
                foreach ($item_meta_column as $key => $column) {
                    if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                        $check_column[$key] = $check_num;
                        $check_num++;
                    }
                }
                foreach ($item_sku_column as $key => $column) {
                    if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                        $check_column[$key] = $check_num;
                        $check_num++;
                    }
                }
                foreach ($item_sku_meta_column as $key => $column) {
                    if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                        $check_column[$key] = $check_num;
                        $check_num++;
                    }
                }
                foreach ($check_column as $column_key => $data_num) {
                    switch ($column_key) {
                        case ITEM_PRODUCT_TYPE:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the Product type is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_CHARGES_TYPE:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the Billing type is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_PURCHASE_LIMIT_LOWEST:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the Purchase limit(lowest) is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_PURCHASE_LIMIT_HIGHEST:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the Purchase limit(highest) is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_POINT_RATE:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the point rate is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_QUANTITY_DISCOUNT_NUM1:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the Quantity discount1(number) is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_QUANTITY_DISCOUNT_RATE1:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the Quantity discount1(rate) is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_QUANTITY_DISCOUNT_NUM2:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the Quantity discount2(number) is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_QUANTITY_DISCOUNT_RATE2:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the Quantity discount2(rate) is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_QUANTITY_DISCOUNT_NUM3:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the Quantity discount3(number) is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_QUANTITY_DISCOUNT_RATE3:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the Quantity discount3(rate) is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_SKU_CODE:
                            if (0 == strlen($this->values[$data_num])) {
                                $this->error_log($row, __('A SKU code is non-input.', 'wc2'));
                            }
                            break;
                        case ITEM_SKU_NAME:
                        case ITEM_SKU_UNIT:
                            break;
                        case ITEM_SKU_STOCK:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the SKU stock is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_SKU_STATUS:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the SKU status is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_SKU_PRICE:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the SKU price is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_SKU_COSTPRICE:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the SKU cost price is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_SKU_LISTPRICE:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the SKU list price is abnormal.', 'wc2'));
                            }
                            break;
                        case ITEM_SKU_SET_QUANTITY_DISCOUNT:
                            if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) {
                                $this->error_log($row, __('A value of the Quantity discount applies is abnormal.', 'wc2'));
                            }
                            break;
                    }
                }
                if ('' != $this->get_log_line()) {
                    $this->create_log();
                    $this->progress_add();
                    continue;
                }
                $post = array();
                if ($pre_item_code != $this->values[COL_ITEM_CODE]) {
                    $sku_id = 1;
                    if ($this->values[COL_POST_MODIFIED] == '' || $this->values[COL_POST_MODIFIED] == '0000-00-00 00:00:00') {
                        $post['post_date'] = current_time('mysql');
                        $post['post_date_gmt'] = current_time('mysql', 1);
                        $post['post_modified'] = current_time('mysql');
                        $post['post_modified_gmt'] = current_time('mysql', 1);
                    } else {
                        if (preg_match("/^[0-9]+\$/", substr($this->values[COL_POST_MODIFIED], 0, 4))) {
                            $time_data = strtotime($this->values[COL_POST_MODIFIED]);
                        } else {
                            $datetime = explode(' ', $this->values[COL_POST_MODIFIED]);
                            $date_str = $this->dates_interconv($datetime[0]) . ' ' . $datetime[1];
                            $time_data = strtotime($date_str);
                        }
                        $post['post_date'] = date('Y-m-d H:i:s', $time_data);
                        $post['post_date_gmt'] = gmdate('Y-m-d H:i:s', $time_data);
                        $post['post_modified'] = date('Y-m-d H:i:s', $time_data);
                        $post['post_modified_gmt'] = gmdate('Y-m-d H:i:s', $time_data);
                    }
                    if ('publish' == $this->values[COL_POST_STATUS]) {
                        $now = current_time('mysql');
                        if (mysql2date('U', $post['post_modified'], false) > mysql2date('U', $now, false)) {
                            $this->values[COL_POST_STATUS] = 'future';
                        }
                    } elseif ('future' == $this->values[COL_POST_STATUS]) {
                        $now = current_time('mysql');
                        if (mysql2date('U', $post['post_modified'], false) <= mysql2date('U', $now, false)) {
                            $this->values[COL_POST_STATUS] = 'publish';
                        }
                    }
                    $post['ID'] = $post_id;
                    $post['post_author'] = !WC2_Utils::is_blank($this->values[COL_POST_AUTHOR]) ? $this->values[COL_POST_AUTHOR] : 1;
                    $post['post_content'] = $this->convert_encoding($this->values[COL_POST_CONTENT]);
                    $post['post_title'] = $this->convert_encoding($this->values[COL_POST_TITLE]);
                    $post['post_excerpt'] = $this->convert_encoding($this->values[COL_POST_EXCERPT]);
                    $post['post_status'] = $this->values[COL_POST_STATUS];
                    $post['comment_status'] = !WC2_Utils::is_blank($this->values[COL_POST_COMMENT_STATUS]) ? $this->values[COL_POST_COMMENT_STATUS] : 'close';
                    $post['ping_status'] = 'close';
                    $post['post_password'] = '******' == $post['post_status'] ? '' : $this->values[COL_POST_PASSWORD];
                    $post['post_type'] = ITEM_POST_TYPE;
                    $post['post_parent'] = 0;
                    $post_name = sanitize_title($this->convert_encoding($this->values[COL_POST_NAME]));
                    $post['post_name'] = wp_unique_post_slug($post_name, $post_id, $post['post_status'], $post['post_type'], $post['post_parent']);
                    $post['to_ping'] = '';
                    $post['pinged'] = '';
                    $post['menu_order'] = 0;
                    $post['post_content_filtered'] = '';
                    if (empty($post['post_name']) && !in_array($post['post_status'], array('draft', 'pending', 'auto-draft'))) {
                        $post['post_name'] = sanitize_title($post['post_title'], $post_id);
                    }
                    if ($mode == 'add') {
                        $post['guid'] = '';
                        if (false === $wpdb->insert($wpdb->posts, $post)) {
                            $this->error_log($row, __('This data was not registered in the database.', 'wc2'));
                            $pre_item_code = $this->values[COL_ITEM_CODE];
                            $this->create_log();
                            $this->progress_add();
                            continue;
                        }
                        $post_id = $wpdb->insert_id;
                        $wc2_item->set_the_post_id($post_id);
                        $where = array('ID' => $post_id);
                        $wpdb->update($wpdb->posts, array('guid' => get_permalink($post_id)), $where);
                    } elseif ($mode == 'upd') {
                        $where = array('ID' => $post_id);
                        if (false === $wpdb->update($wpdb->posts, $post, $where)) {
                            $this->error_log($row, __('The data were not registered with a database.', 'wc2'));
                            $pre_item_code = $this->values[COL_ITEM_CODE];
                            $this->create_log();
                            $this->progress_add();
                            continue;
                        }
                        //delete all metas of Item
                        $meta_key_table = array();
                        $cfrows = explode(';', trim($this->values[COL_POST_CUSTOM_FIELD]));
                        //if( !(1 === count($cfrows) && '' == reset($cfrows)) ) {
                        if ('' != reset($cfrows)) {
                            foreach ($cfrows as $cf) {
                                list($meta_key, $meta_value) = explode('=', $cf, 2);
                                if (!WC2_Utils::is_blank($meta_key)) {
                                    array_push($meta_key_table, $this->convert_encoding($meta_key));
                                }
                            }
                        }
                        $meta_key_table = apply_filters('wc2_filter_importitem_delete_postmeta', $meta_key_table);
                        $res = $wc2_item->delete_custome_field_key($meta_key_table);
                        if (false === $res) {
                            $this->error_log($row, __('Error : delete postmeta', 'wc2'));
                            $pre_item_code = $this->values[COL_ITEM_CODE];
                            $this->create_log();
                            $this->progress_add();
                            continue;
                        }
                        //delete Item revisions
                        $res = $wc2_item->delete_item_revision();
                        if (false === $res) {
                            $this->error_log($row, __('Error : delete revisions', 'wc2'));
                            $pre_item_code = $this->values[COL_ITEM_CODE];
                            $this->create_log();
                            $this->progress_add();
                            continue;
                        }
                        //delete relationships of category
                        $res = $wc2_item->delete_term_relationship();
                        if (false === $res) {
                            $this->error_log($row, __('Error : delete term_relationships(category)', 'wc2'));
                            $pre_item_code = $this->values[COL_ITEM_CODE];
                            $this->create_log();
                            $this->progress_add();
                            continue;
                        }
                        //delete relationships of tag
                        //$query = "SELECT term_taxonomy_id, COUNT(*) AS ct FROM {$wpdb->term_relationships} GROUP BY term_taxonomy_id";
                        //$relation_data = $wpdb->get_results( $query, ARRAY_A );
                        $relation_data = $wc2_item->get_count_term_taxonomy();
                        foreach ((array) $relation_data as $relation_rows) {
                            $term_taxonomy_where['term_taxonomy_id'] = $relation_rows['term_taxonomy_id'];
                            //	$term_taxonomy_id['term_taxonomy_id'] = $relation_rows['term_taxonomy_id'];
                            $term_taxonomy_updatas['count'] = $relation_rows['ct'];
                            if (false === $wpdb->update($wpdb->term_taxonomy, $term_taxonomy_updatas, $term_taxonomy_where)) {
                                $this->error_log($row, __('Error : delete term_relationships(tag)', 'wc2'));
                                $pre_item_code = $this->values[COL_ITEM_CODE];
                                continue;
                            }
                        }
                    }
                    //add term_relationships, edit term_taxonomy
                    //category
                    $categories = explode(';', $this->values[COL_POST_CATEGORY]);
                    $category_ids = array();
                    foreach ((array) $categories as $category) {
                        $cat = get_term_by('slug', $category, 'item');
                        if ($cat == false) {
                            $category = (string) $category;
                            $this->error_log($row, __(sprintf('Since the category slug "%s" does not exist or could not be category registration.', $this->convert_encoding($category)), 'wc2'));
                            continue;
                        }
                        $category_ids[] = $cat->term_id;
                    }
                    $term_taxonomy_ids = wp_set_post_terms($post_id, $category_ids, 'item');
                    foreach ($term_taxonomy_ids as $term_taxonomy_id) {
                        $wc2_item->term_taxonomy_count_post($term_taxonomy_id);
                    }
                    //tag
                    $tags_concat = str_replace(';', ',', $this->convert_encoding($this->values[COL_POST_TAG]));
                    $term_taxonomy_ids = wp_set_post_terms($post_id, $tags_concat, 'item-tag');
                    foreach ($term_taxonomy_ids as $term_taxonomy_id) {
                        $wc2_item->term_taxonomy_count_post($term_taxonomy_id);
                    }
                    //add custom field
                    $cfrows = explode(';', trim($this->values[COL_POST_CUSTOM_FIELD]));
                    //if( !(1 === count($cfrows) && '' == reset($cfrows)) ) {
                    if ('' != reset($cfrows)) {
                        $valstr = '';
                        foreach ($cfrows as $cf) {
                            list($meta_key, $meta_value) = explode('=', $cf, 2);
                            if (!WC2_Utils::is_blank($meta_key)) {
                                update_post_meta($post_id, $this->convert_encoding($meta_key), $this->convert_encoding($meta_value));
                            }
                        }
                    }
                    $wc2_item->clear_column();
                    //Item data set
                    $col = $start_col;
                    foreach ($item_base_column as $key => $column) {
                        if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                            $wc2_item->set_the_item_value($key, $this->set_value($col, $column['type']));
                            $col++;
                        }
                    }
                    foreach ($item_meta_column as $key => $column) {
                        if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                            $wc2_item->set_the_item_value($key, $this->set_value($col, $column['type']));
                            $col++;
                        }
                    }
                    //SKU data set
                    $col = $sku_start_col;
                    foreach ($item_sku_column as $key => $column) {
                        if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                            $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type']));
                            $col++;
                        }
                    }
                    foreach ($item_sku_meta_column as $key => $column) {
                        if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                            $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type']));
                            $col++;
                        }
                    }
                    if ($mode == 'add') {
                        $wc2_item->add_item_data();
                    } elseif ($mode == 'upd') {
                        $wc2_item->update_item_data();
                    }
                } else {
                    //sku登録のみの行
                    $sku_id++;
                    //SKU data set
                    $col = $sku_start_col;
                    foreach ($item_sku_column as $key => $column) {
                        if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                            $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type']));
                            $col++;
                        }
                    }
                    foreach ($item_sku_meta_column as $key => $column) {
                        if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) {
                            $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type']));
                            $col++;
                        }
                    }
                    $item_id = $wc2_item->get_item_id_by_post_id($post_id);
                    $sku_data = $wc2_item->get_item_sku_data($item_id, $sku_id);
                    if (0 == $wc2_item->count_sku_data($sku_id)) {
                        if (0 < $sku_id and '' != $wc2_item->get_the_item_sku_code($sku_id)) {
                            $res = $wc2_item->add_item_sku_data($sku_id, $wc2_item->get_item_sku_data($item_id, $sku_id));
                            if (false === $res) {
                                break;
                            }
                        }
                    } else {
                        $res = $wc2_item->update_item_sku_data($sku_id, $wc2_item->get_item_sku_data($item_id, $sku_id));
                        if (false === $res) {
                            break;
                        }
                    }
                }
                if ('' != $this->get_log_line()) {
                    $this->create_log();
                }
                //登録成功数加算
                $this->success += 1;
                $pre_item_code = $this->values[COL_ITEM_CODE];
                clean_post_cache($post_id);
                wp_cache_delete($post_id, 'posts');
                wp_cache_delete($post_id, 'post_meta');
                clean_object_term_cache($post_id, 'post');
                //進捗加算
                $this->progress_add();
            }
            wp_import_cleanup($this->id);
            $this->false = $this->data_rows - $this->success;
            echo '<h3>' . __('All Done.', 'wc2') . '</h3>
				  <h3>' . sprintf(__('Success %d failure %d', 'wc2'), $this->success, $this->false) . '</h3>';
            if (0 < strlen($this->log)) {
                WC2_Utils::wc2_log($this->log, "import_item.log");
                echo str_replace("\n", "<br />", $this->log);
            }
        }
Example #2
0
	/**
	 * Delivery input check
	 *
	 */
	public function delivery_check() {
		$mes = array();
		if( isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == 1 ) {
			//氏名
			if ( WC2_Utils::is_blank($_POST['delivery']['name1']) || WC2_Utils::is_blank($_POST['delivery']['name2']) ){
				$mes[] = __('氏名を入力してください。', 'wc2');
			}
			//郵便番号
			if ( WC2_Utils::is_blank($_POST['delivery']['zipcode']) ){
				$mes[] = __('郵便番号が入力されていません。', 'wc2');
			}elseif( preg_match('/[^\d-]/', trim($_POST['delivery']['zipcode'])) ){
				$mes[] = __('郵便番号は半角数字で入力してください。', 'wc2');
			}
			//都道府県
			if ( WC2_UNSELECTED == ($_POST['delivery']['pref']) )
				$mes[] = __('都道府県が選択されていません。', 'wc2');
			//市区町村・番地
			if ( WC2_Utils::is_blank($_POST['delivery']['address1']) )
				$mes[] = __('市区町村・番地が入力されていません。', 'wc2');
			//電話番号
			if( WC2_Utils::is_blank($_POST['delivery']['tel']) ){
				$mes[] = __('電話番号が入力されていません。', 'wc2');
			}elseif( !WC2_Utils::is_blank($_POST['delivery']['tel']) && preg_match('/[^\d]/', trim($_POST['delivery']['tel'])) ){
				$mes[] = __('電話番号は半角数字で入力してください。', 'wc2');
			}
		}
		if( !isset($_POST['offer']['delivery_method']) || (empty($_POST['offer']['delivery_method']) && !WC2_Utils::is_zero($_POST['offer']['delivery_method'])) )
			$mes[] = __('配送方法を選択してください。', 'wc2');
		if( !isset($_POST['offer']['payment_method']) ) {
			$mes[] = __('支払方法を選択してください。', 'wc2');
		} else {
			$entry_data = wc2_get_entry();
			$delivery = wc2_get_option( 'delivery' );
			$general = wc2_get_option( 'general' );
			$payment = wc2_get_payment( $_POST['offer']['payment_method'] );
			if( 'COD' == $payment['settlement'] ) {
				$item_total_price = wc2_get_item_total_price();
				$materials = array(
					'total_price' => $item_total_price,
					'discount' => $entry_data['order']['discount'],
					'shipping_charge' => $entry_data['order']['shipping_charge'],
					'cod_fee' => $entry_data['order']['cod_fee'],
				);
				$item_total_price += wc2_get_tax( $materials );
				$cod_limit_amount = ( isset($general['cod_limit_amount']) && 0 < (int)$general['cod_limit_amount'] ) ? $general['cod_limit_amount'] : 0;
				if( 0 < $cod_limit_amount && $item_total_price > $cod_limit_amount )
					$mes[] = sprintf(__('商品合計金額が、代引きでご購入できる上限額(%s)を超えています。', 'wc2'), wc2_crform( $general['cod_limit_amount'], true, false ));
			}

			$d_method_index = wc2_get_delivery_method_index( (int)$_POST['offer']['delivery_method'] );
			if( $delivery['delivery_method'][$d_method_index]['nocod'] == 1 ) {
				if('COD' == $payment['settlement'])
					$mes[] = __('この配送方法では、代引きはご利用できません。', 'wc2');
			}

			$country = $entry_data['delivery']['country'];
			$local_country = wc2_get_base_country();
			if( $country == $local_country ) {
				if( $delivery['delivery_method'][$d_method_index]['intl'] == 1 ) {
					$mes[] = __('配送方法が誤っています。国際便は指定できません。', 'wc2');
				}
			} else {
				if( WC2_Utils::is_zero($delivery['delivery_method'][$d_method_index]['intl']) ) {
					$mes[] = __('配送方法が誤っています。国際便を指定してください。', 'wc2');
				}
			}
		}
	
		//custom_delivery check
		$csde_mes = wc2_custom_field_enter_check('delivery');
		foreach( $csde_mes as $csde_mes_val ){
			$mes[] = $csde_mes_val;
		}

		//custom_order check
		$csod_mes = wc2_custom_field_enter_check('order');
		foreach( $csod_mes as $csod_mes_val ){
			$mes[] = $csod_mes_val;
		}

		$mes = apply_filters( 'wc2_filter_delivery_check', $mes );
		return $mes;
	}
Example #3
0
 public function member_check($type, $member_id = '')
 {
     global $wpdb;
     //Variable "type" is "order" or "customer" or "delivery" or "member"
     $mes = array();
     $action = '';
     if (is_admin()) {
         if (isset($_POST['addButton'])) {
             $action = 'admin_add';
         } elseif (isset($_POST['upButton'])) {
             $action = 'admin_update';
         }
     } else {
         if (isset($_POST['wcaction'])) {
             if ('register_member' == $_POST['wcaction'] || 'customer_process' == $_POST['wcaction']) {
                 $action = 'front_add';
             } elseif ('update_member' == $_POST['wcaction']) {
                 //カートから編集あとで追加
                 $action = 'front_update';
             }
         }
     }
     if (empty($action)) {
         $mes[] = __('不正なデータが送信されました。', 'wc2');
         return $mes;
     }
     $general = wc2_get_option('general');
     $wc2_db_member = WC2_DB_Member::get_instance();
     $wc2_db_member->get_member_data($member_id);
     $account = $wc2_db_member->get_value('account');
     $email = $wc2_db_member->get_value('email');
     $member_pass_rule_min = $general['member_pass_rule_min'];
     $member_pass_rule_max = $general['member_pass_rule_max'];
     //アカウント
     if (WC2_Utils::is_blank($_POST[$type]['account'])) {
         $mes[] = __('ログインアカウントを入力してください。', 'wc2');
     } elseif (!preg_match("/^[a-zA-Z0-9]+\$/", trim($_POST[$type]['account']))) {
         $mes[] = __('ログインアカウントは半角英数字で入力してください。', 'wc2');
     } else {
         if (isset($_POST[$type]['account']) && trim($_POST[$type]['account']) != $account) {
             $mem_ID = $wc2_db_member->get_member_id_by_account(trim($_POST[$type]['account']));
             if (!empty($mem_ID) && $member_id != $mem_ID) {
                 $mes[] = __('このログインアカウントは既に使用されています。', 'wc2');
             }
         }
     }
     //パスワード
     if ('front_update' == $action) {
         if (!empty($_POST[$type]['passwd']) || !empty($_POST[$type]['passwd2'])) {
             //フロント更新
             if (trim($_POST[$type]['passwd']) != trim($_POST[$type]['passwd2'])) {
                 $mes[] = __('確認用パスワードと異なります。', 'wc2');
             } elseif (!preg_match("/^[a-zA-Z0-9]+\$/", trim($_POST[$type]['passwd']))) {
                 $mes[] = __('ログインパスワードは半角英数字で入力してください。', 'wc2');
             } else {
                 if (!empty($member_pass_rule_max)) {
                     if ($member_pass_rule_min > strlen(trim($_POST[$type]['passwd'])) || strlen(trim($_POST[$type]['passwd'])) > $member_pass_rule_max) {
                         $mes[] = sprintf(__('パスワードは%1$s文字以上%2$s文字以下で入力してください。', 'wc2'), $member_pass_rule_min, $member_pass_rule_max);
                     }
                 } else {
                     if ($member_pass_rule_min > strlen(trim($_POST[$type]['passwd']))) {
                         $mes[] = sprintf(__('パスワードは%s文字以上で入力してください。', 'wc2'), $member_pass_rule_min);
                     }
                 }
             }
         }
     } elseif ('front_add' == $action) {
         //フロント新規登録 (パスワード・パスワード確認項目有)
         if (WC2_Utils::is_blank($_POST[$type]['passwd']) || WC2_Utils::is_blank($_POST[$type]['passwd2'])) {
             $mes[] = __('ログインパスワードを入力してください。', 'wc2');
         } elseif (trim($_POST[$type]['passwd']) != trim($_POST[$type]['passwd2'])) {
             $mes[] = __('確認用パスワードと異なります。', 'wc2');
         } elseif (!preg_match("/^[a-zA-Z0-9]+\$/", trim($_POST[$type]['passwd']))) {
             $mes[] = __('ログインパスワードは半角英数字で入力してください。', 'wc2');
         } else {
             if (!empty($member_pass_rule_max)) {
                 if ($member_pass_rule_min > strlen(trim($_POST[$type]['passwd'])) || strlen(trim($_POST[$type]['passwd'])) > $member_pass_rule_max) {
                     $mes[] = sprintf(__('パスワードは%1$s文字以上%2$s文字以下で入力してください。', 'wc2'), $member_pass_rule_min, $member_pass_rule_max);
                 }
             } else {
                 if ($member_pass_rule_min > strlen(trim($_POST[$type]['passwd']))) {
                     $mes[] = sprintf(__('パスワードは%s文字以上で入力してください。', 'wc2'), $member_pass_rule_min);
                 }
             }
         }
     } elseif ('admin_add' == $action) {
         //管理画面新規 (パスワード有・パスワード確認無し)
         if (WC2_Utils::is_blank($_POST[$type]['passwd'])) {
             $mes[] = __('ログインパスワードを入力してください。', 'wc2');
         } elseif (!preg_match("/^[a-zA-Z0-9]+\$/", trim($_POST[$type]['passwd']))) {
             $mes[] = __('ログインパスワードは半角英数字で入力してください。', 'wc2');
         } else {
             if (!empty($member_pass_rule_max)) {
                 if ($member_pass_rule_min > strlen(trim($_POST[$type]['passwd'])) || strlen(trim($_POST[$type]['passwd'])) > $member_pass_rule_max) {
                     $mes[] = sprintf(__('パスワードは%1$s文字以上%2$s文字以下で入力してください。', 'wc2'), $member_pass_rule_min, $member_pass_rule_max);
                 }
             } else {
                 if ($member_pass_rule_min > strlen(trim($_POST[$type]['passwd']))) {
                     $mes[] = sprintf(__('パスワードは%s文字以上で入力してください。', 'wc2'), $member_pass_rule_min);
                 }
             }
         }
     }
     //メールアドレス&メールアドレス確認項目有
     if (array_key_exists('email', $_POST[$type]) && array_key_exists('email2', $_POST[$type])) {
         if (WC2_Utils::is_blank($_POST[$type]['email']) || WC2_Utils::is_blank($_POST[$type]['email2'])) {
             $mes[] = __('メールアドレスを入力してください。', 'wc2');
         } elseif (trim($_POST[$type]['email']) != trim($_POST[$type]['email2'])) {
             $mes[] = __('確認用メールアドレスと異なります。', 'wc2');
         } elseif (!is_email(trim($_POST[$type]['email']))) {
             $mes[] = __('メールアドレスの値が不正です。', 'wc2');
         } else {
             if (trim($_POST[$type]['email']) != $email) {
                 $mem_ID = $wc2_db_member->get_member_id_by_email($_POST[$type]['email']);
                 if (!empty($mem_ID)) {
                     $mes[] = __('このメールアドレスは既に使用されています。', 'wc2');
                 }
             }
         }
         //メールアドレス項目有 確認無し
     } elseif (array_key_exists('email', $_POST[$type]) && !array_key_exists('email2', $_POST[$type])) {
         if (WC2_Utils::is_blank($_POST[$type]['email'])) {
             $mes[] = __('メールアドレスを入力してください。', 'wc2');
         } elseif (!is_email(trim($_POST[$type]['email']))) {
             $mes[] = __('メールアドレスの値が不正です。', 'wc2');
         } else {
             if (trim($_POST[$type]['email']) != $email) {
                 $mem_ID = $wc2_db_member->get_member_id_by_email($_POST[$type]['email']);
                 if (!empty($mem_ID)) {
                     $mes[] = __('このメールアドレスは既に使用されています。', 'wc2');
                 }
             }
         }
     }
     //氏名
     if (WC2_Utils::is_blank($_POST[$type]['name1']) || WC2_Utils::is_blank($_POST[$type]['name2'])) {
         $mes[] = __('氏名を入力してください。', 'wc2');
     }
     //郵便番号
     if (WC2_Utils::is_blank($_POST[$type]['zipcode'])) {
         $mes[] = __('郵便番号が入力されていません。', 'wc2');
     } elseif (preg_match('/[^\\d-]/', trim($_POST[$type]['zipcode']))) {
         $mes[] = __('郵便番号は半角数字で入力してください。', 'wc2');
     }
     //都道府県
     if (WC2_UNSELECTED == $_POST[$type]['pref']) {
         $mes[] = __('都道府県が選択されていません。', 'wc2');
     }
     //市区町村・番地
     if (WC2_Utils::is_blank($_POST[$type]['address1'])) {
         $mes[] = __('市区町村・番地が入力されていません。', 'wc2');
     }
     //電話番号
     if (WC2_Utils::is_blank($_POST[$type]['tel'])) {
         $mes[] = __('電話番号が入力されていません。', 'wc2');
     } elseif (!WC2_Utils::is_blank($_POST[$type]['tel']) && preg_match('/[^\\d-]/', trim($_POST[$type]['tel']))) {
         $mes[] = __('電話番号は半角数字で入力してください。', 'wc2');
     }
     //FAX番号
     if (!WC2_Utils::is_blank($_POST[$type]['fax']) && preg_match('/[^\\d-]/', trim($_POST[$type]['fax']))) {
         $mes[] = __('FAX番号は半角数字で入力してください。', 'wc2');
     }
     //custom_field check
     $cstm_mes = wc2_custom_field_enter_check($type);
     foreach ($cstm_mes as $cstm_mes_val) {
         $mes[] = $cstm_mes_val;
     }
     $message = apply_filters('wc2_filter_member_check', $mes, $type, $action);
     return $message;
 }
 public function phrase_ajax()
 {
     //if( !check_ajax_referer( 'wc2_setting_phrase', 'wc2_nonce', false ) ) die();
     if (!isset($_POST['action']) or !isset($_POST['mode'])) {
         die;
     }
     if ($_POST['action'] != 'phrase_ajax') {
         die;
     }
     $res = '';
     switch ($_POST['mode']) {
         case 'select':
             $phrase = $_POST['phrase'];
             $phrase_options = wc2_get_option('phrase');
             $phrase_default = wc2_get_option('phrase_default');
             $title = WC2_Utils::is_blank($phrase_options['title'][$phrase]) ? $phrase_default['title'][$phrase] : $phrase_options['title'][$phrase];
             $header = WC2_Utils::is_blank($phrase_options['header'][$phrase]) ? $phrase_default['header'][$phrase] : $phrase_options['header'][$phrase];
             $footer = WC2_Utils::is_blank($phrase_options['footer'][$phrase]) ? $phrase_default['footer'][$phrase] : $phrase_options['footer'][$phrase];
             $res = 'OK' . WC2_SPLIT . $title . WC2_SPLIT . $header . WC2_SPLIT . $footer;
             break;
         case 'update':
             if (!check_ajax_referer('wc2_setting_phrase', 'wc2_nonce', false)) {
                 $res = 'NG' . WC2_SPLIT . __('Security error.');
             } else {
                 $_POST = wc2_stripslashes_deep_post($_POST);
                 $phrase = $_POST['phrase'];
                 $phrase_options = wc2_get_option('phrase');
                 $phrase_options['title'][$phrase] = urldecode(trim($_POST['title']));
                 $phrase_options['header'][$phrase] = urldecode(trim($_POST['header']));
                 $phrase_options['footer'][$phrase] = urldecode(trim($_POST['footer']));
                 $phrase_options = apply_filters('wc2_filter_admin_phrase_update', $phrase_options, $phrase);
                 wc2_update_option('phrase', $phrase_options);
                 $res = 'OK' . WC2_SPLIT . $phrase_options['footer'][$phrase];
             }
             break;
     }
     $res = apply_filters('wc2_filter_admin_phrase_ajax', $res);
     die($res);
 }
Example #5
0
function wc2_is_blank($val, $strict=false){
	$res = WC2_Utils::is_blank($val, $strict);
	return $res;
}
Example #6
0
	public function changepass_check(){
		$mes = array();
		//文字数チェック追加
		if( WC2_Utils::is_blank($_POST['new_password1']) || WC2_Utils::is_blank($_POST['new_password2']) ){
			$mes[] = __('新しいパスワードを入力してください。', 'wc2');
		}elseif( trim($_POST['new_password1']) != trim($_POST['new_password2']) ){
			$mes[] = __('確認用パスワードと異なります。', 'wc2');
		}elseif( !preg_match( "/^[a-zA-Z0-9]+$/", trim( $_POST['new_password1'] ) ) ){
			$mes[] = __('パスワードは半角英数字で入力してください。', 'wc2');
		}else{
			$general = wc2_get_option('general');
			$member_pass_rule_min = $general['member_pass_rule_min'];
			$member_pass_rule_max = $general['member_pass_rule_max'];
			if( !empty( $member_pass_rule_max ) ){
				if( $member_pass_rule_min > strlen( trim($_POST['new_password1']) ) || strlen( trim($_POST['new_password1']) ) > $member_pass_rule_max ){
					$mes[] = sprintf(__('パスワードは%1$s文字以上%2$s文字以下で入力してください。', 'wc2'), $member_pass_rule_min, $member_pass_rule_max );
				}
			}else{
				if( $member_pass_rule_min > strlen( trim($_POST['new_password1']) ) ){
					$mes[] = sprintf(__('パスワードは%s文字以上で入力してください。', 'wc2'), $member_pass_rule_min);
				}
			}
		}
		return $mes;
	}
 function setup_cod_ajax()
 {
     if (!check_ajax_referer('wc2_setting_payment', 'wc2_nonce', false)) {
         die;
     }
     $payment_info = wc2_get_option('payment_info');
     $message = '';
     $_POST = WC2_Utils::stripslashes_deep_post($_POST);
     $payment_info['cod_type'] = isset($_POST['cod_type']) ? $_POST['cod_type'] : 'fix';
     if (isset($_POST['cod_fee'])) {
         $payment_info['cod_fee'] = (int) $_POST['cod_fee'];
     }
     if ('fix' == $payment_info['cod_type']) {
         if (isset($_POST['cod_fee'])) {
             $payment_info['cod_fee'] = (int) $_POST['cod_fee'];
             if (!is_numeric($_POST['cod_fee'])) {
                 $message = __('値が不正な項目があります', 'wc2');
             }
         }
         if (isset($_POST['cod_limit_amount'])) {
             $payment_info['cod_limit_amount'] = (int) $_POST['cod_limit_amount'];
             if (!WC2_Utils::is_blank($_POST['cod_limit_amount']) && 0 === (int) $_POST['cod_limit_amount']) {
                 $message = __('値が不正な項目があります', 'wc2');
             }
         }
     } elseif ('change' == $payment_info['cod_type']) {
         if (isset($_POST['cod_first_amount'])) {
             $payment_info['cod_first_amount'] = (int) $_POST['cod_first_amount'];
             if (0 === (int) $_POST['cod_first_amount']) {
                 $message = __('値が不正な項目があります', 'wc2');
             }
         }
         if (isset($_POST['cod_limit_amount'])) {
             $payment_info['cod_limit_amount'] = (int) $_POST['cod_limit_amount'];
             if (!WC2_Utils::is_blank($_POST['cod_limit_amount']) && 0 === (int) $_POST['cod_limit_amount']) {
                 $message = __('値が不正な項目があります', 'wc2');
             }
         }
         if (isset($_POST['cod_first_fee'])) {
             $payment_info['cod_first_fee'] = (int) $_POST['cod_first_fee'];
             if (0 === (int) $_POST['cod_first_fee'] && '0' !== $_POST['cod_first_fee']) {
                 $message = __('値が不正な項目があります', 'wc2');
             }
         }
         if (isset($_POST['cod_end_fee'])) {
             $payment_info['cod_end_fee'] = (int) $_POST['cod_end_fee'];
             if (0 === (int) $_POST['cod_end_fee'] && '0' !== $_POST['cod_end_fee']) {
                 $message = __('値が不正な項目があります', 'wc2');
             }
         }
         unset($payment_info['cod_amounts'], $payment_info['cod_fees']);
         if (isset($_POST['cod_amounts'])) {
             for ($i = 0; $i < count((array) $_POST['cod_amounts']); $i++) {
                 $payment_info['cod_amounts'][$i] = (int) $_POST['cod_amounts'][$i];
                 $payment_info['cod_fees'][$i] = (int) $_POST['cod_fees'][$i];
                 if (0 === (int) $_POST['cod_amounts'][$i] || 0 === (int) $_POST['cod_fees'][$i] && '0' !== $_POST['cod_fees'][$i]) {
                     $message = __('値が不正な項目があります', 'wc2');
                 }
             }
         }
     }
     if ('' == $message) {
         $r = 'success';
         wc2_update_option('payment_info', $payment_info);
     } else {
         $r = 'error' . WC2_SPLIT . $message;
     }
     $r = apply_filters('wc2_filter_admin_payment_setup_cod_ajax', $r);
     die($r);
 }
 public function system_setting_page()
 {
     if (!isset($this->plugin_screen_hook_suffix)) {
         return;
     }
     $screen = get_current_screen();
     if ($this->plugin_screen_hook_suffix != $screen->id) {
         return;
     }
     $system_options = wc2_get_option('system');
     $states = wc2_get_option('states_options');
     $locale = wc2_get_option('locale_options');
     if (array_key_exists('wc2_option_update', $_POST)) {
         $this->action_status = 'success';
         $_POST = WC2_Utils::stripslashes_deep_post($_POST);
         $system_options['divide_item'] = isset($_POST['divide_item']) ? 1 : 0;
         $system_options['itemimg_anchor_rel'] = isset($_POST['itemimg_anchor_rel']) ? trim($_POST['itemimg_anchor_rel']) : '';
         $system_options['composite_category_orderby'] = isset($_POST['composite_category_orderby']) ? $_POST['composite_category_orderby'] : '';
         $system_options['composite_category_order'] = isset($_POST['composite_category_order']) ? $_POST['composite_category_order'] : '';
         $system_options['settlement_path'] = isset($_POST['settlement_path']) ? $_POST['settlement_path'] : '';
         if (WC2_Utils::is_blank($system_options['settlement_path'])) {
             $system_options['settlement_path'] = WC2_PLUGIN_DIR . '/settlement/';
         }
         $sl = substr($system_options['settlement_path'], -1);
         if ($sl != '/' && $sl != '\\') {
             $system_options['settlement_path'] .= '/';
         }
         $system_options['logs_path'] = isset($_POST['logs_path']) ? $_POST['logs_path'] : '';
         if (!WC2_Utils::is_blank($system_options['logs_path'])) {
             $sl = substr($system_options['logs_path'], -1);
             if ($sl == '/' || $sl == '\\') {
                 $system_options['logs_path'] = substr($system_options['logs_path'], 0, -1);
             }
         }
         $system_options['use_ssl'] = isset($_POST['use_ssl']) ? 1 : 0;
         $system_options['ssl_url'] = isset($_POST['ssl_url']) ? rtrim($_POST['ssl_url'], '/') : '';
         $system_options['ssl_url_admin'] = isset($_POST['ssl_url_admin']) ? rtrim($_POST['ssl_url_admin'], '/') : '';
         if (WC2_Utils::is_blank($system_options['ssl_url']) || WC2_Utils::is_blank($system_options['ssl_url_admin'])) {
             $system_options['use_ssl'] = 0;
         }
         $system_options['inquiry_id'] = isset($_POST['inquiry_id']) ? esc_html(rtrim($_POST['inquiry_id'])) : '';
         $system_options['use_javascript'] = isset($_POST['use_javascript']) ? (int) $_POST['use_javascript'] : 1;
         $system_options['front_lang'] = isset($_POST['front_lang']) && 'others' != $_POST['front_lang'] ? $_POST['front_lang'] : wc2_get_local_language();
         $system_options['currency'] = isset($_POST['currency']) && 'others' != $_POST['currency'] ? $_POST['currency'] : wc2_get_base_country();
         $system_options['addressform'] = isset($_POST['addressform']) ? $_POST['addressform'] : wc2_get_local_addressform();
         $system_options['target_market'] = isset($_POST['target_market']) ? $_POST['target_market'] : wc2_get_local_target_market();
         $system_options['no_cart_css'] = isset($_POST['no_cart_css']) ? 1 : 0;
         $system_options['dec_orderID_flag'] = isset($_POST['dec_orderID_flag']) ? (int) $_POST['dec_orderID_flag'] : 0;
         $system_options['dec_orderID_prefix'] = isset($_POST['dec_orderID_prefix']) ? esc_html(rtrim($_POST['dec_orderID_prefix'])) : '';
         $system_options['pdf_delivery'] = isset($_POST['pdf_delivery']) ? (int) $_POST['pdf_delivery'] : 0;
         $system_options['csv_encode_type'] = isset($_POST['csv_encode_type']) ? (int) $_POST['csv_encode_type'] : 0;
         if (isset($_POST['dec_orderID_digit'])) {
             $dec_orderID_digit = (int) rtrim($_POST['dec_orderID_digit']);
             if (6 > $dec_orderID_digit) {
                 $system_options['dec_orderID_digit'] = 6;
             } else {
                 $system_options['dec_orderID_digit'] = $dec_orderID_digit;
             }
         } else {
             $system_options['dec_orderID_digit'] = 6;
         }
         $system_options['subimage_rule'] = isset($_POST['subimage_rule']) ? (int) $_POST['subimage_rule'] : 0;
         unset($system_options['province']);
         foreach ((array) $system_options['target_market'] as $target_market) {
             $province = array();
             if (!empty($_POST['province_' . $target_market])) {
                 $temp_pref = explode("\n", $_POST['province_' . $target_market]);
                 foreach ($temp_pref as $pref) {
                     if (!WC2_Utils::is_blank($pref)) {
                         $province[] = trim($pref);
                     }
                 }
                 if (1 == count($province)) {
                     $this->action_status = 'error';
                 }
             } else {
                 if (isset($states[$target_market]) && is_array($states[$target_market])) {
                     $province = $states[$target_market];
                 } else {
                     $this->action_status = 'error';
                 }
             }
             $system_options['province'][$target_market] = $province;
         }
         if ($this->action_status != 'success') {
             $this->action_message = __('データに不備があります', 'wc2');
         } else {
             wc2_update_option('system', $system_options);
             $this->action_message = __('Updated!');
         }
     } else {
         if (!isset($system_options['province']) || empty($system_options['province'])) {
             $system_options['province'][$system_options['base_country']] = $states[$system_options['base_country']];
         }
         $this->action_status = 'none';
         $this->action_message = '';
     }
     $status = $this->action_status;
     $message = $this->action_message;
     $divide_item = $system_options['divide_item'];
     $itemimg_anchor_rel = $system_options['itemimg_anchor_rel'];
     $composite_category_orderby = $system_options['composite_category_orderby'];
     $composite_category_order = $system_options['composite_category_order'];
     $logs_path = isset($system_options['logs_path']) ? $system_options['logs_path'] : '';
     $use_ssl = $system_options['use_ssl'];
     $ssl_url = $system_options['ssl_url'];
     $ssl_url_admin = $system_options['ssl_url_admin'];
     $inquiry_id = $system_options['inquiry_id'];
     $orderby_itemsku = isset($system_options['orderby_itemsku']) ? $system_options['orderby_itemsku'] : 0;
     $orderby_itemopt = isset($system_options['orderby_itemopt']) ? $system_options['orderby_itemopt'] : 0;
     $system_front_lang = isset($system_options['front_lang']) && !empty($system_options['front_lang']) ? $system_options['front_lang'] : wc2_get_local_language();
     $system_currency = isset($system_options['currency']) && !empty($system_options['currency']) ? $system_options['currency'] : wc2_get_base_country();
     $system_addressform = isset($system_options['addressform']) && !empty($system_options['addressform']) ? $system_options['addressform'] : wc2_get_local_addressform();
     $system_target_markets = isset($system_options['target_market']) && !empty($system_options['target_market']) ? $system_options['target_market'] : wc2_get_local_target_market();
     $no_cart_css = isset($system_options['no_cart_css']) ? $system_options['no_cart_css'] : 0;
     $dec_orderID_flag = isset($system_options['dec_orderID_flag']) ? $system_options['dec_orderID_flag'] : 0;
     $dec_orderID_prefix = isset($system_options['dec_orderID_prefix']) ? $system_options['dec_orderID_prefix'] : '';
     $dec_orderID_digit = isset($system_options['dec_orderID_digit']) ? $system_options['dec_orderID_digit'] : '';
     $subimage_rule = isset($system_options['subimage_rule']) ? $system_options['subimage_rule'] : 0;
     $pdf_delivery = isset($system_options['pdf_delivery']) ? $system_options['pdf_delivery'] : 0;
     $csv_encode_type = isset($system_options['csv_encode_type']) ? $system_options['csv_encode_type'] : 0;
     require_once WC2_PLUGIN_DIR . '/admin/views/setting-system.php';
 }