admin_establishment.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. require '../../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/hrm/lib/hrm.lib.php';
  24. require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
  25. // Load translation files required by the page
  26. $langs->loadLangs(array('admin', 'hrm'));
  27. $error = 0;
  28. $permissiontoread = $user->admin;
  29. $permissiontoadd = $user->admin;
  30. // Security check - Protection if external user
  31. //if ($user->socid > 0) accessforbidden();
  32. //if ($user->socid > 0) $socid = $user->socid;
  33. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  34. //restrictedArea($user, $object->element, $object->id, '', '', 'fk_soc', 'rowid', 0);
  35. if (empty($conf->hrm->enabled)) accessforbidden();
  36. if (empty($permissiontoread)) accessforbidden();
  37. /*
  38. * Actions
  39. */
  40. // None
  41. /*
  42. * View
  43. */
  44. $form = new Form($db);
  45. $establishmenttmp = new Establishment($db);
  46. $title = $langs->trans('Establishments');
  47. llxHeader('', $title, '');
  48. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  49. $sortorder = GETPOST('sortorder', 'aZ09comma');
  50. $sortfield = GETPOST('sortfield', 'aZ09comma');
  51. if (!$sortorder) {
  52. $sortorder = "DESC";
  53. }
  54. if (!$sortfield) {
  55. $sortfield = "e.rowid";
  56. }
  57. if (empty($page) || $page == -1) {
  58. $page = 0;
  59. }
  60. $offset = $limit * $page;
  61. $pageprev = $page - 1;
  62. $pagenext = $page + 1;
  63. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  64. // Subheader
  65. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  66. print load_fiche_titre($langs->trans("HRMSetup"), $linkback, 'title_setup');
  67. $newcardbutton = dolGetButtonTitle($langs->trans('NewEstablishment'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/hrm/establishment/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  68. // Configuration header
  69. $head = hrmAdminPrepareHead();
  70. print dol_get_fiche_head($head, 'establishments', $langs->trans("HRM"), -1, "user", 0, $newcardbutton);
  71. $sql = "SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
  72. $sql .= " FROM ".MAIN_DB_PREFIX."establishment as e";
  73. $sql .= " WHERE e.entity IN (".getEntity('establishment').')';
  74. $sql .= $db->order($sortfield, $sortorder);
  75. $sql .= $db->plimit($limit + 1, $offset);
  76. $result = $db->query($sql);
  77. if ($result) {
  78. $num = $db->num_rows($result);
  79. $i = 0;
  80. print '<table class="noborder centpercent">';
  81. print '<tr class="liste_titre">';
  82. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "e.ref", "", "", "", $sortfield, $sortorder);
  83. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "e.label", "", "", "", $sortfield, $sortorder);
  84. print_liste_field_titre("Address", $_SERVER["PHP_SELF"], "e.address", "", "", "", $sortfield, $sortorder);
  85. print_liste_field_titre("Zip", $_SERVER["PHP_SELF"], "e.zip", "", "", "", $sortfield, $sortorder);
  86. print_liste_field_titre("Town", $_SERVER["PHP_SELF"], "e.town", "", "", "", $sortfield, $sortorder);
  87. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "e.status", "", "", '', $sortfield, $sortorder, 'right ');
  88. print "</tr>\n";
  89. if ($num > 0) {
  90. $establishmentstatic = new Establishment($db);
  91. while ($i < min($num, $limit)) {
  92. $obj = $db->fetch_object($result);
  93. $establishmentstatic->id = $obj->rowid;
  94. $establishmentstatic->ref = $obj->ref;
  95. $establishmentstatic->label = $obj->label;
  96. $establishmentstatic->status = $obj->status;
  97. print '<tr class="oddeven">';
  98. print '<td>'.$establishmentstatic->getNomUrl(1).'</td>';
  99. print '<td>'.$obj->label.'</td>';
  100. print '<td class="left">'.$obj->address.'</td>';
  101. print '<td class="left">'.$obj->zip.'</td>';
  102. print '<td class="left">'.$obj->town.'</td>';
  103. print '<td class="right">';
  104. print $establishmentstatic->getLibStatut(5);
  105. print '</td>';
  106. print "</tr>\n";
  107. $i++;
  108. }
  109. } else {
  110. print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  111. }
  112. print '</table>';
  113. } else {
  114. dol_print_error($db);
  115. }
  116. print dol_get_fiche_end();
  117. // End of page
  118. llxFooter();
  119. $db->close();