2010-09-18 09:52:17 +02:00
|
|
|
<?php
|
2021-09-06 16:21:30 +02:00
|
|
|
/* Copyright (C) 2010-2021 Regis Houssin <regis.houssin@inodbox.com>
|
2017-04-11 02:48:16 +02:00
|
|
|
* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
2010-09-18 09:52:17 +02:00
|
|
|
*
|
|
|
|
|
* 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
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2010-09-18 09:52:17 +02:00
|
|
|
* (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/>.
|
2010-09-18 09:52:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2011-10-25 19:03:12 +02:00
|
|
|
* \file htdocs/core/ajax/row.php
|
2017-06-18 19:42:59 +02:00
|
|
|
* \brief File to return Ajax response on Row move.
|
|
|
|
|
* This ajax page is called when doing an up or down drag and drop.
|
2019-06-03 22:07:34 +02:00
|
|
|
* Parameters:
|
|
|
|
|
* roworder (Example: '1,3,2,4'),
|
|
|
|
|
* table_element_line (Example: 'commandedet')
|
|
|
|
|
* fk_element (Example: 'fk_order')
|
|
|
|
|
* element_id (Example: 1)
|
2010-09-18 09:52:17 +02:00
|
|
|
*/
|
|
|
|
|
|
2021-02-23 22:03:23 +01:00
|
|
|
if (!defined('NOTOKENRENEWAL')) {
|
|
|
|
|
define('NOTOKENRENEWAL', '1'); // Disable token renewal
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIREMENU')) {
|
|
|
|
|
define('NOREQUIREMENU', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIREHTML')) {
|
|
|
|
|
define('NOREQUIREHTML', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIREAJAX')) {
|
|
|
|
|
define('NOREQUIREAJAX', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIRESOC')) {
|
|
|
|
|
define('NOREQUIRESOC', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIRETRAN')) {
|
|
|
|
|
define('NOREQUIRETRAN', '1');
|
|
|
|
|
}
|
2010-09-18 09:52:17 +02:00
|
|
|
|
2012-08-22 23:24:21 +02:00
|
|
|
require '../../main.inc.php';
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
|
2010-09-18 09:52:17 +02:00
|
|
|
|
2021-05-18 01:58:54 +02:00
|
|
|
// Security check
|
|
|
|
|
// This is done later into view.
|
|
|
|
|
|
2010-09-18 09:52:17 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* View
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
top_httphead();
|
|
|
|
|
|
2017-06-18 19:42:59 +02:00
|
|
|
print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
|
2010-09-18 09:52:17 +02:00
|
|
|
|
|
|
|
|
// Registering the location of boxes
|
2021-05-18 01:58:54 +02:00
|
|
|
if (GETPOST('roworder', 'alpha', 3) && GETPOST('table_element_line', 'aZ09', 3)
|
|
|
|
|
&& GETPOST('fk_element', 'aZ09', 3) && GETPOST('element_id', 'int', 3)) {
|
|
|
|
|
$roworder = GETPOST('roworder', 'alpha', 3);
|
|
|
|
|
$table_element_line = GETPOST('table_element_line', 'aZ09', 3);
|
|
|
|
|
$fk_element = GETPOST('fk_element', 'aZ09', 3);
|
|
|
|
|
$element_id = GETPOST('element_id', 'int', 3);
|
2011-09-10 19:48:15 +02:00
|
|
|
|
2012-09-15 15:33:00 +02:00
|
|
|
dol_syslog("AjaxRow roworder=".$roworder." table_element_line=".$table_element_line." fk_element=".$fk_element." element_id=".$element_id, LOG_DEBUG);
|
|
|
|
|
|
2021-05-18 01:58:54 +02:00
|
|
|
// Make test on permission
|
2021-03-23 16:09:02 +01:00
|
|
|
$perm = 0;
|
|
|
|
|
if ($table_element_line == 'propaldet' && $user->rights->propal->creer) {
|
|
|
|
|
$perm = 1;
|
|
|
|
|
} elseif ($table_element_line == 'commandedet' && $user->rights->commande->creer) {
|
|
|
|
|
$perm = 1;
|
|
|
|
|
} elseif ($table_element_line == 'facturedet' && $user->rights->facture->creer) {
|
|
|
|
|
$perm = 1;
|
2021-09-06 16:21:30 +02:00
|
|
|
} elseif ($table_element_line == 'facturedet_rec' && $user->rights->facture->creer) {
|
2021-03-23 16:09:02 +01:00
|
|
|
$perm = 1;
|
|
|
|
|
} elseif ($table_element_line == 'emailcollector_emailcollectoraction' && $user->admin) {
|
|
|
|
|
$perm = 1;
|
|
|
|
|
} elseif ($table_element_line == 'bom_bomline' && $user->rights->bom->write) {
|
|
|
|
|
$perm = 1;
|
|
|
|
|
} elseif ($table_element_line == 'mrp_production' && $user->rights->mrp->write) {
|
|
|
|
|
$perm = 1;
|
2021-09-06 15:19:35 +02:00
|
|
|
} elseif ($table_element_line == 'supplier_proposaldet' && $user->rights->supplier_proposal->creer) {
|
2021-03-23 16:09:02 +01:00
|
|
|
$perm = 1;
|
2021-06-18 20:03:03 +02:00
|
|
|
} elseif ($table_element_line == 'commande_fournisseurdet' && $user->rights->fournisseur->commande->creer) {
|
2021-03-23 16:09:02 +01:00
|
|
|
$perm = 1;
|
2021-06-18 20:03:03 +02:00
|
|
|
} elseif ($table_element_line == 'facture_fourn_det' && $user->rights->fournisseur->facture->creer) {
|
2021-03-23 16:09:02 +01:00
|
|
|
$perm = 1;
|
2022-02-07 14:34:27 +01:00
|
|
|
} elseif ($table_element_line == 'facture_fourn_det_rec' && $user->rights->fournisseur->facture->creer) {
|
|
|
|
|
$perm = 1;
|
2022-03-18 15:38:44 +01:00
|
|
|
} elseif ($table_element_line == 'product_attribute_value' && $fk_element == 'fk_product_attribute' && ($user->rights->produit->lire || $user->rights->service->lire)) {
|
|
|
|
|
$perm = 1;
|
2022-03-07 16:04:55 +01:00
|
|
|
} elseif ($table_element_line == 'ecm_files') { // Used when of page "documents.php"
|
|
|
|
|
if (!empty($user->rights->ecm->creer)) {
|
|
|
|
|
$perm = 1;
|
|
|
|
|
} elseif ($fk_element == 'fk_product' && (!empty($user->rights->produit->creer) || !empty($user->rights->service->creer))) {
|
|
|
|
|
$perm = 1;
|
|
|
|
|
} elseif ($fk_element == 'fk_ticket' && !empty($user->rights->ticket->write)) {
|
|
|
|
|
$perm = 1;
|
|
|
|
|
} elseif ($fk_element == 'fk_holiday' && !empty($user->rights->holiday->write)) {
|
|
|
|
|
$perm = 1;
|
|
|
|
|
} elseif ($fk_element == 'fk_soc' && !empty($user->rights->societe->creer)) {
|
|
|
|
|
$perm = 1;
|
|
|
|
|
}
|
2021-10-29 08:28:41 +02:00
|
|
|
} elseif ($table_element_line == 'product_association' && $fk_element == 'fk_product' && (!empty($user->rights->produit->creer) || !empty($user->rights->service->creer))) {
|
2021-08-30 14:45:42 +02:00
|
|
|
$perm = 1;
|
2021-09-30 14:27:01 +02:00
|
|
|
} elseif ($table_element_line == 'projet_task' && $fk_element == 'fk_projet' && $user->rights->projet->creer) {
|
2021-09-24 02:24:04 +02:00
|
|
|
$perm = 1;
|
2021-03-23 16:09:02 +01:00
|
|
|
} else {
|
|
|
|
|
$tmparray = explode('_', $table_element_line);
|
|
|
|
|
$tmpmodule = $tmparray[0]; $tmpobject = preg_replace('/line$/', '', $tmparray[1]);
|
2021-03-24 13:32:09 +01:00
|
|
|
if (!empty($tmpmodule) && !empty($tmpobject) && !empty($conf->$tmpmodule->enabled) && !empty($user->rights->$tmpobject->write)) {
|
2021-03-23 16:09:02 +01:00
|
|
|
$perm = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! $perm) {
|
2021-05-18 01:58:54 +02:00
|
|
|
// We should not be here. If we are not allowed to reorder rows, feature should not be visible on script.
|
|
|
|
|
// If we are here, it is a hack attempt, so we report a warning.
|
2021-03-23 16:09:02 +01:00
|
|
|
print 'Bad permission to modify position of lines for object in table '.$table_element_line;
|
2021-09-24 02:24:04 +02:00
|
|
|
dol_syslog('Bad permission to modify position of lines for object in table='.$table_element_line.', fk_element='.$fk_element, LOG_WARNING);
|
2021-03-23 16:09:02 +01:00
|
|
|
accessforbidden('Bad permission to modify position of lines for object in table '.$table_element_line);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
$rowordertab = explode(',', $roworder);
|
2018-11-15 19:58:06 +01:00
|
|
|
$newrowordertab = array();
|
2021-02-23 22:03:23 +01:00
|
|
|
foreach ($rowordertab as $value) {
|
|
|
|
|
if (!empty($value)) {
|
|
|
|
|
$newrowordertab[] = $value;
|
|
|
|
|
}
|
2010-09-18 09:52:17 +02:00
|
|
|
}
|
2011-09-10 19:48:15 +02:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$row = new GenericObject($db);
|
2012-09-15 15:33:00 +02:00
|
|
|
$row->table_element_line = $table_element_line;
|
|
|
|
|
$row->fk_element = $fk_element;
|
|
|
|
|
$row->id = $element_id;
|
2018-11-15 19:58:06 +01:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$row->line_ajaxorder($newrowordertab); // This update field rank or position in table row->table_element_line
|
2012-09-15 15:33:00 +02:00
|
|
|
|
2017-11-10 18:14:29 +01:00
|
|
|
// Reorder line to have position of children lines sharing same counter than parent lines
|
2015-12-18 17:31:50 +01:00
|
|
|
// This should be useless because there is no need to have children sharing same counter than parent, but well, it's cleaner into database.
|
2021-02-23 22:03:23 +01:00
|
|
|
if (in_array($fk_element, array('fk_facture', 'fk_propal', 'fk_commande'))) {
|
2020-04-10 10:59:32 +02:00
|
|
|
$result = $row->line_order(true);
|
2012-09-15 15:33:00 +02:00
|
|
|
}
|
2021-03-23 16:09:02 +01:00
|
|
|
} else {
|
|
|
|
|
print 'Bad parameters for row.php';
|
2010-09-18 09:52:17 +02:00
|
|
|
}
|