25require
'../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
27require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_expression.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_global_variable.class.php';
30require_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);
72if ($action ==
'add' && $usercancreate) {
74 $result = $price_expression->find_title($title);
77 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
79 $price_result = $priceparser->testExpression($id, $expression);
80 if ($price_result < 0) {
83 $price_expression->title = $title;
84 $price_expression->expression = $expression;
85 $result = $price_expression->create($user);
87 $eid = $price_expression->id;
90 setEventMessages(
"add: ".$price_expression->error, $price_expression->errors,
'errors');
93 } elseif ($result < 0) {
94 setEventMessages(
"add find: ".$price_expression->error, $price_expression->errors,
'errors');
101if ($action ==
'update' && $usercancreate) {
103 $result = $price_expression->find_title($title);
104 if ($result == 0 || $result == $eid) {
106 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
108 $price_result = $priceparser->testExpression($id, $expression);
109 if ($price_result < 0) {
112 $price_expression->id = $eid;
113 $price_expression->title = $title;
114 $price_expression->expression = $expression;
115 $result = $price_expression->update($user);
117 setEventMessages(
"update: ".$price_expression->error, $price_expression->errors,
'errors');
122 } elseif ($result < 0) {
123 setEventMessages(
"update find: ".$price_expression->error, $price_expression->errors,
'errors');
125 setEventMessages($langs->trans(
"ErrorRecordAlreadyExists"),
null,
'errors');
130if ($action ==
'delete' && $usercancreate) {
132 $price_expression->fetch($eid);
133 $result = $price_expression->delete($user);
135 setEventMessages(
"delete: ".$price_expression->error, $price_expression->errors,
'errors');
146$form =
new Form($db);
148llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type),
'', 0, 0,
'',
'',
'',
'mod-product page-dynamic_price_editor');
153print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$id.
'&tab='.$tab.
'&eid='.$eid.
'" method="POST">';
154print
'<input type="hidden" name="token" value="'.newToken().
'">';
155print
'<input type="hidden" name="action" value='.($eid == 0 ?
'add' :
'update').
'>';
159print
'<table class="border centpercent">';
162print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"PriceExpressionSelected").
'</td><td>';
163$price_expression_list = array(0 => $langs->trans(
"New"));
164foreach ($price_expression->list_price_expression() as $entry) {
165 $price_expression_list[$entry->id] = $entry->title;
167print $form->selectarray(
'expression_selection', $price_expression_list, $eid);
171print
'<tr><td class="fieldrequired">'.$langs->trans(
"Name").
'</td><td>';
172print
'<input class="flat" name="expression_title" size="15" value="'.(GETPOSTISSET(
'expression_title') ?
GETPOST(
'expression_title') : ($price_expression->title ? $price_expression->title :
'')).
'">';
176$help_text = $langs->trans(
"PriceExpressionEditorHelp1");
177$help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp2");
178$help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp3");
179$help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp4");
180$help_text .=
'<br><br>'.$langs->trans(
"PriceExpressionEditorHelp5");
181foreach ($price_globals->listGlobalVariables() as $entry) {
182 $help_text .=
'<br><b>#global_'.$entry->code.
'#</b> '.$entry->description.
' = '.$entry->value;
186print
'<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans(
"PriceExpressionEditor"), $help_text, 1).
'</td><td>';
187require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
188$doleditor =
new DolEditor(
'expression', isset($price_expression->expression) ? $price_expression->expression :
'',
'', 300,
'',
'', false, false, false, ROWS_4,
'90%');
196print
'<div class="center">';
197print
'<input type="submit" class="butAction button-save" value="'.$langs->trans(
"Save").
'">';
198print
'<span id="back" class="butAction">'.$langs->trans(
"Back").
'</span>';
200 print
'<div class="inline-block divButAction"><span id="action-delete" class="butActionRefused classfortooltip">'.$langs->trans(
'Delete').
'</span></div>'.
"\n";
202 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>';
209print
'<script type="text/javascript">
210 jQuery(document).ready(run);
212 jQuery("#back").click(on_click);
213 jQuery("#expression_selection").change(on_change);
215 function on_click() {
216 window.location = "'.str_replace(
'dynamic_price/editor.php', $tab.
'.php', $_SERVER[
"PHP_SELF"]).
'?id='.
$id.($tab ==
'price' ?
'&action=edit_price&token='.newToken() :
'').
'";
218 function on_change() {
219 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.