27require
'../main.inc.php';
28require
'class/ProductAttribute.class.php';
29require
'class/ProductAttributeValue.class.php';
30require
'lib/variants.lib.php';
43$langs->loadLangs(array(
'products'));
47$action =
GETPOST(
'action',
'aZ09');
48$confirm =
GETPOST(
'confirm',
'alpha');
49$cancel =
GETPOST(
'cancel',
'alpha');
50$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'productattribute';
51$backtopage =
GETPOST(
'backtopage',
'alpha');
52$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
53$lineid =
GETPOST(
'lineid',
'alpha');
56if (!isModEnabled(
'variants')) {
59if ($user->socid > 0) {
64$hookmanager->initHooks(array(
'productattributecard',
'globalcard'));
72$extrafields->fetch_name_optionals_label(
$object->table_element);
75include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
77$permissiontoread = $user->hasRight(
'variants',
'read');
78$permissiontoadd = $user->hasRight(
'variants',
'write');
79$permissiontoedit = $user->hasRight(
'variants',
'write');
80$permissiontodelete = $user->hasRight(
'variants',
'delete');
92$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
102 if (empty($backtopage) || ($cancel && empty($id))) {
103 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
104 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
105 $backtopage = $backurlforlist;
107 $backtopage =
dol_buildpath(
'/variants/card.php', 1).
'?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
113 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
115 if (!empty($backtopage)) {
116 header(
"Location: " . $backtopage);
123 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
126 if ($action ==
'up' && $permissiontoedit) {
129 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'#'.
GETPOST(
'rowid'));
131 } elseif ($action ==
'down' && $permissiontoedit) {
134 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'#'.
GETPOST(
'rowid'));
138 if ($action ==
'addline' && $permissiontoedit) {
139 $line_ref =
GETPOST(
'line_ref',
'alpha');
140 $line_value =
GETPOST(
'line_value',
'alpha');
142 $result =
$object->addLine($line_ref, $line_value);
145 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id);
151 } elseif ($action ==
'updateline' && $permissiontoedit) {
152 $line_ref =
GETPOST(
'line_ref',
'alpha');
153 $line_value =
GETPOST(
'line_value',
'alpha');
155 $result =
$object->updateLine($lineid, $line_ref, $line_value);
158 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id);
162 $action =
'editline';
173$help_url =
'EN:Module_Products#Variants';
177if ($action ==
'create') {
178 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"ProductAttribute")),
'',
'object_' .
$object->picto);
180 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
181 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
182 print
'<input type="hidden" name="action" value="add">';
184 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
186 if ($backtopageforcancel) {
187 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
192 print
'<table class="border centpercent tableforfieldcreate">' .
"\n";
195 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_add.tpl.php';
198 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
200 print
'</table>' .
"\n";
204 print
'<div class="center">';
205 print
'<input type="submit" class="button" name="add" value="' .
dol_escape_htmltag($langs->trans(
"Create")) .
'">';
207 print
'<input type="' . ($backtopage ?
"submit" :
"button") .
'" class="button button-cancel" name="cancel" value="' .
dol_escape_htmltag($langs->trans(
"Cancel")) .
'"' . ($backtopage ?
'' :
' onclick="history.go(-1)"') .
'>';
213} elseif (($id || $ref) && $action ==
'edit') {
217 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
218 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
219 print
'<input type="hidden" name="action" value="update">';
220 print
'<input type="hidden" name="id" value="' .
$object->id .
'">';
222 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
224 if ($backtopageforcancel) {
225 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
230 print
'<table class="border centpercent tableforfieldedit">' .
"\n";
233 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_edit.tpl.php';
236 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_edit.tpl.php';
238 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
239 print $hookmanager->resPrint;
245 print
'<div class="center"><input type="submit" class="button button-save" name="save" value="' . $langs->trans(
"Save") .
'">';
246 print
' <input type="submit" class="button button-cancel" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
250} elseif (
$object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
252 $res =
$object->fetch_optionals();
260 if ($action ==
'delete') {
261 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id, $langs->trans(
'DeleteMyObject'), $langs->trans(
'ProductAttributeDeleteDialog'),
'confirm_delete',
'', 0, 1);
262 } elseif ($action ==
'ask_deleteline') {
265 if ($object_value->fetch($lineid) > 0) {
266 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&lineid=' . $lineid, $langs->trans(
'DeleteLine'), $langs->trans(
'ProductAttributeValueDeleteDialog',
dol_htmlentities($object_value->value),
dol_htmlentities($object_value->ref)),
'confirm_deleteline',
'', 0, 1);
271 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
272 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
273 if (empty($reshook)) {
274 $formconfirm .= $hookmanager->resPrint;
275 } elseif ($reshook > 0) {
276 $formconfirm = $hookmanager->resPrint;
284 $backtolist = (
GETPOST(
'backtolist') ?
GETPOST(
'backtolist') : DOL_URL_ROOT .
'/variants/list.php?leftmenu=?restore_lastsearch_values=1');
285 $linkback =
'<a href="' .
dol_sanitizeUrl($backtolist) .
'">' . $langs->trans(
"BackToList") .
'</a>';
287 dol_banner_tab(
$object,
'id', $linkback);
289 print
'<div class="fichecenter">';
290 print
'<div class="fichehalfleft">';
291 print
'<div class="underbanner clearboth"></div>';
292 print
'<table class="border centpercent tableforfield">' .
"\n";
295 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_view.tpl.php';
298 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
304 print
'<div class="clearboth"></div>';
309 if ($action !=
'editline') {
310 print
'<div class="tabsAction">' .
"\n";
311 $parameters = array();
312 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
317 if (empty($reshook)) {
319 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=edit',
'', $permissiontoedit);
322 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id .
'&action=delete',
'', $permissiontodelete);
324 print
'</div>' .
"\n";
330 if (!empty(
$object->table_element_line)) {
332 $result =
$object->getLinesArray();
334 print
load_fiche_titre($langs->trans(
"PossibleValues") . (!empty(
$object->lines) ?
'<span class="opacitymedium colorblack paddingleft">(' . count(
$object->lines) .
')</span>' :
''));
336 print
'<form name="addproduct" id="addproduct" action="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id . (($action !=
'editline') ?
'' :
'#line_' .
GETPOSTINT(
'lineid')) .
'" method="POST">
337 <input type="hidden" name="token" value="' .
newToken() .
'">
338 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline') .
'">
339 <input type="hidden" name="mode" value="">
340 <input type="hidden" name="page_y" value="">
341 <input type="hidden" name="id" value="' .
$object->id .
'">
344 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
346 if ($backtopageforcancel) {
347 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
350 if (!empty(
$conf->use_javascript_ajax)) {
351 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
354 print
'<div class="div-table-responsive-no-min">';
355 if (!empty(
$object->lines) || ($permissiontoedit && $action !=
'selectlines' && $action !=
'editline')) {
356 print
'<table id="tablelines" class="noborder centpercent">';
359 $object->printObjectLines($action, $mysoc,
null,
GETPOSTINT(
'lineid'), 1,
'/variants/tpl', ($permissiontoedit ? 1 : 0));
361 if (!empty(
$object->lines) || ($permissiontoedit && $action !=
'selectlines' && $action !=
'editline')) {
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 ProductAttribute Used to represent a Product attribute Examples:
Class ProductAttributeValue Used to represent a product attribute value.
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.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
dol_sanitizeUrl($stringtoclean, $type=1)
Clean a string to use it as an URL (into a href or src attribute)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
productAttributePrepareHead($object)
Prepare array with list of tabs.