recruitment_recruitmentjobposition.lib.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* Copyright (C) ---Put here your own copyright and developer email---
  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 lib/recruitment_recruitmentjobposition.lib.php
  19. * \ingroup recruitment
  20. * \brief Library files with common functions for RecruitmentJobPosition
  21. */
  22. /**
  23. * Prepare array of tabs for RecruitmentJobPosition
  24. *
  25. * @param RecruitmentJobPosition $object RecruitmentJobPosition
  26. * @return array Array of tabs
  27. */
  28. function recruitmentjobpositionPrepareHead($object)
  29. {
  30. global $db, $langs, $conf;
  31. $langs->load("recruitment");
  32. $h = 0;
  33. $head = array();
  34. $head[$h][0] = dol_buildpath("/recruitment/recruitmentjobposition_card.php", 1).'?id='.$object->id;
  35. $head[$h][1] = $langs->trans("PositionToBeFilled");
  36. $head[$h][2] = 'card';
  37. $h++;
  38. $head[$h][0] = dol_buildpath("/recruitment/recruitmentcandidature_list.php", 1).'?id='.$object->id;
  39. $head[$h][1] = $langs->trans("RecruitmentCandidatures");
  40. $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."recruitment_recruitmentcandidature WHERE fk_recruitmentjobposition = ".((int) $object->id);
  41. $resql = $db->query($sql);
  42. if ($resql) {
  43. $obj = $db->fetch_object($resql);
  44. if ($obj) {
  45. $nCandidature = $obj->nb;
  46. if ($nCandidature > 0) {
  47. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nCandidature.'</span>';
  48. }
  49. }
  50. } else {
  51. dol_print_error($db);
  52. }
  53. $head[$h][2] = 'candidatures';
  54. $h++;
  55. if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
  56. $nbNote = 0;
  57. if (!empty($object->note_private)) {
  58. $nbNote++;
  59. }
  60. if (!empty($object->note_public)) {
  61. $nbNote++;
  62. }
  63. $head[$h][0] = dol_buildpath('/recruitment/recruitmentjobposition_note.php', 1).'?id='.$object->id;
  64. $head[$h][1] = $langs->trans('Notes');
  65. if ($nbNote > 0) {
  66. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  67. }
  68. $head[$h][2] = 'note';
  69. $h++;
  70. }
  71. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  72. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  73. $upload_dir = $conf->recruitment->dir_output."/recruitmentjobposition/".dol_sanitizeFileName($object->ref);
  74. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  75. $nbLinks = Link::count($db, $object->element, $object->id);
  76. $head[$h][0] = dol_buildpath("/recruitment/recruitmentjobposition_document.php", 1).'?id='.$object->id;
  77. $head[$h][1] = $langs->trans('Documents');
  78. if (($nbFiles + $nbLinks) > 0) {
  79. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  80. }
  81. $head[$h][2] = 'document';
  82. $h++;
  83. $head[$h][0] = dol_buildpath("/recruitment/recruitmentjobposition_agenda.php", 1).'?id='.$object->id;
  84. $head[$h][1] = $langs->trans("Events");
  85. $head[$h][2] = 'agenda';
  86. $h++;
  87. // Show more tabs from modules
  88. // Entries must be declared in modules descriptor with line
  89. //$this->tabs = array(
  90. // 'entity:+tabname:Title:@recruitment:/recruitment/mypage.php?id=__ID__'
  91. //); // to add new tab
  92. //$this->tabs = array(
  93. // 'entity:-tabname:Title:@recruitment:/recruitment/mypage.php?id=__ID__'
  94. //); // to remove a tab
  95. complete_head_from_modules($conf, $langs, $object, $head, $h, 'recruitmentjobposition');
  96. complete_head_from_modules($conf, $langs, $object, $head, $h, 'recruitmentjobposition', 'remove');
  97. return $head;
  98. }
  99. /**
  100. * Return string with full Url
  101. *
  102. * @param int $mode 0=True url, 1=Url formated with colors
  103. * @param string $ref Ref of object
  104. * @param string $localorexternal 0=Url for browser, 1=Url for external access
  105. * @return string Url string
  106. */
  107. function getPublicJobPositionUrl($mode, $ref = '', $localorexternal = 0)
  108. {
  109. global $conf, $dolibarr_main_url_root;
  110. $ref = str_replace(' ', '', $ref);
  111. $out = '';
  112. // Define $urlwithroot
  113. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  114. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  115. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  116. $urltouse = DOL_MAIN_URL_ROOT;
  117. if ($localorexternal) {
  118. $urltouse = $urlwithroot;
  119. }
  120. $out = $urltouse.'/public/recruitment/view.php?ref='.($mode ? '<span style="color: #666666">' : '').$ref.($mode ? '</span>' : '');
  121. /*if (!empty($conf->global->RECRUITMENT_SECURITY_TOKEN))
  122. {
  123. if (empty($conf->global->RECRUITMENT_SECURITY_TOKEN)) $out .= '&securekey='.urlencode($conf->global->RECRUITMENT_SECURITY_TOKEN);
  124. else $out .= '&securekey='.urlencode(dol_hash($conf->global->RECRUITMENT_SECURITY_TOKEN, 2));
  125. }*/
  126. // For multicompany
  127. if (!empty($out) && isModEnabled('multicompany')) {
  128. $out .= "&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
  129. }
  130. return $out;
  131. }