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,
'');
57 } elseif ($action !=
'delete')
59 $price_expression->fetch($eid);
71 $result = $price_expression->find_title($title);
76 $price_result = $priceparser->testExpression($id, $expression);
77 if ($price_result < 0) {
80 $price_expression->title = $title;
81 $price_expression->expression = $expression;
82 $result = $price_expression->create($user);
85 $eid = $price_expression->id;
88 setEventMessages(
"add: ".$price_expression->error, $price_expression->errors,
'errors');
91 } elseif ($result < 0)
93 setEventMessages(
"add find: ".$price_expression->error, $price_expression->errors,
'errors');
100 if ($action ==
'update')
104 $result = $price_expression->find_title($title);
105 if ($result == 0 || $result == $eid)
109 $price_result = $priceparser->testExpression($id, $expression);
110 if ($price_result < 0) {
113 $price_expression->id = $eid;
114 $price_expression->title = $title;
115 $price_expression->expression = $expression;
116 $result = $price_expression->update($user);
119 setEventMessages(
"update: ".$price_expression->error, $price_expression->errors,
'errors');
124 } elseif ($result < 0)
126 setEventMessages(
"update find: ".$price_expression->error, $price_expression->errors,
'errors');
128 setEventMessages($langs->trans(
"ErrorRecordAlreadyExists"), null,
'errors');
133 if ($action ==
'delete')
137 $price_expression->fetch($eid);
138 $result = $price_expression->delete($user);
141 setEventMessages(
"delete: ".$price_expression->error, $price_expression->errors,
'errors');
152 $form =
new Form($db);
154 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type));
159 print '<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'&tab='.$tab.
'&eid='.$eid.
'" method="POST">';
160 print '<input type="hidden" name="token" value="'.newToken().
'">';
161 print '<input type="hidden" name="action" value='.($eid == 0 ?
'add' :
'update').
'>';
165 print '<table class="border centpercent">';
168 print '<tr><td class="titlefield fieldrequired">'.$langs->trans(
"PriceExpressionSelected").
'</td><td>';
169 $price_expression_list = array(0 => $langs->trans(
"New"));
170 foreach ($price_expression->list_price_expression() as $entry) {
171 $price_expression_list[$entry->id] = $entry->title;
173 print $form->selectarray(
'expression_selection', $price_expression_list, $eid);
177 print '<tr><td class="fieldrequired">'.$langs->trans(
"Name").
'</td><td>';
178 print '<input class="flat" name="expression_title" size="15" value="'.($price_expression->title ? $price_expression->title :
'').
'">';
182 $help_text = $langs->trans(
"PriceExpressionEditorHelp1");
183 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp2");
184 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp3");
185 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp4");
186 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp5");
187 foreach ($price_globals->listGlobalVariables() as $entry) {
188 $help_text .=
'<br><b>#globals_'.$entry->code.
'#</b> '.$entry->description.
' = '.$entry->value;
192 print
'<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans(
"PriceExpressionEditor"), $help_text, 1).
'</td><td>';
193 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
194 $doleditor =
new DolEditor(
'expression', isset($price_expression->expression) ? $price_expression->expression :
'',
'', 300,
'',
'',
false,
false,
false, ROWS_4,
'90%');
195 $doleditor->Create();
202 print
'<div class="center">';
203 print
'<input type="submit" class="butAction button-save" value="'.$langs->trans(
"Save").
'">';
204 print
'<span id="back" class="butAction">'.$langs->trans(
"Back").
'</span>';
207 print
'<div class="inline-block divButAction"><span id="action-delete" class="butActionRefused classfortooltip">'.$langs->trans(
'Delete').
'</span></div>'.
"\n";
209 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>';
216 print
'<script type="text/javascript">
217 jQuery(document).ready(run);
219 jQuery("#back").click(on_click);
220 jQuery("#expression_selection").change(on_change);
222 function on_click() {
223 window.location = "'.str_replace(
'dynamic_price/editor.php', $tab.
'.php',
$_SERVER[
"PHP_SELF"]).
'?id='.$id.($tab ==
'price' ?
'&action=edit_price' :
'').
'";
225 function on_change() {
226 window.location = "'.
$_SERVER[
"PHP_SELF"].
'?id='.$id.
'&tab='.$tab.
'&eid=" + $("#expression_selection").val();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to parse product price expressions.
Class to manage products or services.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class for accesing price expression table.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Class for accesing price global variables table.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.