dolibarr  13.0.2
create.php
1 <?php
2 /* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
3  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
19 require '../main.inc.php';
20 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
21 
22 $ref = GETPOST('ref', 'alpha');
23 $label = GETPOST('label', 'alpha');
24 $backtopage = GETPOST('backtopage', 'alpha');
25 $action = GETPOST('action', 'alpha');
26 
27 
28 /*
29  * Actions
30  */
31 
32 if ($action == 'add') {
33  if (empty($ref) || empty($label)) {
34  setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
35  } else {
36  $prodattr = new ProductAttribute($db);
37  $prodattr->label = $label;
38  $prodattr->ref = $ref;
39 
40  $resid = $prodattr->create($user);
41  if ($resid > 0) {
42  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
43  if ($backtopage)
44  {
45  header('Location: '.$backtopage);
46  } else {
47  header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$resid.'&backtopage='.urlencode($backtopage));
48  }
49  exit;
50  } else {
51  setEventMessages($langs->trans('ErrorRecordAlreadyExists'), $prodattr->errors, 'errors');
52  }
53  }
54 }
55 
56 $langs->load('products');
57 
58 
59 /*
60  * View
61  */
62 
63 $title = $langs->trans('NewProductAttribute');
64 
65 llxHeader('', $title);
66 
67 print load_fiche_titre($title);
68 
70 
71 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
72 print '<input type="hidden" name="token" value="'.newToken().'">';
73 print '<input type="hidden" name="action" value="add">';
74 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
75 
76 ?>
77 
78  <table class="border centpercent">
79  <tr>
80  <td class="titlefield fieldrequired"><label for="ref"><?php echo $langs->trans('Ref') ?></label></td>
81  <td><input type="text" id="ref" name="ref" value="<?php echo $ref ?>"></td>
82  <td><?php echo $langs->trans("VariantRefExample"); ?>
83  </tr>
84  <tr>
85  <td class="fieldrequired"><label for="label"><?php echo $langs->trans('Label') ?></label></td>
86  <td><input type="text" id="label" name="label" value="<?php echo $label ?>"></td>
87  <td><?php echo $langs->trans("VariantLabelExample"); ?>
88  </tr>
89 
90  </table>
91 
92 <?php
94 
95 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></div>';
96 
97 print '</form>';
98 
99 // End of page
100 llxFooter();
101 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
Class ProductAttribute Used to represent a product attribute.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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.
print
Draft customers invoices.
Definition: index.php:89
dol_get_fiche_end($notab=0)
Return tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105