dolibarr/htdocs/variants/list.php

164 lines
5.4 KiB
PHP
Raw Normal View History

2016-07-23 16:37:21 +02:00
<?php
/* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
*
* This program 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.
*
* This program 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
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2016-07-23 16:37:21 +02:00
*/
require '../main.inc.php';
2021-06-11 15:08:54 +02:00
require DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
2016-07-23 16:37:21 +02:00
$action = GETPOST('action', 'aZ09');
2016-07-23 16:37:21 +02:00
$object = new ProductAttribute($db);
2021-06-11 15:08:54 +02:00
$rowid = GETPOST('rowid', 'int'); // Id of line for up / down when no javascript available
2016-07-23 16:37:21 +02:00
2021-03-20 18:58:34 +01:00
$permissiontoread = $user->rights->produit->lire || $user->rights->service->lire;
2021-06-11 15:08:54 +02:00
$permissiontoadd = $user->rights->produit->creer || $user->rights->service->creer;
2021-03-20 18:58:34 +01:00
// Security check
if (empty($conf->variants->enabled)) {
accessforbidden('Module not enabled');
}
if ($user->socid > 0) { // Protection if external user
accessforbidden();
}
2021-06-11 15:08:54 +02:00
2021-03-20 18:58:34 +01:00
//$result = restrictedArea($user, 'variant');
if (!$permissiontoread) accessforbidden();
/*
* Actions
*/
2021-06-11 15:08:54 +02:00
if ($action == 'up' && $permissiontoadd) {
2016-07-23 16:37:21 +02:00
$object->fetch($rowid);
$object->moveUp();
header('Location: '.$_SERVER['PHP_SELF']);
2017-02-08 12:52:31 +01:00
exit();
2021-06-11 15:08:54 +02:00
} elseif ($action == 'down' && $permissiontoadd) {
2016-07-23 16:37:21 +02:00
$object->fetch($rowid);
$object->moveDown();
header('Location: '.$_SERVER['PHP_SELF']);
2017-02-08 12:52:31 +01:00
exit();
2016-07-23 16:37:21 +02:00
}
/*
* View
*/
2016-07-23 16:37:21 +02:00
$langs->load('products');
$title = $langs->trans($langs->trans('ProductAttributes'));
$variants = $object->fetchAll();
2016-07-23 16:37:21 +02:00
llxHeader('', $title);
$newcardbutton = '';
if ($user->rights->produit->creer) {
$newcardbutton .= dolGetButtonTitle($langs->trans('Create'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/variants/create.php');
}
2018-04-18 02:10:23 +02:00
2020-04-12 21:36:57 +02:00
print load_fiche_titre($title, $newcardbutton, 'product');
2016-07-23 16:37:21 +02:00
$forcereloadpage = empty($conf->global->MAIN_FORCE_RELOAD_PAGE) ? 0 : 1;
2016-07-23 16:37:21 +02:00
?>
<script>
2016-07-23 16:37:21 +02:00
$(document).ready(function(){
$(".imgupforline, .imgdownforline").hide();
$(".lineupdown").removeAttr('href');
$(".tdlineupdown")
.css("background-image", 'url(<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png'; ?>)')
.css("background-repeat", "no-repeat")
.css("background-position", "center center")
.hover(
function () {
$(this).addClass('showDragHandle');
}, function () {
$(this).removeClass('showDragHandle');
}
);
$("#tablelines").tableDnD({
onDrop: function(table, row) {
console.log('drop');
var reloadpage = "<?php echo $forcereloadpage; ?>";
2017-11-07 16:25:57 +01:00
var roworder = cleanSerialize(decodeURI($("#tablelines").tableDnDSerialize()));
$.post("<?php echo DOL_URL_ROOT; ?>/variants/ajax/orderAttribute.php",
2016-07-23 16:37:21 +02:00
{
2021-03-24 02:06:16 +01:00
roworder: roworder,
token: "<?php echo currentToken(); ?>"
2016-07-23 16:37:21 +02:00
},
function() {
if (reloadpage == 1) {
location.href = '<?php echo dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']); ?>';
2016-07-23 16:37:21 +02:00
} else {
$("#tablelines .drag").each(
function( intIndex ) {
$(this).removeClass("pair impair");
if (intIndex % 2 == 0) $(this).addClass('impair');
if (intIndex % 2 == 1) $(this).addClass('pair');
});
}
});
},
onDragClass: "dragClass",
2017-11-07 16:25:57 +01:00
dragHandle: "td.tdlineupdown"
2016-07-23 16:37:21 +02:00
});
});
</script>
2019-11-04 19:28:04 +01:00
<table class="liste nobottom" id="tablelines">
2016-07-23 16:37:21 +02:00
<tr class="liste_titre nodrag nodrop">
<th class="liste_titre"><?php print $langs->trans('Ref') ?></th>
<th class="liste_titre"><?php print $langs->trans('Label') ?></th>
2019-02-16 08:00:16 +01:00
<th class="liste_titre right"><?php print $langs->trans('NbOfDifferentValues') ?></th>
<th class="liste_titre right"><?php print $langs->trans('NbProducts') ?></th>
2016-07-23 16:37:21 +02:00
<th class="liste_titre" colspan="2"></th>
</tr>
<?php
2019-10-26 20:53:39 +02:00
foreach ($variants as $key => $attribute) {
print '<tr id="row-'.$attribute->id.'" class="drag drop oddeven">';
print '<td><a href="card.php?id='.$attribute->id.'">'.dol_htmlentities($attribute->ref).'</a></td>';
print '<td><a href="card.php?id='.$attribute->id.'">'.dol_htmlentities($attribute->label).'</a></td>';
print '<td class="right">'.$attribute->countChildValues().'</td>';
print '<td class="right">'.$attribute->countChildProducts().'</td>';
print '<td class="right">';
2020-06-12 19:30:23 +02:00
print '<a class="editfielda marginrightonly paddingleftonly" href="card.php?id='.$attribute->id.'&action=edit">'.img_edit().'</a>';
print '<a class="marginrightonly paddingleftonlyhref="card.php?id='.$attribute->id.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
2019-10-26 20:53:39 +02:00
print '</td>';
print '<td class="center linecolmove tdlineupdown">';
if ($key > 0) {
print '<a class="lineupdown" href="'.$_SERVER['PHP_SELF'].'?action=up&amp;rowid='.$attribute->id.'">'.img_up('default', 0, 'imgupforline').'</a>';
}
if ($key < count($variants) - 1) {
2019-10-26 20:53:39 +02:00
print '<a class="lineupdown" href="'.$_SERVER['PHP_SELF'].'?action=down&amp;rowid='.$attribute->id.'">'.img_down('default', 0, 'imgdownforline').'</a>';
}
print '</td>';
print "</tr>\n";
}
print '</table>';
2016-07-23 16:37:21 +02:00
2018-08-04 15:58:05 +02:00
// End of page
llxFooter();
2019-02-16 08:00:16 +01:00
$db->close();