* * 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 * along with this program. If not, see . */ /** * \file htdocs/product/admin/expression_globals.php * \ingroup product * \brief Page for configuring dynamic prices */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_global_variable.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_global_variable_updater.class.php'; $langs->load("products"); $id = GETPOST('id', 'int'); $action = GETPOST('action', 'alpha'); $save = GETPOST('save', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $selection = GETPOST('selection', 'int'); // Security check if (!$user->admin) accessforbidden(); //Objects $price_globals = new PriceGlobalVariable($db); if ($action == 'edit_variable') { $res = $price_globals->fetch($selection); if ($res < 1) { setEventMessage($price_globals->error, 'errors'); } } $price_updaters = new PriceGlobalVariableUpdater($db); if ($action == 'edit_updater') { $res = $price_updaters->fetch($selection); if ($res < 1) { setEventMessage($price_updaters->error, 'errors'); } } /* * Actions */ if (!empty($action) && empty($cancel)) { //Global variable actions if ($action == 'create_variable' || $action == 'edit_variable') { $price_globals->code = isset($_POST['code'])?GETPOST('code', 'alpha'):$price_globals->code; $price_globals->description = isset($_POST['description'])?GETPOST('description', 'alpha'):$price_globals->description; $price_globals->value = isset($_POST['value'])?GETPOST('value', 'int'):$price_globals->value; //Check if record already exists only when saving if (!empty($save)) { foreach ($price_globals->listGlobalVariables() as $entry) { if ($price_globals->id != $entry->id && dol_strtolower($price_globals->code) == dol_strtolower($entry->code)) { setEventMessage($langs->trans("ErrorRecordAlreadyExists"), 'errors'); $save = null; } } } } if ($action == 'create_variable' && !empty($save)) { $res = $price_globals->create($user); if ($res > 0) { $action = ''; } else { setEventMessage($price_globals->error, 'errors'); } } elseif ($action == 'edit_variable' && !empty($save)) { $res = $price_globals->update($user); if ($res > 0) { $action = ''; } else { setEventMessage($price_globals->error, 'errors'); } } elseif ($action == 'delete_variable') { $res = $price_globals->delete($selection, $user); if ($res > 0) { $action = ''; } else { setEventMessage($price_globals->error, 'errors'); } } //Updaters actions if ($action == 'create_updater' || $action == 'edit_updater') { $price_updaters->type = isset($_POST['type'])?GETPOST('type', 'int'):$price_updaters->type; $price_updaters->description = isset($_POST['description'])?GETPOST('description', 'alpha'):$price_updaters->description; $price_updaters->parameters = isset($_POST['parameters'])?GETPOST('parameters'):$price_updaters->parameters; $price_updaters->fk_variable = isset($_POST['fk_variable'])?GETPOST('fk_variable', 'int'):$price_updaters->fk_variable; $price_updaters->update_interval = isset($_POST['update_interval'])?GETPOST('update_interval', 'int'):$price_updaters->update_interval; } if ($action == 'create_updater' && !empty($save)) { //Verify if process() works $res = $price_updaters->process(); if ($res > 0) { $res = $price_updaters->create($user); } if ($res > 0) { $action = ''; } else { setEventMessage($price_updaters->error, 'errors'); } } elseif ($action == 'edit_updater' && !empty($save)) { //Verify if process() works $res = $price_updaters->process(); if ($res > 0) { $res = $price_updaters->update($user); } if ($res > 0) { $action = ''; } else { setEventMessage($price_updaters->error, 'errors'); } } elseif ($action == 'delete_updater') { $res = $price_updaters->delete($selection, $user); if ($res > 0) { $action = ''; } else { setEventMessage($price_updaters->error, 'errors'); } } } elseif (!empty($cancel)) { $action = ''; } /* * View */ //Header llxHeader("","",$langs->trans("CardProduct".$product->type)); print_fiche_titre($langs->trans("DynamicPriceConfiguration")); $form = new Form($db); //Global variables table if ($action != 'create_updater' && $action != 'edit_updater') { print $langs->trans("GlobalVariables"); print ''; print ''; print ''; print ''; print ''; print ''; //Space for buttons print ''; $var=True; foreach ($price_globals->listGlobalVariables() as $i=>$entry) { $var = !$var; print ''; print ''; print ''; print ''; print ''; print ''; } print '
'.$langs->trans("Code").''.$langs->trans("Description").''.$langs->trans("Value").' 
'.$entry->code.''.$entry->description.''.price($entry->value).'id.'">'.img_edit().'  '; print 'id.'">'.img_delete().'
'; } //Global variable editor if ($action == 'create_variable' || $action == 'edit_variable') { //Form print '
'; print ''; print ''; print ''; //Table print '
'; //Code print ''; print ''; print ''; print ''; //Description print ''; print ''; print ''; print ''; //Value print ''; print ''; print ''; print ''; print '
'.$langs->trans("Code").'
'.$langs->trans("Description").'
'.$langs->trans("Value").'
'; //Form Buttons print '
'; print '  '; print ''; print '
'; print '
'; } else { //Action Buttons print '
'; print ''.$langs->trans("Add").''; print '
'; //Separator is only need for updaters table is showed after buttons print '

'; } //Updaters table if ($action != 'create_variable' && $action != 'edit_variable') { print $langs->trans("GlobalVariableUpdaters"); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; //Space for buttons print ''; $var=True; foreach ($price_updaters->listUpdaters() as $i=>$entry) { $code = ""; if ($entry->fk_variable > 0) { $res = $price_globals->fetch($entry->fk_variable); if ($res > 0) { $code = $price_globals->code; } } $var = !$var; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } print '
'.$langs->trans("Code").''.$langs->trans("Description").''.$langs->trans("Type").''.$langs->trans("Parameters").''.$langs->trans("UpdateInterval").''.$langs->trans("LastUpdated").' 
'.$code.''.$entry->description.''.$langs->trans("GlobalVariableUpdaterType".$entry->type).''.$entry->parameters.''.$entry->update_interval.''.$entry->getLastUpdated().'id.'">'.img_edit().'  '; print 'id.'">'.img_delete().'
'; } //Updater editor if ($action == 'create_updater' || $action == 'edit_updater') { //Form print '
'; print ''; print ''; print ''; //Table print '
'; //Code print ''; print ''; //Description print ''; print ''; print ''; print ''; //Type print ''; print ''; //Parameters print ''; $help = $langs->trans("GlobalVariableUpdaterHelp".$type).'
'.$langs->trans("GlobalVariableUpdaterHelpFormat".$type).''; print ''; print ''; //Interval print ''; print ''; print ''; print ''; print '
'.$langs->trans("Code").''; $globals_list = array(); foreach ($price_globals->listGlobalVariables() as $entry) { $globals_list[$entry->id]=$entry->code; } print $form->selectarray('fk_variable', $globals_list, (empty($price_updaters->fk_variable)?0:$price_updaters->fk_variable)); print '
'.$langs->trans("Description").'
'.$langs->trans("Type").''; $type = empty($price_updaters->type)?0:$price_updaters->type; $type_list = array(); foreach ($price_updaters->types as $val) { $type_list[$val] = $langs->trans("GlobalVariableUpdaterType".$val); } print $form->selectarray('type', $type_list, $type); // This code submits form when type is changed print ''; print '
'.$form->textwithpicto($langs->trans("Parameters"),$help,1).''; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('parameters',empty($price_updaters->parameters)?'':$price_updaters->parameters,'',300,'','',false,false,false,10,80); $doleditor->Create(); print '
'.$langs->trans("UpdateInterval").'
'; //Form Buttons print '
'; print '  '; print ''; print '
'; print '
'; } else { //Action Buttons print '
'; print ''.$langs->trans("Add").''; print '
'; } llxFooter(); $db->close();