list.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 <http://www.gnu.org/licenses/>.
  16. */
  17. require '../main.inc.php';
  18. require DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
  19. $id = GETPOST('id','int');
  20. $action = GETPOST('action','aZ09');
  21. $object = new ProductAttribute($db);
  22. /*
  23. * Actions
  24. */
  25. if ($action == 'up') {
  26. $object->fetch($rowid);
  27. $object->moveUp();
  28. header('Location: '.$_SERVER['PHP_SELF']);
  29. exit();
  30. } elseif ($action == 'down') {
  31. $object->fetch($rowid);
  32. $object->moveDown();
  33. header('Location: '.$_SERVER['PHP_SELF']);
  34. exit();
  35. }
  36. /*
  37. * View
  38. */
  39. $langs->load('products');
  40. $title = $langs->trans($langs->trans('ProductAttributes'));
  41. $variants = $object->fetchAll();
  42. llxHeader('', $title);
  43. $newcardbutton='';
  44. if ($user->rights->produit->creer)
  45. {
  46. $newcardbutton='<a href="'.DOL_URL_ROOT.'/variants/create.php" class="butActionNew"><span class="valignmiddle">'.$langs->trans('Create').'</span>';
  47. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  48. $newcardbutton.= '</a>';
  49. }
  50. print load_fiche_titre($title, $newcardbutton, 'title_products');
  51. $forcereloadpage=empty($conf->global->MAIN_FORCE_RELOAD_PAGE)?0:1;
  52. ?>
  53. <script type="text/javascript">
  54. $(document).ready(function(){
  55. $(".imgupforline, .imgdownforline").hide();
  56. $(".lineupdown").removeAttr('href');
  57. $(".tdlineupdown")
  58. .css("background-image", 'url(<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png'; ?>)')
  59. .css("background-repeat", "no-repeat")
  60. .css("background-position", "center center")
  61. .hover(
  62. function () {
  63. $(this).addClass('showDragHandle');
  64. }, function () {
  65. $(this).removeClass('showDragHandle');
  66. }
  67. );
  68. $("#tablelines").tableDnD({
  69. onDrop: function(table, row) {
  70. console.log('drop');
  71. var reloadpage = "<?php echo $forcereloadpage; ?>";
  72. var roworder = cleanSerialize(decodeURI($("#tablelines").tableDnDSerialize()));
  73. $.post("<?php echo DOL_URL_ROOT; ?>/variants/ajax/orderAttribute.php",
  74. {
  75. roworder: roworder
  76. },
  77. function() {
  78. if (reloadpage == 1) {
  79. location.href = '<?php echo dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']); ?>';
  80. } else {
  81. $("#tablelines .drag").each(
  82. function( intIndex ) {
  83. $(this).removeClass("pair impair");
  84. if (intIndex % 2 == 0) $(this).addClass('impair');
  85. if (intIndex % 2 == 1) $(this).addClass('pair');
  86. });
  87. }
  88. });
  89. },
  90. onDragClass: "dragClass",
  91. dragHandle: "td.tdlineupdown"
  92. });
  93. });
  94. </script>
  95. <table class="liste" id="tablelines">
  96. <tr class="liste_titre nodrag nodrop">
  97. <th class="liste_titre"><?php print $langs->trans('Ref') ?></th>
  98. <th class="liste_titre"><?php print $langs->trans('Label') ?></th>
  99. <th class="liste_titre" align="right"><?php print $langs->trans('NbOfDifferentValues') ?></th>
  100. <th class="liste_titre" align="right"><?php print $langs->trans('NbProducts') ?></th>
  101. <th class="liste_titre" colspan="2"></th>
  102. </tr>
  103. <?php foreach ($variants as $key => $attribute): ?>
  104. <tr id="row-<?php echo $attribute->id ?>" class="drag drop oddeven">
  105. <td><a href="card.php?id=<?php echo $attribute->id ?>"><?php echo dol_htmlentities($attribute->ref) ?></a></td>
  106. <td><a href="card.php?id=<?php echo $attribute->id ?>"><?php echo dol_htmlentities($attribute->label) ?></a></td>
  107. <td align="right"><?php echo $attribute->countChildValues() ?></td>
  108. <td align="right"><?php echo $attribute->countChildProducts() ?></td>
  109. <td style="text-align: right">
  110. <a href="card.php?id=<?php echo $attribute->id ?>&action=edit"><?php echo img_edit() ?></a>
  111. <a href="card.php?id=<?php echo $attribute->id ?>&action=delete"><?php echo img_delete() ?></a>
  112. </td>
  113. <td class="center linecolmove tdlineupdown">
  114. <?php if ($key > 0): ?>
  115. <a class="lineupdown"
  116. href="<?php echo $_SERVER['PHP_SELF'] ?>?action=up&amp;rowid=<?php echo $attribute->id ?>"><?php echo img_up('default', 0, 'imgupforline'); ?></a>
  117. <?php endif ?>
  118. <?php if ($key < count($variants)-1): ?>
  119. <a class="lineupdown"
  120. href="<?php echo $_SERVER['PHP_SELF'] ?>?action=down&amp;rowid=<?php echo $attribute->id ?>"><?php echo img_down('default', 0, 'imgdownforline'); ?></a>
  121. <?php endif ?>
  122. </td>
  123. </tr>
  124. <?php
  125. endforeach
  126. ?>
  127. </table>
  128. <?php
  129. // End of page
  130. llxFooter();
  131. $db->close();