27require
'../main.inc.php';
28require
'class/ProductAttribute.class.php';
29require
'class/ProductAttributeValue.class.php';
30require
'lib/variants.lib.php';
33$langs->loadLangs(array(
'products'));
37$action =
GETPOST(
'action',
'aZ09');
38$confirm =
GETPOST(
'confirm',
'alpha');
39$cancel =
GETPOST(
'cancel',
'alpha');
40$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'productattribute';
41$backtopage =
GETPOST(
'backtopage',
'alpha');
42$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
43$lineid =
GETPOST(
'lineid',
'alpha');
46if (!isModEnabled(
'variants')) {
49if ($user->socid > 0) {
57include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
60$hookmanager->initHooks(array(
'productattributecard',
'globalcard'));
62$permissiontoread = $user->rights->variants->read;
63$permissiontoadd = $user->rights->variants->write;
64$permissiontoedit = $user->rights->variants->write;
65$permissiontodelete = $user->rights->variants->delete;
77$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
87 if (empty($backtopage) || ($cancel && empty($id))) {
88 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
89 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
90 $backtopage = $backurlforlist;
92 $backtopage =
dol_buildpath(
'/variants/card.php', 1).
'?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
98 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
100 if (!empty($backtopage)) {
101 header(
"Location: " . $backtopage);
108 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
111 if ($action ==
'up' && $permissiontoedit) {
112 $object->line_up(
GETPOST(
'rowid'),
false);
114 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'#'.
GETPOST(
'rowid'));
116 } elseif ($action ==
'down' && $permissiontoedit) {
117 $object->line_down(
GETPOST(
'rowid'),
false);
119 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'#'.
GETPOST(
'rowid'));
123 if ($action ==
'addline' && $permissiontoedit) {
124 $line_ref =
GETPOST(
'line_ref',
'alpha');
125 $line_value =
GETPOST(
'line_value',
'alpha');
127 $result = $object->addLine($line_ref, $line_value);
130 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?id=' . $object->id);
136 } elseif ($action ==
'updateline' && $permissiontoedit) {
137 $line_ref =
GETPOST(
'line_ref',
'alpha');
138 $line_value =
GETPOST(
'line_value',
'alpha');
140 $result = $object->updateLine($lineid, $line_ref, $line_value);
143 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?id=' . $object->id);
147 $action =
'editline';
157$title = $langs->trans(
'ProductAttributeName',
dol_htmlentities($object->label));
158$help_url =
'EN:Module_Products#Variants';
162if ($action ==
'create') {
163 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"ProductAttribute")),
'',
'object_' . $object->picto);
165 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
166 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
167 print
'<input type="hidden" name="action" value="add">';
169 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
171 if ($backtopageforcancel) {
172 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
177 print
'<table class="border centpercent tableforfieldcreate">' .
"\n";
180 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_add.tpl.php';
182 print
'</table>' .
"\n";
186 print
'<div class="center">';
187 print
'<input type="submit" class="button" name="add" value="' .
dol_escape_htmltag($langs->trans(
"Create")) .
'">';
189 print
'<input type="' . ($backtopage ?
"submit" :
"button") .
'" class="button button-cancel" name="cancel" value="' .
dol_escape_htmltag($langs->trans(
"Cancel")) .
'"' . ($backtopage ?
'' :
' onclick="history.go(-1)"') .
'>';
195} elseif (($id || $ref) && $action ==
'edit') {
197 print
load_fiche_titre($langs->trans(
"ProductAttribute"),
'',
'object_' . $object->picto);
199 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
200 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
201 print
'<input type="hidden" name="action" value="update">';
202 print
'<input type="hidden" name="id" value="' . $object->id .
'">';
204 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
206 if ($backtopageforcancel) {
207 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
212 print
'<table class="border centpercent tableforfieldedit">' .
"\n";
215 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_edit.tpl.php';
217 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
218 print $hookmanager->resPrint;
224 print
'<div class="center"><input type="submit" class="button button-save" name="save" value="' . $langs->trans(
"Save") .
'">';
225 print
' <input type="submit" class="button button-cancel" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
229} elseif ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
231 $res = $object->fetch_optionals();
234 print
dol_get_fiche_head($head,
'card', $langs->trans(
"ProductAttribute"), -1, $object->picto);
239 if ($action ==
'delete') {
240 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"] .
'?id=' . $object->id, $langs->trans(
'DeleteMyObject'), $langs->trans(
'ProductAttributeDeleteDialog'),
'confirm_delete',
'', 0, 1);
241 } elseif ($action ==
'ask_deleteline') {
244 if ($object_value->fetch($lineid) > 0) {
245 $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);
250 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
251 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
252 if (empty($reshook)) {
253 $formconfirm .= $hookmanager->resPrint;
254 } elseif ($reshook > 0) {
255 $formconfirm = $hookmanager->resPrint;
263 $backtolist = (
GETPOST(
'backtolist') ?
GETPOST(
'backtolist') : DOL_URL_ROOT .
'/variants/list.php?leftmenu=?restore_lastsearch_values=1');
264 $linkback =
'<a href="' .
dol_sanitizeUrl($backtolist) .
'">' . $langs->trans(
"BackToList") .
'</a>';
268 print
'<div class="fichecenter">';
269 print
'<div class="fichehalfleft">';
270 print
'<div class="underbanner clearboth"></div>';
271 print
'<table class="border centpercent tableforfield">' .
"\n";
274 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_view.tpl.php';
280 print
'<div class="clearboth"></div>';
285 if ($action !=
'editline') {
286 print
'<div class="tabsAction">' .
"\n";
287 $parameters = array();
288 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
293 if (empty($reshook)) {
295 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=edit',
'', $permissiontoedit);
298 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'] .
'?id=' . $object->id .
'&action=delete',
'', $permissiontodelete);
300 print
'</div>' .
"\n";
306 if (!empty($object->table_element_line)) {
308 $result = $object->getLinesArray();
310 print
load_fiche_titre($langs->trans(
"PossibleValues") . (!empty($object->lines) ?
'<span class="opacitymedium colorblack paddingleft">(' . count($object->lines) .
')</span>' :
''));
312 print
' <form name="addproduct" id="addproduct" action="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id . (($action !=
'editline') ?
'' :
'#line_' .
GETPOST(
'lineid',
'int')) .
'" method="POST">
313 <input type="hidden" name="token" value="' . newToken() .
'">
314 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline') .
'">
315 <input type="hidden" name="mode" value="">
316 <input type="hidden" name="page_y" value="">
317 <input type="hidden" name="id" value="' . $object->id .
'">
320 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
322 if ($backtopageforcancel) {
323 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
326 if (!empty($conf->use_javascript_ajax)) {
327 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
330 print
'<div class="div-table-responsive-no-min">';
331 if (!empty($object->lines) || ($permissiontoedit && $action !=
'selectlines' && $action !=
'editline')) {
332 print
'<table id="tablelines" class="noborder centpercent">';
335 $object->printObjectLines($action, $mysoc,
null,
GETPOST(
'lineid',
'int'), 1,
'/variants/tpl', ($permissiontoedit ? 1 : 0));
337 if (!empty($object->lines) || ($permissiontoedit && $action !=
'selectlines' && $action !=
'editline')) {
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class ProductAttribute Used to represent a product attribute.
Class ProductAttributeValue Used to represent a product attribute value.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
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='', $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)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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...
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.