PageRenderTime 60ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/product/list.php

https://bitbucket.org/speedealing/speedealing
PHP | 302 lines | 221 code | 31 blank | 50 comment | 38 complexity | 6d3bdbb94b0adbe282bbdbf7b613780d MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
  6. * Copyright (C) 2011-2012 Herve Prot <herve.prot@symeos.com>
  7. * Copyright (C) 2011 Patrick Mary <laube@hotmail.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /* Specific to download the price list file */
  23. if (isset($_GET["action"]) && $_GET["action"] == "builddoc") {
  24. define('NOTOKENRENEWAL', 1); // Disables token renewal
  25. function llxHeader() {
  26. }
  27. if (!defined('NOREQUIREMENU'))
  28. define('NOREQUIREMENU', '1');
  29. if (!defined('NOREQUIREHTML'))
  30. define('NOREQUIREHTML', '1');
  31. if (!defined('NOREQUIREAJAX'))
  32. define('NOREQUIREAJAX', '1');
  33. }
  34. require '../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  36. $type = GETPOST("type", "alpha");
  37. $action = GETPOST('action', 'alpha');
  38. $canvas = GETPOST("canvas");
  39. $objcanvas = '';
  40. if (!empty($canvas)) {
  41. require_once DOL_DOCUMENT_ROOT . '/core/class/canvas.class.php';
  42. $objcanvas = new Canvas($db, $action);
  43. $objcanvas->getCanvas('product', 'list', $canvas);
  44. }
  45. // Security check
  46. if ($type == 'PRODUCT')
  47. $result = restrictedArea($user, 'produit', '', '', '', '', '', $objcanvas);
  48. else if ($type == 'SERVICE')
  49. $result = restrictedArea($user, 'service', '', '', '', '', '', $objcanvas);
  50. else
  51. $result = restrictedArea($user, 'produit|service', '', '', '', '', '', $objcanvas);
  52. $object = new Product($db);
  53. /*
  54. * View
  55. */
  56. llxHeader('', $langs->trans("ProductsAndServices"), '', '', '', '');
  57. $title = $langs->trans("ProductsAndServices");
  58. if (!empty($type)) {
  59. if ($type == "SERVICE") {
  60. $title = $langs->trans("Services");
  61. } else {
  62. $title = $langs->trans("Products");
  63. }
  64. }
  65. if ($action == 'builddoc') {
  66. // Build export file
  67. $result = $object->exportPrice($_GET['price_level']);
  68. if ($result < 0) {
  69. setEventMessage($object->error, "errors");
  70. } else {
  71. setEventMessage($langs->trans("FileSuccessfullyBuilt"));
  72. $object->downloadTempFile($result);
  73. }
  74. }
  75. if ($action == 'import') {
  76. // Build export file
  77. $result = $object->importPrice("price_level_import_UGAP.csv");
  78. if ($result < 0) {
  79. setEventMessage($object->error, "errors");
  80. } else {
  81. setEventMessage($langs->trans("FileSuccessfullyBuilt"));
  82. }
  83. }
  84. print_fiche_titre($title);
  85. /* ?>
  86. <div class="dashboard">
  87. <div class="columns">
  88. <div class="four-columns twelve-columns-mobile graph">
  89. <?php $object->graphPieStatus(); ?>
  90. </div>
  91. <div class="eight-columns twelve-columns-mobile new-row-mobile graph">
  92. <?php $object->graphBarStatus(); ?>
  93. </div>
  94. </div>
  95. </div>
  96. <?php */
  97. print '<div class="with-padding">';
  98. //print start_box($titre,"twelve","16-Companies.png");
  99. /*
  100. * Barre d'actions
  101. *
  102. */
  103. print '<div class="margin-bottom button-group right compact children-tooltip">';
  104. if ($type == "SERVICE" || empty($type))
  105. print '<a class="button icon-star" href="' . strtolower(get_class($object)) . '/fiche.php?action=create&type=SERVICE">' . $langs->trans("NewService") . '</a> ';
  106. if ($type == "PRODUCT" || empty($type))
  107. print '<a class="button icon-star" href="' . strtolower(get_class($object)) . '/fiche.php?action=create&type=PRODUCT">' . $langs->trans("NewProduct") . '</a>';
  108. if ($user->rights->produit->export)
  109. print '<button class="button icon-outbox" onclick="openExportPrice();" title="ExportPriceLevels" ></button>';
  110. if ($user->rights->produit->import)
  111. print '<a class="button icon-inbox" href="' . $_SERVER["PHP_SELF"] . '?action=import&type=' . $_GET["type"] . '" title="ImportPriceLevels" ></a>';
  112. print "</div>";
  113. if ($user->rights->produit->export)
  114. print "<script>
  115. function openExportPrice()
  116. {
  117. var cancelled = false;
  118. $.modal.prompt('Please enter value list price : ', function(value)
  119. {
  120. if (value.length == 0)
  121. {
  122. $(this).getModalContentBlock().message('Please enter a correct value', { append: false, classes: ['red-gradient'] });
  123. return false;
  124. }
  125. window.location.href = '" . $_SERVER['PHP_SELF'] . "?action=builddoc&type=" . $_GET["type"] . "&price_level='+value;
  126. }, function()
  127. {
  128. });
  129. };
  130. </script>";
  131. $i = 0;
  132. $obj = new stdClass();
  133. print '<table class="display dt_act" id="product" >';
  134. // Ligne des titres
  135. print'<thead>';
  136. print'<tr>';
  137. print'<th>';
  138. print'</th>';
  139. $obj->aoColumns[$i] = new stdClass();
  140. $obj->aoColumns[$i]->mDataProp = "_id";
  141. $obj->aoColumns[$i]->bUseRendered = false;
  142. $obj->aoColumns[$i]->bSearchable = false;
  143. $obj->aoColumns[$i]->bVisible = false;
  144. $i++;
  145. print'<th class="essential">';
  146. print $title;
  147. print'</th>';
  148. $obj->aoColumns[$i] = new stdClass();
  149. $obj->aoColumns[$i]->mDataProp = "ref";
  150. $obj->aoColumns[$i]->bUseRendered = false;
  151. $obj->aoColumns[$i]->bSearchable = true;
  152. $obj->aoColumns[$i]->sDefaultContent = "";
  153. $obj->aoColumns[$i]->fnRender = $object->datatablesFnRender("ref", "url");
  154. $i++;
  155. print'<th class="essential">';
  156. print $langs->trans('Label');
  157. print'</th>';
  158. $obj->aoColumns[$i] = new stdClass();
  159. $obj->aoColumns[$i]->mDataProp = "label";
  160. $obj->aoColumns[$i]->sDefaultContent = "";
  161. $i++;
  162. print'<th class="essential">';
  163. print $langs->trans('Categories');
  164. print'</th>';
  165. $obj->aoColumns[$i] = new stdClass();
  166. $obj->aoColumns[$i]->mDataProp = "Tag";
  167. $obj->aoColumns[$i]->sClass = "center";
  168. $obj->aoColumns[$i]->sDefaultContent = "";
  169. $obj->aoColumns[$i]->fnRender = $object->datatablesFnRender("Tag", "tag");
  170. $i++;
  171. print'<th class="essential">';
  172. print $langs->trans('SellingPrice');
  173. print'</th>';
  174. $obj->aoColumns[$i] = new stdClass();
  175. $obj->aoColumns[$i]->mDataProp = "price.pu_ht";
  176. $obj->aoColumns[$i]->sDefaultContent = "";
  177. $obj->aoColumns[$i]->sClass = "fright";
  178. $obj->aoColumns[$i]->fnRender = $object->datatablesFnRender("price.pu_ht", "price");
  179. $i++;
  180. print'<th class="essential">';
  181. print $langs->trans("Date");
  182. print'</th>';
  183. $obj->aoColumns[$i] = new stdClass();
  184. $obj->aoColumns[$i]->mDataProp = "tms";
  185. $obj->aoColumns[$i]->sClass = "center";
  186. $obj->aoColumns[$i]->bUseRendered = false;
  187. $obj->aoColumns[$i]->fnRender = $object->datatablesFnRender("tms", "date");
  188. $i++;
  189. if (empty($type)) {
  190. print'<th class="essential">';
  191. print $langs->trans("Type");
  192. print'</th>';
  193. $obj->aoColumns[$i] = new stdClass();
  194. $obj->aoColumns[$i]->mDataProp = "type";
  195. $obj->aoColumns[$i]->sClass = "center";
  196. $obj->aoColumns[$i]->sWidth = "60px";
  197. $obj->aoColumns[$i]->sDefaultContent = "PRODUCT";
  198. $obj->aoColumns[$i]->fnRender = $object->datatablesFnRender("type", "status");
  199. $i++;
  200. }
  201. print'<th class="essential">';
  202. print $langs->trans("Status");
  203. print'</th>';
  204. $obj->aoColumns[$i] = new stdClass();
  205. $obj->aoColumns[$i]->mDataProp = "Status";
  206. $obj->aoColumns[$i]->sClass = "dol_select center";
  207. $obj->aoColumns[$i]->sWidth = "100px";
  208. $obj->aoColumns[$i]->sDefaultContent = "ST_NEVER";
  209. $obj->aoColumns[$i]->fnRender = $object->datatablesFnRender("Status", "status");
  210. $i++;
  211. print'<th class="essential">';
  212. print $langs->trans('Action');
  213. print'</th>';
  214. $obj->aoColumns[$i] = new stdClass();
  215. $obj->aoColumns[$i]->mDataProp = "";
  216. $obj->aoColumns[$i]->sClass = "center content_actions";
  217. $obj->aoColumns[$i]->sWidth = "60px";
  218. $obj->aoColumns[$i]->bSortable = false;
  219. $obj->aoColumns[$i]->sDefaultContent = "";
  220. $url = "product/fiche.php";
  221. $obj->aoColumns[$i]->fnRender = 'function(obj) {
  222. var ar = [];
  223. ar[ar.length] = "<a href=\"' . $url . '?id=";
  224. ar[ar.length] = obj.aData._id.toString();
  225. ar[ar.length] = "&action=edit&backtopage=' . $_SERVER['PHP_SELF'] . '\" class=\"sepV_a\" title=\"' . $langs->trans("Edit") . '\"><img src=\"' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/edit.png\" alt=\"\" /></a>";
  226. ar[ar.length] = "<a href=\"\"";
  227. ar[ar.length] = " class=\"delEnqBtn\" title=\"' . $langs->trans("Delete") . '\"><img src=\"' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/delete.png\" alt=\"\" /></a>";
  228. var str = ar.join("");
  229. return str;
  230. }';
  231. print'</tr>';
  232. print'</thead>';
  233. print'<tfoot>';
  234. /* input search view */
  235. $i = 0; //Doesn't work with bServerSide
  236. print'<tr>';
  237. print'<th id="' . $i . '"></th>';
  238. $i++;
  239. print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search Product") . '" /></th>';
  240. $i++;
  241. print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search Label") . '" /></th>';
  242. $i++;
  243. print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search category") . '" /></th>';
  244. $i++;
  245. print'<th id="' . $i . '"></th>';
  246. $i++;
  247. print'<th id="' . $i . '"></th>';
  248. $i++;
  249. if (empty($type)) {
  250. print'<th id="' . $i . '"></th>';
  251. $i++;
  252. }
  253. print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search status") . '" /></th>';
  254. $i++;
  255. print'<th id="' . $i . '"></th>';
  256. $i++;
  257. print'</tr>';
  258. print'</tfoot>';
  259. print'<tbody>';
  260. print'</tbody>';
  261. print "</table>";
  262. if (!empty($type))
  263. $obj->sAjaxSource = DOL_URL_ROOT . "/core/ajax/listdatatables.php?json=listType&class=" . get_class($object) . "&key=" . $type;
  264. //$obj->bServerSide = true;
  265. //$obj->sDom = 'C<\"clear\">lfrtip';
  266. $object->datatablesCreate($obj, "product", true, true);
  267. //print end_box();
  268. print '</div>'; // end
  269. llxFooter();
  270. ?>