dolibarr  13.0.2
list.php
1 <?php
2 /* Copyright (C) 2016 Marcos GarcĂ­a <marcosgdf@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 require '../main.inc.php';
19 require DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
20 
21 $action = GETPOST('action', 'aZ09');
22 $object = new ProductAttribute($db);
23 
24 
25 
26 /*
27  * Actions
28  */
29 
30 if ($action == 'up') {
31  $object->fetch($rowid);
32  $object->moveUp();
33 
34  header('Location: '.$_SERVER['PHP_SELF']);
35  exit();
36 } elseif ($action == 'down') {
37  $object->fetch($rowid);
38  $object->moveDown();
39 
40  header('Location: '.$_SERVER['PHP_SELF']);
41  exit();
42 }
43 
44 
45 
46 /*
47  * View
48  */
49 
50 $langs->load('products');
51 
52 $title = $langs->trans($langs->trans('ProductAttributes'));
53 
54 $variants = $object->fetchAll();
55 
56 llxHeader('', $title);
57 
58 $newcardbutton = '';
59 if ($user->rights->produit->creer)
60 {
61  $newcardbutton .= dolGetButtonTitle($langs->trans('Create'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/variants/create.php');
62 }
63 
64 print load_fiche_titre($title, $newcardbutton, 'product');
65 
66 $forcereloadpage = empty($conf->global->MAIN_FORCE_RELOAD_PAGE) ? 0 : 1;
67 ?>
68  <script>
69  $(document).ready(function(){
70  $(".imgupforline, .imgdownforline").hide();
71  $(".lineupdown").removeAttr('href');
72  $(".tdlineupdown")
73  .css("background-image", 'url(<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png'; ?>)')
74  .css("background-repeat", "no-repeat")
75  .css("background-position", "center center")
76  .hover(
77  function () {
78  $(this).addClass('showDragHandle');
79  }, function () {
80  $(this).removeClass('showDragHandle');
81  }
82  );
83 
84  $("#tablelines").tableDnD({
85  onDrop: function(table, row) {
86  console.log('drop');
87  var reloadpage = "<?php echo $forcereloadpage; ?>";
88  var roworder = cleanSerialize(decodeURI($("#tablelines").tableDnDSerialize()));
89  $.post("<?php echo DOL_URL_ROOT; ?>/variants/ajax/orderAttribute.php",
90  {
91  roworder: roworder
92  },
93  function() {
94  if (reloadpage == 1) {
95  location.href = '<?php echo dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']); ?>';
96  } else {
97  $("#tablelines .drag").each(
98  function( intIndex ) {
99  $(this).removeClass("pair impair");
100  if (intIndex % 2 == 0) $(this).addClass('impair');
101  if (intIndex % 2 == 1) $(this).addClass('pair');
102  });
103  }
104  });
105  },
106  onDragClass: "dragClass",
107  dragHandle: "td.tdlineupdown"
108  });
109  });
110  </script>
111 
112  <table class="liste nobottom" id="tablelines">
113  <tr class="liste_titre nodrag nodrop">
114  <th class="liste_titre"><?php print $langs->trans('Ref') ?></th>
115  <th class="liste_titre"><?php print $langs->trans('Label') ?></th>
116  <th class="liste_titre right"><?php print $langs->trans('NbOfDifferentValues') ?></th>
117  <th class="liste_titre right"><?php print $langs->trans('NbProducts') ?></th>
118  <th class="liste_titre" colspan="2"></th>
119  </tr>
120 <?php
121 foreach ($variants as $key => $attribute) {
122  print '<tr id="row-'.$attribute->id.'" class="drag drop oddeven">';
123  print '<td><a href="card.php?id='.$attribute->id.'">'.dol_htmlentities($attribute->ref).'</a></td>';
124  print '<td><a href="card.php?id='.$attribute->id.'">'.dol_htmlentities($attribute->label).'</a></td>';
125  print '<td class="right">'.$attribute->countChildValues().'</td>';
126  print '<td class="right">'.$attribute->countChildProducts().'</td>';
127  print '<td class="right">';
128  print '<a class="editfielda marginrightonly paddingleftonly" href="card.php?id='.$attribute->id.'&action=edit">'.img_edit().'</a>';
129  print '<a class="marginrightonly paddingleftonlyhref="card.php?id='.$attribute->id.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
130  print '</td>';
131  print '<td class="center linecolmove tdlineupdown">';
132  if ($key > 0) {
133  print '<a class="lineupdown" href="'.$_SERVER['PHP_SELF'].'?action=up&amp;rowid='.$attribute->id.'">'.img_up('default', 0, 'imgupforline').'</a>';
134  }
135  if ($key < count($variants) - 1) {
136  print '<a class="lineupdown" href="'.$_SERVER['PHP_SELF'].'?action=down&amp;rowid='.$attribute->id.'">'.img_down('default', 0, 'imgdownforline').'</a>';
137  }
138  print '</td>';
139  print "</tr>\n";
140 }
141 
142 print '</table>';
143 
144 // End of page
145 llxFooter();
146 $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.
dolGetButtonTitle($label, $helpText= '', $iconClass= 'fa fa-file', $url= '', $id= '', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_htmlentities($string, $flags=null, $encoding= 'UTF-8', $double_encode=false)
Replace htmlentities functions.
Class ProductAttribute Used to represent a product attribute.
llxHeader()
Empty header.
Definition: wrapper.php:45
img_down($titlealt= 'default', $selected=0, $moreclass= '')
Show down arrow logo.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_up($titlealt= 'default', $selected=0, $moreclass= '')
Show top arrow logo.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.