24 require
'../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
26 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_global_variable.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_global_variable_updater.class.php';
31 $langs->load(
"products");
34 $action =
GETPOST(
'action',
'aZ09');
35 $save =
GETPOST(
'save',
'alpha');
36 $cancel =
GETPOST(
'cancel',
'alpha');
37 $selection =
GETPOST(
'selection',
'int');
46 if ($action ==
'edit_variable') {
47 $res = $price_globals->fetch($selection);
53 if ($action ==
'edit_updater') {
54 $res = $price_updaters->fetch($selection);
65 if (!empty($action) && empty($cancel)) {
67 if ($action ==
'create_variable' || $action ==
'edit_variable') {
70 $price_globals->value =
GETPOSTISSET(
'value') ?
GETPOST(
'value',
'int') : $price_globals->value;
73 foreach ($price_globals->listGlobalVariables() as $entry) {
81 if ($action ==
'create_variable' && !empty($save)) {
82 $res = $price_globals->create($user);
88 } elseif ($action ==
'edit_variable' && !empty($save)) {
89 $res = $price_globals->update($user);
95 } elseif ($action ==
'delete_variable') {
96 $res = $price_globals->delete($selection, $user);
105 if ($action ==
'create_updater' || $action ==
'edit_updater') {
108 $price_updaters->parameters =
GETPOSTISSET(
'parameters') ?
GETPOST(
'parameters',
'alphanohtml') : $price_updaters->parameters;
109 $price_updaters->fk_variable =
GETPOSTISSET(
'fk_variable') ?
GETPOST(
'fk_variable',
'int') : $price_updaters->fk_variable;
110 $price_updaters->update_interval =
GETPOSTISSET(
'update_interval') ?
GETPOST(
'update_interval',
'int') : $price_updaters->update_interval;
112 if ($action ==
'create_updater' && !empty($save)) {
114 $res = $price_updaters->process();
116 $res = $price_updaters->create($user);
121 setEventMessages($price_updaters->error, $price_updaters->errors,
'errors');
123 } elseif ($action ==
'edit_updater' && !empty($save)) {
125 $res = $price_updaters->process();
127 $res = $price_updaters->update($user);
132 setEventMessages($price_updaters->error, $price_updaters->errors,
'errors');
134 } elseif ($action ==
'delete_updater') {
135 $res = $price_updaters->delete($selection, $user);
139 setEventMessages($price_updaters->error, $price_updaters->errors,
'errors');
142 } elseif (!empty($cancel)) {
153 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type));
155 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
156 print
load_fiche_titre($langs->trans(
"DynamicPriceConfiguration"), $linkback,
'title_setup');
158 print
'<span class="opacitymedium">'.$langs->trans(
"DynamicPriceDesc").
'</span><br>';
162 if ($action !=
'create_updater' && $action !=
'edit_updater') {
165 print
'<table summary="listofattributes" class="noborder centpercent">';
166 print
'<tr class="liste_titre">';
167 print
'<td>'.$langs->trans(
"Variable").
'</td>';
168 print
'<td>'.$langs->trans(
"Description").
'</td>';
169 print
'<td>'.$langs->trans(
"Value").
'</td>';
170 print
'<td width="80"> </td>';
173 $arrayglobalvars = $price_globals->listGlobalVariables();
174 if (!empty($arrayglobalvars)) {
175 foreach ($arrayglobalvars as $i => $entry) {
176 print
'<tr class="oddeven">';
177 print
'<td>'.$entry->code.
'</td>';
178 print
'<td>'.$entry->description.
'</td>';
179 print
'<td>'.price($entry->value).
'</td>';
180 print
'<td class="right"><a class="editfielda paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_variable&token='.
newToken().
'&selection='.$entry->id.
'">'.
img_edit().
'</a> ';
181 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_variable&token='.
newToken().
'&selection='.$entry->id.
'">'.
img_delete().
'</a></td>';
185 print
'<tr colspan="7"><td><span class="opacitymedium">';
186 print $langs->trans(
"None");
187 print
'</span></td></tr>';
191 if (empty($action)) {
195 print
'<div class="tabsAction">';
196 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=create_variable">'.$langs->trans(
"AddVariable").
'</a>';
204 if ($action ==
'create_variable' || $action ==
'edit_variable') {
206 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
207 print
'<input type="hidden" name="token" value="'.newToken().
'">';
208 print
'<input type="hidden" name="action" value="'.$action.
'">';
209 print
'<input type="hidden" name="selection" value="'.$selection.
'">';
212 print
'<br><table summary="listofattributes" class="border centpercent">';
215 print
'<td class="fieldrequired">'.$langs->trans(
"Variable").
'</td>';
216 print
'<td class="valeur"><input type="text" name="code" class="minwidth100" value="'.(empty($price_globals->code) ?
'' : $price_globals->code).
'"></td>';
220 print
'<td>'.$langs->trans(
"Description").
'</td>';
221 print
'<td class="valeur"><input type="text" name="description" class="minwidth200" value="'.(empty($price_globals->description) ?
'' : $price_globals->description).
'"></td>';
225 print
'<td class="fieldrequired">'.$langs->trans(
"Value").
'</td>';
226 print
'<td class="valeur"><input type="text" name="value" class="minwidth100" value="'.(empty($price_globals->value) ?
'' : $price_globals->value).
'"></td>';
231 print
$form->buttonsSaveCancel();
237 if ($action !=
'create_variable' && $action !=
'edit_variable') {
240 print
'<table summary="listofattributes" class="noborder centpercent">';
241 print
'<tr class="liste_titre">';
242 print
'<td>'.$langs->trans(
"VariableToUpdate").
'</td>';
243 print
'<td>'.$langs->trans(
"Description").
'</td>';
244 print
'<td>'.$langs->trans(
"Type").
'</td>';
245 print
'<td>'.$langs->trans(
"Parameters").
'</td>';
246 print
'<td>'.$langs->trans(
"UpdateInterval").
'</td>';
247 print
'<td>'.$langs->trans(
"LastUpdated").
'</td>';
248 print
'<td width="80"> </td>';
251 $arraypriceupdaters = $price_updaters->listUpdaters();
252 if (!empty($arraypriceupdaters)) {
253 foreach ($arraypriceupdaters as $i => $entry) {
255 if ($entry->fk_variable > 0) {
256 $res = $price_globals->fetch($entry->fk_variable);
258 $code = $price_globals->code;
262 print
'<td>'.$code.
'</td>';
263 print
'<td>'.$entry->description.
'</td>';
264 print
'<td>'.$langs->trans(
"GlobalVariableUpdaterType".$entry->type).
'</td>';
265 print
'<td style="max-width: 250px; word-wrap: break-word; white-space: pre-wrap;">'.$entry->parameters.
'</td>';
266 print
'<td>'.$entry->update_interval.
'</td>';
267 print
'<td>'.$entry->getLastUpdated().
'</td>';
268 print
'<td class="right"><a class="editfielda paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_updater&selection='.$entry->id.
'">'.
img_edit().
'</a> ';
269 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_updater&token='.
newToken().
'&selection='.$entry->id.
'">'.
img_delete().
'</a></td>';
273 print
'<tr><td colspan="7" class="opacitymedium">';
274 print $langs->trans(
"None");
279 if (empty($action)) {
283 print
'<div class="tabsAction">';
284 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=create_updater&token='.
newToken().
'">'.$langs->trans(
"AddUpdater").
'</a>';
290 if ($action ==
'create_updater' || $action ==
'edit_updater') {
292 print
'<form id="updaterform" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
293 print
'<input type="hidden" name="token" value="'.newToken().
'">';
294 print
'<input type="hidden" name="action" value="'.$action.
'">';
295 print
'<input type="hidden" name="selection" value="'.$selection.
'">';
298 print
'<br><table summary="listofattributes" class="border centpercent">';
301 print
'<td class="fieldrequired">'.$langs->trans(
"VariableToUpdate").
'</td><td>';
302 $globals_list = array();
303 foreach ($price_globals->listGlobalVariables() as $entry) {
304 $globals_list[$entry->id] = $entry->code;
306 print
$form->selectarray(
'fk_variable', $globals_list, (empty($price_updaters->fk_variable) ? 0 : $price_updaters->fk_variable));
310 print
'<td>'.$langs->trans(
"Description").
'</td>';
311 print
'<td class="valeur"><input type="text" name="description" class="minwidth200" value="'.(empty($price_updaters->description) ?
'' : $price_updaters->description).
'"></td>';
315 print
'<td class="fieldrequired">'.$langs->trans(
"Type").
'</td><td>';
316 $type = empty($price_updaters->type) ? 0 : $price_updaters->type;
317 $type_list = array();
318 foreach ($price_updaters->types as $val) {
319 $type_list[$val] = $langs->trans(
"GlobalVariableUpdaterType".$val);
321 print
$form->selectarray(
'type', $type_list, $type);
323 print
'<script type="text/javascript">
324 jQuery(document).ready(run);
326 jQuery("#type").change(on_change);
328 function on_change() {
329 jQuery("#updaterform").submit();
335 $help = $langs->trans(
"GlobalVariableUpdaterHelp".$type).
'<br><b>'.$langs->trans(
"GlobalVariableUpdaterHelpFormat".$type).
'</b>';
336 print
'<td class="fieldrequired">'.$form->textwithpicto($langs->trans(
"Parameters"), $help, 1).
'</td><td>';
337 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
338 $doleditor =
new DolEditor(
'parameters', empty($price_updaters->parameters) ?
'' : $price_updaters->parameters,
'', 300,
'',
'',
false,
false,
false, ROWS_8,
'90%');
339 $doleditor->Create();
344 print
'<td class="fieldrequired">'.$langs->trans(
"UpdateInterval").
'</td>';
345 print
'<td class="valeur"><input type="text" name="update_interval" size="10" value="'.(empty($price_updaters->update_interval) ?
'' : $price_updaters->update_interval).
'"></td>';
350 print
$form->buttonsSaveCancel();