Commit 1de41db4 authored by philippe's avatar philippe
Browse files

Export products function

parent 31cbb1a1
......@@ -679,4 +679,4 @@ function get_report($module, $name) {
} else {
return NULL;
}
}
\ No newline at end of file
}
......@@ -46,49 +46,38 @@ foreach ($products as $product) {
<!-- start bloc titre -->
<div class="blc_ti">
<h1><?php \pi18n("Products", PLUGIN_NAME); ?></h1>
<span class="nb_article"><?php \pi18n("%d products", PLUGIN_NAME, count($products)); ?></span>
<ul class="bt_fonction">
<li><?php \Pasteque\tpl_btn('btn bt_add ', \Pasteque\get_module_url_action(PLUGIN_NAME, "product_edit"),
\i18n('Add a product', PLUGIN_NAME), 'img/btn_add.png');?></li>
<li><?php \Pasteque\tpl_btn('btn bt_import ', \Pasteque\get_module_url_action(PLUGIN_NAME, "productsManagement"),
\i18n('Import products', PLUGIN_NAME), 'img/btn_add.png');?></li>
</ul>
<h1><?php \pi18n("Products", PLUGIN_NAME); ?></h1>
<span class="nb_article"><?php \pi18n("%d products", PLUGIN_NAME, count($products)); ?></span>
<ul class="bt_fonction">
<li><?php \Pasteque\tpl_btn('btn bt_add ', \Pasteque\get_module_url_action(PLUGIN_NAME, "product_edit"),
\i18n('Add a product', PLUGIN_NAME), 'img/btn_add.png');?></li>
<li><?php \Pasteque\tpl_btn('btn bt_import ', \Pasteque\get_module_url_action(PLUGIN_NAME, "productsManagement"),
\i18n('Import products', PLUGIN_NAME), 'img/btn_add.png');?></li>
<li><?php \Pasteque\tpl_btn('btn bt_export ', \Pasteque\get_report_url(PLUGIN_NAME, "products_export"),
\i18n('Export products', PLUGIN_NAME), 'img/btn_add.png');?></li>
</ul>
</div>
<!-- end bloc titre -->
<!-- start container scroll -->
<div class="container_scroll">
<div class="stick_row stickem-container">
<div class="stick_row stickem-container">
<!-- start colonne contenu -->
<div id="content_liste" class="grid_9">
<div class="blc_content">
<?php \Pasteque\tpl_msg_box($message, $error); ?>
<?php
$par = false;
$archive = false;
foreach ($categories as $category) {
if (isset($prdCat[$category->id])) {
$ancre = \Pasteque\esc_html($category->label);
$ancre = str_replace(' ','',$ancre);
$anchor = \Pasteque\esc_html($category->label);
$anchor = str_replace(' ','',$anchor);
?>
<h2 id="<?php echo $ancre; ?>"><?php echo \Pasteque\esc_html($category->label); ?></h2>
<h2 id="<?php echo $anchor; ?>"><?php echo \Pasteque\esc_html($category->label); ?></h2>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
......@@ -136,16 +125,13 @@ $ancre = str_replace(' ','',$ancre);
?>
<?php if ($archive) { ?>
<?php if ($archive) {
foreach ($categories as $category) {
if (isset($archivesCat[$category->id])) {
$ancre = \Pasteque\esc_html($category->label);
$ancre = str_replace(' ','',$ancre);
$anchor = \Pasteque\esc_html($category->label);
$anchor = str_replace(' ','',$anchor);
?>
<h2 id="<?php echo $ancre; ?>"><?php echo \Pasteque\esc_html($category->label); ?></h2>
<h2 id="<?php echo $anchor; ?>"><?php echo \Pasteque\esc_html($category->label); ?></h2>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
......@@ -192,16 +178,12 @@ if (count($products) == 0) {
</div></div>
<!-- end colonne contenu -->
<!-- start sidebar menu -->
<div id="sidebar_menu" class="grid_3 stickem">
<div class="blc_content visible">
<ul id="menu_site">
<li>
<a href="#">Accès rapide</a>
<!--
<ul>
<li><a href="#cat_1" class="scroll">Formules</a></li>
......@@ -210,60 +192,37 @@ if (count($products) == 0) {
<li><a href="#" class="scroll">Sandwich</a></li>
</ul>
-->
<ul>
<ul>
<?php
$par = false;
$archive = false;
foreach ($categories as $category) {
if (isset($prdCat[$category->id])) {
$ancre = \Pasteque\esc_html($category->label);
$ancre = str_replace(' ','',$ancre);
?>
<li><a href="#<?php echo $ancre; ?>" class="scroll"><?php echo \Pasteque\esc_html($category->label); ?></a></li>
$anchor = \Pasteque\esc_html($category->label);
$anchor = str_replace(' ','',$anchor);
?>
<li><a href="#<?php echo $anchor; ?>" class="scroll"><?php echo \Pasteque\esc_html($category->label); ?></a></li>
<?php
}
}
?>
<?php if ($archive) { ?>
<?php
if ($archive) {
foreach ($categories as $category) {
if (isset($archivesCat[$category->id])) {
$ancre = \Pasteque\esc_html($category->label);
$ancre = str_replace(' ','',$ancre);
$anchor = \Pasteque\esc_html($category->label);
$anchor = str_replace(' ','',$anchor);
?>
<li><a href="#<?php echo $ancre; ?>" class="scroll"><?php echo \Pasteque\esc_html($category->label); ?></a></li>
<li><a href="#<?php echo $anchor; ?>" class="scroll"><?php echo \Pasteque\esc_html($category->label); ?></a></li>
<?php
}
}
} // archive end ?>
</ul>
</ul>
</li>
</ul>
</div>
</div>
<!-- end sidebar menu -->
</div>
</div>
<!-- end container scroll -->
\ No newline at end of file
</div>
</div>
<!-- end container scroll -->
......@@ -4,7 +4,6 @@ namespace BaseProducts;
// open csv return null if the file selected had not extension "csv"
// or user not selected file
function init_csv() {
if ($_FILES['csv']['tmp_name'] === NULL) {
return NULL;
}
......@@ -46,8 +45,8 @@ function initArray($key, $tab) {
}
return $array;
}
function import_csv($csv) {
function import_csv($csv) {
$error = 0;
$create = 0;
$update = 0;
......@@ -232,57 +231,59 @@ if (isset($_FILES['csv'])) {
}
?>
<!-- start bloc titre -->
<div class="blc_ti">
<h1><?php \pi18n("Import products from csv file", PLUGIN_NAME); ?></h1>
</div>
<!-- end bloc titre -->
<div class="blc_ti">
<h1><?php \pi18n("Import or export products", PLUGIN_NAME); ?></h1>
</div>
<!-- start container scroll -->
<div class="container_scroll">
<div class="stick_row stickem-container">
<!-- start colonne contenu -->
<div id="content_liste" class="grid_9">
<div class="blc_content">
<?php \Pasteque\tpl_msg_box($message, $error); ?>
<form class="edit" method="post" action="<?php echo \Pasteque\get_module_url_action(PLUGIN_NAME, 'productsManagement');?>" enctype="multipart/form-data">
<div class="row">
<label for='csv' >
<?php \pi18n("File", PLUGIN_NAME) ?>:
</label>
<input type="file" name="csv">
</div>
<div class="row actions">
<button class="btn-send" type="submit" id="envoyer" name="envoyer" >
<?php \pi18n("send", PLUGIN_NAME)?>
</button>
</div>
</form>
</div></div>
<!-- end colonne contenu -->
<!-- start sidebar menu -->
<div id="sidebar_menu" class="grid_3 stickem">
<div class="blc_content">
<!-- start texte editorial -->
<div class="edito"><!-- zone_edito --></div>
<!-- end texte editorial -->
</div>
<div class="stick_row stickem-container">
<div id="content_liste" class="grid_9">
<div class="blc_content">
<div class="blc_ti">
<h2 id="import"><?php \pi18n("Import products from csv file", PLUGIN_NAME); ?></h2>
</div>
<?php \Pasteque\tpl_msg_box($message, $error); ?>
<form class="edit" method="post" action="<?php echo \Pasteque\get_module_url_action(PLUGIN_NAME, 'productsManagement');?>" enctype="multipart/form-data">
<div class="row">
<label for='csv' >
<?php \pi18n("File", PLUGIN_NAME) ?>:
</label>
<input type="file" name="csv">
</div>
<div class="row actions">
<button class="btn-send" type="submit" id="<?php \pi18n("send", PLUGIN_NAME)?>" name="<?php \pi18n("send", PLUGIN_NAME)?>" >
<?php \pi18n("send", PLUGIN_NAME)?>
</button>
</div>
</form>
<div class="blc_ti">
<h2 id="export"><?php \pi18n("Export products as csv file", PLUGIN_NAME); ?></h2>
</div>
<?php \Pasteque\tpl_msg_box($message, $error); ?>
<form class="edit" method="post" action="<?php echo \Pasteque\get_report_url(PLUGIN_NAME, 'products_export');?>" enctype="multipart/form-data">
<div class="row">
</div>
<!-- end sidebar menu -->
</div>
</div>
<!-- end container scroll -->
\ No newline at end of file
<input type="hidden" name="action" value="export" />
<div class="row actions">
<button class="btn-export" type="submit" id="<?php \pi18n("export", PLUGIN_NAME)?>" name="<?php \pi18n("export", PLUGIN_NAME)?>" >
<?php \pi18n("export", PLUGIN_NAME)?>
</button>
</div>
</form>
</div>
</div>
<div id="sidebar_menu" class="grid_3 stickem">
<div class="blc_content visible">
<ul id="menu_site">
<li>
<a href="#">Accès rapide</a>
<ul>
<li><a href="#import" class="scroll"><?php \pi18n("Import products from csv file", PLUGIN_NAME); ?></a></li>
<li><a href="#export" class="scroll"><?php \pi18n("Export products as csv file", PLUGIN_NAME); ?></a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
......@@ -45,6 +45,7 @@
"Import products": "Importer des produits",
"Import products from csv file": "Importer des produits à partir d'un fichier csv",
"Export products": "Exporter les produits",
"On line %d: Cannot create product: '%s'": "À la ligne %d: Impossible de créer le produit: '%s'",
"On line %d: Cannot update update: '%s'": "À la ligne %d: Impossible de mettre a jour le produit: '%s'",
"On line %d: Category parent doesn't exist": "À la ligne %d: La categorie parent n'existe pas",
......
<?php
// Pastèque Web back office, Users module
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
namespace BaseProducts;
$sql = "SELECT REFERENCE as reference, PRODUCTS.NAME AS label, CODE AS barcode, PRICEBUY AS pricebuy, ISSCALE AS scaled, DISCOUNTENABLED AS discount_enabled, DISCOUNTRATE AS discount_rate, ROUND(PRODUCTS.PRICESELL*(1+TAXES.RATE),2) AS sellVat, "
. " CATEGORIES.NAME AS category, TAXCATEGORIES.NAME AS tax_cat "
. " FROM PRODUCTS "
. " LEFT JOIN CATEGORIES ON CATEGORIES.ID = PRODUCTS.CATEGORY "
. " LEFT JOIN PRODUCTS_CAT ON PRODUCTS_CAT.PRODUCT = PRODUCTS.ID "
. " LEFT JOIN TAXCATEGORIES ON PRODUCTS.TAXCAT = TAXCATEGORIES.ID "
. " LEFT JOIN TAXES ON TAXCATEGORIES.ID = TAXES.CATEGORY "
. " WHERE PRODUCTS.DELETED = 0 "
. " ORDER BY PRODUCTS.NAME";
$fields = array("label","reference","sellVat","tax_cat","category","barcode","price_buy","scaled","disp_order","discount_enabled","discount_rate");
$headers = $fields;
$report = new \Pasteque\Report(PLUGIN_NAME, "products_export",
\i18n("Export products", PLUGIN_NAME),
$sql, $headers, $fields);
\Pasteque\register_report($report);
......@@ -30,4 +30,4 @@ function init() {
$MENU->registerModuleReport("sales", PLUGIN_NAME, "menu_tax.png", "Taxes report", "taxes_report");
\Pasteque\register_i18n(PLUGIN_NAME);
}
\Pasteque\hook("module_load", __NAMESPACE__ . "\init");
\ No newline at end of file
\Pasteque\hook("module_load", __NAMESPACE__ . "\init");
......@@ -74,6 +74,7 @@ function report_csv($module, $name, $values) {
function init_data($data, $line, $field) {
$field = strtoupper($field);
if (isset($line[$field])) {
$data[] = $line[$field];
} else {
......@@ -136,4 +137,4 @@ default:
tpl_report($report);
tpl_close();
break;
}
\ No newline at end of file
}
......@@ -836,38 +836,36 @@ nav a.administration span { background: url(../imgs/ico_nav_reglage.png) no-repe
.blc_content form input[type="checkbox"] {
width:2.4em;
width:2.4em;
}
/* bouton action */
.blc_content form .row.actions {}
.blc_content form .btn-send {
display:block;
padding: 0.6em 1.4em;
background:#ff6319;
color:#fff;
float:right;
margin: 2em 4em 1em 0;
border:none;
font-size:1.2em;
-webkit-transition: all 0.5s ease-in-out;/* transition pour Chrome et Safari */
.blc_content form .btn-send, .blc_content form .btn-export {
display:block;
padding: 0.6em 1.4em;
background:#ff6319;
color:#fff;
float:right;
margin: 2em 4em 1em 0;
border:none;
font-size:1.2em;
-webkit-transition: all 0.5s ease-in-out;/* transition pour Chrome et Safari */
-moz-transition: all 0.5s ease-in-out;/* transition pour Firefox */
-o-transition: all 0.5s ease-in-out;/* transition pour Opéra */
transition: all 0.5s ease-in-out; /* on écrit cette ligne à la fin de façon à ce que ce soit elle qui soit prise en compte lorsque l'attribut transition sera pris en compte par tous les navigateurs */
}
}
.blc_content form .btn-send:hover {
cursor: pointer;
padding: 0.6em 1.8em;
background: #000000;
color:#fff;
}
.blc_content form .btn-send:after {
.blc_content form .btn-send:hover, .blc_content form .btn-export:hover {
cursor: pointer;
padding: 0.6em 1.8em;
background: #000000;
color:#fff;
}
.blc_content form .btn-send:after, .blc_content form .btn-export:after {
clear: both;
content: ".";
display: block;
......
......@@ -24,15 +24,11 @@ function tpl_open() {
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php \pi18n("Pastèque"); ?></title>
<link rel="icon" type="image/png" href="templates/pt2.0/img/icon.png" />
<script src="<?php echo get_template_url(); ?>/js/jquery_1.8.1.js"></script>
<!-- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> -->
<!-- fancybox -->
<script type="text/javascript" src="<?php echo get_template_url(); ?>/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php \pi18n("Pastèque"); ?></title>
<link rel="icon" type="image/png" href="templates/pt2.0/img/icon.png" />
<script src="<?php echo get_template_url(); ?>/js/jquery_1.8.1.js"></script>
<script type="text/javascript" src="<?php echo get_template_url(); ?>/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="<?php echo get_template_url(); ?>/fancybox/jquery.easing-1.4.pack.js"></script>
<script type="text/javascript" src="<?php echo get_template_url(); ?>/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
......@@ -77,7 +73,6 @@ function tpl_open() {
$(document).ready(function(){
$('a[href^="#"]').on('click',function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
......@@ -115,10 +110,8 @@ function tpl_open() {
</script>
<script src="<?php echo get_template_url(); ?>/js/adapt.min.js"></script>
<!-- menu mobile -->
<link type="text/css" rel="stylesheet" href="<?php echo get_template_url(); ?>/css/jquery.mmenu.all.css" />
<!-- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> -->
<script type="text/javascript" src="<?php echo get_template_url(); ?>/js/jquery.mmenu.min.all.js"></script>
<script type="text/javascript">
$(function() {
......@@ -126,8 +119,8 @@ function tpl_open() {
});
</script>
<link href="<?php echo get_template_url(); ?>/css/styles_admin.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="<?php echo get_template_url(); ?>/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
<link href="<?php echo get_template_url(); ?>/css/styles_admin.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="<?php echo get_template_url(); ?>/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
</head>
<body>
......@@ -135,43 +128,35 @@ function tpl_open() {
<!-- START tpl open -->
<div id="page" class="">
<!-- start navigation mobile -->
<?php tpl_menu_mobile() ?>
<!-- start navigation mobile -->
<?php tpl_menu_mobile() ?>
<nav id="nav_main__mobile">
<?php tpl_menu(); ?>
<?php tpl_menu(); ?>
</nav>
<!-- end navigation mobile -->
<!-- start navigation PC -->
<!-- start navigation PC -->
<div id="nav_pc">
<!-- start bande header -->
<header>
<div class="container_12">
<!-- logo -->
<div class="logo"><img src="<?php echo get_template_url(); ?>/imgs/logo_worldline.png" width="247" height="69" alt="Worldline E-payment services" /></div>
</div>
</header>
<!-- end bande header -->
<div id="sticky_navigation_wrapper">
<div id="sticky_navigation">
<!-- start navigation standart -->
<nav id="nav_main">
<div class="container_12">
<?php tpl_menu(); ?>
</div>
<!-- start navigation standart -->
<nav id="nav_main">
<div class="container_12">
<?php tpl_menu(); ?>
</div>
</nav>
<!-- end navigation standart -->
</div>
</div>
</div>
</div>
</div>
<!-- end navigation PC -->
......@@ -270,21 +255,13 @@ function tpl_menu_mobile() {
}
function tpl_menu() {
global $MENU;
// ----------------------> gérer l'affichage du menu reglage
echo '
<!-- start navigation standart -->
<ul id="nav_services">';
// ----------------------> gérer les affichage de nom de class sur les boutons
// ----------------------> gérer l'affichage de la class "activ" sur le li en cours de consultation pour afficher le sous menu
// -> gérer les affichage de nom de class sur les boutons
// -> gérer l'affichage de la class "activ" sur le li en cours de consultation pour afficher le sous menu
foreach ($MENU->getSections() as $section) {
echo "\t<li class=\"" . strtolower($section->getName());
if ($section->isActive()) {
......@@ -329,8 +306,7 @@ function tpl_menu() {
<div class="clear"></div>
<!-- end navigation standart -->
';
<!-- end navigation standart -->';
}
function __tpl_report_title($report) {
......@@ -343,7 +319,7 @@ function __tpl_report_title($report) {
function __tpl_report_input($report, $values) {
// Export button
// Export button
echo '
<ul class="bt_fonction">
<li>
......@@ -353,37 +329,36 @@ function __tpl_report_input($report, $values) {
echo "&" . $param['param'] . "=" . $values[$param['param']];
}
echo '">' . \i18n("Export") . '</a>
</li></ul>
</div>
<!-- end bloc titre -->';
// Input form
echo "<div class=\"blc_content\"><form class=\"edit\" action=\"" . \Pasteque\get_current_url() . "\" "
. "method=\"post\">";
foreach($report->getParams() as $param) {
$id = $param['param'];
echo "<div class=\"row\">";
echo "<label for=\"" . $id . "\">" . $param['label'] . "</label>";
switch ($param['type']) {
case DB::