recruitmentcandidature_card.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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->rights->recruitment->recruitmentjobposition->read;
  65. $permissiontoadd = $user->rights->recruitment->recruitmentjobposition->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  66. $permissiontodelete = $user->rights->recruitment->recruitmentjobposition->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  67. $permissionnote = $user->rights->recruitment->recruitmentjobposition->write; // Used by the include of actions_setnotes.inc.php
  68. $permissiondellink = $user->rights->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->rights->user->user->creer) {
  173. if ($result > 0) {
  174. $jobposition = new RecruitmentJobPosition($db);
  175. $jobposition->fetch($object->fk_recruitmentjobposition);
  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. $langs->load("errors");
  193. setEventMessages($langs->trans($nuser->error), null, 'errors');
  194. $action = 'create_user';
  195. } else {
  196. setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs');
  197. $action = '';
  198. }
  199. } else {
  200. setEventMessages($object->error, $object->errors, 'errors');
  201. $action = 'create_user';
  202. }
  203. }
  204. // Actions to send emails
  205. $triggersendname = 'RECRUITMENTCANDIDATURE_SENTBYMAIL';
  206. $autocopy = 'MAIN_MAIL_AUTOCOPY_RECRUITMENTCANDIDATURE_TO';
  207. $trackid = 'recruitmentcandidature'.$object->id;
  208. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  209. }
  210. /*
  211. * View
  212. *
  213. * Put here all code to build page
  214. */
  215. $form = new Form($db);
  216. $formfile = new FormFile($db);
  217. $formproject = new FormProjets($db);
  218. if ($action == 'create') {
  219. $title = $langs->trans('NewCandidature');
  220. $help_url = '';
  221. } else {
  222. $title = $object->ref." - ".$langs->trans('Card');
  223. $help_url = '';
  224. }
  225. llxHeader('', $title, $help_url);
  226. // Part to create
  227. if ($action == 'create') {
  228. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("RecruitmentCandidature")), '', 'object_'.$object->picto);
  229. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  230. print '<input type="hidden" name="token" value="'.newToken().'">';
  231. print '<input type="hidden" name="action" value="add">';
  232. if ($backtopage) {
  233. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  234. }
  235. if ($backtopageforcancel) {
  236. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  237. }
  238. print dol_get_fiche_head(array(), '');
  239. print '<table class="border centpercent tableforfieldcreate">'."\n";
  240. // Common attributes
  241. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  242. // Other attributes
  243. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  244. print '</table>'."\n";
  245. print dol_get_fiche_end();
  246. print $form->buttonsSaveCancel("Create");
  247. print '</form>';
  248. //dol_set_focus('input[name="ref"]');
  249. }
  250. // Part to edit record
  251. if (($id || $ref) && $action == 'edit') {
  252. print load_fiche_titre($langs->trans("RecruitmentCandidature"), '', 'object_'.$object->picto);
  253. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  254. print '<input type="hidden" name="token" value="'.newToken().'">';
  255. print '<input type="hidden" name="action" value="update">';
  256. print '<input type="hidden" name="id" value="'.$object->id.'">';
  257. if ($backtopage) {
  258. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  259. }
  260. if ($backtopageforcancel) {
  261. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  262. }
  263. print dol_get_fiche_head();
  264. print '<table class="border centpercent tableforfieldedit">'."\n";
  265. // Common attributes
  266. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  267. // Other attributes
  268. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  269. print '</table>';
  270. print dol_get_fiche_end();
  271. print $form->buttonsSaveCancel();
  272. print '</form>';
  273. }
  274. // Part to show record
  275. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  276. $res = $object->fetch_optionals();
  277. $head = recruitmentcandidaturePrepareHead($object);
  278. print dol_get_fiche_head($head, 'card', $langs->trans("RecruitmentCandidature"), -1, $object->picto);
  279. $formconfirm = '';
  280. // Confirmation to delete
  281. if ($action == 'delete') {
  282. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteRecruitmentCandidature'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  283. }
  284. // Confirmation to delete line
  285. if ($action == 'deleteline') {
  286. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  287. }
  288. // Clone confirmation
  289. if ($action == 'clone') {
  290. // Create an array for form
  291. $formquestion = array();
  292. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  293. }
  294. if ($action == 'makeofferordecline') {
  295. $langs->load("propal");
  296. //Form to close proposal (signed or not)
  297. $formquestion = array(
  298. 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))),
  299. array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => '') // Field to complete private note (not replace)
  300. );
  301. $text = '';
  302. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetAcceptedRefused'), $text, 'confirm_makeofferordecline', $formquestion, '', 1, 250);
  303. }
  304. if ($action == 'closeas') {
  305. $langs->load("propal");
  306. //Form to close proposal (signed or not)
  307. $formquestion = array(
  308. 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))),
  309. array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => '') // Field to complete private note (not replace)
  310. );
  311. $text = '';
  312. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetAcceptedRefused'), $text, 'confirm_closeas', $formquestion, '', 1, 250);
  313. }
  314. // Confirm create user
  315. if ($action == 'create_user') {
  316. $login = (GETPOSTISSET('login') ? GETPOST('login', 'alphanohtml') : $object->login);
  317. if (empty($login)) {
  318. // Full firstname and name separated with a dot : firstname.name
  319. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  320. $login = dol_buildlogin($object->lastname, $object->firstname);
  321. }
  322. if (empty($login)) {
  323. $login = strtolower(substr($object->firstname, 0, 4)).strtolower(substr($object->lastname, 0, 4));
  324. }
  325. // Create a form array
  326. $formquestion = array(
  327. array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)
  328. );
  329. $text .= $langs->trans("ConfirmCreateLogin");
  330. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
  331. }
  332. // Call Hook formConfirm
  333. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  334. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  335. if (empty($reshook)) {
  336. $formconfirm .= $hookmanager->resPrint;
  337. } elseif ($reshook > 0) {
  338. $formconfirm = $hookmanager->resPrint;
  339. }
  340. // Print form confirm
  341. print $formconfirm;
  342. // Object card
  343. // ------------------------------------------------------------
  344. $linkback = '<a href="'.dol_buildpath('/recruitment/recruitmentcandidature_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  345. $morehtmlref = '<div class="refidno">';
  346. /*
  347. // Ref customer
  348. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  349. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  350. // Thirdparty
  351. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
  352. // Project
  353. if (!empty($conf->project->enabled))
  354. {
  355. $langs->load("projects");
  356. $morehtmlref .= '<br>'.$langs->trans('Project') . ' ';
  357. if ($permissiontoadd)
  358. {
  359. //if ($action != 'classify') $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
  360. $morehtmlref .= ' : ';
  361. if ($action == 'classify') {
  362. //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  363. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  364. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  365. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  366. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  367. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  368. $morehtmlref .= '</form>';
  369. } else {
  370. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  371. }
  372. } else {
  373. if (!empty($object->fk_project)) {
  374. $proj = new Project($db);
  375. $proj->fetch($object->fk_project);
  376. $morehtmlref .= ': '.$proj->getNomUrl();
  377. } else {
  378. $morehtmlref .= '';
  379. }
  380. }
  381. }*/
  382. // Author
  383. if (!empty($object->email_msgid)) {
  384. $morehtmlref .= $langs->trans("CreatedBy").' : ';
  385. if ($object->fk_user_creat > 0) {
  386. $fuser = new User($db);
  387. $fuser->fetch($object->fk_user_creat);
  388. $morehtmlref .= $fuser->getNomUrl(-1);
  389. }
  390. if (!empty($object->email_msgid)) {
  391. $morehtmlref .= ' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
  392. }
  393. } /* elseif (!empty($object->origin_email)) {
  394. $morehtmlref .= $langs->trans("CreatedBy").' : ';
  395. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  396. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
  397. } */
  398. $morehtmlref .= '</div>';
  399. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  400. print '<div class="fichecenter">';
  401. print '<div class="fichehalfleft">';
  402. print '<div class="underbanner clearboth"></div>';
  403. print '<table class="border centpercent tableforfield">'."\n";
  404. // Common attributes
  405. $keyforbreak = 'description'; // We change column just before this field
  406. unset($object->fields['email']); // Hide field already shown in banner
  407. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  408. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  409. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  410. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  411. print '</table>';
  412. print '</div>';
  413. print '</div>';
  414. print '<div class="clearboth"></div>';
  415. print dol_get_fiche_end();
  416. // Buttons for actions
  417. if ($action != 'presend' && $action != 'editline') {
  418. print '<div class="tabsAction">'."\n";
  419. $parameters = array();
  420. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  421. if ($reshook < 0) {
  422. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  423. }
  424. if (empty($reshook)) {
  425. // Send
  426. if (empty($user->socid)) {
  427. 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";
  428. }
  429. // Back to draft
  430. if ($object->status == $object::STATUS_VALIDATED) {
  431. if ($permissiontoadd) {
  432. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes">'.$langs->trans("SetToDraft").'</a>';
  433. }
  434. }
  435. // Modify
  436. if ($permissiontoadd) {
  437. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
  438. } else {
  439. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
  440. }
  441. // Validate
  442. if ($object->status == $object::STATUS_DRAFT) {
  443. if ($permissiontoadd) {
  444. if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
  445. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&token='.newToken().'&confirm=yes">'.$langs->trans("Validate").'</a>';
  446. } else {
  447. $langs->load("errors");
  448. print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
  449. }
  450. }
  451. }
  452. // Make offer - Refuse - Decline
  453. if ($object->status >= $object::STATUS_VALIDATED && $object->status < $object::STATUS_CONTRACT_PROPOSED) {
  454. if ($permissiontoadd) {
  455. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=makeofferordecline">'.$langs->trans("MakeOffer").' / '.$langs->trans("Decline").'</a>';
  456. }
  457. }
  458. // Contract refused / accepted
  459. if ($object->status == $object::STATUS_CONTRACT_PROPOSED) {
  460. if ($permissiontoadd) {
  461. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=closeas&token='.newToken().'">'.$langs->trans("Accept").' / '.$langs->trans("Decline").'</a>';
  462. }
  463. }
  464. // Clone
  465. if ($permissiontoadd) {
  466. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=recruitmentcandidature">'.$langs->trans("ToClone").'</a>'."\n";
  467. }
  468. // Button to convert into a user
  469. if ($object->status == $object::STATUS_CONTRACT_SIGNED) {
  470. if ($user->rights->user->user->creer) {
  471. // TODO Check if a user already exists
  472. $useralreadyexists = 0;
  473. if (empty($useralreadyexists)) {
  474. 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>';
  475. } else {
  476. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("CreateDolibarrLogin").'</a></div>';
  477. }
  478. } else {
  479. print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrLogin")."</span></div>";
  480. }
  481. }
  482. // Cancel
  483. if ($permissiontoadd) {
  484. if ($object->status == $object::STATUS_VALIDATED) {
  485. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken().'">'.$langs->trans("Cancel").'</a>'."\n";
  486. } elseif ($object->status == $object::STATUS_REFUSED || $object->status == $object::STATUS_CANCELED || $object->status == $object::STATUS_CONTRACT_REFUSED) {
  487. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken().'">'.$langs->trans("Re-Open").'</a>'."\n";
  488. }
  489. }
  490. // Delete (need delete permission, or if draft, just need create/modify permission)
  491. if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)) {
  492. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>'."\n";
  493. } else {
  494. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n";
  495. }
  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->rights->recruitment->recruitmentjobposition->read; // If you can read, you can build the PDF to read content
  514. $delallowed = $user->rights->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();