index.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <?php
  2. /* Copyright (C) 2013-2016 Jean-François FERRY <jfefe@aternatik.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/public/recruitment/index.php
  19. * \ingroup recruitment
  20. * \brief Public file to list jobs
  21. */
  22. if (!defined('NOCSRFCHECK')) {
  23. define('NOCSRFCHECK', '1');
  24. }
  25. // Do not check anti CSRF attack test
  26. if (!defined('NOREQUIREMENU')) {
  27. define('NOREQUIREMENU', '1');
  28. }
  29. // If there is no need to load and show top and left menu
  30. if (!defined("NOLOGIN")) {
  31. define("NOLOGIN", '1');
  32. }
  33. if (!defined('NOIPCHECK')) {
  34. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  35. }
  36. if (!defined('NOBROWSERNOTIF')) {
  37. define('NOBROWSERNOTIF', '1');
  38. }
  39. // If this page is public (can be called outside logged session)
  40. require '../../main.inc.php';
  41. require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentjobposition.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  45. // Load translation files required by the page
  46. $langs->loadLangs(array("companies", "other", "recruitment"));
  47. // Get parameters
  48. $action = GETPOST('action', 'aZ09');
  49. $email = GETPOST('email', 'alpha');
  50. $object = new RecruitmentJobPosition($db);
  51. // Security check
  52. if (empty($conf->recruitment->enabled)) {
  53. accessforbidden('', 0, 0, 1);
  54. }
  55. /*
  56. * Actions
  57. */
  58. // None
  59. /*
  60. * View
  61. */
  62. $form = new Form($db);
  63. $user_assign = new User($db);
  64. $user_create = new User($db);
  65. if (!$conf->global->RECRUITMENT_ENABLE_PUBLIC_INTERFACE) {
  66. $langs->load("errors");
  67. print '<div class="error">'.$langs->trans('ErrorPublicInterfaceNotEnabled').'</div>';
  68. $db->close();
  69. exit();
  70. }
  71. $arrayofjs = array();
  72. $arrayofcss = array();
  73. llxHeaderTicket($langs->trans("Jobs"), "", 0, 0, $arrayofjs, $arrayofcss);
  74. print '<div class="ticketpublicarealist">';
  75. $display_ticket_list = 1;
  76. print '<br>';
  77. if ($display_ticket_list) {
  78. // Filters
  79. $search_fk_status = GETPOST("search_fk_status", 'alpha');
  80. $search_subject = GETPOST("search_subject", 'alpha');
  81. $search_type = GETPOST("search_type", 'alpha');
  82. $search_category = GETPOST("search_category", 'alpha');
  83. $search_severity = GETPOST("search_severity", 'alpha');
  84. $search_fk_user_create = GETPOST("search_fk_user_create", 'int');
  85. $search_fk_user_assign = GETPOST("search_fk_user_assign", 'int');
  86. // Store current page url
  87. $url_page_current = dol_buildpath('/public/ticket/list.php', 1);
  88. // Do we click on purge search criteria ?
  89. if (GETPOST("button_removefilter_x")) {
  90. $search_fk_status = '';
  91. $search_subject = '';
  92. $search_type = '';
  93. $search_category = '';
  94. $search_severity = '';
  95. $search_fk_user_create = '';
  96. $search_fk_user_assign = '';
  97. }
  98. // fetch optionals attributes and labels
  99. $extrafields = new ExtraFields($db);
  100. $extrafields->fetch_name_optionals_label($object->table_element);
  101. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  102. $filter = array();
  103. $param = 'action=viewlist';
  104. // Definition of fields for list
  105. $arrayfields = array(
  106. 't.datec' => array('label' => $langs->trans("Date"), 'checked' => 1),
  107. 't.date_read' => array('label' => $langs->trans("TicketReadOn"), 'checked' => 0),
  108. 't.date_close' => array('label' => $langs->trans("TicketCloseOn"), 'checked' => 0),
  109. 't.ref' => array('label' => $langs->trans("Ref"), 'checked' => 1),
  110. //'t.track_id' => array('label' => $langs->trans("IDTracking"), 'checked' => 0),
  111. 't.fk_statut' => array('label' => $langs->trans("Status"), 'checked' => 1),
  112. 't.subject' => array('label' => $langs->trans("Subject"), 'checked' => 1),
  113. 'type.code' => array('label' => $langs->trans("Type"), 'checked' => 1),
  114. 'category.code' => array('label' => $langs->trans("Category"), 'checked' => 1),
  115. 'severity.code' => array('label' => $langs->trans("Severity"), 'checked' => 1),
  116. 't.progress' => array('label' => $langs->trans("Progression"), 'checked' => 0),
  117. //'t.fk_contract' => array('label' => $langs->trans("Contract"), 'checked' => 0),
  118. 't.fk_user_create' => array('label' => $langs->trans("Author"), 'checked' => 1),
  119. 't.fk_user_assign' => array('label' => $langs->trans("AssignedTo"), 'checked' => 0),
  120. //'t.entity'=>array('label'=>$langs->trans("Entity"), 'checked'=>1, 'enabled'=>(! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode))),
  121. //'t.datec' => array('label' => $langs->trans("DateCreation"), 'checked' => 0, 'position' => 500),
  122. //'t.tms' => array('label' => $langs->trans("DateModificationShort"), 'checked' => 0, 'position' => 2)
  123. //'t.statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  124. );
  125. // Extra fields
  126. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  127. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  128. if ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate') {
  129. $arrayfields["ef.".$key] = array('label' => $extrafields->attributes[$object->table_element]['label'][$key], 'checked' => ($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1, 'position' => $extrafields->attributes[$object->table_element]['pos'][$key], 'enabled' =>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3) && $extrafields->attributes[$object->table_element]['perms'][$key]);
  130. }
  131. }
  132. }
  133. if (!empty($search_subject)) {
  134. $filter['t.subject'] = $search_subject;
  135. $param .= '&search_subject='.urlencode($search_subject);
  136. }
  137. if (!empty($search_type)) {
  138. $filter['t.type_code'] = $search_type;
  139. $param .= '&search_type='.urlencode($search_type);
  140. }
  141. if (!empty($search_category)) {
  142. $filter['t.category_code'] = $search_category;
  143. $param .= '&search_category='.urlencode($search_category);
  144. }
  145. if (!empty($search_severity)) {
  146. $filter['t.severity_code'] = $search_severity;
  147. $param .= '&search_severity='.urlencode($search_severity);
  148. }
  149. if (!empty($search_fk_user_assign)) {
  150. // -1 value = all so no filter
  151. if ($search_fk_user_assign > 0) {
  152. $filter['t.fk_user_assign'] = $search_fk_user_assign;
  153. $param .= '&search_fk_user_assign='.urlencode($search_fk_user_assign);
  154. }
  155. }
  156. if (!empty($search_fk_user_create)) {
  157. // -1 value = all so no filter
  158. if ($search_fk_user_create > 0) {
  159. $filter['t.fk_user_create'] = $search_fk_user_create;
  160. $param .= '&search_fk_user_create='.urlencode($search_fk_user_create);
  161. }
  162. }
  163. if ((isset($search_fk_status) && $search_fk_status != '') && $search_fk_status != '-1' && $search_fk_status != 'non_closed') {
  164. $filter['t.fk_statut'] = $search_fk_status;
  165. $param .= '&search_fk_status='.urlencode($search_fk_status);
  166. }
  167. if (isset($search_fk_status) && $search_fk_status == 'non_closed') {
  168. $filter['t.fk_statut'] = array(0, 1, 3, 4, 5, 6);
  169. $param .= '&search_fk_status=non_closed';
  170. }
  171. require DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  172. $sortfield = GETPOST("sortfield", 'alpha');
  173. $sortorder = GETPOST("sortorder", 'alpha');
  174. if (!$sortfield) {
  175. $sortfield = 't.datec';
  176. }
  177. if (!$sortorder) {
  178. $sortorder = 'DESC';
  179. }
  180. $limit = $conf->liste_limit;
  181. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  182. if (empty($page) || $page == -1) {
  183. $page = 0;
  184. } // If $page is not defined, or '' or -1
  185. $offset = $limit * $page;
  186. $pageprev = $page - 1;
  187. $pagenext = $page + 1;
  188. // Request SQL
  189. $sql = "SELECT DISTINCT";
  190. $sql .= " t.rowid,";
  191. $sql .= " t.ref,";
  192. $sql .= " t.track_id,";
  193. $sql .= " t.fk_soc,";
  194. $sql .= " t.fk_project,";
  195. $sql .= " t.origin_email,";
  196. $sql .= " t.fk_user_create, uc.lastname as user_create_lastname, uc.firstname as user_create_firstname,";
  197. $sql .= " t.fk_user_assign, ua.lastname as user_assign_lastname, ua.firstname as user_assign_firstname,";
  198. $sql .= " t.subject,";
  199. $sql .= " t.message,";
  200. $sql .= " t.fk_statut,";
  201. $sql .= " t.resolution,";
  202. $sql .= " t.progress,";
  203. $sql .= " t.timing,";
  204. $sql .= " t.type_code,";
  205. $sql .= " t.category_code,";
  206. $sql .= " t.severity_code,";
  207. $sql .= " t.datec,";
  208. $sql .= " t.date_read,";
  209. $sql .= " t.date_close,";
  210. $sql .= " t.tms,";
  211. $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label";
  212. // Add fields for extrafields
  213. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  214. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  215. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  216. }
  217. }
  218. $sql .= " FROM ".MAIN_DB_PREFIX."recruitment_recruitmentjobposition as t";
  219. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=t.fk_soc";
  220. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as uc ON uc.rowid=t.fk_user_create";
  221. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  222. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."recruitment_recruitmentjobposition_extrafields as ef on (t.rowid = ef.fk_object)";
  223. }
  224. $sql .= " WHERE t.entity IN (".getEntity('recruitmentjobposition').")";
  225. // Manage filter
  226. if (!empty($filter)) {
  227. foreach ($filter as $key => $value) {
  228. if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year
  229. $sql .= " AND ".$key." = '".$db->escape($value)."'";
  230. } elseif ($key == 't.fk_statut') {
  231. if (is_array($value) && count($value) > 0) {
  232. $sql .= " AND ".$key.' IN ('.$db->sanitize(implode(',', $value)).')';
  233. } else {
  234. $sql .= " AND ".$key." = ".((int) $value);
  235. }
  236. } else {
  237. $sql .= " AND ".$key." LIKE '%".$db->escape($value)."%'";
  238. }
  239. }
  240. }
  241. $sql .= " ORDER BY ".$sortfield.' '.$sortorder;
  242. $resql = $db->query($sql);
  243. if ($resql) {
  244. $num_total = $db->num_rows($resql);
  245. if (!empty($limit)) {
  246. $sql .= ' '.$db->plimit($limit + 1, $offset);
  247. }
  248. $resql = $db->query($sql);
  249. if ($resql) {
  250. $num = $db->num_rows($resql);
  251. print_barre_liste($langs->trans('JobList'), $page, 'public/recruitment/list.php', $param, $sortfield, $sortorder, '', $num, $num_total, 'ticket');
  252. // Search bar
  253. print '<form method="get" action="'.$url_form.'" id="searchFormList" >'."\n";
  254. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  255. print '<input type="hidden" name="action" value="viewlist">';
  256. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  257. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  258. $varpage = empty($contextpage) ? $url_page_current : $contextpage;
  259. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  260. print '<table class="liste '.($moreforfilter ? "listwithfilterbefore" : "").'">';
  261. // Filter bar
  262. print '<tr class="liste_titre">';
  263. if (!empty($arrayfields['t.datec']['checked'])) {
  264. print '<td class="liste_titre"></td>';
  265. }
  266. if (!empty($arrayfields['t.ref']['checked'])) {
  267. print '<td class="liste_titre"></td>';
  268. }
  269. if (!empty($arrayfields['t.fk_user_create']['checked'])) {
  270. print '<td class="liste_titre"></td>';
  271. }
  272. if (!empty($arrayfields['t.tms']['checked'])) {
  273. print '<td class="liste_titre"></td>';
  274. }
  275. // Extra fields
  276. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  277. // Fields from hook
  278. $parameters = array('arrayfields'=>$arrayfields);
  279. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  280. print $hookmanager->resPrint;
  281. // Status
  282. if (!empty($arrayfields['t.fk_statut']['checked'])) {
  283. print '<td class="liste_titre">';
  284. $selected = ($search_fk_status != "non_closed" ? $search_fk_status : '');
  285. //$object->printSelectStatus($selected);
  286. print '</td>';
  287. }
  288. // Action column
  289. print '<td class="liste_titre maxwidthsearch">';
  290. $searchpicto = $form->showFilterButtons();
  291. print $searchpicto;
  292. print '</td>';
  293. print '</tr>';
  294. // Field title
  295. print '<tr class="liste_titre">';
  296. if (!empty($arrayfields['t.datec']['checked'])) {
  297. print_liste_field_titre($arrayfields['t.datec']['label'], $url_page_current, 't.datec', '', $param, '', $sortfield, $sortorder);
  298. }
  299. if (!empty($arrayfields['t.ref']['checked'])) {
  300. print_liste_field_titre($arrayfields['t.ref']['label'], $url_page_current, 't.ref', '', $param, '', $sortfield, $sortorder);
  301. }
  302. if (!empty($arrayfields['t.fk_user_create']['checked'])) {
  303. print_liste_field_titre($arrayfields['t.fk_user_create']['label'], $url_page_current, 't.fk_user_create', '', $param, '', $sortfield, $sortorder);
  304. }
  305. if (!empty($arrayfields['t.tms']['checked'])) {
  306. print_liste_field_titre($arrayfields['t.tms']['label'], $url_page_current, 't.tms', '', $param, '', $sortfield, $sortorder);
  307. }
  308. // Extra fields
  309. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  310. // Hook fields
  311. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  312. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  313. print $hookmanager->resPrint;
  314. if (!empty($arrayfields['t.fk_statut']['checked'])) {
  315. print_liste_field_titre($arrayfields['t.fk_statut']['label'], $url_page_current, 't.fk_statut', '', $param, '', $sortfield, $sortorder);
  316. }
  317. print_liste_field_titre($selectedfields, $url_page_current, "", '', '', 'align="right"', $sortfield, $sortorder, 'center maxwidthsearch ');
  318. print '</tr>';
  319. while ($obj = $db->fetch_object($resql)) {
  320. print '<tr class="oddeven">';
  321. // Date ticket
  322. if (!empty($arrayfields['t.datec']['checked'])) {
  323. print '<td>';
  324. print dol_print_date($db->jdate($obj->datec), 'dayhour');
  325. print '</td>';
  326. }
  327. // Ref
  328. if (!empty($arrayfields['t.ref']['checked'])) {
  329. print '<td class="nowraponall">';
  330. print $obj->ref;
  331. print '</td>';
  332. }
  333. // Message author
  334. if (!empty($arrayfields['t.fk_user_create']['checked'])) {
  335. print '<td>';
  336. if ($obj->fk_user_create > 0) {
  337. $user_create->firstname = (!empty($obj->user_create_firstname) ? $obj->user_create_firstname : '');
  338. $user_create->name = (!empty($obj->user_create_lastname) ? $obj->user_create_lastname : '');
  339. $user_create->id = (!empty($obj->fk_user_create) ? $obj->fk_user_create : '');
  340. print $user_create->getFullName($langs);
  341. } else {
  342. print $langs->trans('Email');
  343. }
  344. print '</td>';
  345. }
  346. if (!empty($arrayfields['t.tms']['checked'])) {
  347. print '<td>'.dol_print_date($db->jdate($obj->tms), 'dayhour').'</td>';
  348. }
  349. // Extra fields
  350. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  351. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  352. if (!empty($arrayfields["ef.".$key]['checked'])) {
  353. print '<td';
  354. $align = $extrafields->getAlignFlag($key);
  355. if ($align) {
  356. print ' align="'.$align.'"';
  357. }
  358. print '>';
  359. $tmpkey = 'options_'.$key;
  360. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  361. print '</td>';
  362. }
  363. }
  364. }
  365. // Statut
  366. if (!empty($arrayfields['t.fk_statut']['checked'])) {
  367. print '<td class="nowraponall">';
  368. $object->fk_statut = $obj->fk_statut;
  369. print $object->getLibStatut(2);
  370. print '</td>';
  371. }
  372. print '<td></td>';
  373. $i++;
  374. print '</tr>';
  375. }
  376. print '</table>';
  377. print '</form>';
  378. print '<form method="post" id="form_view" name="form_view" enctype="multipart/form-data" action="'.dol_buildpath('/public/recruitment/view.php', 1).'" style="display:none;">';
  379. print '<input type="hidden" name="token" value="'.newToken().'">';
  380. print '<input type="hidden" name="action" value="view">';
  381. print '<input type="hidden" name="btn_view_list" value="1">';
  382. print '<input type="hidden" name="track_id" value="">';
  383. print '<input type="hidden" name="email" value="">';
  384. print "</form>";
  385. print '<script type="text/javascript">
  386. function viewticket(ticket_id, email) {
  387. var form = $("#form_view");
  388. form.submit();
  389. }
  390. </script>';
  391. }
  392. }
  393. } else {
  394. print '<div class="error">Not Allowed<br><a href="'.$_SERVER['PHP_SELF'].'?ref='.$object->ref.'">'.$langs->trans('Back').'</a></div>';
  395. }
  396. print "</div>";
  397. // End of page
  398. htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix, $object);
  399. llxFooter('', 'public');
  400. $db->close();