Commit 089a1f2b authored by philippepary's avatar philippepary
Browse files

all standard pages done, started extended modules ones

parent 8fea6177
......@@ -22,9 +22,9 @@
namespace BaseBackup;
//Title
\Pasteque\row(\Pasteque\mainTitle(\i18n("Backup", PLUGIN_NAME)));
echo \Pasteque\row(\Pasteque\mainTitle(\i18n("Backup", PLUGIN_NAME)));
//Hint
\Pasteque\row(\Pasteque\infoDiv(\i18n("Backup_help", PLUGIN_NAME)));
echo \Pasteque\row(\Pasteque\infoDiv(\i18n("Backup_help", PLUGIN_NAME)));
$user_id = \Pasteque\get_user_id();
$dbhost = \Pasteque\get_db_host($user_id);
......@@ -39,27 +39,26 @@ $dbport = \Pasteque\get_db_port($user_id);
// Tip: create a firewall rule to ban bruteforce on this randomstring
$dir = opendir("cache");
while(($f = readdir($dir)) != false) {
if(preg_match("/pasteque-[0-9]{8}-" . $database . "-.[a-z0-9]*.sql.gz/",$f) == 1) {
// old file's name (old date, old random string)
$filename = "cache/" . $f;
if(time() - filemtime($filename) > 86400) {
$cmd = "rm " . $filename;
exec($cmd);
// new file's name (new date, new random string)
$filename = "cache/pasteque-" . date("Ymd") . "-" . $database . "-" . md5(time() . rand(0,getrandmax())) . ".sql.gz";
$cmd = "mysqldump -u " . $dbuser . " --password=" . $dbpasswd . " " . $database ." --port=" . $dbport . "|gzip -c > " . $filename;
exec($cmd);
}
break;
}
if(preg_match("/pasteque-[0-9]{8}-" . $database . "-.[a-z0-9]*.sql.gz/",$f) == 1) {
// old file's name (old date, old random string)
$filename = "cache/" . $f;
if(time() - filemtime($filename) > 86400) {
$cmd = "rm " . $filename;
exec($cmd);
// new file's name (new date, new random string)
$filename = "cache/pasteque-" . date("Ymd") . "-" . $database . "-" . md5(time() . rand(0,getrandmax())) . ".sql.gz";
$cmd = "mysqldump -u " . $dbuser . " --password=" . $dbpasswd . " " . $database ." --port=" . $dbport . "|gzip -c > " . $filename;
exec($cmd);
}
break;
}
}
// We didn’t find a file, we generate one
if($filename == "") {
$filename = "cache/pasteque-" . date("Ymd") . "-" . $database . "-" . md5(time() . rand(0,getrandmax())) . ".sql.gz";
$cmd = "mysqldump -u " . $dbuser . " --password=" . $dbpasswd . " " . $database ." --port=" . $dbport . "|gzip -c > " . $filename;
exec($cmd);
$filename = "cache/pasteque-" . date("Ymd") . "-" . $database . "-" . md5(time() . rand(0,getrandmax())) . ".sql.gz";
$cmd = "mysqldump -u " . $dbuser . " --password=" . $dbpasswd . " " . $database ." --port=" . $dbport . "|gzip -c > " . $filename;
exec($cmd);
}
if(file_exists($filename)) {
echo \Pasteque\importButton(\i18n('Download backup', PLUGIN_NAME), $filename);
echo \Pasteque\importButton(\i18n('Download backup', PLUGIN_NAME), $filename);
}
......@@ -42,7 +42,7 @@ foreach ($sessions as $session) {
$content[$i][1] = \i18nDatetime($session->openDate);
$content[$i][2] = $session->tickets;
$content[$i][3] = \i18nCurr($session->total);
$content[$i][4] = "<a href=\"" . \Pasteque\get_module_url_action(PLUGIN_NAME, 'session_details', array('id' => $session->id)) . "\"><img src=\"" . \Pasteque\get_template_url() . "img/edit.png\" alt=\"" . \i18n('Edit') ."\" title=\"" . \i18n('Edit') ."\"></a>";
$content[$i][4] = \Pasteque\editButton(\i18n("Edit"), \Pasteque\get_module_url_action(PLUGIN_NAME, 'session_details', array('id' => $session->id)));
$i++;
}
}
......
<?php
// Pastèque Web back office, Currencies module
//
// Copyright (C) 2013 Scil (http://scil.coop)
// Copyright (C) 2013-2016 Scil (http://scil.coop)
// Philippe Pary philippe@scil.coop
//
// This file is part of Pastèque.
//
......@@ -25,54 +26,42 @@ namespace BaseCurrencies;
$message = NULL;
$error = NULL;
$currSrv = new \Pasteque\CurrenciesService();
if (isset($_POST['delete-currency'])) {
if ($currSrv->delete($_POST['delete-currency'])) {
$message = \i18n("Changes saved");
} else {
$error = \i18n("Unable to save changes");
}
if (isset($_GET['delete-currency'])) {
if ($currSrv->delete($_GET['delete-currency'])) {
$message = \i18n("Changes saved");
} else {
$error = \i18n("Unable to save changes");
}
}
$currencies = $currSrv->getAll();
?>
<h1><?php \pi18n("Currencies", PLUGIN_NAME); ?></h1>
<?php \Pasteque\tpl_msg_box($message, $error); ?>
<?php \Pasteque\tpl_btn('btn', \Pasteque\get_module_url_action(PLUGIN_NAME, "currency_edit"),
\i18n('Add a currency', PLUGIN_NAME), 'img/btn_add.png');?>
//Title
echo \Pasteque\row(\Pasteque\mainTitle(\i18n("Currencies", PLUGIN_NAME)));
//Button
$buttons = \Pasteque\addButton(\i18n("Add a currency", PLUGIN_NAME), \Pasteque\get_module_url_action(PLUGIN_NAME, "currency_edit"));
echo \Pasteque\row(\Pasteque\buttonGroup($buttons));
//Information
\Pasteque\tpl_msg_box($message, $error);
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><?php \pi18n("Currency.label"); ?></th>
<th><?php \pi18n("Currency.rate"); ?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach ($currencies as $currency) {
?>
<tr>
<td><?php echo $currency->label; ?></td>
<td><?php
if ($currency->isMain) {
\pi18n("Main", PLUGIN_NAME);
} else {
echo($currency->rate);
} ?></td>
<td class="edition">
<?php \Pasteque\tpl_btn("edition", \Pasteque\get_module_url_action(PLUGIN_NAME,
'currency_edit', array("id" => $currency->id)), "",
'img/edit.png', \i18n('Edit'), \i18n('Edit'));
?>
<form action="<?php echo \Pasteque\get_current_url(); ?>" method="post"><?php \Pasteque\form_delete("currency", $currency->id, \Pasteque\get_template_url() . 'img/delete.png') ?></form>
</td>
</tr>
<?php
if(count($currencies) == 0) {
echo \Pasteque\errorDiv(\i18n("No currency found", PLUGIN_NAME));
}
else {
$content[0][0] = \i18n("Currency.label");
$content[0][1] = \i18n("Currency.rate");
$i = 1;
foreach ($currencies as $currency) {
$content[$i][0] = $currency->label;
if ($currency->isMain) {
$content[$i][1] = \i18n("Main", PLUGIN_NAME);
} else {
$content[$i][1] = $currency->rate;
}
$btn_group = \Pasteque\editButton(\i18n('Edit', PLUGIN_NAME), \Pasteque\get_module_url_action(PLUGIN_NAME, 'currency_edit', array("id" => $currency->id)));
$btn_group .= \Pasteque\deleteButton(\i18n('Delete', PLUGIN_NAME), \Pasteque\get_current_url() . "&delete-currency=" . $tax->id);
$content[$i][1] .= \Pasteque\buttonGroup($btn_group, "pull-right");
}
echo \Pasteque\row(\Pasteque\standardTable($content));
}
?>
</tbody>
</table>
<?php
// Pastèque Web back office, Payment modes module
//
// Copyright (C) 2015 Scil (http://scil.coop)
// Copyright (C) 2015-2016 Scil (http://scil.coop)
// Pierre Ducroquet, Philippe Pary
//
// This file is part of Pastèque.
//
......@@ -26,56 +27,44 @@ $message = NULL;
$error = NULL;
$modeSrv = new \Pasteque\PaymentModesService();
if (isset($_POST['toggle-paymentmode'])) {
if ($modeSrv->toggle($_POST['toggle-paymentmode'])) {
$message = \i18n("Changes saved");
} else {
$error = \i18n("Unable to save changes");
}
if ($modeSrv->toggle($_POST['toggle-paymentmode'])) {
$message = \i18n("Changes saved");
} else {
$error = \i18n("Unable to save changes");
}
}
$paymentModes = $modeSrv->getAll();
?>
<h1><?php \pi18n("Payment modes", PLUGIN_NAME); ?></h1>
<br />
//Title
echo \Pasteque\row(\Pasteque\mainTitle(\i18n("Payement modes", PLUGIN_NAME)));
//Information
\Pasteque\tpl_msg_box($message, $error);
<?php \Pasteque\tpl_msg_box($message, $error); ?>
$content[0][0] = \i18n("PaymentMode.code");
$content[0][1] = \i18n("PaymentMode.label");
$content[0][2] = \i18n("PaymentMode.backLabel");
$content[0][3] = "";
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><?php \pi18n("PaymentMode.code"); ?></th>
<th><?php \pi18n("PaymentMode.label"); ?></th>
<th><?php \pi18n("PaymentMode.backLabel"); ?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
foreach ($paymentModes as $paymentMode) {
if ($paymentMode->system) {
continue;
}
?>
<tr>
<td><?php echo $paymentMode->code; ?></td>
<td><?php echo $paymentMode->label; ?></td>
<td><?php echo $paymentMode->backLabel; ?></td>
<td class="edition">
<form action="<?php echo \Pasteque\get_current_url(); ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="toggle-paymentmode" value="<?php echo $paymentMode->id; ?>" />
<?php
$action = \i18n("Enable");
if ($paymentMode->active === true)
$action = \i18n("Disable");
?>
<input type="submit" value="<?php echo $action; ?>" />
</form>
</td>
</tr>
<?php
if ($paymentMode->system) {
continue;
}
$content[$i][0] = $paymentMode->code;
$content[$i][1] = $paymentMode->label;
$content[$i][2] = $paymentMode->backLabel;
$content[$i][3] = "<form action=\"" . \Pasteque\get_current_url() . "\" method=\"post\" enctype=\"multipart/form-data\">\n<input type=\"hidden\" name=\"toggle-paymentmode\" value=\"" . $paymentMode->id ."\">";
if ($paymentMode->active === true) {
$action = \i18n("Disable");
$content[$i][3] .= \Pasteque\form_button($action,"btn-delete");
}
else {
$action = \i18n("Enable");
$content[$i][3] .= \Pasteque\form_button($action);
}
$content[$i][3] .= "</form>";
$i++;
}
echo \Pasteque\row(\Pasteque\standardTable($content));
?>
</tbody>
</table>
......@@ -26,11 +26,11 @@ namespace BaseProducts;
$message = NULL;
$error = NULL;
if (isset($_GET['delete-taxcat'])) {
if (\Pasteque\TaxesService::deleteCat($_GET['delete-taxcat'])) {
$message = \i18n("Changes saved");
} else {
$error = \i18n("Unable to delete tax. Tax cannot be deleted when in use.", PLUGIN_NAME);
}
if (\Pasteque\TaxesService::deleteCat($_GET['delete-taxcat'])) {
$message = \i18n("Changes saved");
} else {
$error = \i18n("Unable to delete tax. Tax cannot be deleted when in use.", PLUGIN_NAME);
}
}
$taxes = \Pasteque\TaxesService::getAll();
......
......@@ -88,43 +88,28 @@ if (isset($_POST['floorData'])) {
$floors = \Pasteque\PlacesService::getAllFloors();
//Title
\Pasteque\row(\Pasteque\mainTitle(\i18n("Floors configuration", PLUGIN_NAME)));
echo \Pasteque\row(\Pasteque\mainTitle(\i18n("Floors configuration", PLUGIN_NAME)));
//Informations
\Pasteque\tpl_msg_box($message, $error);
?>
<form class="edit" method="post" onsubmit="javascript:save()" action="<?php echo \Pasteque\get_current_url();?>">
<?
$legend = \i18n("Floor", PLUGIN_NAME);
$content = "
<div class=\"row\">
<label for=\"listFloors\">" . \i18n("Floors", PLUGIN_NAME) . "</label>
<select id=\"listFloors\" onchange=\"showFloor()\"></select>
</div>
<div class=\"row\">
<label for=\"floorLabel\">" . \i18n('Floor.label') . "</label>
<input type=\"text\" id=\"floorLabel\" onchange=\"javascript:updateFloor();\">
</div>
<div class=\"row actions\">";
$content = \Pasteque\row("<label for=\"listFloors\">" . \i18n("Floors", PLUGIN_NAME) . "</label>\n<select id=\"listFloors\" onchange=\"showFloor()\"></select>");
$content .= \Pasteque\row("<label for=\"floorLabel\">" . \i18n('Floor.label') . "</label>\n<input type=\"text\" id=\"floorLabel\" onchange=\"javascript:updateFloor();\">");
$buttonGroup = \Pasteque\jsAddButton(\i18n("Add a floor", PLUGIN_NAME), "newFloor()");
$buttonGroup .= \Pasteque\jsDeleteButton(\i18n("Delete floor", PLUGIN_NAME),"deleteCurrentFloor()");
$content .= \Pasteque\buttonGroup($buttonGroup);
$content .= "</div>";
$content .= \Pasteque\row(\Pasteque\buttonGroup($buttonGroup));
echo \Pasteque\form_fieldset($legend,$content);
$legend = \i18n("Place", PLUGIN_NAME);
$content = "
<div class=\"row\">
<label for=\"placeLabel\">" . \i18n('Place.label') . "</label>
<input type=\"text\" id=\"placeLabel\" onchange=\"javascript:updatePlaceLabel();\" onkeyup=\"javascript:updatePlaceLabel();\">
</div>
<div class=\"row actions\">";
$content = \Pasteque\row("<label for=\"placeLabel\">" . \i18n('Place.label') . "</label>\n<input type=\"text\" id=\"placeLabel\" onchange=\"javascript:updatePlaceLabel();\" onkeyup=\"javascript:updatePlaceLabel();\">");
$buttonGroup = \Pasteque\jsAddButton(\i18n("Add place", PLUGIN_NAME), "newPlace()");
$buttonGroup .= \Pasteque\jsDeleteButton(\i18n("Delete place", PLUGIN_NAME), "deletePlace()");
$content .= \Pasteque\buttonGroup($buttonGroup);
$content .= "</div>";
$content .= \Pasteque\row(\Pasteque\buttonGroup($buttonGroup));
echo \Pasteque\form_fieldset($legend,$content);
echo \Pasteque\row(\Pasteque\vanillaDiv("","floorDivContainer"));
?>
<div id="floorDivContainer" class="row"></div>
<div class="row actions">
<input id="floorData" name="floorData" type="hidden">
<?php echo \Pasteque\form_save();?>
......
<?php
// Pastèque Web back office, Stocks module
//
// Copyright (C) 2013 Scil (http://scil.coop)
// Copyright (C) 2013-2016 Scil (http://scil.coop)
// Philippe Pary philippe@scil.coop
//
// This file is part of Pastèque.
//
......@@ -28,207 +29,194 @@ $locSrv = new \Pasteque\LocationsService();
$locations = $locSrv->getAll();
$defaultLocationId = $locations[0]->id;
if (in_array("stock_multilocations", $modules)) {
$multilocations = true;
$multilocations = true;
}
$countedStock = null;
$locationId = null;
if (isset($_POST['send']) && !isset($_POST['sendCsv'])) {
$countedStock = array();
if (isset($_POST['location'])) {
$locationId = $_POST['location'];
} else {
$locationId = $defaultLocationId;
}
foreach ($_POST as $key => $value) {
if (strpos($key, "qty-") === 0) {
$productId = substr($key, 4);
$qty = $value;
$countedStock[$productId] = $qty;
}
}
$countedStock = array();
if (isset($_POST['location'])) {
$locationId = $_POST['location'];
} else {
$locationId = $defaultLocationId;
}
foreach ($_POST as $key => $value) {
if (strpos($key, "qty-") === 0) {
$productId = substr($key, 4);
$qty = $value;
$countedStock[$productId] = $qty;
}
}
} else if (isset($_POST['sendCsv'])) {
$key = array('Quantity', 'Reference');
$csv = new \Pasteque\Csv($_FILES['csv']['tmp_name'], $key, array(),
PLUGIN_NAME);
if (!$csv->open()) {
$error = $csv->getErrors();
} else {
//manage empty string
$csv->setEmptyStringValue("Quantity", "0");
echo "<script type=\"text/javascript\">\n";
echo "jQuery(document).ready(function() {\n";
while ($tab = $csv->readLine()) {
$productOk = false;
$quantityOk = false;
$product = \Pasteque\ProductsService::getByRef($tab['Reference']);
if ($product !== null) {
$productOk = true;
} else {
if ($error === null) {
$error = array();
}
$error[] = \i18n("Unable to find product %s", PLUGIN_NAME,
$tab['Reference']);
continue;
}
if ($tab['Quantity'] === "0" || intval($tab['Quantity']) !== 0) {
$quantityOk = true;
} else {
if ($error === null) {
$error = array();
}
$error[] = \i18n("Undefined quantity for product %s",
PLUGIN_NAME, $tab['Reference']);
continue;
}
if ($productOk && $quantityOk) {
echo "setProduct(\"" . \Pasteque\esc_js($product->id) . "\", \""
. \Pasteque\esc_js($product->reference) . "\", "
. ($product->hasImage ? "1":"0") . ", \""
. \Pasteque\esc_js($product->label) . "\", "
. $tab['Quantity'] . ");\n";
}
}
echo "});\n";
echo "</script>\n\n";
$csv->close();
}
$key = array('Quantity', 'Reference');
$csv = new \Pasteque\Csv($_FILES['csv']['tmp_name'], $key, array(),
PLUGIN_NAME);
if (!$csv->open()) {
$error = $csv->getErrors();
} else {
//manage empty string
$csv->setEmptyStringValue("Quantity", "0");
echo "<script type=\"text/javascript\">\n";
echo "jQuery(document).ready(function() {\n";
while ($tab = $csv->readLine()) {
$productOk = false;
$quantityOk = false;
$product = \Pasteque\ProductsService::getByRef($tab['Reference']);
if ($product !== null) {
$productOk = true;
} else {
if ($error === null) {
$error = array();
}
$error[] = \i18n("Unable to find product %s", PLUGIN_NAME,
$tab['Reference']);
continue;
}
if ($tab['Quantity'] === "0" || intval($tab['Quantity']) !== 0) {
$quantityOk = true;
} else {
if ($error === null) {
$error = array();
}
$error[] = \i18n("Undefined quantity for product %s",
PLUGIN_NAME, $tab['Reference']);
continue;
}
if ($productOk && $quantityOk) {
echo "setProduct(\"" . \Pasteque\esc_js($product->id) . "\", \""
. \Pasteque\esc_js($product->reference) . "\", "
. ($product->hasImage ? "1":"0") . ", \""
. \Pasteque\esc_js($product->label) . "\", "
. $tab['Quantity'] . ");\n";
}
}
echo "});\n";
echo "</script>\n\n";
$csv->close();
}
}
$categories = \Pasteque\CategoriesService::getAll();
$products = \Pasteque\ProductsService::getAll(TRUE);
$products = \Pasteque\ProductsService::getAll();
$locNames = array();
$locIds = array();
foreach ($locations as $location) {
$locNames[] = $location->label;
$locIds[] = $location->id;
$locNames[] = $location->label;
$locIds[] = $location->id;
}
$prdCat = array();
$levels = array();
if ($countedStock !== null) {
// Build listing by categories
foreach ($products as $product) {
if ($product->categoryId !== \Pasteque\CompositionsService::CAT_ID) {
$prdCat[$product->categoryId][] = $product;
}
}
// Get stock to compare with counted stock
$rawLevels = \Pasteque\StocksService::getLevels($locationId);
foreach ($rawLevels as $level) {
$levels[$level->productId] = $level;
}
// Build listing by categories
foreach ($products as $product) {
if ($product->categoryId !== \Pasteque\CompositionsService::CAT_ID) {
$prdCat[$product->categoryId][] = $product;
}
}
// Get stock to compare with counted stock
$rawLevels = \Pasteque\StocksService::getLevels($locationId);
foreach ($rawLevels as $level) {
$levels[$level->productId] = $level;
}
}
?>
<h1><?php \pi18n("Stock check", PLUGIN_NAME); ?></h1>
<?php \Pasteque\tpl_msg_box($message, $error); ?>
//Title
echo \Pasteque\row(\Pasteque\mainTitle(\i18n("Stock check", PLUGIN_NAME)));
//Buttons
$action = \Pasteque\get_report_url(PLUGIN_NAME, "check");
foreach($_POST as $key => $value) {
$action .= "&" . $key . "=" . $value;
}
$buttons = \Pasteque\exportButton(\i18n("Export"),$action);
echo \Pasteque\row(\Pasteque\buttonGroup($buttons));
//Information
\Pasteque\tpl_msg_box($message, $error);
<?php // Mimic report export button ?>
<div id="btn"><a class="btn" href="<?php echo \Pasteque\get_report_url(PLUGIN_NAME, "check");
foreach($_POST as $key => $value) {
echo "&" . $key . "=" . $value;
} ?>"><?php \pi18n("Export"); ?></a></div>
if ($multilocations) {
$content .= \Pasteque\row(\Pasteque\form_select("location", \i18n("Location"), $locIds, $locNames, null));
$content .= \Pasteque\row(\Pasteque\form_select("destination", \i18n("Destination"), $locIds, $locNames, null));
}
$content .= \Pasteque\row(\Pasteque\form_file("file","csv",\i18n("Load csv file", PLUGIN_NAME)));
$content .= \Pasteque\row(\Pasteque\form_button(\i18n("Load", PLUGIN_NAME)));
<form class="edit" action="<?php echo \Pasteque\get_current_url(); ?>" id="move" method="post" enctype="multipart/form-data">
<input type="hidden" name="send" value="true" />
<?php if ($multilocations) { \Pasteque\form_select("location", \i18n("Location"), $locIds, $locNames, null); }?>
$content .= \Pasteque\row(\Pasteque\vanillaDiv("","catalog-picker"));
<div id="catalog-picker"></div>
$table[0][0] = "";
$table[0][1] = \i18n("Product.reference");
$table[0][2] = \i18n("Product.label");
$table[0][3] = \i18n("Quantity");
$table[0][4] = "";
$content .= \Pasteque\row(\Pasteque\standardTable($table));
<div class="row">
<label for="file"><?php \pi18n("Load csv file", PLUGIN_NAME);?></label>
<input id="file" type="file" name="csv">
</div>
<div class="row actions">
<button class="btn-send" type="submit" name="sendCsv"><?php \pi18n("Load", PLUGIN_NAME); ?></button>
</div>
$content .= \Pasteque\row(\Pasteque\form_save());
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th></th>
<th><?php \pi18n("Product.reference"); ?></th>
<th><?php \pi18n("Product.label"); ?></th>
<th><?php \pi18n("Quantity"); ?></th>
<th></th>
</tr>
</thead>
<tbody id="list">
</tbody>