예제 #1
0
 /**
  * Returns the ID of the first ShopCategory found in the database.
  *
  * If none is available, a default ShopCateogry named 'Import'
  * is inserted and its ID returned instead.
  * @static
  * @return  integer     The ShopCategory, or 0 on failure
  * @author  Unknown <*****@*****.**> (Original author)
  * @author  Reto Kohli <*****@*****.**> (Added creation of default ShopCategory, made static)
  */
 static function GetFirstCat()
 {
     $category_id = ShopCategory::getNextShopCategoryId();
     if ($category_id) {
         return $category_id;
     }
     return CsvImport::InsertNewCat('Import', 0);
 }
예제 #2
0
 /**
  * @expectedException \Exception
  */
 public function testException()
 {
     $import = CsvImport::import('some-bad-filename.csv');
 }
예제 #3
0
 public function execute($dataContainer)
 {
     $this->_acl = $dataContainer->getAcl();
     parent::execute($dataContainer);
 }
예제 #4
0
function automation()
{
    global $tpl, $mysql, $twig;
    $tpath = locatePluginTemplates(array('config/main', 'config/automation'), 'eshop', 1);
    if (isset($_REQUEST['yml_url']) && !empty($_REQUEST['yml_url']) && isset($_REQUEST['import'])) {
        import_yml($_REQUEST['yml_url']);
        //$import_str = implode('<br/>',$_SESSION['import_yml']);
        //$info = "Импорт YML успешно завершен<br/><br/>".$import_str;
        $info = "Импорт YML успешно завершен";
        msg(array("type" => "info", "info" => $info));
    }
    if (isset($_REQUEST['currency'])) {
        $rates_str = update_currency();
        $info = "Валюты обновлены<br/><br/>" . $rates_str;
        msg(array("type" => "info", "info" => $info));
    }
    if (isset($_REQUEST['change_price'])) {
        $change_price_type = intval($_REQUEST['change_price_type']);
        $change_price_qnt = intval($_REQUEST['change_price_qnt']);
        update_prices($change_price_type, $change_price_qnt);
        $info = "Цены обновлены<br/>";
        msg(array("type" => "info", "info" => $info));
    }
    if (isset($_REQUEST['export_csv'])) {
        $SUPRESS_TEMPLATE_SHOW = 1;
        $SUPRESS_MAINBLOCK_SHOW = 1;
        require_once dirname(__FILE__) . '/csv_lib/CsvImportInterface.php';
        require_once dirname(__FILE__) . '/csv_lib/CsvImport.php';
        require_once dirname(__FILE__) . '/csv_lib/CsvExportInterface.php';
        require_once dirname(__FILE__) . '/csv_lib/CsvExport.php';
        $export = new CsvExport();
        $cat_array = array();
        foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_categories ORDER BY position ASC') as $cat_row) {
            $catlink = checkLinkAvailable('eshop', '') ? generateLink('eshop', '', array('cat' => $cat_row['id'])) : generateLink('core', 'plugin', array('plugin' => 'eshop'), array('cat' => $cat_row['id']));
            $cat_array[] = array('id' => $cat_row['id'], 'url' => $cat_row['url'], 'image' => $cat_row['image'], 'name' => $cat_row['name'], 'description' => $cat_row['description'], 'parent_id' => $cat_row['parent_id'], 'position' => $cat_row['position'], 'meta_title' => $cat_row['meta_title'], 'meta_keywords' => $cat_row['meta_keywords'], 'meta_description' => $cat_row['meta_description'], 'link' => $catlink);
        }
        $conditions = array();
        array_push($conditions, "p.active = 1");
        //$limitCount = "10000";
        $fSort = " GROUP BY p.id ORDER BY p.id DESC ";
        $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
        $sqlQ = "SELECT p.id AS id, p.url AS url, p.code AS code, p.name AS name, p.annotation AS annotation, p.body AS body, p.active AS active, p.featured AS featured, p.stocked AS stocked, p.position AS position, p.meta_title AS meta_title, p.meta_keywords AS meta_keywords, p.meta_description AS meta_description, p.date AS date, p.editdate AS editdate, p.views AS views, c.id AS cid, c.name AS category " . $sqlQPart;
        $entries = array();
        foreach ($mysql->select($sqlQ) as $row) {
            $entriesImg = array();
            foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_images i WHERE i.product_id = ' . $row['id'] . ' ') as $row2) {
                $entriesImg[] = $row2['filepath'];
            }
            $entriesVariants = array();
            foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_variants v WHERE v.product_id = ' . $row['id'] . ' ') as $vrow) {
                $entriesVariants[] = $vrow;
            }
            $options_array = array();
            foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_options LEFT JOIN " . prefix . "_eshop_features ON " . prefix . "_eshop_features.id=" . prefix . "_eshop_options.feature_id WHERE " . prefix . "_eshop_options.product_id = " . $row['id'] . " ORDER BY position, id") as $orow) {
                $options_array[$orow['id']] = $orow['value'];
            }
            $xf_name_id = array();
            $features_array = array();
            foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_features ORDER BY position, id") as $frow) {
                $frow['value'] = $options_array[$frow['id']];
                $frow['foptions'] = json_decode($frow['foptions'], true);
                foreach ($frow['foptions'] as $key => $value) {
                    $frow['foptions'][$key] = iconv("utf-8", "windows-1251", $value);
                }
                $features_array["xfields_" . $frow['name']] = $frow['value'];
                $xf_name_id[$frow['name']] = $frow['id'];
            }
            $images_comma_separated = implode(",", $entriesImg);
            $entry = array();
            $entry = array('id' => $row['id'], 'code' => $row['code'], 'url' => $row['url'], 'name' => $row['name'], 'variants' => $entriesVariants, 'annotation' => $row['annotation'], 'body' => $row['body'], 'active' => $row['active'], 'featured' => $row['featured'], 'stocked' => $row['stocked'], 'meta_title' => $row['meta_title'], 'meta_keywords' => $row['meta_keywords'], 'meta_description' => $row['meta_description'], 'date' => empty($row['date']) ? '' : $row['date'], 'editdate' => empty($row['editdate']) ? '' : $row['editdate'], 'cat_name' => $row['category'], 'cid' => $row['cid'], 'images' => $images_comma_separated);
            foreach ($features_array as $fk => $fv) {
                $entry[$fk] = $fv;
            }
            $entries[] = $entry;
        }
        $count = 0;
        foreach ($entries as $entry) {
            foreach ($entry['variants'] as $variant) {
                $entry_row = array();
                $entry_row = $entry;
                unset($entry_row['variants']);
                $entry_row['v_id'] = $variant['id'];
                $entry_row['v_sku'] = $variant['sku'];
                $entry_row['v_name'] = $variant['name'];
                $entry_row['v_price'] = $variant['price'];
                $entry_row['v_compare_price'] = $variant['compare_price'];
                $entry_row['v_stock'] = $variant['stock'];
                $entry_row['v_amount'] = $variant['amount'];
                if ($count == 0) {
                    $export->setHeader(array_keys($entry_row));
                }
                $count += 1;
                $export->append(array($entry_row));
                unset($entry_row);
            }
        }
        $export->export('products.csv', ';');
        die;
    }
    if (isset($_REQUEST['import_csv'])) {
        $SUPRESS_TEMPLATE_SHOW = 1;
        $SUPRESS_MAINBLOCK_SHOW = 1;
        if (is_uploaded_file($_FILES["filename"]["tmp_name"])) {
            require_once dirname(__FILE__) . '/csv_lib/CsvImportInterface.php';
            require_once dirname(__FILE__) . '/csv_lib/CsvImport.php';
            require_once dirname(__FILE__) . '/csv_lib/CsvExportInterface.php';
            require_once dirname(__FILE__) . '/csv_lib/CsvExport.php';
            $import = new CsvImport();
            $filepath = dirname(__FILE__) . "/import/" . $_FILES["filename"]["name"];
            move_uploaded_file($_FILES["filename"]["tmp_name"], $filepath);
            $import->setFile($filepath, 10000, ";");
            $items = $import->getRows();
            $xf_name_id = array();
            foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_features ORDER BY position, id") as $frow) {
                $xf_name_id[$frow['name']] = $frow['id'];
            }
            foreach ($items as $iv) {
                $current_time = time();
                $id = $iv['id'];
                $code = empty($iv['code']) ? "" : $iv['code'];
                $url = empty($iv['url']) ? "" : $iv['url'];
                $name = empty($iv['name']) ? "" : $iv['name'];
                $v_id = empty($iv['v_id']) ? "" : $iv['v_id'];
                $v_sku = empty($iv['v_sku']) ? "" : $iv['v_sku'];
                $v_name = empty($iv['v_name']) ? "" : $iv['v_name'];
                $v_price = empty($iv['v_price']) ? "" : $iv['v_price'];
                $v_compare_price = empty($iv['v_compare_price']) ? "" : $iv['v_compare_price'];
                $v_stock = empty($iv['v_stock']) ? "" : $iv['v_stock'];
                $v_amount = empty($iv['v_amount']) ? "" : $iv['v_amount'];
                if ($v_amount == '') {
                    $v_amount = 'NULL';
                }
                $annotation = empty($iv['annotation']) ? "" : $iv['annotation'];
                $body = empty($iv['body']) ? "" : $iv['body'];
                $active = empty($iv['active']) ? "1" : $iv['active'];
                $featured = empty($iv['featured']) ? "0" : $iv['featured'];
                $stocked = empty($iv['stocked']) ? "0" : $iv['stocked'];
                $meta_title = empty($iv['meta_title']) ? "" : $iv['meta_title'];
                $meta_keywords = empty($iv['meta_keywords']) ? "" : $iv['meta_keywords'];
                $meta_description = empty($iv['meta_description']) ? "" : $iv['meta_description'];
                $date = empty($iv['date']) ? $current_time : $iv['date'];
                $editdate = empty($iv['editdate']) ? $current_time : $iv['editdate'];
                $cat_name = empty($iv['cat_name']) ? "" : $iv['cat_name'];
                $cid = empty($iv['cid']) ? "0" : $iv['cid'];
                //$images = explode(',',$iv['images']);
                $xfields_items = array();
                foreach ($iv as $xfk => $xfv) {
                    preg_match("/xfields_/", $xfk, $find_xf);
                    if (isset($find_xf[0])) {
                        $xf_name = str_replace('xfields_', '', $xfk);
                        $xf_id = $xf_name_id[$xf_name];
                        $xfields_items[$xf_id] = $xfv;
                    }
                }
                if ($iv['id'] != "") {
                    $product_row = $mysql->record("SELECT * FROM " . prefix . "_eshop_products WHERE id=" . db_squote($iv['id']) . " ");
                    if (empty($product_row)) {
                        if ($url != "") {
                            if (!is_array($mysql->record("select id from " . prefix . "_eshop_products where url = " . db_squote($product_row["url"]) . " limit 1"))) {
                                $mysql->query("INSERT INTO " . prefix . "_eshop_products (`id`, `code`, `url`, `name`, `annotation`, `body`, `active`, `featured`, `stocked`, `meta_title`, `meta_keywords`, `meta_description`, `date`, `editdate`) VALUES ('{$id}','{$code}','{$url}','{$name}','{$annotation}','{$body}','{$active}','{$featured}','{$stocked}','{$meta_title}','{$meta_keywords}','{$meta_description}','{$date}','{$editdate}')");
                                $qid = $mysql->lastid('eshop_products');
                                import_upload_images($qid);
                                if (!empty($xfields_items)) {
                                    foreach ($xfields_items as $f_key => $f_value) {
                                        if ($f_value != '') {
                                            $mysql->query("INSERT INTO " . prefix . "_eshop_options (`product_id`, `feature_id`, `value`) VALUES ('{$qid}','{$f_key}','{$f_value}')");
                                        }
                                    }
                                }
                                $category_id = intval($cid);
                                if ($category_id != 0) {
                                    $mysql->query("INSERT INTO " . prefix . "_eshop_products_categories (`product_id`, `category_id`) VALUES ('{$qid}','{$category_id}')");
                                }
                                $mysql->query("INSERT INTO " . prefix . "_eshop_variants (`product_id`, `sku`, `name`, `price`, `compare_price`, `stock`, `amount`) VALUES ('{$qid}', '{$v_sku}', '{$v_name}', '{$v_price}', '{$v_compare_price}', '{$v_stock}', '{$v_amount}')");
                            }
                        }
                    } else {
                        if ($product_row["url"]) {
                            if (is_array($mysql->record("select id from " . prefix . "_eshop_products where url = " . db_squote($url) . " limit 1"))) {
                                $mysql->query("REPLACE INTO " . prefix . "_eshop_products (`id`, `code`, `url`, `name`, `annotation`, `body`, `active`, `featured`, `stocked`, `meta_title`, `meta_keywords`, `meta_description`, `date`, `editdate`) VALUES ('{$id}','{$code}','{$url}','{$name}','{$annotation}','{$body}','{$active}','{$featured}','{$stocked}','{$meta_title}','{$meta_keywords}','{$meta_description}','{$date}','{$editdate}')");
                                $qid = $product_row["id"];
                                import_upload_images($qid);
                                if (!empty($xfields_items)) {
                                    //$mysql->query("DELETE FROM ".prefix."_eshop_options WHERE product_id='$qid'");
                                    foreach ($xfields_items as $f_key => $f_value) {
                                        if ($f_value != '') {
                                            $mysql->query("REPLACE INTO " . prefix . "_eshop_options (`product_id`, `feature_id`, `value`) VALUES ('{$qid}','{$f_key}','{$f_value}')");
                                        }
                                    }
                                }
                                $category_id = intval($cid);
                                if ($category_id != 0) {
                                    //$mysql->query("DELETE FROM ".prefix."_eshop_products_categories WHERE product_id='$qid'");
                                    $mysql->query("REPLACE INTO " . prefix . "_eshop_products_categories (`product_id`, `category_id`) VALUES ('{$qid}','{$category_id}')");
                                } else {
                                    $mysql->query("DELETE FROM " . prefix . "_eshop_products_categories WHERE product_id='{$qid}'");
                                }
                                $SQLv = array();
                                $SQLv['product_id'] = $qid;
                                $SQLv['sku'] = $v_sku;
                                $SQLv['name'] = $v_name;
                                $SQLv['price'] = $v_price;
                                $SQLv['compare_price'] = $v_compare_price;
                                $SQLv['stock'] = $v_stock;
                                $SQLv['amount'] = $v_amount;
                                foreach ($SQLv as $k => $v) {
                                    $vnames[] = $k . ' = ' . db_squote($v);
                                }
                                if ($v_id != "") {
                                    $mysql->query('UPDATE ' . prefix . '_eshop_variants SET ' . implode(', ', $vnames) . ' WHERE id = \'' . intval($v_id) . '\'  ');
                                } else {
                                    $mysql->query("INSERT INTO " . prefix . "_eshop_variants (`product_id`, `sku`, `name`, `price`, `compare_price`, `stock`, `amount`) VALUES ('{$qid}', '{$v_sku}', '{$v_name}', '{$v_price}', '{$v_compare_price}', '{$v_stock}', '{$v_amount}')");
                                }
                                //$mysql->query("DELETE FROM ".prefix."_eshop_variants WHERE product_id='$qid'");
                                //$mysql->query("INSERT INTO ".prefix."_eshop_variants (`product_id`, `price`, `compare_price`, `stock`) VALUES ('$qid', '$price', '$compare_price', '$stock')");
                            }
                        }
                    }
                } else {
                    $mysql->query("INSERT INTO " . prefix . "_eshop_products (`code`, `url`, `name`, `annotation`, `body`, `active`, `featured`, `stocked`, `meta_title`, `meta_keywords`, `meta_description`, `date`, `editdate`) VALUES ('{$code}','{$url}','{$name}','{$annotation}','{$body}','{$active}','{$featured}','{$stocked}','{$meta_title}','{$meta_keywords}','{$meta_description}','{$date}','{$editdate}')");
                    $qid = $mysql->lastid('eshop_products');
                    import_upload_images($qid);
                    if (!empty($xfields_items)) {
                        foreach ($xfields_items as $f_key => $f_value) {
                            if ($f_value != '') {
                                $mysql->query("INSERT INTO " . prefix . "_eshop_options (`product_id`, `feature_id`, `value`) VALUES ('{$qid}','{$f_key}','{$f_value}')");
                            }
                        }
                    }
                    $category_id = intval($cid);
                    if ($category_id != 0) {
                        $mysql->query("INSERT INTO " . prefix . "_eshop_products_categories (`product_id`, `category_id`) VALUES ('{$qid}','{$category_id}')");
                    }
                    $mysql->query("INSERT INTO " . prefix . "_eshop_variants (`product_id`, `sku`, `name`, `price`, `compare_price`, `stock`, `amount`) VALUES ('{$qid}', '{$v_sku}', '{$v_name}', '{$v_price}', '{$v_compare_price}', '{$v_stock}', '{$v_amount}')");
                }
            }
            unlink($filepath);
            $info = "Импорт CSV завершен<br/>";
            msg(array("type" => "info", "info" => $info));
            die;
        } else {
            $info = "Ошибка загрузки файла<br/>";
            msg(array("type" => "info", "info" => $info));
            die;
        }
    }
    if (isset($_REQUEST['multiple_upload_images'])) {
        $images = $_REQUEST['data']['images'];
        if ($images != NULL) {
            foreach ($images as $inx_img => $img) {
                $img_parts = explode(".", $img);
                $img_s = explode("_", $img_parts[0]);
                $qid = $img_s[0];
                if ($qid != "") {
                    $prd_row = $mysql->record("select * from " . prefix . "_eshop_products where id = " . db_squote($qid) . " limit 1");
                    if (!is_array($prd_row)) {
                        break;
                    }
                    $positions_img = array();
                    foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_images WHERE product_id = '{$qid}' ORDER BY position, id") as $irow) {
                        $positions_img[] = $irow['position'];
                    }
                    if (!empty($positions_img)) {
                        $max_img_pos = max($positions_img) + 1;
                    } else {
                        $max_img_pos = 0;
                    }
                    $inx_img = $max_img_pos;
                    @mkdir($_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/' . $qid . '/', 0777);
                    @mkdir($_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/' . $qid . '/thumb', 0777);
                    $timestamp = time();
                    $iname = $timestamp . "-" . $img;
                    $temp_name = $_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/temp/' . $img;
                    $current_name = $_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/' . $qid . '/' . $iname;
                    rename($temp_name, $current_name);
                    $temp_name = $_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/temp/thumb/' . $img;
                    $current_name = $_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/' . $qid . '/thumb/' . $iname;
                    rename($temp_name, $current_name);
                    $mysql->query("INSERT INTO " . prefix . "_eshop_images (`filepath`, `product_id`, `position`) VALUES ('{$iname}','{$qid}','{$inx_img}')");
                }
            }
        }
        $info = "Изображения загружены<br/>";
        msg(array("type" => "info", "info" => $info));
    }
    $xt = $twig->loadTemplate($tpath['config/automation'] . 'config/' . 'automation.tpl');
    $yml_export_link = checkLinkAvailable('eshop', 'yml_export') ? generateLink('eshop', 'yml_export', array()) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'yml_export'), array());
    $tVars = array('yml_export_link' => $yml_export_link, 'info' => '');
    $xg = $twig->loadTemplate($tpath['config/main'] . 'config/' . 'main.tpl');
    $tVars = array('entries' => $xt->render($tVars), 'php_self' => $PHP_SELF, 'plugin_url' => admin_url . '/admin.php?mod=extra-config&plugin=eshop', 'skins_url' => skins_url, 'admin_url' => admin_url, 'home' => home, 'current_title' => 'Автоматизация');
    print $xg->render($tVars);
}
예제 #5
0
 /**
  * Iniciar la importación de cuentas.
  *
  * @param array  $fileData  Los datos del archivo
  * @return array resultado del proceso
  */
 public static function doImport(&$fileData)
 {
     try {
         $file = new FileImport($fileData);
         switch ($file->getFileType()) {
             case 'text/csv':
             case 'application/vnd.ms-excel':
                 $import = new CsvImport($file);
                 $import->setFieldDelimiter(self::$csvDelimiter);
                 break;
             case 'text/xml':
                 $import = new XmlImport($file);
                 $import->setImportPass(self::$importPwd);
                 break;
             default:
                 throw new SPException(SPException::SP_WARNING, _('Tipo mime no soportado'), _('Compruebe el formato del archivo'));
         }
         $import->setUserId(self::$defUser);
         $import->setUserGroupId(self::$defGroup);
         $import->doImport();
     } catch (SPException $e) {
         Log::writeNewLog(_('Importar Cuentas'), $e->getMessage() . ';;' . $e->getHint());
         $result['error'] = array('description' => $e->getMessage(), 'hint' => $e->getHint());
         return $result;
     }
     Log::writeNewLog(_('Importar Cuentas'), _('Importación finalizada'));
     $result['ok'] = array(_('Importación finalizada'), _('Revise el registro de eventos para más detalles'));
     return $result;
 }
예제 #6
0
            $_SESSION['CSV_CancelButton'] = '../index.php';
    }
} else {
    if (empty($_SESSION['CSV_CancelButton'])) {
        $_SESSION['CSV_CancelButton'] = '../index.php';
    }
}
$backButtonUrl = Url::Contextualize($_SESSION['CSV_CancelButton']);
$content_default = get_lang('You must specify the CSV format used in your file') . ':' . "\n" . '<br /><br />' . "\n" . '<form method="post" action="' . claro_htmlspecialchars($_SERVER['PHP_SELF']) . '" enctype="multipart/form-data"  >' . "\n" . '<input type="hidden" name="step" value="1" />' . "\n" . '<input type="hidden" name="class_id" value="' . $class_id . '" />' . "\n" . claro_form_relay_context() . '<input type="radio" name="firstLineFormat" value="YES" id="firstLineFormat_YES" /> ' . '<label for="firstLineFormat_YES">' . get_lang('Use format defined in first line of file') . '</label>' . "\n" . '<br /><br />' . "\n" . '<input type="radio" name="firstLineFormat" value="NO" checked="checked" id="firstLineFormat_NO" />' . "\n" . '<label for="firstLineFormat_NO">' . get_lang('Use the following format') . ' : ' . '</label>' . "\n" . '<br /><br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . '<span style="font-weight: bold;">' . $usedFormat . '</span><br /><br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n" . claro_html_cmd_link(claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?display=default' . '&cmd=rqLoadDefaultFormat' . '&addType=' . $addType)), get_lang('Load default format')) . "\n" . ' | ' . claro_html_cmd_link(claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?display=default' . '&cmd=rqChangeFormat' . '&addType=' . $addType)), get_lang('Edit format to use')) . "\n" . '<br /><br />' . "\n" . get_lang('CSV file with the user list :') . "\n" . '<input type="file" name="CSVfile" />' . "\n" . '<br /><br />' . "\n" . "\n";
$content_default .= '<h3>' . get_lang('Options') . '</h3>';
$content_default .= '<input type="checkbox" name="sendEmailToUserCreated" value="1" id="sendEmailToUserCreated" />' . "\n" . '<label for="sendEmailToUserCreated">' . get_lang('Send email to new users') . ' ' . '</label>' . "\n" . '<br /><br />' . "\n";
if (get_conf('update_user_properties')) {
    $content_default .= '<input type="checkbox" name="updateUserProperties" value="1" id="updateUserProperties" />' . "\n" . '<label for="updateUserProperties">' . get_lang('Update user\'properties ') . ' ' . '</label>' . "\n" . '<br /><br />' . "\n";
}
$content_default .= '<input type="submit" name="submitCSV" value="' . get_lang('Add user list') . '" />' . "\n" . claro_html_button(claro_htmlspecialchars($backButtonUrl), get_lang('Cancel')) . "\n" . '</form>' . "\n";
$csvImport = new CsvImport();
$csvImport->heading = $firstLineFormat;
if (!$firstLineFormat) {
    // $csvImport->titles = explode( ',' , $usedFormat);
    $csvImport->fields = explode(',', $usedFormat);
}
switch ($step) {
    case 1:
        if (!isset($_FILES['CSVfile']) || empty($_FILES['CSVfile']['name']) || $_FILES['CSVfile']['size'] == 0) {
            $dialogBox->error(get_lang('You must select a file'));
            $content .= $content_default;
        } else {
            $tmpName = $_FILES['CSVfile']['tmp_name'];
            $csvContent = file_get_contents($tmpName);
            if (!$csvImport->auto($tmpName)) {
                $dialogBox->error(get_lang('Unable to read the content of the CSV'));
예제 #7
0
 /**
  * Import and Export data from/to csv
  * @author  Reto Kohli <*****@*****.**> (parts)
  */
 function _import()
 {
     global $_ARRAYLANG, $objDatabase;
     self::$pageTitle = $_ARRAYLANG['TXT_SHOP_IMPORT_TITLE'];
     self::$objTemplate->loadTemplateFile('module_shop_import.html');
     self::$objTemplate->setGlobalVariable(array('TXT_SHOP_IMPORT_CATEGORIES_TIPS' => contrexx_raw2xhtml($_ARRAYLANG['TXT_SHOP_IMPORT_CATEGORIES_TIPS']), 'TXT_SHOP_IMPORT_CHOOSE_TEMPLATE_TIPS' => contrexx_raw2xhtml($_ARRAYLANG['TXT_SHOP_IMPORT_CHOOSE_TEMPLATE_TIPS'])));
     $objCSVimport = new CsvImport();
     // Delete template
     if (isset($_REQUEST['deleteImg'])) {
         $query = "\n                DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_importimg\n                 WHERE img_id=" . $_REQUEST['img'];
         if ($objDatabase->Execute($query)) {
             \Message::ok($_ARRAYLANG['TXT_SHOP_IMPORT_SUCCESSFULLY_DELETED']);
         } else {
             \Message::error($_ARRAYLANG['TXT_SHOP_IMPORT_ERROR_DELETE']);
         }
     }
     // Save template
     if (isset($_REQUEST['SaveImg'])) {
         $query = "\n                INSERT INTO " . DBPREFIX . "module_shop" . MODULE_INDEX . "_importimg (\n                    img_name, img_cats, img_fields_file, img_fields_db\n                ) VALUES (\n                    '" . $_REQUEST['ImgName'] . "',\n                    '" . $_REQUEST['category'] . "',\n                    '" . $_REQUEST['pairs_left_keys'] . "',\n                    '" . $_REQUEST['pairs_right_keys'] . "'\n                )";
         if ($objDatabase->Execute($query)) {
             \Message::ok($_ARRAYLANG['TXT_SHOP_IMPORT_SUCCESSFULLY_SAVED']);
         } else {
             \Message::error($_ARRAYLANG['TXT_SHOP_IMPORT_ERROR_SAVE']);
         }
     }
     $objCSVimport->initTemplateArray();
     $fileExists = false;
     $fileName = isset($_POST['csvFile']) ? contrexx_input2raw($_POST['csvFile']) : '';
     $uploaderId = isset($_POST['importCsvUploaderId']) ? contrexx_input2raw($_POST['importCsvUploaderId']) : '';
     if (!empty($fileName) && !empty($uploaderId)) {
         $objSession = \cmsSession::getInstance();
         $tmpFile = $objSession->getTempPath() . '/' . $uploaderId . '/' . $fileName;
         $fileExists = \Cx\Lib\FileSystem\FileSystem::exists($tmpFile);
     }
     // Import Categories
     // This is not subject to change, so it's hardcoded
     if (isset($_REQUEST['ImportCategories']) && $fileExists) {
         // delete existing categories on request only!
         // mind that this necessarily also clears all products and
         // their associated attributes!
         if (!empty($_POST['clearCategories'])) {
             Products::deleteByShopCategory(0, false, true);
             ShopCategories::deleteAll();
             // NOTE: Removing Attributes is now disabled.  Optionally enable this.
             //                Attributes::deleteAll();
         }
         $objCsv = new CsvBv($tmpFile);
         $importedLines = 0;
         $arrCategoryLevel = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
         $line = $objCsv->NextLine();
         while ($line) {
             $level = 0;
             foreach ($line as $catName) {
                 ++$level;
                 if (!empty($catName)) {
                     $parentCatId = $objCSVimport->getCategoryId($catName, $arrCategoryLevel[$level - 1]);
                     $arrCategoryLevel[$level] = $parentCatId;
                 }
             }
             ++$importedLines;
             $line = $objCsv->NextLine();
         }
         \Message::ok($_ARRAYLANG['TXT_SHOP_IMPORT_SUCCESSFULLY_IMPORTED_CATEGORIES'] . ': ' . $importedLines);
     }
     // Import
     if (isset($_REQUEST['importFileProducts']) && $fileExists) {
         if (isset($_POST['clearProducts']) && $_POST['clearProducts']) {
             Products::deleteByShopCategory(0, false, true);
             // The categories need not be removed, but it is done by design!
             ShopCategories::deleteAll();
             // NOTE: Removing Attributes is now disabled.  Optionally enable this.
             //                Attributes::deleteAll();
         }
         $arrFileContent = $objCSVimport->GetFileContent($tmpFile);
         $query = '
             SELECT img_id, img_name, img_cats, img_fields_file, img_fields_db
               FROM ' . DBPREFIX . 'module_shop' . MODULE_INDEX . '_importimg
              WHERE img_id=' . $_REQUEST['ImportImage'];
         $objResult = $objDatabase->Execute($query);
         $arrCategoryName = preg_split('/;/', $objResult->fields['img_cats'], null, PREG_SPLIT_NO_EMPTY);
         $arrFirstLine = $arrFileContent[0];
         $arrCategoryColumnIndex = array();
         for ($x = 0; $x < count($arrCategoryName); ++$x) {
             foreach ($arrFirstLine as $index => $strColumnName) {
                 if ($strColumnName == $arrCategoryName[$x]) {
                     $arrCategoryColumnIndex[] = $index;
                 }
             }
         }
         $arrTemplateFieldName = preg_split('/;/', $objResult->fields['img_fields_file'], null, PREG_SPLIT_NO_EMPTY);
         $arrDatabaseFieldIndex = array();
         for ($x = 0; $x < count($arrTemplateFieldName); ++$x) {
             foreach ($arrFirstLine as $index => $strColumnName) {
                 if ($strColumnName == $arrTemplateFieldName[$x]) {
                     $arrDatabaseFieldIndex[] = $index;
                 }
             }
         }
         $arrProductFieldName = preg_split('/;/', $objResult->fields['img_fields_db'], null, PREG_SPLIT_NO_EMPTY);
         $arrProductDatabaseFieldName = array();
         for ($x = 0; $x < count($arrProductFieldName); ++$x) {
             $dbname = $objCSVimport->DBfieldsName($arrProductFieldName[$x]);
             $arrProductDatabaseFieldName[$dbname] = (isset($arrProductDatabaseFieldName[$dbname]) ? $arrProductDatabaseFieldName[$dbname] . ';' : '') . $x;
         }
         $importedLines = 0;
         $errorLines = 0;
         // Array of IDs of newly inserted records
         $arrId = array();
         for ($x = 1; $x < count($arrFileContent); ++$x) {
             $category_id = false;
             for ($cat = 0; $cat < count($arrCategoryColumnIndex); ++$cat) {
                 $catName = $arrFileContent[$x][$arrCategoryColumnIndex[$cat]];
                 if (empty($catName) && !empty($category_id)) {
                     break;
                 }
                 if (empty($catName)) {
                     $category_id = $objCSVimport->GetFirstCat();
                 } else {
                     $category_id = $objCSVimport->getCategoryId($catName, $category_id);
                 }
             }
             if ($category_id == 0) {
                 $category_id = $objCSVimport->GetFirstCat();
             }
             $objProduct = new Product('', $category_id, '', Distribution::TYPE_DELIVERY, 0, 1, 0, 0, 0);
             foreach ($arrProductDatabaseFieldName as $index => $strFieldIndex) {
                 $value = '';
                 if (strpos($strFieldIndex, ';')) {
                     $prod2line = explode(';', $strFieldIndex);
                     for ($z = 0; $z < count($prod2line); ++$z) {
                         $value .= $arrFileContent[$x][$arrDatabaseFieldIndex[$prod2line[$z]]] . '<br />';
                     }
                 } else {
                     $value = $arrFileContent[$x][$arrDatabaseFieldIndex[$strFieldIndex]];
                 }
                 $objProduct->{$index}($value);
             }
             if ($objProduct->store()) {
                 $arrId[] = $objProduct->id();
                 ++$importedLines;
             } else {
                 ++$errorLines;
             }
         }
         // Fix picture field and create thumbnails
         Products::makeThumbnailsById($arrId);
         if ($importedLines) {
             \Message::ok($_ARRAYLANG['TXT_SHOP_IMPORT_SUCCESSFULLY_IMPORTED_PRODUCTS'] . ': ' . $importedLines);
         }
         if ($errorLines) {
             \Message::error($_ARRAYLANG['TXT_SHOP_IMPORT_NOT_SUCCESSFULLY_IMPORTED_PRODUCTS'] . ': ' . $errorLines);
         }
     }
     // end import
     $jsnofiles = '';
     $fileFields = $dblist = null;
     $arrTemplateArray = $objCSVimport->getTemplateArray();
     if (isset($_REQUEST['mode']) && $_REQUEST['mode'] != 'ImportImg') {
         if (count($arrTemplateArray) == 0) {
             self::$objTemplate->hideBlock('import_products');
             self::$objTemplate->touchBlock('import_products_no_template');
         } else {
             $imageChoice = $objCSVimport->GetImageChoice();
             self::$objTemplate->setVariable(array('IMAGE_CHOICE' => $imageChoice));
         }
     } else {
         if (!isset($_REQUEST['SelectFields'])) {
             $jsnofiles = "selectTab('import1');";
         } else {
             if (isset($_POST['mode']) && $_POST['csvFile'] == '') {
                 $jsnofiles = "selectTab('import4');";
             } else {
                 $jsnofiles = "selectTab('import2');";
                 if ($fileExists) {
                     $fileFields = '
                         <select name="FileFields" id="file_field" style="width: 200px;" size="10">
                             ' . $objCSVimport->getFilefieldMenuOptions($tmpFile) . '
                         </select>' . "\n";
                 }
                 $dblist = '
                     <select name="DbFields" id="given_field" style="width: 200px;" size="10">
                         ' . $objCSVimport->getAvailableNamesMenuOptions() . '
                     </select>' . "\n";
             }
         }
     }
     $jsSelectLayer = 'selectTab("import1");';
     if (isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'ImportImg') {
         $jsSelectLayer = 'selectTab("import2");';
     }
     $arrTemplateArray = $objCSVimport->getTemplateArray();
     if ($arrTemplateArray) {
         $arrName = $objCSVimport->getNameArray();
         self::$objTemplate->setVariable('SHOP_IMPORT_TEMPLATE_MENU', \Html::getSelect('ImportImage', $arrName));
     } else {
         self::$objTemplate->touchBlock('import_products_no_template');
     }
     for ($x = 0; $x < count($arrTemplateArray); ++$x) {
         self::$objTemplate->setVariable(array('IMG_NAME' => $arrTemplateArray[$x]['name'], 'IMG_ID' => $arrTemplateArray[$x]['id'], 'CLASS_NAME' => 'row' . ($x % 2 + 1), 'SHOP_CMS_OFFSET' => \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteOffsetPath()));
         self::$objTemplate->parse('imgRow');
     }
     //initialize the uploader
     $uploader = new \Cx\Core_Modules\Uploader\Model\Entity\Uploader();
     //create an uploader
     $uploader->setCallback('importUploaderCallback');
     $uploader->setOptions(array('id' => 'importCsvUploader', 'allowed-extensions' => array('csv', 'xls'), 'data-upload-limit' => 1, 'style' => 'display:none'));
     self::$objTemplate->setVariable(array('SELECT_LAYER_ONLOAD' => $jsSelectLayer, 'NO_FILES' => isset($jsnofiles) ? $jsnofiles : '', 'FILE_FIELDS_LIST' => isset($fileFields) ? $fileFields : '', 'DB_FIELDS_LIST' => isset($dblist) ? $dblist : '', 'SHOP_IMPORT_CSV_UPLOADER_CODE' => $uploader->getXHtml(), 'SHOP_IMPORT_CSV_UPLOADER_ID' => $uploader->getId()));
     // TODO: !!! CSV EXPORT IS OBSOLETE AND DYSFUNCT !!!
     /*
             // Export groups -- hardcoded
             $content_location = '';
             if (isset($_REQUEST['group'])) {
                 $query = $fieldNames = $content_location = '';
                 $arrPictures = null;
                 switch ($_REQUEST['group']) {
                     // products - plain fields:
                     case 'tproduct':
                         $content_location = "ProdukteTabelle.csv";
                         $fieldNames = array(
                             'id', 'product_id', 'picture', 'title', 'catid', 'distribution',
                             'normalprice', 'resellerprice', 'short', 'long',
                             'stock', 'stock_visible', 'discountprice', 'discount_active',
                             'active', 'b2b', 'b2c', 'date_start', 'date_end',
                             'manufacturer', 'manufacturer_url', 'external_link',
                             'ord', 'vat_id', 'weight',
                             'flags', 'group_id', 'article_id', 'keywords', );
                         $query = "
                             SELECT id, product_id, picture, title, catid, distribution,
                                    normalprice, resellerprice, short, long,
                                    stock, stock_visible, discountprice, discount_active,
                                    active, b2b, b2c, date_start, date_end,
                                    manufacturer, manufacturer_url, external_link,
                                    sort_order, vat_id, weight,
                                    flags, group_id, article_id, keywords
                               FROM ".DBPREFIX."module_shop_products
                              ORDER BY id ASC";
                         break;
                     // products - custom:
                     case 'rproduct':
                         $content_location = "ProdukteRelationen.csv";
                         $fieldNames = array(
                             'id', 'product_id', 'picture', 'title',
                             'catid', 'category', 'parentcategory', 'distribution',
                             'normalprice', 'resellerprice', 'discountprice', 'discount_active',
                             'short', 'long',
                             'stock', 'stock_visible',
                             'active', 'b2b', 'b2c',
                             'date_start', 'date_end',
                             'manufacturer_name', 'manufacturer_website',
                             'manufacturer_url', 'external_link',
                             'ord',
                             'vat_percent', 'weight',
                             'discount_group', 'article_group', 'keywords', );
                         // c1.catid *MUST NOT* be NULL
                         // c2.catid *MAY* be NULL (if c1.catid is root)
                         // vat_id *MAY* be NULL
                         $query = "
                             SELECT p.id, p.product_id, p.picture, p.title,
                                    p.catid, c1.catname as category, c2.catname as parentcategory, p.distribution,
                                    p.normalprice, p.resellerprice, p.discountprice, p.discount_active,
                                    p.short, p.long, p.stock, p.stock_visible,
                                    p.active, p.b2b, p.b2c, p.date_start, p.date_end,
                                    m.name as manufacturer_name,
                                    m.url as manufacturer_website,
                                    p.manufacturer_url, p.external_link,
                                    p.ord,
                                    v.percent as vat_percent, p.weight,
                                    d.name AS discount_group,
                                    a.name AS article_group,
                                    p.keywords
                               FROM ".DBPREFIX."module_shop_products p
                              INNER JOIN ".DBPREFIX."module_shop_categories c1 ON p.catid=c1.catid
                               LEFT JOIN ".DBPREFIX."module_shop_categories c2 ON c1.parentid=c2.catid
                               LEFT JOIN ".DBPREFIX."module_shop_vat v ON vat_id=v.id
                               LEFT JOIN ".DBPREFIX."module_shop_manufacturer as m ON m.id = p.manufacturer
                               LEFT JOIN ".DBPREFIX."module_shop_discountgroup_count_name as d ON d.id = p.group_id
                               LEFT JOIN ".DBPREFIX."module_shop_article_group as a ON a.id = p.article_id
                              ORDER BY catid ASC, product_id ASC";
                         break;
                     // customer - plain fields:
     // TODO: Use Customer class!
                     case 'tcustomer':
                         $content_location = "KundenTabelle.csv";
                         $fieldNames = array(
                             'customerid', 'username', 'password', 'prefix', 'company', 'firstname', 'lastname',
                             'address', 'city', 'zip', 'country_id', 'phone', 'fax', 'email',
                             'ccnumber', 'ccdate', 'ccname', 'cvc_code', 'company_note',
                             'is_reseller', 'register_date', 'customer_status', 'group_id', );
                         $query = "
                             SELECT customerid, username, password, prefix, company, firstname, lastname,
                                    address, city, zip, country_id, phone, fax, email,
                                    ccnumber, ccdate, ccname, cvc_code, company_note,
                                    is_reseller, register_date, customer_status,
                                    group_id
                               FROM ".DBPREFIX."module_shop_customers
                              ORDER BY lastname ASC, firstname ASC";
                         break;
                     // customer - custom:
     // TODO: Use Customer class!
                     case 'rcustomer':
                         $content_location = "KundenRelationen.csv";
                         $fieldNames = array(
                             'customerid', 'username', 'firstname', 'lastname', 'prefix', 'company',
                             'address', 'zip', 'city', 'countries_name',
                             'phone', 'fax', 'email', 'is_reseller', 'register_date', 'group_name', );
                         $query = "
                             SELECT c.customerid, c.username, c.firstname, c.lastname, c.prefix, c.company,
                                    c.address, c.zip, c.city, n.countries_name,
                                    c.phone, c.fax, c.email, c.is_reseller, c.register_date,
                                    d.name AS group_name
                               FROM ".DBPREFIX."module_shop_customers c
                              INNER JOIN ".DBPREFIX."module_shop_countries n ON c.country_id=n.countries_id
                               LEFT JOIN ".DBPREFIX."module_shop_customer_group d ON c.group_id=d.id
                              ORDER BY c.lastname ASC, c.firstname ASC";
                         break;
                     // orders - plain fields:
                     case 'torder':
                         $content_location = "BestellungenTabelle.csv";
                         $fieldNames = array(
                             'id', 'customer_id', 'currency_id', 'order_sum', 'sum',
                             'date_time', 'status', 'ship_prefix', 'ship_company', 'ship_firstname', 'ship_lastname',
                             'ship_address', 'ship_city', 'ship_zip', 'ship_country_id', 'ship_phone',
                             'vat_amount', 'currency_ship_price', 'shipment_id', 'payment_id', 'currency_payment_price',
                             'ip', 'host', 'lang_id', 'browser', 'note',
                             'last_modified', 'modified_by');
                         $query = "
                             SELECT id, customer_id, currency_id, order_sum, sum,
                                    date_time, status, ship_prefix, ship_company, ship_firstname, ship_lastname,
                                    ship_address, ship_city, ship_zip, ship_country_id, ship_phone,
                                    vat_amount, currency_ship_price, shipment_id, payment_id, currency_payment_price,
                                    ip, host, lang_id, browser, note,
                                    last_modified, modified_by
                               FROM ".DBPREFIX."module_shop".MODULE_INDEX."_orders
                              ORDER BY id ASC";
                         break;
                     // orders - custom:
                     case 'rorder':
     // TODO: Use Customer class!
                         $content_location = "BestellungenRelationen.csv";
                         $fieldNames = array(
                             'id', 'order_sum', 'vat_amount', 'currency_ship_price', 'currency_payment_price',
                             'sum', 'date_time', 'status', 'ship_prefix', 'ship_company',
                             'ship_firstname', 'ship_lastname', 'ship_address', 'ship_city', 'ship_zip',
                             'ship_phone', 'note',
                             'customer_id', 'username', 'firstname', 'lastname', 'prefix', 'company',
                             'address', 'zip', 'city', 'countries_name',
                             'phone', 'fax', 'email', 'is_reseller', 'register_date',
                             'currency_code', 'shipper_name', 'payment_name',
                             'account_number', 'bank_name', 'bank_code');
                         $query = "
                             SELECT o.id, o.order_sum, o.vat_amount, o.currency_ship_price, o.currency_payment_price,
                                    o.sum, o.date_time, o.status, o.ship_prefix, o.ship_company,
                                    o.ship_firstname, o.ship_lastname, o.ship_address, o.ship_city, o.ship_zip,
                                    o.ship_phone, o.note,
                                    o.customer_id,
                                    c.username, c.firstname, c.lastname, c.prefix, c.company,
                                    c.address, c.zip, c.city, n.countries_name,
                                    c.phone, c.fax, c.email, c.is_reseller, c.register_date,
                                    u.code AS currency_code, s.name AS shipper_name, p.name AS payment_name,
                                    l.holder, l.bank, l.blz
                               FROM ".DBPREFIX."module_shop_orders o
                              INNER JOIN ".DBPREFIX."module_shop_customers c ON o.customer_id=c.customerid
                              INNER JOIN ".DBPREFIX."module_shop_countries n ON c.country_id=n.countries_id
                              INNER JOIN ".DBPREFIX."module_shop_currencies u ON o.currency_id=u.id
                               LEFT JOIN ".DBPREFIX."module_shop_shipper s ON o.shipment_id=s.id
                               LEFT JOIN ".DBPREFIX."module_shop_payment p ON o.payment_id=p.id
                               LEFT JOIN ".DBPREFIX."module_shop_lsv l ON o.id=l.order_id
                              ORDER BY o.id ASC";
                         break;
                 } // switch
     
                 if ($query && $objResult = $objDatabase->Execute($query)) {
                     // field names
                     $fileContent = '"'.join('";"', $fieldNames)."\"\n";
                     while (!$objResult->EOF) {
                         $arrRow = $objResult->FetchRow();
                         $arrReplaced = array();
                         // Decode the pictures
                         foreach ($arrRow as $index => $field) {
                             if ($index == 'picture') {
                                 $arrPictures = Products::get_image_array_from_base64($field);
                                 $field =
                                     'http://'.
                                     $_SERVER['HTTP_HOST'].'/'.
                                     ASCMS_SHOP_IMAGES_WEB_PATH.'/'.
                                     $arrPictures[1]['img'];
                             }
                             $arrReplaced[] = str_replace('"', '""', $field);
                         }
                         $fileContent .= '"'.join('";"', $arrReplaced)."\"\n";
                     }
                     // Test the output for UTF8!
                     if (strtoupper(CONTREXX_CHARSET) == 'UTF-8') {
                         $fileContent = utf8_decode($fileContent);
                     }
     // TODO: Add success message?
                     // set content to filename and -type for download
                     header("Content-Disposition: inline; filename=$content_location");
                     header("Content-Type: text/comma-separated-values");
                     echo($fileContent);
                     exit();
                 }
                 \Message::error($_ARRAYLANG['TXT_SHOP_EXPORT_ERROR']);
             } else {
                 // can't submit without a group selection
             } // if/else group
             // end export
     
             // make sure that language entries exist for all of
             // TXT_SHOP_EXPORT_GROUP_*, TXT_SHOP_EXPORT_GROUP_*_TIP !!
             $arrGroups = array('tproduct', 'rproduct', 'tcustomer', 'rcustomer', 'torder', 'rorder');
             $tipText = '';
             for ($i = 0; $i < count($arrGroups); ++$i) {
                 self::$objTemplate->setCurrentBlock('groupRow');
                 self::$objTemplate->setVariable(array(
                     'SHOP_EXPORT_GROUP' => $_ARRAYLANG['TXT_SHOP_EXPORT_GROUP_'.strtoupper($arrGroups[$i])],
                     'SHOP_EXPORT_GROUP_CODE' => $arrGroups[$i],
                     'SHOP_EXPORT_INDEX' => $i,
                     'CLASS_NAME' => 'row'.($i % 2 + 1),
                 ));
                 self::$objTemplate->parse('groupRow');
                 $tipText .= 'Text['.$i.']=["","'.$_ARRAYLANG['TXT_SHOP_EXPORT_GROUP_'.strtoupper($arrGroups[$i]).'_TIP'].'"];';
             }
     */
 }
예제 #8
0
#FIX Aumentar y deben ser opcionales el numero de campos a importar.
#FIX Modificar de tal forma Que sea opcional el campo de ISBN
#FIX Documentar todo lo referente en el HELP
$tab = "cataloging";
$nav = "csv_import";
$helpPage = "CsvImport";
$cancelLocation = "../catalog/index.php";
require_once "../shared/common.php";
require_once "../shared/logincheck.php";
require_once "../classes/Localize.php";
require_once "../functions/inputFuncs.php";
$loc = new Localize(OBIB_LOCALE, $tab);
require_once "../shared/header.php";
if (isset($_POST['submit'])) {
    require_once "../classes/CsvImport.php";
    $ci = new CsvImport();
    $status = $ci->importFromCsv($_FILES['upload']);
    // Report.
    echo <<<INNERHTML
<h1>{$loc->getText('CSVImportHeader')}</h1>

INNERHTML;
    if (isset($status['error'])) {
        if (isset($status['pos'])) {
            $status['error'] .= ' @ ' . $status['pos'];
        }
        echo <<<INNERHTML
<div id="errorMsg">
Error: {$status[error]}
</div>
<a href="csv_import.php">{$loc->getText('CSVImportContinue')}</a>