* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file recruitmentcandidature_card.php * \ingroup recruitment * \brief Page to create/edit/view recruitmentcandidature */ // Load Dolibarr environment require_once '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentjobposition.class.php'; require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentcandidature.class.php'; require_once DOL_DOCUMENT_ROOT.'/recruitment/lib/recruitment_recruitmentcandidature.lib.php'; // Load translation files required by the page $langs->loadLangs(array("recruitment", "other", "users")); // Get parameters $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'recruitmentcandidaturecard'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); $lineid = GETPOST('lineid', 'int'); // Initialize technical objects $object = new RecruitmentCandidature($db); $extrafields = new ExtraFields($db); $diroutputmassaction = $conf->recruitment->dir_output.'/temp/massgeneration/'.$user->id; $hookmanager->initHooks(array('recruitmentcandidaturecard', 'globalcard')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // Initialize array of search criterias $search_all = GETPOST("search_all", 'alpha'); $search = array(); foreach ($object->fields as $key => $val) { if (GETPOST('search_'.$key, 'alpha')) { $search[$key] = GETPOST('search_'.$key, 'alpha'); } } if (empty($action) && empty($id) && empty($ref)) { $action = 'create'; } // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. $permissiontoread = $user->rights->recruitment->recruitmentjobposition->read; $permissiontoadd = $user->rights->recruitment->recruitmentjobposition->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php $permissiontodelete = $user->rights->recruitment->recruitmentjobposition->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); $permissionnote = $user->rights->recruitment->recruitmentjobposition->write; // Used by the include of actions_setnotes.inc.php $permissiondellink = $user->rights->recruitment->recruitmentjobposition->write; // Used by the include of actions_dellink.inc.php $upload_dir = $conf->recruitment->multidir_output[isset($object->entity) ? $object->entity : 1]; // Security check - Protection if external user //if ($user->socid > 0) accessforbidden(); //if ($user->socid > 0) $socid = $user->socid; $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); $result = restrictedArea($user, 'recruitment', $object->id, 'recruitment_recruitmentcandidature', 'recruitmentjobposition', '', 'rowid', $isdraft); /* * Actions */ $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if (empty($reshook)) { $error = 0; $backurlforlist = dol_buildpath('/recruitment/recruitmentcandidature_list.php', 1); if (empty($backtopage) || ($cancel && empty($id))) { if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) { $backtopage = $backurlforlist; } else { $backtopage = dol_buildpath('/recruitment/recruitmentcandidature_card.php', 1).'?id='.($id > 0 ? $id : '__ID__'); } } } $triggermodname = 'RECRUITMENTCANDIDATURE_MODIFY'; // Name of trigger action code to execute when we modify record // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen $object->email_fields_no_propagate_in_actioncomm = 1; include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; $object->email_fields_no_propagate_in_actioncomm = 0; // Actions when linking object each other include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Actions when printing a doc from card include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; // Action to move up and down lines of object //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Action to build doc include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; if ($action == 'classin' && $permissiontoadd) { $object->setProject(GETPOST('projectid', 'int')); } if ($action == 'confirm_decline' && $confirm == 'yes' && $permissiontoadd) { $result = $object->setStatut($object::STATUS_REFUSED, null, '', $triggermodname); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } if ($action == 'confirm_makeofferordecline' && $permissiontoadd && !GETPOST('cancel', 'alpha')) { if (!(GETPOST('status', 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors'); $action = 'makeofferordecline'; } else { // prevent browser refresh from closing proposal several times if ($object->status == $object::STATUS_VALIDATED) { $db->begin(); if (GETPOST('status', 'int') == $object::STATUS_REFUSED) { $result = $object->setStatut($object::STATUS_REFUSED, null, '', $triggermodname); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } else { $result = $object->setStatut($object::STATUS_CONTRACT_PROPOSED, null, '', $triggermodname); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } if (!$error) { $db->commit(); } else { $db->rollback(); } } } } if ($action == 'confirm_closeas' && $permissiontoadd && !GETPOST('cancel', 'alpha')) { if (!(GETPOST('status', 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors'); $action = 'makeofferordecline'; } else { // prevent browser refresh from closing proposal several times if ($object->status == $object::STATUS_CONTRACT_PROPOSED) { $db->begin(); if (GETPOST('status', 'int') == $object::STATUS_CONTRACT_REFUSED) { $result = $object->setStatut($object::STATUS_CONTRACT_REFUSED, null, '', $triggermodname); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } else { $result = $object->setStatut($object::STATUS_CONTRACT_SIGNED, null, '', $triggermodname); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } if (!$error) { $db->commit(); } else { $db->rollback(); } } } } // Create user from a member if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) { if ($result > 0) { $jobposition = new RecruitmentJobPosition($db); $jobposition->fetch($object->fk_recruitmentjobposition); // Creation user $nuser = new User($db); $nuser->login = GETPOST('login', 'alphanohtml'); $nuser->fk_soc = 0; $nuser->employee = 1; $nuser->firstname = $object->firstname; $nuser->lastname = $object->lastname; $nuser->email = ''; $nuser->personal_email = $object->email; $nuser->personal_mobile = $object->phone; $nuser->birth = $object->date_birth; $nuser->salary = $object->remuneration_proposed; $nuser->fk_user = $jobposition->fk_user_supervisor; // Supervisor $nuser->email = $object->email; $result = $nuser->create($user); if ($result < 0) { $langs->load("errors"); setEventMessages($langs->trans($nuser->error), null, 'errors'); $action = 'create_user'; } else { setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs'); $action = ''; } } else { setEventMessages($object->error, $object->errors, 'errors'); $action = 'create_user'; } } // Actions to send emails $triggersendname = 'RECRUITMENTCANDIDATURE_SENTBYMAIL'; $autocopy = 'MAIN_MAIL_AUTOCOPY_RECRUITMENTCANDIDATURE_TO'; $trackid = 'recruitmentcandidature'.$object->id; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; } /* * View * * Put here all code to build page */ $form = new Form($db); $formfile = new FormFile($db); $formproject = new FormProjets($db); if ($action == 'create') { $title = $langs->trans('NewCandidature'); $help_url = ''; } else { $title = $object->ref." - ".$langs->trans('Card'); $help_url = ''; } llxHeader('', $title, $help_url); // Part to create if ($action == 'create') { print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("RecruitmentCandidature")), '', 'object_'.$object->picto); print '
'; print ''; print ''; if ($backtopage) { print ''; } if ($backtopageforcancel) { print ''; } print dol_get_fiche_head(array(), ''); print ''."\n"; // Common attributes include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php'; // Other attributes include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; print '
'."\n"; print dol_get_fiche_end(); print $form->buttonsSaveCancel("Create"); print '
'; //dol_set_focus('input[name="ref"]'); } // Part to edit record if (($id || $ref) && $action == 'edit') { print load_fiche_titre($langs->trans("RecruitmentCandidature"), '', 'object_'.$object->picto); print '
'; print ''; print ''; print ''; if ($backtopage) { print ''; } if ($backtopageforcancel) { print ''; } print dol_get_fiche_head(); print ''."\n"; // Common attributes include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php'; // Other attributes include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php'; print '
'; print dol_get_fiche_end(); print $form->buttonsSaveCancel(); print '
'; } // Part to show record if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { $res = $object->fetch_optionals(); $head = recruitmentcandidaturePrepareHead($object); print dol_get_fiche_head($head, 'card', $langs->trans("RecruitmentCandidature"), -1, $object->picto); $formconfirm = ''; // Confirmation to delete if ($action == 'delete') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteRecruitmentCandidature'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1); } // Confirmation to delete line if ($action == 'deleteline') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1); } // Clone confirmation if ($action == 'clone') { // Create an array for form $formquestion = array(); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); } if ($action == 'makeofferordecline') { $langs->load("propal"); //Form to close proposal (signed or not) $formquestion = array( array('type' => 'select', 'name' => 'status', 'label' => ''.$langs->trans("CloseAs").'', 'values' => array($object::STATUS_CONTRACT_PROPOSED => $object->LibStatut($object::STATUS_CONTRACT_PROPOSED), $object::STATUS_REFUSED => $object->LibStatut($object::STATUS_REFUSED))), array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => '') // Field to complete private note (not replace) ); $text = ''; $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetAcceptedRefused'), $text, 'confirm_makeofferordecline', $formquestion, '', 1, 250); } if ($action == 'closeas') { $langs->load("propal"); //Form to close proposal (signed or not) $formquestion = array( array('type' => 'select', 'name' => 'status', 'label' => ''.$langs->trans("CloseAs").'', 'values' => array($object::STATUS_CONTRACT_SIGNED => $object->LibStatut($object::STATUS_CONTRACT_SIGNED), $object::STATUS_CONTRACT_REFUSED => $object->LibStatut($object::STATUS_CONTRACT_REFUSED))), array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => '') // Field to complete private note (not replace) ); $text = ''; $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetAcceptedRefused'), $text, 'confirm_closeas', $formquestion, '', 1, 250); } // Confirm create user if ($action == 'create_user') { $login = (GETPOSTISSET('login') ? GETPOST('login', 'alphanohtml') : $object->login); if (empty($login)) { // Full firstname and name separated with a dot : firstname.name include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $login = dol_buildlogin($object->lastname, $object->firstname); } if (empty($login)) { $login = strtolower(substr($object->firstname, 0, 4)).strtolower(substr($object->lastname, 0, 4)); } // Create a form array $formquestion = array( array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login) ); $text .= $langs->trans("ConfirmCreateLogin"); print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes'); } // Call Hook formConfirm $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { $formconfirm .= $hookmanager->resPrint; } elseif ($reshook > 0) { $formconfirm = $hookmanager->resPrint; } // Print form confirm print $formconfirm; // Object card // ------------------------------------------------------------ $linkback = ''.$langs->trans("BackToList").''; $morehtmlref = '
'; /* // Ref customer $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); // Thirdparty $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : ''); // Project if (!empty($conf->project->enabled)) { $langs->load("projects"); $morehtmlref .= '
'.$langs->trans('Project') . ' '; if ($permissiontoadd) { //if ($action != 'classify') $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' '; $morehtmlref .= ' : '; if ($action == 'classify') { //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 0, 1, '', 'maxwidth300'); $morehtmlref .= '
'; $morehtmlref .= ''; $morehtmlref .= ''; $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref .= ''; $morehtmlref .= '
'; } else { $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300'); } } else { if (!empty($object->fk_project)) { $proj = new Project($db); $proj->fetch($object->fk_project); $morehtmlref .= ': '.$proj->getNomUrl(); } else { $morehtmlref .= ''; } } }*/ // Author if (!empty($object->email_msgid)) { $morehtmlref .= '
'.$langs->trans("CreatedBy").' '; if ($object->fk_user_creat > 0) { $fuser = new User($db); $fuser->fetch($object->fk_user_creat); $morehtmlref .= $fuser->getNomUrl(-1); } if (!empty($object->email_msgid)) { $morehtmlref .= ' ('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')'; } } /* elseif (!empty($object->origin_email)) { $morehtmlref .= $langs->trans("CreatedBy").' : '; $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"'); $morehtmlref .= dol_escape_htmltag($object->origin_email).' ('.$langs->trans("CreatedByPublicPortal").')'; } */ $morehtmlref .= '
'; dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); print '
'; print '
'; print '
'; print ''."\n"; // Common attributes $keyforbreak = 'description'; // We change column just before this field unset($object->fields['email']); // Hide field already shown in banner //unset($object->fields['fk_soc']); // Hide field already shown in banner include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php'; // Other attributes. Fields from hook formObjectOptions and Extrafields. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; print '
'; print '
'; print '
'; print '
'; print dol_get_fiche_end(); // Buttons for actions if ($action != 'presend' && $action != 'editline') { print '
'."\n"; $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if (empty($reshook)) { // Send if (empty($user->socid)) { print 'email).'#formmailbeforetitle">'.$langs->trans('SendMail').''."\n"; } // Back to draft if ($object->status == $object::STATUS_VALIDATED) { if ($permissiontoadd) { print ''.$langs->trans("SetToDraft").''; } } // Modify if ($permissiontoadd) { print ''.$langs->trans("Modify").''."\n"; } else { print ''.$langs->trans('Modify').''."\n"; } // Validate if ($object->status == $object::STATUS_DRAFT) { if ($permissiontoadd) { if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) { print ''.$langs->trans("Validate").''; } else { $langs->load("errors"); print ''.$langs->trans("Validate").''; } } } // Make offer - Refuse - Decline if ($object->status >= $object::STATUS_VALIDATED && $object->status < $object::STATUS_CONTRACT_PROPOSED) { if ($permissiontoadd) { print ''.$langs->trans("MakeOffer").' / '.$langs->trans("Decline").''; } } // Contract refused / accepted if ($object->status == $object::STATUS_CONTRACT_PROPOSED) { if ($permissiontoadd) { print ''.$langs->trans("Accept").' / '.$langs->trans("Decline").''; } } // Clone if ($permissiontoadd) { print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : '').'&action=clone&object=recruitmentcandidature', 'clone', $permissiontoadd); } // Button to convert into a user if ($object->status == $object::STATUS_CONTRACT_SIGNED) { if ($user->rights->user->user->creer) { // TODO Check if a user already exists $useralreadyexists = 0; if (empty($useralreadyexists)) { print ''; } else { print ''; } } else { print '
'.$langs->trans("CreateDolibarrLogin")."
"; } } // Cancel if ($permissiontoadd) { if ($object->status == $object::STATUS_VALIDATED) { print ''.$langs->trans("Cancel").''."\n"; } elseif ($object->status == $object::STATUS_REFUSED || $object->status == $object::STATUS_CANCELED || $object->status == $object::STATUS_CONTRACT_REFUSED) { print ''.$langs->trans("Re-Open").''."\n"; } } // Delete print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); } print '
'."\n"; } // Select mail models is same action as presend if (GETPOST('modelselected')) { $action = 'presend'; } if ($action != 'presend') { print '
'; print ''; // ancre $includedocgeneration = 1; // Documents if ($includedocgeneration) { $objref = dol_sanitizeFileName($object->ref); $relativepath = $objref.'/'.$objref.'.pdf'; $filedir = $conf->recruitment->dir_output.'/'.$object->element.'/'.$objref; $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed = $user->rights->recruitment->recruitmentjobposition->read; // If you can read, you can build the PDF to read content $delallowed = $user->rights->recruitment->recruitmentjobposition->write; // If you can create/edit, you can remove a file on card print $formfile->showdocuments('recruitment:RecruitmentCandidature', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang); } // Show links to link elements $linktoelem = $form->showLinkToObjectBlock($object, null, array('recruitmentcandidature')); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); print '
'; $MAXEVENT = 10; $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/recruitment/recruitmentcandidature_agenda.php?id='.$object->id); // List of actions on element include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; $formactions = new FormActions($db); $somethingshown = $formactions->showactions($object, $object->element.'@recruitment', (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter); print '
'; } //Select mail models is same action as presend if (GETPOST('modelselected')) { $action = 'presend'; } // Presend form $modelmail = 'recruitmentcandidature_send'; $defaulttopic = 'InformationMessage'; $diroutput = $conf->recruitment->dir_output; $trackid = 'recruitmentcandidature'.$object->id; $inreplyto = $object->email_msgid; $job = new RecruitmentJobPosition($db); $job->fetch($object->fk_recruitmentjobposition); require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; $recruiter = new User($db); $recruiter->fetch($job->fk_user_recruiter); $recruitername = $recruiter->getFullName(''); $recruitermail = (!empty($job->email_recruiter) ? $job->email_recruiter : $recruiter->email); include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; } // End of page llxFooter(); $db->close();