dolibarr  13.0.2
card.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 $valueid = GETPOST('valueid', 'alpha');
25 $action = GETPOST('action', 'aZ09');
26 $label = GETPOST('label', 'alpha');
27 $ref = GETPOST('ref', 'alpha');
28 $confirm = GETPOST('confirm', 'alpha');
29 $cancel = GETPOST('cancel', '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) $action = '';
45 
46 if ($action) {
47  if ($action == 'update') {
48  $object->ref = $ref;
49  $object->label = $label;
50 
51  if ($object->update($user) < 1) {
52  setEventMessages($langs->trans('CoreErrorMessage'), $object->errors, 'errors');
53  } else {
54  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
55  header('Location: '.dol_buildpath('/variants/card.php?id='.$id, 2));
56  exit();
57  }
58  } elseif ($action == 'update_value') {
59  if ($objectval->fetch($valueid) > 0) {
60  $objectval->ref = $ref;
61  $objectval->value = GETPOST('value', 'alpha');
62 
63  if (empty($objectval->ref))
64  {
65  $error++;
66  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors');
67  }
68  if (empty($objectval->value))
69  {
70  $error++;
71  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
72  }
73 
74  if (!$error)
75  {
76  if ($objectval->update($user) > 0) {
77  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
78  } else {
79  setEventMessage($langs->trans('CoreErrorMessage'), $objectval->errors, 'errors');
80  }
81  }
82  }
83 
84  header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2));
85  exit();
86  }
87 }
88 
89 if ($confirm == 'yes') {
90  if ($action == 'confirm_delete') {
91  $db->begin();
92 
93  $res = $objectval->deleteByFkAttribute($object->id, $user);
94 
95  if ($res < 1 || ($object->delete($user) < 1)) {
96  $db->rollback();
97  setEventMessages($langs->trans('CoreErrorMessage'), $object->errors, 'errors');
98  header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2));
99  } else {
100  $db->commit();
101  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
102  header('Location: '.dol_buildpath('/variants/list.php', 2));
103  }
104  exit();
105  } elseif ($action == 'confirm_deletevalue')
106  {
107  if ($objectval->fetch($valueid) > 0) {
108  if ($objectval->delete($user) < 1) {
109  setEventMessages($langs->trans('CoreErrorMessage'), $objectval->errors, 'errors');
110  } else {
111  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
112  }
113 
114  header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2));
115  exit();
116  }
117  }
118 }
119 
120 
121 /*
122  * View
123  */
124 
125 $langs->load('products');
126 
127 $title = $langs->trans('ProductAttributeName', dol_htmlentities($object->label));
128 
129 llxHeader('', $title);
130 
131 //print load_fiche_titre($title);
132 
133 $h = 0;
134 $head[$h][0] = DOL_URL_ROOT.'/variants/card.php?id='.$object->id;
135 $head[$h][1] = $langs->trans("ProductAttributeName");
136 $head[$h][2] = 'variant';
137 $h++;
138 
139 print dol_get_fiche_head($head, 'variant', $langs->trans('ProductAttributeName'), -1, 'generic');
140 
141 if ($action == 'edit') {
142  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
143  print '<input type="hidden" name="token" value="'.newToken().'">';
144  print '<input type="hidden" name="action" value="update">';
145  print '<input type="hidden" name="id" value="'.$id.'">';
146  print '<input type="hidden" name="valueid" value="'.$valueid.'">';
147  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
148 }
149 
150 
151 if ($action != 'edit') {
152  print '<div class="fichecenter">';
153  print '<div class="underbanner clearboth"></div>';
154 }
155 print '<table class="border centpercent tableforfield">';
156 print '<tr>';
157 print '<td class="titlefield'.($action == 'edit' ? ' fieldrequired' : '').'">'.$langs->trans('Ref').'</td>';
158 print '<td>';
159 if ($action == 'edit') {
160  print '<input type="text" name="ref" value="'.$object->ref.'">';
161 } else {
162  print dol_htmlentities($object->ref);
163 }
164 print '</td>';
165 print '</tr>';
166 print '<tr>';
167 print '<td'.($action == 'edit' ? ' class="fieldrequired"' : '').'>'.$langs->trans('Label').'</td>';
168 print '<td>';
169 if ($action == 'edit') {
170  print '<input type="text" name="label" value="'.$object->label.'">';
171 } else {
172  print dol_htmlentities($object->label);
173 }
174 print '</td>';
175 print '</tr>';
176 
177 print '</table>';
178 
179 
180 if ($action != 'edit') {
181  print '</div>';
182 }
183 
185 
186 if ($action == 'edit') {
187  print '<div style="text-align: center;">';
188  print '<div class="inline-block divButAction">';
189  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
190  print '&nbsp; &nbsp;';
191  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
192  print '</div>';
193  print '</div></form>';
194 } else {
195  if ($action == 'delete') {
196  $form = new Form($db);
197 
198  print $form->formconfirm(
199  "card.php?id=".$object->id,
200  $langs->trans('Delete'),
201  $langs->trans('ProductAttributeDeleteDialog'),
202  "confirm_delete",
203  '',
204  0,
205  1
206  );
207  } elseif ($action == 'delete_value') {
208  if ($objectval->fetch($valueid) > 0) {
209  $form = new Form($db);
210 
211  print $form->formconfirm(
212  "card.php?id=".$object->id."&valueid=".$objectval->id,
213  $langs->trans('Delete'),
214  $langs->trans('ProductAttributeValueDeleteDialog', dol_htmlentities($objectval->value), dol_htmlentities($objectval->ref)),
215  "confirm_deletevalue",
216  '',
217  0,
218  1
219  );
220  }
221  }
222 
223  ?>
224 
225  <div class="tabsAction">
226  <div class="inline-block divButAction">
227  <a href="card.php?id=<?php echo $object->id ?>&action=edit&token=<?php echo newToken(); ?>" class="butAction"><?php echo $langs->trans('Modify') ?></a>
228  <a href="card.php?id=<?php echo $object->id ?>&action=delete&token=<?php echo newToken(); ?>" class="butAction"><?php echo $langs->trans('Delete') ?></a>
229  </div>
230  </div>
231 
232 
233  <?php
234 
235  print load_fiche_titre($langs->trans("PossibleValues"));
236 
237  if ($action == 'edit_value') {
238  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
239  print '<input type="hidden" name="token" value="'.newToken().'">';
240  print '<input type="hidden" name="action" value="update_value">';
241  print '<input type="hidden" name="id" value="'.$id.'">';
242  print '<input type="hidden" name="valueid" value="'.$valueid.'">';
243  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
244  }
245 
246  print '<table class="liste">';
247  print '<tr class="liste_titre">';
248  print '<th class="liste_titre titlefield">'.$langs->trans('Ref').'</th>';
249  print '<th class="liste_titre">'.$langs->trans('Value').'</th>';
250  print '<th class="liste_titre"></th>';
251  print '</tr>';
252 
253  foreach ($objectval->fetchAllByProductAttribute($object->id) as $attrval) {
254  print '<tr class="oddeven">';
255  if ($action == 'edit_value' && ($valueid == $attrval->id)) {
256  ?>
257  <td><input type="text" name="ref" value="<?php echo $attrval->ref ?>"></td>
258  <td><input type="text" name="value" value="<?php echo $attrval->value ?>"></td>
259  <td class="right">
260  <input type="submit" value="<?php echo $langs->trans("Save") ?>" class="button button-save">
261  &nbsp; &nbsp;
262  <input type="submit" name="cancel" value="<?php echo $langs->trans("Cancel") ?>" class="button button-cancel">
263  </td>
264  <?php
265  } else {
266  ?>
267  <td><?php echo dol_htmlentities($attrval->ref) ?></td>
268  <td><?php echo dol_htmlentities($attrval->value) ?></td>
269  <td class="right">
270  <a class="editfielda marginrightonly" href="card.php?id=<?php echo $object->id ?>&action=edit_value&valueid=<?php echo $attrval->id ?>"><?php echo img_edit() ?></a>
271  <a href="card.php?id=<?php echo $object->id ?>&action=delete_value&token=<?php echo newToken(); ?>&valueid=<?php echo $attrval->id ?>"><?php echo img_delete() ?></a>
272  </td>
273  <?php
274  }
275  print '</tr>';
276  }
277  print '</table>';
278 
279  if ($action == 'edit_value') {
280  print '</form>';
281  }
282 
283  print '<div class="tabsAction">';
284  print '<div class="inline-block divButAction">';
285  print '<a href="create_val.php?id='.$object->id.'" class="butAction">'.$langs->trans('Create').'</a>';
286  print '</div>';
287  print '</div>';
288 }
289 
290 // End of page
291 llxFooter();
292 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
dol_htmlentities($string, $flags=null, $encoding= 'UTF-8', $double_encode=false)
Replace htmlentities functions.
setEventMessage($mesgs, $style= 'mesgs')
Set event message in dol_events session object.
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
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
Class to manage generation of HTML components Only common components must be here.
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
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105