recruitmentcandidature_card.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <?php
  2. /* Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
  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 recruitmentcandidature_card.php
  19. * \ingroup recruitment
  20. * \brief Page to create/edit/view recruitmentcandidature
  21. */
  22. // Load Dolibarr environment
  23. require_once '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentjobposition.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentcandidature.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/recruitment/lib/recruitment_recruitmentcandidature.lib.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("recruitment", "other", "users"));
  33. // Get parameters
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $action = GETPOST('action', 'aZ09');
  37. $confirm = GETPOST('confirm', 'alpha');
  38. $cancel = GETPOST('cancel', 'aZ09');
  39. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'recruitmentcandidaturecard'; // To manage different context of search
  40. $backtopage = GETPOST('backtopage', 'alpha');
  41. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  42. $lineid = GETPOST('lineid', 'int');
  43. // Initialize technical objects
  44. $object = new RecruitmentCandidature($db);
  45. $extrafields = new ExtraFields($db);
  46. $diroutputmassaction = $conf->recruitment->dir_output.'/temp/massgeneration/'.$user->id;
  47. $hookmanager->initHooks(array('recruitmentcandidaturecard', 'globalcard')); // Note that conf->hooks_modules contains array
  48. // Fetch optionals attributes and labels
  49. $extrafields->fetch_name_optionals_label($object->table_element);
  50. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  51. // Initialize array of search criterias
  52. $search_all = GETPOST("search_all", 'alpha');
  53. $search = array();
  54. foreach ($object->fields as $key => $val) {
  55. if (GETPOST('search_'.$key, 'alpha')) {
  56. $search[$key] = GETPOST('search_'.$key, 'alpha');
  57. }
  58. }
  59. if (empty($action) && empty($id) && empty($ref)) {
  60. $action = 'create';
  61. }
  62. // Load object
  63. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  64. $permissiontoread = $user->hasRight('recruitment', 'recruitmentjobposition', 'read');
  65. $permissiontoadd = $user->hasRight('recruitment', 'recruitmentjobposition', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  66. $permissiontodelete = $user->hasRight('recruitment', 'recruitmentjobposition', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  67. $permissionnote = $user->hasRight('recruitment', 'recruitmentjobposition', 'write'); // Used by the include of actions_setnotes.inc.php
  68. $permissiondellink = $user->hasRight('recruitment', 'recruitmentjobposition', 'write'); // Used by the include of actions_dellink.inc.php
  69. $upload_dir = $conf->recruitment->multidir_output[isset($object->entity) ? $object->entity : 1];
  70. // Security check - Protection if external user
  71. //if ($user->socid > 0) accessforbidden();
  72. //if ($user->socid > 0) $socid = $user->socid;
  73. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  74. $result = restrictedArea($user, 'recruitment', $object->id, 'recruitment_recruitmentcandidature', 'recruitmentjobposition', '', 'rowid', $isdraft);
  75. /*
  76. * Actions
  77. */
  78. $parameters = array();
  79. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  80. if ($reshook < 0) {
  81. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  82. }
  83. if (empty($reshook)) {
  84. $error = 0;
  85. $backurlforlist = dol_buildpath('/recruitment/recruitmentcandidature_list.php', 1);
  86. if (empty($backtopage) || ($cancel && empty($id))) {
  87. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  88. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  89. $backtopage = $backurlforlist;
  90. } else {
  91. $backtopage = dol_buildpath('/recruitment/recruitmentcandidature_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
  92. }
  93. }
  94. }
  95. $triggermodname = 'RECRUITMENTCANDIDATURE_MODIFY'; // Name of trigger action code to execute when we modify record
  96. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  97. $object->email_fields_no_propagate_in_actioncomm = 1;
  98. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  99. $object->email_fields_no_propagate_in_actioncomm = 0;
  100. // Actions when linking object each other
  101. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  102. // Actions when printing a doc from card
  103. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  104. // Action to move up and down lines of object
  105. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  106. // Action to build doc
  107. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  108. if ($action == 'classin' && $permissiontoadd) {
  109. $object->setProject(GETPOST('projectid', 'int'));
  110. }
  111. if ($action == 'confirm_decline' && $confirm == 'yes' && $permissiontoadd) {
  112. $result = $object->setStatut($object::STATUS_REFUSED, null, '', $triggermodname);
  113. if ($result < 0) {
  114. setEventMessages($object->error, $object->errors, 'errors');
  115. }
  116. }
  117. if ($action == 'confirm_makeofferordecline' && $permissiontoadd && !GETPOST('cancel', 'alpha')) {
  118. if (!(GETPOST('status', 'int') > 0)) {
  119. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors');
  120. $action = 'makeofferordecline';
  121. } else {
  122. // prevent browser refresh from closing proposal several times
  123. if ($object->status == $object::STATUS_VALIDATED) {
  124. $db->begin();
  125. if (GETPOST('status', 'int') == $object::STATUS_REFUSED) {
  126. $result = $object->setStatut($object::STATUS_REFUSED, null, '', $triggermodname);
  127. if ($result < 0) {
  128. setEventMessages($object->error, $object->errors, 'errors');
  129. }
  130. } else {
  131. $result = $object->setStatut($object::STATUS_CONTRACT_PROPOSED, null, '', $triggermodname);
  132. if ($result < 0) {
  133. setEventMessages($object->error, $object->errors, 'errors');
  134. }
  135. }
  136. if (!$error) {
  137. $db->commit();
  138. } else {
  139. $db->rollback();
  140. }
  141. }
  142. }
  143. }
  144. if ($action == 'confirm_closeas' && $permissiontoadd && !GETPOST('cancel', 'alpha')) {
  145. if (!(GETPOST('status', 'int') > 0)) {
  146. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors');
  147. $action = 'makeofferordecline';
  148. } else {
  149. // prevent browser refresh from closing proposal several times
  150. if ($object->status == $object::STATUS_CONTRACT_PROPOSED) {
  151. $db->begin();
  152. if (GETPOST('status', 'int') == $object::STATUS_CONTRACT_REFUSED) {
  153. $result = $object->setStatut($object::STATUS_CONTRACT_REFUSED, null, '', $triggermodname);
  154. if ($result < 0) {
  155. setEventMessages($object->error, $object->errors, 'errors');
  156. }
  157. } else {
  158. $result = $object->setStatut($object::STATUS_CONTRACT_SIGNED, null, '', $triggermodname);
  159. if ($result < 0) {
  160. setEventMessages($object->error, $object->errors, 'errors');
  161. }
  162. }
  163. if (!$error) {
  164. $db->commit();
  165. } else {
  166. $db->rollback();
  167. }
  168. }
  169. }
  170. }
  171. // Create user from a member
  172. if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->hasRight('user', 'user', 'creer')) {
  173. $jobposition = new RecruitmentJobPosition($db);
  174. $jobposition->fetch($object->fk_recruitmentjobposition);
  175. $db->begin();
  176. // Creation user
  177. $nuser = new User($db);
  178. $nuser->login = GETPOST('login', 'alphanohtml');
  179. $nuser->fk_soc = 0;
  180. $nuser->employee = 1;
  181. $nuser->firstname = $object->firstname;
  182. $nuser->lastname = $object->lastname;
  183. $nuser->email = '';
  184. $nuser->personal_email = $object->email;
  185. $nuser->personal_mobile = $object->phone;
  186. $nuser->birth = $object->date_birth;
  187. $nuser->salary = $object->remuneration_proposed;
  188. $nuser->fk_user = $jobposition->fk_user_supervisor; // Supervisor
  189. $nuser->email = $object->email;
  190. $result = $nuser->create($user);
  191. if ($result < 0) {
  192. $error++;
  193. $langs->load("errors");
  194. setEventMessages($langs->trans($nuser->error), null, 'errors');
  195. $action = 'create_user';
  196. } else {
  197. $object->fk_user = $result;
  198. $object->update($user);
  199. }
  200. if (!$error) {
  201. $db->commit();
  202. setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs');
  203. $action = '';
  204. } else {
  205. $db->rollback();
  206. }
  207. }
  208. // Actions to send emails
  209. $triggersendname = 'RECRUITMENTCANDIDATURE_SENTBYMAIL';
  210. $autocopy = 'MAIN_MAIL_AUTOCOPY_RECRUITMENTCANDIDATURE_TO';
  211. $trackid = 'recruitmentcandidature'.$object->id;
  212. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  213. }
  214. /*
  215. * View
  216. *
  217. * Put here all code to build page
  218. */
  219. $form = new Form($db);
  220. $formfile = new FormFile($db);
  221. $formproject = new FormProjets($db);
  222. if ($action == 'create') {
  223. $title = $langs->trans('NewCandidature');
  224. $help_url = '';
  225. } else {
  226. $title = $object->ref." - ".$langs->trans('Card');
  227. $help_url = '';
  228. }
  229. llxHeader('', $title, $help_url);
  230. // Part to create
  231. if ($action == 'create') {
  232. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("RecruitmentCandidature")), '', 'object_'.$object->picto);
  233. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  234. print '<input type="hidden" name="token" value="'.newToken().'">';
  235. print '<input type="hidden" name="action" value="add">';
  236. if ($backtopage) {
  237. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  238. }
  239. if ($backtopageforcancel) {
  240. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  241. }
  242. print dol_get_fiche_head(array(), '');
  243. print '<table class="border centpercent tableforfieldcreate">'."\n";
  244. // Common attributes
  245. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  246. // Other attributes
  247. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  248. print '</table>'."\n";
  249. print dol_get_fiche_end();
  250. print $form->buttonsSaveCancel("Create");
  251. print '</form>';
  252. //dol_set_focus('input[name="ref"]');
  253. }
  254. // Part to edit record
  255. if (($id || $ref) && $action == 'edit') {
  256. print load_fiche_titre($langs->trans("RecruitmentCandidature"), '', 'object_'.$object->picto);
  257. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  258. print '<input type="hidden" name="token" value="'.newToken().'">';
  259. print '<input type="hidden" name="action" value="update">';
  260. print '<input type="hidden" name="id" value="'.$object->id.'">';
  261. if ($backtopage) {
  262. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  263. }
  264. if ($backtopageforcancel) {
  265. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  266. }
  267. print dol_get_fiche_head();
  268. print '<table class="border centpercent tableforfieldedit">'."\n";
  269. // Common attributes
  270. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  271. // Other attributes
  272. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  273. print '</table>';
  274. print dol_get_fiche_end();
  275. print $form->buttonsSaveCancel();
  276. print '</form>';
  277. }
  278. // Part to show record
  279. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  280. $res = $object->fetch_optionals();
  281. $head = recruitmentcandidaturePrepareHead($object);
  282. print dol_get_fiche_head($head, 'card', $langs->trans("RecruitmentCandidature"), -1, $object->picto);
  283. $formconfirm = '';
  284. // Confirmation to delete
  285. if ($action == 'delete') {
  286. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteRecruitmentCandidature'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  287. }
  288. // Confirmation to delete line
  289. if ($action == 'deleteline') {
  290. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  291. }
  292. // Clone confirmation
  293. if ($action == 'clone') {
  294. // Create an array for form
  295. $formquestion = array();
  296. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  297. }
  298. if ($action == 'makeofferordecline') {
  299. $langs->load("propal");
  300. //Form to close proposal (signed or not)
  301. $formquestion = array(
  302. array('type' => 'select', 'name' => 'status', 'label' => '<span class="fieldrequired">'.$langs->trans("CloseAs").'</span>', 'values' => array($object::STATUS_CONTRACT_PROPOSED => $object->LibStatut($object::STATUS_CONTRACT_PROPOSED), $object::STATUS_REFUSED => $object->LibStatut($object::STATUS_REFUSED))),
  303. array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => '') // Field to complete private note (not replace)
  304. );
  305. $text = '';
  306. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetAcceptedRefused'), $text, 'confirm_makeofferordecline', $formquestion, '', 1, 250);
  307. }
  308. if ($action == 'closeas') {
  309. $langs->load("propal");
  310. //Form to close proposal (signed or not)
  311. $formquestion = array(
  312. array('type' => 'select', 'name' => 'status', 'label' => '<span class="fieldrequired">'.$langs->trans("CloseAs").'</span>', 'values' => array($object::STATUS_CONTRACT_SIGNED => $object->LibStatut($object::STATUS_CONTRACT_SIGNED), $object::STATUS_CONTRACT_REFUSED => $object->LibStatut($object::STATUS_CONTRACT_REFUSED))),
  313. array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => '') // Field to complete private note (not replace)
  314. );
  315. $text = '';
  316. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetAcceptedRefused'), $text, 'confirm_closeas', $formquestion, '', 1, 250);
  317. }
  318. // Confirm create user
  319. if ($action == 'create_user') {
  320. $login = (GETPOSTISSET('login') ? GETPOST('login', 'alphanohtml') : $object->login);
  321. if (empty($login)) {
  322. // Full firstname and name separated with a dot : firstname.name
  323. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  324. $login = dol_buildlogin($object->lastname, $object->firstname);
  325. }
  326. if (empty($login)) {
  327. $login = strtolower(substr($object->firstname, 0, 4)).strtolower(substr($object->lastname, 0, 4));
  328. }
  329. // Create a form array
  330. $formquestion = array(
  331. array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)
  332. );
  333. $text .= $langs->trans("ConfirmCreateLogin");
  334. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
  335. }
  336. // Call Hook formConfirm
  337. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  338. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  339. if (empty($reshook)) {
  340. $formconfirm .= $hookmanager->resPrint;
  341. } elseif ($reshook > 0) {
  342. $formconfirm = $hookmanager->resPrint;
  343. }
  344. // Print form confirm
  345. print $formconfirm;
  346. // Object card
  347. // ------------------------------------------------------------
  348. $linkback = '<a href="'.dol_buildpath('/recruitment/recruitmentcandidature_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  349. $morehtmlref = '<div class="refidno">';
  350. $morehtmlref.= $object->getFullName('', 1);
  351. /*
  352. // Ref customer
  353. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  354. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  355. // Thirdparty
  356. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
  357. // Project
  358. if (isModEnabled('project'))
  359. {
  360. $langs->load("projects");
  361. $morehtmlref .= '<br>'.$langs->trans('Project') . ' ';
  362. if ($permissiontoadd)
  363. {
  364. //if ($action != 'classify') $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
  365. $morehtmlref .= ' : ';
  366. if ($action == 'classify') {
  367. //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 0, 1, '', 'maxwidth300');
  368. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  369. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  370. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  371. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  372. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  373. $morehtmlref .= '</form>';
  374. } else {
  375. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
  376. }
  377. } else {
  378. if (!empty($object->fk_project)) {
  379. $proj = new Project($db);
  380. $proj->fetch($object->fk_project);
  381. $morehtmlref .= ': '.$proj->getNomUrl();
  382. } else {
  383. $morehtmlref .= '';
  384. }
  385. }
  386. }*/
  387. // Author
  388. if (!empty($object->email_msgid)) {
  389. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' ';
  390. if ($object->fk_user_creat > 0) {
  391. $fuser = new User($db);
  392. $fuser->fetch($object->fk_user_creat);
  393. $morehtmlref .= $fuser->getNomUrl(-1);
  394. }
  395. if (!empty($object->email_msgid)) {
  396. $morehtmlref .= ' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
  397. }
  398. } /* elseif (!empty($object->origin_email)) {
  399. $morehtmlref .= $langs->trans("CreatedBy").' : ';
  400. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  401. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
  402. } */
  403. $morehtmlref .= '</div>';
  404. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  405. print '<div class="fichecenter">';
  406. print '<div class="fichehalfleft">';
  407. print '<div class="underbanner clearboth"></div>';
  408. print '<table class="border centpercent tableforfield">'."\n";
  409. // Common attributes
  410. $keyforbreak = 'description'; // We change column just before this field
  411. unset($object->fields['email']); // Hide field already shown in banner
  412. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  413. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  414. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  415. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  416. print '</table>';
  417. print '</div>';
  418. print '</div>';
  419. print '<div class="clearboth"></div>';
  420. print dol_get_fiche_end();
  421. // Buttons for actions
  422. if ($action != 'presend' && $action != 'editline') {
  423. print '<div class="tabsAction">'."\n";
  424. $parameters = array();
  425. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  426. if ($reshook < 0) {
  427. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  428. }
  429. if (empty($reshook)) {
  430. // Send
  431. if (empty($user->socid)) {
  432. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init&sendto='.urlencode($object->email).'#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n";
  433. }
  434. // Back to draft
  435. if ($object->status == $object::STATUS_VALIDATED) {
  436. if ($permissiontoadd) {
  437. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&token='.newToken().'&confirm=yes">'.$langs->trans("SetToDraft").'</a>';
  438. }
  439. }
  440. // Modify
  441. if ($permissiontoadd) {
  442. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
  443. } else {
  444. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
  445. }
  446. // Validate
  447. if ($object->status == $object::STATUS_DRAFT) {
  448. if ($permissiontoadd) {
  449. if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
  450. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&token='.newToken().'&confirm=yes">'.$langs->trans("Validate").'</a>';
  451. } else {
  452. $langs->load("errors");
  453. print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
  454. }
  455. }
  456. }
  457. // Make offer - Refuse - Decline
  458. if ($object->status >= $object::STATUS_VALIDATED && $object->status < $object::STATUS_CONTRACT_PROPOSED) {
  459. if ($permissiontoadd) {
  460. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=makeofferordecline&token='.newToken().'">'.$langs->trans("MakeOffer").' / '.$langs->trans("Decline").'</a>';
  461. }
  462. }
  463. // Contract refused / accepted
  464. if ($object->status == $object::STATUS_CONTRACT_PROPOSED) {
  465. if ($permissiontoadd) {
  466. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=closeas&token='.newToken().'">'.$langs->trans("Accept").' / '.$langs->trans("Decline").'</a>';
  467. }
  468. }
  469. // Clone
  470. if ($permissiontoadd) {
  471. print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : '').'&action=clone&object=recruitmentcandidature', 'clone', $permissiontoadd);
  472. }
  473. // Button to convert into a user
  474. if ($object->status == $object::STATUS_CONTRACT_SIGNED) {
  475. if ($user->hasRight('user', 'user', 'creer')) {
  476. $useralreadyexists = $object->fk_user;
  477. if (empty($useralreadyexists)) {
  478. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=create_user">'.$langs->trans("CreateDolibarrLogin").'</a></div>';
  479. } else {
  480. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("CreateDolibarrLogin").'</a></div>';
  481. }
  482. } else {
  483. print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrLogin")."</span></div>";
  484. }
  485. }
  486. // Cancel
  487. if ($permissiontoadd) {
  488. if ($object->status == $object::STATUS_VALIDATED) {
  489. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken().'">'.$langs->trans("Cancel").'</a>'."\n";
  490. } elseif ($object->status == $object::STATUS_REFUSED || $object->status == $object::STATUS_CANCELED || $object->status == $object::STATUS_CONTRACT_REFUSED) {
  491. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken().'">'.$langs->trans("Re-Open").'</a>'."\n";
  492. }
  493. }
  494. // Delete
  495. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
  496. }
  497. print '</div>'."\n";
  498. }
  499. // Select mail models is same action as presend
  500. if (GETPOST('modelselected')) {
  501. $action = 'presend';
  502. }
  503. if ($action != 'presend') {
  504. print '<div class="fichecenter"><div class="fichehalfleft">';
  505. print '<a name="builddoc"></a>'; // ancre
  506. $includedocgeneration = 1;
  507. // Documents
  508. if ($includedocgeneration) {
  509. $objref = dol_sanitizeFileName($object->ref);
  510. $relativepath = $objref.'/'.$objref.'.pdf';
  511. $filedir = $conf->recruitment->dir_output.'/'.$object->element.'/'.$objref;
  512. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  513. $genallowed = $user->hasRight('recruitment', 'recruitmentjobposition', 'read'); // If you can read, you can build the PDF to read content
  514. $delallowed = $user->hasRight('recruitment', 'recruitmentjobposition', 'write'); // If you can create/edit, you can remove a file on card
  515. print $formfile->showdocuments('recruitment:RecruitmentCandidature', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  516. }
  517. // Show links to link elements
  518. $linktoelem = $form->showLinkToObjectBlock($object, null, array('recruitmentcandidature'));
  519. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  520. print '</div><div class="fichehalfright">';
  521. $MAXEVENT = 10;
  522. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/recruitment/recruitmentcandidature_agenda.php?id='.$object->id);
  523. // List of actions on element
  524. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  525. $formactions = new FormActions($db);
  526. $somethingshown = $formactions->showactions($object, $object->element.'@recruitment', (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  527. print '</div></div>';
  528. }
  529. //Select mail models is same action as presend
  530. if (GETPOST('modelselected')) {
  531. $action = 'presend';
  532. }
  533. // Presend form
  534. $modelmail = 'recruitmentcandidature_send';
  535. $defaulttopic = 'InformationMessage';
  536. $diroutput = $conf->recruitment->dir_output;
  537. $trackid = 'recruitmentcandidature'.$object->id;
  538. $inreplyto = $object->email_msgid;
  539. $job = new RecruitmentJobPosition($db);
  540. $job->fetch($object->fk_recruitmentjobposition);
  541. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  542. $recruiter = new User($db);
  543. $recruiter->fetch($job->fk_user_recruiter);
  544. $recruitername = $recruiter->getFullName('');
  545. $recruitermail = (!empty($job->email_recruiter) ? $job->email_recruiter : $recruiter->email);
  546. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  547. }
  548. // End of page
  549. llxFooter();
  550. $db->close();