26require
'../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_expression.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_global_variable.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
42$langs->loadLangs(array(
'products',
'accountancy'));
46$action =
GETPOST(
'action',
'aZ09');
47$title =
GETPOST(
'expression_title',
'alpha');
48$expression =
GETPOST(
'expression');
50$tab = (!empty($tab)) ? $tab :
'card';
51$tab = strtolower($tab);
54$result =
restrictedArea($user,
'produit|service&fournisseur', $id,
'product&product',
'',
'',
'rowid');
58$product->fetch($id,
'');
66} elseif ($action !=
'delete') {
67 $price_expression->fetch($eid);
81if ($action ==
'add' && $usercancreate) {
83 $result = $price_expression->find_title($title);
86 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
88 $price_result = $priceparser->testExpression($id, $expression);
89 if ($price_result < 0) {
92 $price_expression->title = $title;
93 $price_expression->expression = $expression;
94 $result = $price_expression->create($user);
96 $eid = $price_expression->id;
99 setEventMessages(
"add: ".$price_expression->error, $price_expression->errors,
'errors');
102 } elseif ($result < 0) {
103 setEventMessages(
"add find: ".$price_expression->error, $price_expression->errors,
'errors');
105 setEventMessages($langs->trans(
"ErrorRecordAlreadyExists"),
null,
'errors');
110if ($action ==
'update' && $usercancreate) {
112 $result = $price_expression->find_title($title);
113 if ($result == 0 || $result == $eid) {
115 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
117 $price_result = $priceparser->testExpression($id, $expression);
118 if ($price_result < 0) {
121 $price_expression->id = $eid;
122 $price_expression->title = $title;
123 $price_expression->expression = $expression;
124 $result = $price_expression->update($user);
126 setEventMessages(
"update: ".$price_expression->error, $price_expression->errors,
'errors');
131 } elseif ($result < 0) {
132 setEventMessages(
"update find: ".$price_expression->error, $price_expression->errors,
'errors');
134 setEventMessages($langs->trans(
"ErrorRecordAlreadyExists"),
null,
'errors');
139if ($action ==
'delete' && $usercancreate) {
141 $price_expression->fetch($eid);
142 $result = $price_expression->delete($user);
144 setEventMessages(
"delete: ".$price_expression->error, $price_expression->errors,
'errors');
155$form =
new Form($db);
157llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type),
'', 0, 0,
'',
'',
'',
'mod-product page-dynamic_price_editor');
162print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$id.
'&tab='.$tab.
'&eid='.$eid.
'" method="POST">';
163print
'<input type="hidden" name="token" value="'.newToken().
'">';
164print
'<input type="hidden" name="action" value='.($eid == 0 ?
'add' :
'update').
'>';
168print
'<table class="border centpercent">';
171print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"PriceExpressionSelected").
'</td><td>';
172$price_expression_list = array(0 => $langs->trans(
"New"));
173foreach ($price_expression->list_price_expression() as $entry) {
174 $price_expression_list[$entry->id] = $entry->title;
176print $form->selectarray(
'expression_selection', $price_expression_list, $eid);
180print
'<tr><td class="fieldrequired">'.$langs->trans(
"Name").
'</td><td>';
181print
'<input class="flat" name="expression_title" size="15" value="'.(GETPOSTISSET(
'expression_title') ?
GETPOST(
'expression_title') : ($price_expression->title ? $price_expression->title :
'')).
'">';
185$help_text = $langs->trans(
"PriceExpressionEditorHelp1");
186$help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp2");
187$help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp3");
188$help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp4");
189$help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp5");
190foreach ($price_globals->listGlobalVariables() as $entry) {
191 $help_text .=
'<br><b>#global_'.$entry->code.
'#</b> '.$entry->description.
' = '.$entry->value;
195print
'<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans(
"PriceExpressionEditor"), $help_text, 1).
'</td><td>';
196require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
197$doleditor =
new DolEditor(
'expression', isset($price_expression->expression) ? $price_expression->expression :
'',
'', 300,
'',
'', false, false, false, ROWS_4,
'90%');
205print
'<div class="center">';
206print
'<input type="submit" class="butAction button-save" value="'.$langs->trans(
"Save").
'">';
207print
'<span id="back" class="butAction">'.$langs->trans(
"Back").
'</span>';
209 print
'<div class="inline-block divButAction"><span id="action-delete" class="butActionRefused classfortooltip">'.$langs->trans(
'Delete').
'</span></div>'.
"\n";
211 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>';
218print
'<script type="text/javascript">
219 jQuery(document).ready(run);
221 jQuery("#back").click(on_click);
222 jQuery("#expression_selection").change(on_change);
224 function on_click() {
225 window.location = "'.str_replace(
'dynamic_price/editor.php', $tab.
'.php', $_SERVER[
"PHP_SELF"]).
'?id='.
$id.($tab ==
'price' ?
'&action=edit_price&token='.newToken() :
'').
'";
227 function on_change() {
228 window.location = "'.$_SERVER[
"PHP_SELF"].
'?id='.
$id.
'&tab='.$tab.
'&eid=" + $("#expression_selection").val();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage a WYSIWYG editor.
Class for accessing price expression table.
Class for accessing price global variables table.
Class to parse product price expressions.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.