Merge pull request #20358 from atm-greg/FIX_missing_hooks_for_dictionaryadmin

add more specific context and doAction hook
This commit is contained in:
Laurent Destailleur 2022-03-16 21:52:25 +01:00 committed by GitHub
commit b0525c7a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,7 +94,7 @@ if (!GETPOSTISSET('search_country_id') && $search_country_id == '' && ($id == 2
$search_code = GETPOST('search_code', 'alpha'); $search_code = GETPOST('search_code', 'alpha');
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('admin')); $hookmanager->initHooks(array('admin', 'dictionaryadmin'));
// This page is a generic page to edit dictionaries // This page is a generic page to edit dictionaries
// Put here declaration of dictionaries properties // Put here declaration of dictionaries properties
@ -683,407 +683,433 @@ if ($id == 10) {
* Actions * Actions
*/ */
if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) { $parameters = array(
$search_country_id = ''; 'id' =>$id,
$search_code = ''; 'rowid' =>$rowid,
'code' =>$code,
'confirm' =>$confirm,
'entity' =>$entity,
'taborder' =>$taborder,
'tabname' =>$tabname,
'tablib' =>$tablib,
'tabsql' =>$tabsql,
'tabsqlsort' =>$tabsqlsort,
'tabfield' =>$tabfield,
'tabfieldvalue' =>$tabfieldvalue,
'tabfieldinsert'=>$tabfieldinsert,
'tabrowid' =>$tabrowid,
'tabcond' =>$tabcond,
'tabhelp' =>$tabhelp,
'tabcomplete' =>$tabcomplete
);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
} }
// Actions add or modify an entry into a dictionary if (empty($reshook)) {
if (GETPOST('actionadd') || GETPOST('actionmodify')) { if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
$listfield = explode(',', str_replace(' ', '', $tabfield[$id])); $search_country_id = '';
$listfieldinsert = explode(',', $tabfieldinsert[$id]); $search_code = '';
$listfieldmodify = explode(',', $tabfieldinsert[$id]);
$listfieldvalue = explode(',', $tabfieldvalue[$id]);
// Check that all mandatory fields are filled
$ok = 1;
foreach ($listfield as $f => $value) {
// Discard check of mandatory fields for country for some tables
if ($value == 'country_id' && in_array($tablib[$id], array('DictionaryPublicHolidays', 'DictionaryVAT', 'DictionaryRegion', 'DictionaryCompanyType', 'DictionaryHolidayTypes', 'DictionaryRevenueStamp', 'DictionaryAccountancysystem', 'DictionaryAccountancyCategory'))) {
continue; // For some pages, country is not mandatory
}
if ($value == 'country' && in_array($tablib[$id], array('DictionaryPublicHolidays', 'DictionaryCanton', 'DictionaryCompanyType', 'DictionaryHolidayTypes', 'DictionaryRevenueStamp'))) {
continue; // For some pages, country is not mandatory
}
// Discard check of mandatory fiedls for other fields
if ($value == 'localtax1' && empty($_POST['localtax1_type'])) {
continue;
}
if ($value == 'localtax2' && empty($_POST['localtax2_type'])) {
continue;
}
if ($value == 'color' && empty($_POST['color'])) {
continue;
}
if ($value == 'formula' && empty($_POST['formula'])) {
continue;
}
if ($value == 'dayrule' && empty($_POST['dayrule'])) {
continue;
}
if ($value == 'sortorder') {
continue; // For a column name 'sortorder', we use the field name 'position'
}
if ((!GETPOSTISSET($value) || GETPOST($value) == '')
&& (!in_array($value, array('decalage', 'module', 'accountancy_code', 'accountancy_code_sell', 'accountancy_code_buy', 'tracking', 'picto')) // Fields that are not mandatory
&& ($id != 10 || ($value != 'code' && $value != 'note')) // Field code and note is not mandatory for dictionary table 10
)
) {
$ok = 0;
$fieldnamekey = $value;
// We take translate key of field
if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
$fieldnamekey = 'Label';
}
if ($fieldnamekey == 'libelle_facture') {
$fieldnamekey = 'LabelOnDocuments';
}
if ($fieldnamekey == 'nbjour') {
$fieldnamekey = 'NbOfDays';
}
if ($fieldnamekey == 'decalage') {
$fieldnamekey = 'Offset';
}
if ($fieldnamekey == 'module') {
$fieldnamekey = 'Module';
}
if ($fieldnamekey == 'code') {
$fieldnamekey = 'Code';
}
if ($fieldnamekey == 'note') {
$fieldnamekey = 'Note';
}
if ($fieldnamekey == 'taux') {
$fieldnamekey = 'Rate';
}
if ($fieldnamekey == 'type') {
$fieldnamekey = 'Type';
}
if ($fieldnamekey == 'position') {
$fieldnamekey = 'Position';
}
if ($fieldnamekey == 'unicode') {
$fieldnamekey = 'Unicode';
}
if ($fieldnamekey == 'deductible') {
$fieldnamekey = 'Deductible';
}
if ($fieldnamekey == 'sortorder') {
$fieldnamekey = 'SortOrder';
}
if ($fieldnamekey == 'category_type') {
$fieldnamekey = 'Calculated';
}
if ($fieldnamekey == 'revenuestamp_type') {
$fieldnamekey = 'TypeOfRevenueStamp';
}
if ($fieldnamekey == 'use_default') {
$fieldnamekey = 'UseByDefault';
}
setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
}
}
// Other checks
if (GETPOST('actionadd') && $tabname[$id] == MAIN_DB_PREFIX."c_actioncomm" && GETPOSTISSET("type") && in_array(GETPOST("type"), array('system', 'systemauto'))) {
$ok = 0;
setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
}
if (GETPOSTISSET("code")) {
if (GETPOST("code") == '0') {
$ok = 0;
setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
}
/*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
{
$ok = 0;
$msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br>';
}*/
}
if (GETPOSTISSET("country") && (GETPOST("country") == '0') && ($id != 2)) {
if (in_array($tablib[$id], array('DictionaryCompanyType', 'DictionaryHolidayTypes'))) { // Field country is no mandatory for such dictionaries
$_POST["country"] = '';
} else {
$ok = 0;
setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Country")), null, 'errors');
}
}
if (($id == 3 || $id == 42) && !is_numeric(GETPOST("code"))) {
$ok = 0;
setEventMessages($langs->transnoentities("ErrorFieldMustBeANumeric", $langs->transnoentities("Code")), null, 'errors');
} }
// Clean some parameters // Actions add or modify an entry into a dictionary
if ((GETPOST("localtax1_type") || (GETPOST('localtax1_type') == '0')) && !GETPOST("localtax1")) { if (GETPOST('actionadd') || GETPOST('actionmodify')) {
$_POST["localtax1"] = '0'; // If empty, we force to 0 $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
} $listfieldinsert = explode(',', $tabfieldinsert[$id]);
if ((GETPOST("localtax2_type") || (GETPOST('localtax2_type') == '0')) && !GETPOST("localtax2")) { $listfieldmodify = explode(',', $tabfieldinsert[$id]);
$_POST["localtax2"] = '0'; // If empty, we force to 0 $listfieldvalue = explode(',', $tabfieldvalue[$id]);
}
if (GETPOST("accountancy_code") <= 0) {
$_POST["accountancy_code"] = ''; // If empty, we force to null
}
if (GETPOST("accountancy_code_sell") <= 0) {
$_POST["accountancy_code_sell"] = ''; // If empty, we force to null
}
if (GETPOST("accountancy_code_buy") <= 0) {
$_POST["accountancy_code_buy"] = ''; // If empty, we force to null
}
if ($id == 10 && GETPOSTISSET("code")) { // Spaces are not allowed into code for tax dictionary
$_POST["code"] = preg_replace('/[^a-zA-Z0-9\-\+]/', '', $_POST["code"]);
}
// If check ok and action add, add the line // Check that all mandatory fields are filled
if ($ok && GETPOST('actionadd')) { $ok = 1;
if ($tabrowid[$id]) { foreach ($listfield as $f => $value) {
// Get free id for insert // Discard check of mandatory fields for country for some tables
$newid = 0; if ($value == 'country_id' && in_array($tablib[$id], array('DictionaryPublicHolidays', 'DictionaryVAT', 'DictionaryRegion', 'DictionaryCompanyType', 'DictionaryHolidayTypes', 'DictionaryRevenueStamp', 'DictionaryAccountancysystem', 'DictionaryAccountancyCategory'))) {
$sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id]; continue; // For some pages, country is not mandatory
$result = $db->query($sql); }
if ($result) { if ($value == 'country' && in_array($tablib[$id], array('DictionaryPublicHolidays', 'DictionaryCanton', 'DictionaryCompanyType', 'DictionaryHolidayTypes', 'DictionaryRevenueStamp'))) {
$obj = $db->fetch_object($result); continue; // For some pages, country is not mandatory
$newid = ($obj->newid + 1); }
// Discard check of mandatory fiedls for other fields
if ($value == 'localtax1' && empty($_POST['localtax1_type'])) {
continue;
}
if ($value == 'localtax2' && empty($_POST['localtax2_type'])) {
continue;
}
if ($value == 'color' && empty($_POST['color'])) {
continue;
}
if ($value == 'formula' && empty($_POST['formula'])) {
continue;
}
if ($value == 'dayrule' && empty($_POST['dayrule'])) {
continue;
}
if ($value == 'sortorder') {
continue; // For a column name 'sortorder', we use the field name 'position'
}
if ((!GETPOSTISSET($value) || GETPOST($value) == '')
&& (!in_array($value, array('decalage', 'module', 'accountancy_code', 'accountancy_code_sell', 'accountancy_code_buy', 'tracking', 'picto')) // Fields that are not mandatory
&& ($id != 10 || ($value != 'code' && $value != 'note')) // Field code and note is not mandatory for dictionary table 10
)
) {
$ok = 0;
$fieldnamekey = $value;
// We take translate key of field
if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
$fieldnamekey = 'Label';
}
if ($fieldnamekey == 'libelle_facture') {
$fieldnamekey = 'LabelOnDocuments';
}
if ($fieldnamekey == 'nbjour') {
$fieldnamekey = 'NbOfDays';
}
if ($fieldnamekey == 'decalage') {
$fieldnamekey = 'Offset';
}
if ($fieldnamekey == 'module') {
$fieldnamekey = 'Module';
}
if ($fieldnamekey == 'code') {
$fieldnamekey = 'Code';
}
if ($fieldnamekey == 'note') {
$fieldnamekey = 'Note';
}
if ($fieldnamekey == 'taux') {
$fieldnamekey = 'Rate';
}
if ($fieldnamekey == 'type') {
$fieldnamekey = 'Type';
}
if ($fieldnamekey == 'position') {
$fieldnamekey = 'Position';
}
if ($fieldnamekey == 'unicode') {
$fieldnamekey = 'Unicode';
}
if ($fieldnamekey == 'deductible') {
$fieldnamekey = 'Deductible';
}
if ($fieldnamekey == 'sortorder') {
$fieldnamekey = 'SortOrder';
}
if ($fieldnamekey == 'category_type') {
$fieldnamekey = 'Calculated';
}
if ($fieldnamekey == 'revenuestamp_type') {
$fieldnamekey = 'TypeOfRevenueStamp';
}
if ($fieldnamekey == 'use_default') {
$fieldnamekey = 'UseByDefault';
}
setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
}
}
// Other checks
if (GETPOST('actionadd') && $tabname[$id] == MAIN_DB_PREFIX."c_actioncomm" && GETPOSTISSET("type") && in_array(GETPOST("type"), array('system', 'systemauto'))) {
$ok = 0;
setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
}
if (GETPOSTISSET("code")) {
if (GETPOST("code") == '0') {
$ok = 0;
setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
}
/*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
{
$ok = 0;
$msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br>';
}*/
}
if (GETPOSTISSET("country") && (GETPOST("country") == '0') && ($id != 2)) {
if (in_array($tablib[$id], array('DictionaryCompanyType', 'DictionaryHolidayTypes'))) { // Field country is no mandatory for such dictionaries
$_POST["country"] = '';
} else { } else {
dol_print_error($db); $ok = 0;
setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Country")), null, 'errors');
} }
} }
if (($id == 3 || $id == 42) && !is_numeric(GETPOST("code"))) {
// Add new entry $ok = 0;
$sql = "INSERT INTO ".$tabname[$id]." ("; setEventMessages($langs->transnoentities("ErrorFieldMustBeANumeric", $langs->transnoentities("Code")), null, 'errors');
// List of fields
if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
$sql .= $tabrowid[$id].",";
} }
$sql .= $tabfieldinsert[$id];
$sql .= ",active)";
$sql .= " VALUES(";
// List of values // Clean some parameters
if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) { if ((GETPOST("localtax1_type") || (GETPOST('localtax1_type') == '0')) && !GETPOST("localtax1")) {
$sql .= $newid.","; $_POST["localtax1"] = '0'; // If empty, we force to 0
} }
$i = 0; if ((GETPOST("localtax2_type") || (GETPOST('localtax2_type') == '0')) && !GETPOST("localtax2")) {
foreach ($listfieldinsert as $f => $value) { $_POST["localtax2"] = '0'; // If empty, we force to 0
$keycode = $listfieldvalue[$i]; }
if (empty($keycode)) { if (GETPOST("accountancy_code") <= 0) {
$keycode = $value; $_POST["accountancy_code"] = ''; // If empty, we force to null
}
if (GETPOST("accountancy_code_sell") <= 0) {
$_POST["accountancy_code_sell"] = ''; // If empty, we force to null
}
if (GETPOST("accountancy_code_buy") <= 0) {
$_POST["accountancy_code_buy"] = ''; // If empty, we force to null
}
if ($id == 10 && GETPOSTISSET("code")) { // Spaces are not allowed into code for tax dictionary
$_POST["code"] = preg_replace('/[^a-zA-Z0-9\-\+]/', '', $_POST["code"]);
}
// If check ok and action add, add the line
if ($ok && GETPOST('actionadd')) {
if ($tabrowid[$id]) {
// Get free id for insert
$newid = 0;
$sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
$result = $db->query($sql);
if ($result) {
$obj = $db->fetch_object($result);
$newid = ($obj->newid + 1);
} else {
dol_print_error($db);
}
} }
if ($value == 'price' || preg_match('/^amount/i', $value)) { // Add new entry
$_POST[$keycode] = price2num(GETPOST($keycode), 'MU'); $sql = "INSERT INTO ".$tabname[$id]." (";
} elseif ($value == 'taux' || $value == 'localtax1') { // List of fields
$_POST[$keycode] = price2num(GETPOST($keycode), 8); // Note that localtax2 can be a list of rates separated by coma like X:Y:Z if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
} elseif ($value == 'entity') { $sql .= $tabrowid[$id].",";
$_POST[$keycode] = getEntity($tabname[$id]);
} }
$sql .= $tabfieldinsert[$id];
$sql .= ",active)";
$sql .= " VALUES(";
if ($i) { // List of values
$sql .= ","; if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
$sql .= $newid.",";
} }
$i = 0;
foreach ($listfieldinsert as $f => $value) {
$keycode = $listfieldvalue[$i];
if (empty($keycode)) {
$keycode = $value;
}
if ($keycode == 'sortorder') { // For column name 'sortorder', we use the field name 'position' if ($value == 'price' || preg_match('/^amount/i', $value)) {
$sql .= (int) GETPOST('position', 'int'); $_POST[$keycode] = price2num(GETPOST($keycode), 'MU');
} elseif ($_POST[$keycode] == '' && !($keycode == 'code' && $id == 10)) { } elseif ($value == 'taux' || $value == 'localtax1') {
$sql .= "null"; // For vat, we want/accept code = '' $_POST[$keycode] = price2num(GETPOST($keycode), 8); // Note that localtax2 can be a list of rates separated by coma like X:Y:Z
} elseif ($keycode == 'content') { } elseif ($value == 'entity') {
$sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'"; $_POST[$keycode] = getEntity($tabname[$id]);
} elseif (in_array($keycode, array('joinfile', 'private', 'pos', 'position', 'scale', 'use_default'))) { }
$sql .= (int) GETPOST($keycode, 'int');
if ($i) {
$sql .= ",";
}
if ($keycode == 'sortorder') { // For column name 'sortorder', we use the field name 'position'
$sql .= (int) GETPOST('position', 'int');
} elseif ($_POST[$keycode] == '' && !($keycode == 'code' && $id == 10)) {
$sql .= "null"; // For vat, we want/accept code = ''
} elseif ($keycode == 'content') {
$sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
} elseif (in_array($keycode, array('joinfile', 'private', 'pos', 'position', 'scale', 'use_default'))) {
$sql .= (int) GETPOST($keycode, 'int');
} else {
$sql .= "'".$db->escape(GETPOST($keycode, 'nohtml'))."'";
}
$i++;
}
$sql .= ",1)";
dol_syslog("actionadd", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) { // Add is ok
setEventMessages($langs->transnoentities("RecordCreatedSuccessfully"), null, 'mesgs');
// Clean $_POST array, we keep only id of dictionary
if ($id == 10 && GETPOST('country', 'int') > 0) {
$search_country_id = GETPOST('country', 'int');
}
$_POST = array('id'=>$id);
} else { } else {
$sql .= "'".$db->escape(GETPOST($keycode, 'nohtml'))."'"; if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
} else {
dol_print_error($db);
}
} }
$i++;
} }
$sql .= ",1)";
dol_syslog("actionadd", LOG_DEBUG); // If verif ok and action modify, modify the line
$resql = $db->query($sql); if ($ok && GETPOST('actionmodify')) {
if ($resql) { // Add is ok if ($tabrowid[$id]) {
setEventMessages($langs->transnoentities("RecordCreatedSuccessfully"), null, 'mesgs'); $rowidcol = $tabrowid[$id];
// Clean $_POST array, we keep only id of dictionary
if ($id == 10 && GETPOST('country', 'int') > 0) {
$search_country_id = GETPOST('country', 'int');
}
$_POST = array('id'=>$id);
} else {
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
} else { } else {
dol_print_error($db); $rowidcol = "rowid";
}
// Modify entry
$sql = "UPDATE ".$tabname[$id]." SET ";
// Modifie valeur des champs
if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
$sql .= $tabrowid[$id]."=";
$sql .= "'".$db->escape($rowid)."', ";
}
$i = 0;
foreach ($listfieldmodify as $field) {
$keycode = $listfieldvalue[$i];
if (empty($keycode)) {
$keycode = $field;
}
if ($field == 'price' || preg_match('/^amount/i', $field)) {
$_POST[$keycode] = price2num(GETPOST($keycode), 'MU');
} elseif ($field == 'taux' || $field == 'localtax1') {
$_POST[$keycode] = price2num(GETPOST($keycode), 8); // Note that localtax2 can be a list of rates separated by coma like X:Y:Z
} elseif ($field == 'entity') {
$_POST[$keycode] = getEntity($tabname[$id]);
}
if ($i) {
$sql .= ",";
}
$sql .= $field."=";
if ($listfieldvalue[$i] == 'sortorder') { // For column name 'sortorder', we use the field name 'position'
$sql .= (int) GETPOST('position', 'int');
} elseif ($_POST[$keycode] == '' && !($keycode == 'code' && $id == 10)) {
$sql .= "null"; // For vat, we want/accept code = ''
} elseif ($keycode == 'content') {
$sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
} elseif (in_array($keycode, array('joinfile', 'private', 'pos', 'position', 'scale', 'use_default'))) {
$sql .= (int) GETPOST($keycode, 'int');
} else {
$sql .= "'".$db->escape(GETPOST($keycode, 'nohtml'))."'";
}
$i++;
}
if (in_array($rowidcol, array('code', 'code_iso'))) {
$sql .= " WHERE ".$rowidcol." = '".$db->escape($rowid)."'";
} else {
$sql .= " WHERE ".$rowidcol." = ".((int) $rowid);
}
if (in_array('entity', $listfieldmodify)) {
$sql .= " AND entity = ".((int) getEntity($tabname[$id], 0));
}
dol_syslog("actionmodify", LOG_DEBUG);
//print $sql;
$resql = $db->query($sql);
if (!$resql) {
setEventMessages($db->error(), null, 'errors');
} }
} }
//$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
} }
// If verif ok and action modify, modify the line if (GETPOST('actioncancel')) {
if ($ok && GETPOST('actionmodify')) { //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
}
if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
if ($tabrowid[$id]) { if ($tabrowid[$id]) {
$rowidcol = $tabrowid[$id]; $rowidcol = $tabrowid[$id];
} else { } else {
$rowidcol = "rowid"; $rowidcol = "rowid";
} }
// Modify entry $sql = "DELETE FROM ".$tabname[$id]." WHERE ".$rowidcol."='".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
$sql = "UPDATE ".$tabname[$id]." SET ";
// Modifie valeur des champs
if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
$sql .= $tabrowid[$id]."=";
$sql .= "'".$db->escape($rowid)."', ";
}
$i = 0;
foreach ($listfieldmodify as $field) {
$keycode = $listfieldvalue[$i];
if (empty($keycode)) {
$keycode = $field;
}
if ($field == 'price' || preg_match('/^amount/i', $field)) { dol_syslog("delete", LOG_DEBUG);
$_POST[$keycode] = price2num(GETPOST($keycode), 'MU'); $result = $db->query($sql);
} elseif ($field == 'taux' || $field == 'localtax1') { if (!$result) {
$_POST[$keycode] = price2num(GETPOST($keycode), 8); // Note that localtax2 can be a list of rates separated by coma like X:Y:Z if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
} elseif ($field == 'entity') { setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
$_POST[$keycode] = getEntity($tabname[$id]);
}
if ($i) {
$sql .= ",";
}
$sql .= $field."=";
if ($listfieldvalue[$i] == 'sortorder') { // For column name 'sortorder', we use the field name 'position'
$sql .= (int) GETPOST('position', 'int');
} elseif ($_POST[$keycode] == '' && !($keycode == 'code' && $id == 10)) {
$sql .= "null"; // For vat, we want/accept code = ''
} elseif ($keycode == 'content') {
$sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
} elseif (in_array($keycode, array('joinfile', 'private', 'pos', 'position', 'scale', 'use_default'))) {
$sql .= (int) GETPOST($keycode, 'int');
} else { } else {
$sql .= "'".$db->escape(GETPOST($keycode, 'nohtml'))."'"; dol_print_error($db);
} }
$i++;
}
if (in_array($rowidcol, array('code', 'code_iso'))) {
$sql .= " WHERE ".$rowidcol." = '".$db->escape($rowid)."'";
} else {
$sql .= " WHERE ".$rowidcol." = ".((int) $rowid);
}
if (in_array('entity', $listfieldmodify)) {
$sql .= " AND entity = ".((int) getEntity($tabname[$id], 0));
}
dol_syslog("actionmodify", LOG_DEBUG);
//print $sql;
$resql = $db->query($sql);
if (!$resql) {
setEventMessages($db->error(), null, 'errors');
} }
} }
//$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
}
if (GETPOST('actioncancel')) { // activate
//$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition if ($action == $acts[0]) {
} if ($tabrowid[$id]) {
$rowidcol = $tabrowid[$id];
if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
if ($tabrowid[$id]) {
$rowidcol = $tabrowid[$id];
} else {
$rowidcol = "rowid";
}
$sql = "DELETE FROM ".$tabname[$id]." WHERE ".$rowidcol."='".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
dol_syslog("delete", LOG_DEBUG);
$result = $db->query($sql);
if (!$result) {
if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
} else { } else {
$rowidcol = "rowid";
}
if ($rowid) {
$sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
} elseif ($code) {
$sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
}
$result = $db->query($sql);
if (!$result) {
dol_print_error($db); dol_print_error($db);
} }
} }
}
// activate // disable
if ($action == $acts[0]) { if ($action == $acts[1]) {
if ($tabrowid[$id]) { if ($tabrowid[$id]) {
$rowidcol = $tabrowid[$id]; $rowidcol = $tabrowid[$id];
} else { } else {
$rowidcol = "rowid"; $rowidcol = "rowid";
}
if ($rowid) {
$sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
} elseif ($code) {
$sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
}
$result = $db->query($sql);
if (!$result) {
dol_print_error($db);
}
} }
if ($rowid) { // favorite
$sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : ''); if ($action == 'activate_favorite') {
} elseif ($code) { if ($tabrowid[$id]) {
$sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = ".(int) $entity : ''); $rowidcol = $tabrowid[$id];
} else {
$rowidcol = "rowid";
}
if ($rowid) {
$sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
} elseif ($code) {
$sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
}
$result = $db->query($sql);
if (!$result) {
dol_print_error($db);
}
} }
$result = $db->query($sql); // disable favorite
if (!$result) { if ($action == 'disable_favorite') {
dol_print_error($db); if ($tabrowid[$id]) {
} $rowidcol = $tabrowid[$id];
} } else {
$rowidcol = "rowid";
}
// disable if ($rowid) {
if ($action == $acts[1]) { $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
if ($tabrowid[$id]) { } elseif ($code) {
$rowidcol = $tabrowid[$id]; $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
} else { }
$rowidcol = "rowid";
}
if ($rowid) { $result = $db->query($sql);
$sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : ''); if (!$result) {
} elseif ($code) { dol_print_error($db);
$sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = ".(int) $entity : ''); }
}
$result = $db->query($sql);
if (!$result) {
dol_print_error($db);
}
}
// favorite
if ($action == 'activate_favorite') {
if ($tabrowid[$id]) {
$rowidcol = $tabrowid[$id];
} else {
$rowidcol = "rowid";
}
if ($rowid) {
$sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
} elseif ($code) {
$sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
}
$result = $db->query($sql);
if (!$result) {
dol_print_error($db);
}
}
// disable favorite
if ($action == 'disable_favorite') {
if ($tabrowid[$id]) {
$rowidcol = $tabrowid[$id];
} else {
$rowidcol = "rowid";
}
if ($rowid) {
$sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
} elseif ($code) {
$sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
}
$result = $db->query($sql);
if (!$result) {
dol_print_error($db);
} }
} }