admin_establishment.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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. * \file htdocs/hrm/admin/admin_establishment.php
  19. * \ingroup HRM
  20. * \brief HRM Establishment module setup page
  21. */
  22. // Load Dolibarr environment
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/hrm/lib/hrm.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
  26. // Load translation files required by the page
  27. $langs->loadLangs(array('admin', 'hrm'));
  28. $error = 0;
  29. // Permissions
  30. $permissiontoread = $user->admin;
  31. $permissiontoadd = $user->admin;
  32. // Security check - Protection if external user
  33. //if ($user->socid > 0) accessforbidden();
  34. //if ($user->socid > 0) $socid = $user->socid;
  35. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  36. //restrictedArea($user, $object->element, $object->id, '', '', 'fk_soc', 'rowid', 0);
  37. if (!isModEnabled('hrm')) accessforbidden();
  38. if (empty($permissiontoread)) accessforbidden();
  39. $sortorder = GETPOST('sortorder', 'aZ09comma');
  40. $sortfield = GETPOST('sortfield', 'aZ09comma');
  41. if (!$sortorder) {
  42. $sortorder = "DESC";
  43. }
  44. if (!$sortfield) {
  45. $sortfield = "e.rowid";
  46. }
  47. if (empty($page) || $page == -1) {
  48. $page = 0;
  49. }
  50. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. /*
  55. * Actions
  56. */
  57. // None
  58. /*
  59. * View
  60. */
  61. $form = new Form($db);
  62. $establishmenttmp = new Establishment($db);
  63. $title = $langs->trans('Establishments');
  64. llxHeader('', $title, '');
  65. // Subheader
  66. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  67. print load_fiche_titre($langs->trans("HRMSetup"), $linkback, 'title_setup');
  68. // Configuration header
  69. $head = hrmAdminPrepareHead();
  70. print dol_get_fiche_head($head, 'establishments', $langs->trans("HRM"), -1, "hrm", 0, '');
  71. $param = '';
  72. $sql = "SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
  73. $sql .= " FROM ".MAIN_DB_PREFIX."establishment as e";
  74. $sql .= " WHERE e.entity IN (".getEntity('establishment').')';
  75. // Count total nb of records
  76. $nbtotalofrecords = '';
  77. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  78. $resql = $db->query($sql);
  79. $nbtotalofrecords = $db->num_rows($resql);
  80. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  81. $page = 0;
  82. $offset = 0;
  83. }
  84. $db->free($resql);
  85. }
  86. $sql .= $db->order($sortfield, $sortorder);
  87. $sql .= $db->plimit($limit + 1, $offset);
  88. $newcardbutton = dolGetButtonTitle($langs->trans('NewEstablishment'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/hrm/establishment/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  89. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', 0, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit, 0, 0, 1);
  90. $result = $db->query($sql);
  91. if ($result) {
  92. $num = $db->num_rows($result);
  93. $i = 0;
  94. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  95. print '<table class="noborder centpercent">';
  96. print '<tr class="liste_titre">';
  97. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "e.ref", "", "", "", $sortfield, $sortorder);
  98. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "e.label", "", "", "", $sortfield, $sortorder);
  99. print_liste_field_titre("Address", $_SERVER["PHP_SELF"], "e.address", "", "", "", $sortfield, $sortorder);
  100. print_liste_field_titre("Zip", $_SERVER["PHP_SELF"], "e.zip", "", "", "", $sortfield, $sortorder);
  101. print_liste_field_titre("Town", $_SERVER["PHP_SELF"], "e.town", "", "", "", $sortfield, $sortorder);
  102. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "e.status", "", "", '', $sortfield, $sortorder, 'right ');
  103. print "</tr>\n";
  104. if ($num > 0) {
  105. $establishmentstatic = new Establishment($db);
  106. while ($i < min($num, $limit)) {
  107. $obj = $db->fetch_object($result);
  108. $establishmentstatic->id = $obj->rowid;
  109. $establishmentstatic->ref = $obj->ref;
  110. $establishmentstatic->label = $obj->label;
  111. $establishmentstatic->status = $obj->status;
  112. print '<tr class="oddeven">';
  113. print '<td>'.$establishmentstatic->getNomUrl(1).'</td>';
  114. print '<td>'.dol_escape_htmltag($obj->label).'</td>';
  115. print '<td>'.dol_escape_htmltag($obj->address).'</td>';
  116. print '<td>'.dol_escape_htmltag($obj->zip).'</td>';
  117. print '<td>'.dol_escape_htmltag($obj->town).'</td>';
  118. print '<td class="right">';
  119. print $establishmentstatic->getLibStatut(5);
  120. print '</td>';
  121. print "</tr>\n";
  122. $i++;
  123. }
  124. } else {
  125. print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  126. }
  127. print '</table>';
  128. print '</div>';
  129. } else {
  130. dol_print_error($db);
  131. }
  132. print dol_get_fiche_end();
  133. // End of page
  134. llxFooter();
  135. $db->close();