dolibarr  13.0.2
create_val.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 'class/ProductAttribute.class.php';
21 require 'class/ProductAttributeValue.class.php';
22 
23 $id = GETPOST('id', 'int');
24 $ref = GETPOST('ref', 'alpha');
25 $value = GETPOST('value', 'alpha');
26 
27 $action = GETPOST('action', 'aZ09');
28 $cancel = GETPOST('cancel', 'alpha');
29 $backtopage = GETPOST('backtopage', 'alpha');
30 
31 $object = new ProductAttribute($db);
32 $objectval = new ProductAttributeValue($db);
33 
34 if ($object->fetch($id) < 1) {
35  dol_print_error($db, $langs->trans('ErrorRecordNotFound'));
36  exit();
37 }
38 
39 
40 /*
41  * Actions
42  */
43 
44 if ($cancel)
45 {
46  $action = '';
47  header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$object->id);
48  exit();
49 }
50 
51 // None
52 
53 
54 
55 /*
56  * View
57  */
58 
59 if ($action == 'add')
60 {
61  if (empty($ref) || empty($value)) {
62  setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
63  } else {
64  $objectval->fk_product_attribute = $object->id;
65  $objectval->ref = $ref;
66  $objectval->value = $value;
67 
68  if ($objectval->create($user) > 0) {
69  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
70  header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$object->id);
71  exit();
72  } else {
73  setEventMessages($langs->trans('ErrorCreatingProductAttributeValue'), $objectval->errors, 'errors');
74  }
75  }
76 }
77 
78 $langs->load('products');
79 
80 $title = $langs->trans('ProductAttributeName', dol_htmlentities($object->label));
81 
82 llxHeader('', $title);
83 
84 $h = 0;
85 $head[$h][0] = DOL_URL_ROOT.'/variants/card.php?id='.$object->id;
86 $head[$h][1] = $langs->trans("ProductAttributeName");
87 $head[$h][2] = 'variant';
88 $h++;
89 
90 print dol_get_fiche_head($head, 'variant', $langs->trans('ProductAttributeName'), -1, 'generic');
91 
92 print '<div class="fichecenter">';
93 print '<div class="underbanner clearboth"></div>';
94 ?>
95 <table class="border" style="width: 100%">
96  <tr>
97  <td class="titlefield fieldrequired"><?php echo $langs->trans('Ref') ?></td>
98  <td><?php echo dol_htmlentities($object->ref) ?>
99  </tr>
100  <tr>
101  <td class="fieldrequired"><?php echo $langs->trans('Label') ?></td>
102  <td><?php echo dol_htmlentities($object->label) ?></td>
103  </tr>
104 </table>
105 
106 <?php
107 print '</div>';
108 
109 print dol_get_fiche_end();
110 
111 print '<br>';
112 
113 
114 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
115 print '<input type="hidden" name="token" value="'.newToken().'">';
116 print '<input type="hidden" name="action" value="add">';
117 print '<input type="hidden" name="id" value="'.$object->id.'">';
118 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
119 
120 print load_fiche_titre($langs->trans('NewProductAttributeValue'));
121 
122 print dol_get_fiche_head();
123 
124 ?>
125  <table class="border" style="width: 100%">
126  <tr>
127  <td class="titlefield fieldrequired"><label for="ref"><?php echo $langs->trans('Ref') ?></label></td>
128  <td><input id="ref" type="text" name="ref" value="<?php echo $ref ?>"></td>
129  </tr>
130  <tr>
131  <td class="fieldrequired"><label for="value"><?php echo $langs->trans('Label') ?></label></td>
132  <td><input id="value" type="text" name="value" value="<?php echo $value ?>"></td>
133  </tr>
134  </table>
135 <?php
136 
137 print dol_get_fiche_end();
138 
139 print '<div class="center">';
140 print '<input type="submit" class="button" name="create" value="'.$langs->trans("Create").'">';
141 print ' &nbsp; ';
142 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
143 print '</div>';
144 
145 print '</form>';
146 
147 // End of page
148 llxFooter();
149 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_htmlentities($string, $flags=null, $encoding= 'UTF-8', $double_encode=false)
Replace htmlentities functions.
Class ProductAttributeValue Used to represent a product attribute value.
$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_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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