25 require
'../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_expression.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_global_variable.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
33 $langs->loadLangs(array(
'products',
'accountancy'));
37 $action =
GETPOST(
'action',
'aZ09');
38 $title =
GETPOST(
'expression_title',
'alpha');
39 $expression =
GETPOST(
'expression');
41 $tab = (!empty($tab)) ? $tab :
'card';
42 $tab = strtolower($tab);
45 $result =
restrictedArea($user,
'produit|service&fournisseur', $id,
'product&product',
'',
'',
'rowid');
49 $product->fetch($id,
'');
57 } elseif ($action !=
'delete') {
58 $price_expression->fetch($eid);
66 if ($action ==
'add') {
68 $result = $price_expression->find_title($title);
71 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
73 $price_result = $priceparser->testExpression($id, $expression);
74 if ($price_result < 0) {
77 $price_expression->title = $title;
78 $price_expression->expression = $expression;
79 $result = $price_expression->create($user);
81 $eid = $price_expression->id;
84 setEventMessages(
"add: ".$price_expression->error, $price_expression->errors,
'errors');
87 } elseif ($result < 0) {
88 setEventMessages(
"add find: ".$price_expression->error, $price_expression->errors,
'errors');
95 if ($action ==
'update') {
97 $result = $price_expression->find_title($title);
98 if ($result == 0 || $result == $eid) {
100 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
102 $price_result = $priceparser->testExpression($id, $expression);
103 if ($price_result < 0) {
106 $price_expression->id = $eid;
107 $price_expression->title = $title;
108 $price_expression->expression = $expression;
109 $result = $price_expression->update($user);
111 setEventMessages(
"update: ".$price_expression->error, $price_expression->errors,
'errors');
116 } elseif ($result < 0) {
117 setEventMessages(
"update find: ".$price_expression->error, $price_expression->errors,
'errors');
119 setEventMessages($langs->trans(
"ErrorRecordAlreadyExists"),
null,
'errors');
124 if ($action ==
'delete') {
126 $price_expression->fetch($eid);
127 $result = $price_expression->delete($user);
129 setEventMessages(
"delete: ".$price_expression->error, $price_expression->errors,
'errors');
142 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type));
147 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'&tab='.$tab.
'&eid='.$eid.
'" method="POST">';
148 print
'<input type="hidden" name="token" value="'.newToken().
'">';
149 print
'<input type="hidden" name="action" value='.($eid == 0 ?
'add' :
'update').
'>';
153 print
'<table class="border centpercent">';
156 print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"PriceExpressionSelected").
'</td><td>';
157 $price_expression_list = array(0 => $langs->trans(
"New"));
158 foreach ($price_expression->list_price_expression() as $entry) {
159 $price_expression_list[$entry->id] = $entry->title;
161 print
$form->selectarray(
'expression_selection', $price_expression_list, $eid);
165 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Name").
'</td><td>';
166 print
'<input class="flat" name="expression_title" size="15" value="'.($price_expression->title ? $price_expression->title :
'').
'">';
170 $help_text = $langs->trans(
"PriceExpressionEditorHelp1");
171 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp2");
172 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp3");
173 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp4");
174 $help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp5");
175 foreach ($price_globals->listGlobalVariables() as $entry) {
176 $help_text .=
'<br><b>#globals_'.$entry->code.
'#</b> '.$entry->description.
' = '.$entry->value;
180 print
'<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans(
"PriceExpressionEditor"), $help_text, 1).
'</td><td>';
181 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
182 $doleditor =
new DolEditor(
'expression', isset($price_expression->expression) ? $price_expression->expression :
'',
'', 300,
'',
'',
false,
false,
false, ROWS_4,
'90%');
183 $doleditor->Create();
190 print
'<div class="center">';
191 print
'<input type="submit" class="butAction button-save" value="'.$langs->trans(
"Save").
'">';
192 print
'<span id="back" class="butAction">'.$langs->trans(
"Back").
'</span>';
194 print
'<div class="inline-block divButAction"><span id="action-delete" class="butActionRefused classfortooltip">'.$langs->trans(
'Delete').
'</span></div>'.
"\n";
196 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>';
203 print
'<script type="text/javascript">
204 jQuery(document).ready(run);
206 jQuery("#back").click(on_click);
207 jQuery("#expression_selection").change(on_change);
209 function on_click() {
210 window.location = "'.str_replace(
'dynamic_price/editor.php', $tab.
'.php', $_SERVER[
"PHP_SELF"]).
'?id='.$id.($tab ==
'price' ?
'&action=edit_price&token='.newToken() :
'').
'";
212 function on_change() {
213 window.location = "'.$_SERVER[
"PHP_SELF"].
'?id='.$id.
'&tab='.$tab.
'&eid=" + $("#expression_selection").val();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage a WYSIWYG editor.
Class for accesing price expression table.
Class for accesing price global variables table.
Class to parse product price expressions.
Class to manage products or services.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.