function import($tempfile, $csv_format_type_id, $ignore_first_line, $unlink = true)
 {
     global $ProductCSV;
     global $format;
     global $data;
     global $messageStack;
     global $line_count;
     global $success_count;
     global $error_count;
     global $missing_count;
     global $body;
     $format = $ProductCSV->getFormatById($csv_format_type_id);
     $conf = File_CSV::DiscoverFormat($tempfile);
     File_CSV::getPointer($tempfile, $conf);
     // check format
     if ($conf['fields'] == count($format['columns'])) {
         $count = 1;
         // skip first line
         if ($ignore_first_line) {
             File_CSV::read($tempfile, $conf);
             $count++;
         }
         // output table header
         $body = '<tr><td><table border="1">';
         $body .= '<tr>';
         $body .= '<th>' . PRODUCT_CSV_TABLE_LINE_NUMBER . '</th>';
         foreach ($format['columns'] as $val) {
             $body .= '<th>' . $val['csv_column_name'] . '</th>';
         }
         $body .= '<th>' . PRODUCT_CSV_TABLE_HEADER . '</th>';
         $body .= '</tr>';
         // init count
         $line_count = 0;
         $success_count = 0;
         $error_count = 0;
         $missing_count = 0;
         // read lines
         while (($data = File_CSV::read($tempfile, $conf)) !== false) {
             if (count($data) == 0) {
                 continue;
             }
             echo ' ';
             flush();
             // convert charactr set to internal encoding
             foreach ($data as $key => $val) {
                 $data[$key] = mb_convert_encoding($val, MODULE_PRODUCT_CSV_INTERNAL_CHARACTER, MODULE_PRODUCT_CSV_IMPORT_CHARACTER);
             }
             $ProductCSV->messageStack->reset();
             switch ($format['csv_format_type_id']) {
                 case 1:
                     $import_status = $ProductCSV->importProduct($data, $format);
                     break;
                 case 2:
                     $format = zen_add_number_to_format($format);
                     $import_status = $ProductCSV->importCategory($data, $format);
                     break;
                 case 3:
                     $import_status = $ProductCSV->importOption($data, $format);
                     break;
             }
             // store success/error/line count
             $line_count++;
             if ($import_status === true) {
                 $success_count++;
             } elseif ($import_status === false) {
                 $error_count++;
             } else {
                 $missing_count++;
             }
             $body .= '<tr>';
             $body .= '<td>' . $count++ . '</td>';
             foreach ($data as $val) {
                 if ($val == '') {
                     $val = '&nbsp;';
                 }
                 $body .= '<td>' . $val . '</td>';
             }
             $body .= '<td>' . $ProductCSV->messageStack->output() . '</td>';
             $body .= '</tr>';
         }
         $body .= '</table></td></tr>';
         $messageStack->add(sprintf(PRODUCT_CSV_MESSAGE_IMPORT_STATUS, $line_count, $success_count, $error_count), 'success');
         if ($unlink) {
             unlink($tempfile);
         }
     } else {
         $messageStack->add(PRODUCT_CSV_ERROR_INVALID_FORMAT, 'caution');
     }
 }
Esempio n. 2
0
function checkDepth($posted_columns, $saved_columns)
{
    global $messageStack;
    // create id=>array
    $columns = array();
    foreach ($saved_columns as $val) {
        $columns[$val['id']] = $val;
    }
    // get category array
    $arr = array();
    $preferred = array();
    foreach ($posted_columns as $val) {
        if (preg_match('/^(.*)(' . FORM_FORMAT_CATEGORY_LEVEL_PREFIX . ')(\\d+)/', $columns[$val]['text'], $matches)) {
            if ($columns[$val]['language_id'] == MODULE_PRODUCT_CSV_PREFERRED_LANGUAGE_ID) {
                $preferred[0]['columns'][] = $columns[$val];
                $preferred[0]['name'] = $matches[1];
            } else {
                $arr[$matches[1]]['columns'][] = $columns[$val];
            }
        }
    }
    // check
    $return = true;
    $preferred = zen_add_number_to_format($preferred[0]);
    $preferred_max_depth = zen_get_max_depth($preferred);
    foreach ($arr as $val) {
        $val = zen_add_number_to_format($val);
        if ($preferred_max_depth < zen_get_max_depth($val)) {
            $messageStack->add(sprintf(FORM_FORMAT_CATEGORY_LEVEL_OVER, $preferred['name']), 'caution');
            $return = false;
        }
    }
    return $return;
}
Esempio n. 3
0
     $categories_products_id_list = array();
     $products_ids = zen_get_categories_products_list($_POST['category_id'], true, true);
     $products_ids = array_unique($products_ids);
     // write line
     foreach ($products_ids as $val) {
         $data = $ProductCSV->getExportDataProduct($val, $format);
         foreach ($data as $key => $d) {
             $data[$key] = mb_convert_encoding($d, MODULE_PRODUCT_CSV_EXPORT_CHARACTER, MODULE_PRODUCT_CSV_INTERNAL_CHARACTER);
             $data[$key] = str_replace("\r\n", "\n", $data[$key]);
         }
         File_CSV::write($tempfile, $data, $conf);
     }
     break;
 case 2:
     $prefix = 'categories_';
     $format = zen_add_number_to_format($format);
     $max_depth = zen_get_max_depth($format);
     $categories = zen_get_categories_with_depth($_POST['category_id'], $max_depth);
     foreach ($categories as $key => $category) {
         foreach ($category as $key2 => $id) {
             if (empty($id)) {
                 continue;
             }
             $categories_products_id_list = array();
             $products = zen_get_categories_products_list($id, true, false);
             $count = count($products) == 0 ? 1 : count($products);
             for ($i = 0; $i < $count; $i++) {
                 $products_id = $products[$i];
                 $data = $ProductCSV->getExportDataCategory($id, $format, $products_id);
                 if ($data !== false) {
                     foreach ($data as $key => $d) {