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_expression.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_global_variable.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
32 $langs->loadLangs(array(
'products',
'accountancy'));
36 $action =
GETPOST(
'action',
'aZ09');
37 $title =
GETPOST(
'expression_title',
'alpha');
38 $expression =
GETPOST(
'expression');
40 $tab = (!empty($tab)) ? $tab :
'card';
41 $tab = strtolower($tab);
44 $result =
restrictedArea($user,
'produit|service&fournisseur', $id,
'product&product',
'',
'',
'rowid');
48 $product->fetch($id,
'');
56 } elseif ($action !=
'delete') {
57 $price_expression->fetch($eid);
65 if ($action ==
'add') {
67 $result = $price_expression->find_title($title);
71 $price_result = $priceparser->testExpression($id, $expression);
72 if ($price_result < 0) {
75 $price_expression->title = $title;
76 $price_expression->expression = $expression;
77 $result = $price_expression->create($user);
79 $eid = $price_expression->id;
82 setEventMessages(
"add: ".$price_expression->error, $price_expression->errors,
'errors');
85 } elseif ($result < 0) {
86 setEventMessages(
"add find: ".$price_expression->error, $price_expression->errors,
'errors');
93 if ($action ==
'update') {
95 $result = $price_expression->find_title($title);
96 if ($result == 0 || $result == $eid) {
99 $price_result = $priceparser->testExpression($id, $expression);
100 if ($price_result < 0) {
103 $price_expression->id = $eid;
104 $price_expression->title = $title;
105 $price_expression->expression = $expression;
106 $result = $price_expression->update($user);
108 setEventMessages(
"update: ".$price_expression->error, $price_expression->errors,
'errors');
113 } elseif ($result < 0) {
114 setEventMessages(
"update find: ".$price_expression->error, $price_expression->errors,
'errors');
116 setEventMessages($langs->trans(
"ErrorRecordAlreadyExists"),
null,
'errors');
121 if ($action ==
'delete') {
123 $price_expression->fetch($eid);
124 $result = $price_expression->delete($user);
126 setEventMessages(
"delete: ".$price_expression->error, $price_expression->errors,
'errors');
139 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type));
144 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'&tab='.$tab.
'&eid='.$eid.
'" method="POST">';
145 print
'<input type="hidden" name="token" value="'.newToken().
'">';
146 print
'<input type="hidden" name="action" value='.($eid == 0 ?
'add' :
'update').
'>';
150 print
'<table class="border centpercent">';
153 print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"PriceExpressionSelected").
'</td><td>';
154 $price_expression_list = array(0 => $langs->trans(
"New"));
155 foreach ($price_expression->list_price_expression() as $entry) {
156 $price_expression_list[$entry->id] = $entry->title;
158 print
$form->selectarray(
'expression_selection', $price_expression_list, $eid);
162 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Name").
'</td><td>';
163 print
'<input class="flat" name="expression_title" size="15" value="'.($price_expression->title ? $price_expression->title :
'').
'">';
167 $help_text = $langs->trans(
"PriceExpressionEditorHelp1");
168 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp2");
169 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp3");
170 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp4");
171 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp5");
172 foreach ($price_globals->listGlobalVariables() as $entry) {
173 $help_text .=
'<br><b>#globals_'.$entry->code.
'#</b> '.$entry->description.
' = '.$entry->value;
177 print
'<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans(
"PriceExpressionEditor"), $help_text, 1).
'</td><td>';
178 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
179 $doleditor =
new DolEditor(
'expression', isset($price_expression->expression) ? $price_expression->expression :
'',
'', 300,
'',
'',
false,
false,
false, ROWS_4,
'90%');
180 $doleditor->Create();
187 print
'<div class="center">';
188 print
'<input type="submit" class="butAction button-save" value="'.$langs->trans(
"Save").
'">';
189 print
'<span id="back" class="butAction">'.$langs->trans(
"Back").
'</span>';
191 print
'<div class="inline-block divButAction"><span id="action-delete" class="butActionRefused classfortooltip">'.$langs->trans(
'Delete').
'</span></div>'.
"\n";
193 print
'<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$id.
'&tab='.$tab.
'&eid='.$eid.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
"Delete").
'</a></div>';
200 print
'<script type="text/javascript">
201 jQuery(document).ready(run);
203 jQuery("#back").click(on_click);
204 jQuery("#expression_selection").change(on_change);
206 function on_click() {
207 window.location = "'.str_replace(
'dynamic_price/editor.php', $tab.
'.php', $_SERVER[
"PHP_SELF"]).
'?id='.$id.($tab ==
'price' ?
'&action=edit_price&token='.newToken() :
'').
'";
209 function on_change() {
210 window.location = "'.$_SERVER[
"PHP_SELF"].
'?id='.$id.
'&tab='.$tab.
'&eid=" + $("#expression_selection").val();