';
if ($permtoadd) {
@@ -482,8 +482,8 @@ if ($action != 'edit' && $action != 'delete') {
}
// Confirm remove file
-if ($action == 'delete') {
- print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.GETPOST("section", 'alpha').'&urlfile='.urlencode($_GET["urlfile"]).($backtopage ? '&backtopage='.urlencode($backtopage) : ''), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile');
+if ($action == 'deletefile') {
+ print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.urlencode(GETPOST("section", 'alpha')).'&urlfile='.urlencode(GETPOST("urlfile")).($backtopage ? '&backtopage='.urlencode($backtopage) : ''), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile');
}
// Confirm remove file
@@ -498,7 +498,7 @@ if ($action == 'delete_dir') {
);
}
- print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.GETPOST('section', 'alpha').($module ? '&module='.$module : '').($backtopage ? '&backtopage='.urlencode($backtopage) : ''), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection', $relativepathwithoutslash), 'confirm_deletedir', $formquestion, 1, 1);
+ print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.urlencode(GETPOST('section', 'alpha')).($module ? '&module='.$module : '').($backtopage ? '&backtopage='.urlencode($backtopage) : ''), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection', $relativepathwithoutslash), 'confirm_deletedir', $formquestion, 1, 1);
}
diff --git a/htdocs/ecm/file_card.php b/htdocs/ecm/file_card.php
index 44bc91e387e..e38c3caf3f3 100644
--- a/htdocs/ecm/file_card.php
+++ b/htdocs/ecm/file_card.php
@@ -411,8 +411,8 @@ if ($action == 'edit') {
}
-// Confirmation de la suppression d'une ligne categorie
-if ($action == 'delete_file') {
+// Confirm deletion of a file
+if ($action == 'deletefile') {
print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.urlencode($section), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile', $urlfile), 'confirm_deletefile', '', 1, 1);
}
@@ -426,7 +426,7 @@ if ($action != 'edit') {
/*
if ($user->rights->ecm->setup)
{
- print '
';
}
else
{
diff --git a/htdocs/ecm/index_auto.php b/htdocs/ecm/index_auto.php
index d54dcf14d1e..e737d1b62a2 100644
--- a/htdocs/ecm/index_auto.php
+++ b/htdocs/ecm/index_auto.php
@@ -376,7 +376,7 @@ print dol_get_fiche_head($head, 'index_auto', '', -1, '');
// Confirm remove file (for non javascript users)
-if ($action == 'delete' && empty($conf->use_javascript_ajax)) {
+if ($action == 'deletefile' && empty($conf->use_javascript_ajax)) {
print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', '', 1);
}
@@ -413,8 +413,8 @@ if ($action == 'delete_section') {
// End confirm
-if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i', $action) || $action == 'delete') {
- print '
'."\n";
+if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i', $action) || $action == 'deletefile') {
+ print ''."\n";
print ''."\n";
print ''."\n";
diff --git a/htdocs/ecm/search.php b/htdocs/ecm/search.php
index aa792e0c9d7..9a6c20392a9 100644
--- a/htdocs/ecm/search.php
+++ b/htdocs/ecm/search.php
@@ -239,7 +239,7 @@ $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$formfile = new FormFile($db);
-$param = '§ion='.$section;
+$param = '§ion='.urlencode($section);
$textifempty = ($section ? $langs->trans("NoFileFound") : $langs->trans("ECMSelectASection"));
$formfile->list_of_documents($filearray, '', 'ecm', $param, 1, $relativepath, $user->rights->ecm->upload, 1, $textifempty);
diff --git a/htdocs/ecm/tpl/enablefiletreeajax.tpl.php b/htdocs/ecm/tpl/enablefiletreeajax.tpl.php
index 197d995a808..6397a333fb0 100644
--- a/htdocs/ecm/tpl/enablefiletreeajax.tpl.php
+++ b/htdocs/ecm/tpl/enablefiletreeajax.tpl.php
@@ -78,13 +78,14 @@ $(document).ready(function() {
$('#refreshbutton').click( function() {
console.log("Click on refreshbutton");
$.pleaseBePatient("trans('PleaseBePatient'); ?>");
- $.get( "", {
- action: "build",
- element: "ecm"
+ $.get("", {
+ action: 'build',
+ token: '',
+ element: 'ecm'
},
function(response) {
$.unblockUI();
- location.href="";
+ location.href='';
});
});
});
diff --git a/htdocs/eventorganization/class/conferenceorbooth.class.php b/htdocs/eventorganization/class/conferenceorbooth.class.php
index 328f3504497..90462fdb762 100644
--- a/htdocs/eventorganization/class/conferenceorbooth.class.php
+++ b/htdocs/eventorganization/class/conferenceorbooth.class.php
@@ -238,9 +238,10 @@ class ConferenceOrBooth extends ActionComm
* @param string $ref Ref
* @param string $ref_ext Ref ext to get
* @param string $email_msgid Email msgid
+ * @param int $loadresources 1=Load also resources
* @return int <0 if KO, 0 if not found, >0 if OK
*/
- public function fetch($id, $ref = null, $ref_ext = '', $email_msgid = '')
+ public function fetch($id, $ref = null, $ref_ext = '', $email_msgid = '', $loadresources = 1)
{
global $dolibarr_main_url_root, $conf, $langs;
@@ -271,7 +272,6 @@ class ConferenceOrBooth extends ActionComm
*/
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
{
-
//TODO set percent according status
global $conf;
diff --git a/htdocs/eventorganization/class/conferenceorboothattendee.class.php b/htdocs/eventorganization/class/conferenceorboothattendee.class.php
index 0826a53b772..bf3470b7445 100644
--- a/htdocs/eventorganization/class/conferenceorboothattendee.class.php
+++ b/htdocs/eventorganization/class/conferenceorboothattendee.class.php
@@ -105,9 +105,9 @@ class ConferenceOrBoothAttendee extends CommonObject
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>2, 'index'=>1, 'comment'=>"Reference of object"),
'fk_actioncomm' => array('type'=>'integer:ActionComm:comm/action/class/actioncomm.class.php:1', 'label'=>'ConferenceOrBooth', 'enabled'=>'1', 'position'=>55, 'notnull'=>0, 'visible'=>0, 'index'=>1, 'picto'=>'agenda'),
'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>0, 'index'=>1, 'picto'=>'project', 'css'=>'tdoverflowmax150 maxwidth500'),
- 'email' => array('type'=>'mail', 'label'=>'EmailAttendee', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'index'=>1,),
- 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status = 1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>40, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'help'=>"LinkToThirparty", 'picto'=>'company', 'css'=>'tdoverflowmax150 maxwidth500'),
- 'date_subscription' => array('type'=>'datetime', 'label'=>'DateOfRegistration', 'enabled'=>'1', 'position'=>56, 'notnull'=>0, 'visible'=>1, 'showoncombobox'=>'1',),
+ 'email' => array('type'=>'mail', 'label'=>'EmailAttendee', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'autofocusoncreate'=>1),
+ 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status = 1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>40, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'help'=>"OrganizationEventLinkToThirdParty", 'picto'=>'company', 'css'=>'tdoverflowmax150 maxwidth500'),
+ 'date_subscription' => array('type'=>'datetime', 'label'=>'DateOfRegistration', 'enabled'=>'1', 'position'=>56, 'notnull'=>1, 'visible'=>1, 'showoncombobox'=>'1',),
'fk_invoice' => array('type'=>'integer:Facture:compta/facture/class/facture.class.php', 'label'=>'Invoice', 'enabled'=>'1', 'position'=>57, 'notnull'=>0, 'visible'=>-1, 'index'=>0, 'picto'=>'bill', 'css'=>'tdoverflowmax150 maxwidth500'),
'amount' => array('type'=>'price', 'label'=>'AmountPaid', 'enabled'=>'1', 'position'=>57, 'notnull'=>0, 'visible'=>1, 'default'=>'null', 'isameasure'=>'1', 'help'=>"AmountOfSubscriptionPaid",),
'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>3,),
diff --git a/htdocs/eventorganization/conferenceorbooth_list.php b/htdocs/eventorganization/conferenceorbooth_list.php
index 9b997c8b0e9..5e382590fca 100644
--- a/htdocs/eventorganization/conferenceorbooth_list.php
+++ b/htdocs/eventorganization/conferenceorbooth_list.php
@@ -475,7 +475,8 @@ if ($projectid > 0) {
if (!empty($project->id)) {
$head = conferenceorboothProjectPrepareHead($project);
$tab = 'conferenceorbooth';
- print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($project->public ? 'projectpub' : 'project'), 0, '', '');
+
+ print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($project->public ? 'projectpub' : 'project'), 0, '', 'reposition');
}
// Build and execute select
@@ -628,7 +629,7 @@ $arrayofmassactions = array(
if ($permissiontodelete) {
$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
}
-if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'presend_attendees', 'predelete'))) {
+if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
$arrayofmassactions = array();
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
diff --git a/htdocs/eventorganization/conferenceorboothattendee_card.php b/htdocs/eventorganization/conferenceorboothattendee_card.php
index 03e309aa41d..994ff9a7ee7 100644
--- a/htdocs/eventorganization/conferenceorboothattendee_card.php
+++ b/htdocs/eventorganization/conferenceorboothattendee_card.php
@@ -57,9 +57,10 @@ $projectstatic = new Project($db);
$diroutputmassaction = $conf->eventorganization->dir_output.'/temp/massgeneration/'.$user->id;
$hookmanager->initHooks(array('conferenceorboothattendeecard', 'globalcard')); // Note that conf->hooks_modules contains array
+
if ($conf_or_booth_id > 0) {
$confOrBooth = new ConferenceOrBooth($db);
- $result = $confOrBooth->fetch($conf_or_booth_id);
+ $result = $confOrBooth->fetch($id > 0 ? $id : $conf_or_booth_id);
if ($result < 0) {
setEventMessages(null, $confOrBooth->errors, 'errors');
} else {
@@ -102,6 +103,10 @@ if (empty($action) && empty($id) && empty($ref)) {
// Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
+// Now we have loaded the attendee, we can force the project (in case value provided as parameter is wrong or value not provided)
+if ($object->fk_project > 0) {
+ $fk_project = $object->fk_project;
+}
$permissiontoread = $user->rights->eventorganization->read;
$permissiontoadd = $user->rights->eventorganization->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
@@ -125,7 +130,7 @@ if (empty($reshook)) {
$error = 0;
if (!empty($withproject)) {
- $backurlforlist = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_list.php?withproject=1';
+ $backurlforlist = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_list.php?withproject=1&fk_project='.((int) $fk_project);
} else {
$backurlforlist = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_list.php';
}
@@ -151,7 +156,6 @@ if (empty($reshook)) {
$action = '';
}
-
$triggermodname = 'EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_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
@@ -653,14 +657,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if (empty($user->socid)) {
print dolGetButtonAction($langs->trans('SendMail'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.(!empty($confOrBooth->id)?'&conforboothid='.$confOrBooth->id:'').(!empty($projectstatic->id)?'&fk_project='.$projectstatic->id:'').'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle');
}
- print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.(!empty($confOrBooth->id)?'&conforboothid='.$confOrBooth->id:'').(!empty($projectstatic->id)?'&fk_project='.$projectstatic->id:'').'&action=edit&token='.newToken().'', '', $permissiontoadd);
+ print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.(!empty($confOrBooth->id)?'&conforboothid='.$confOrBooth->id:'').(!empty($projectstatic->id)?'&fk_project='.$projectstatic->id:'').'&action=edit&token='.newToken(), '', $permissiontoadd);
// Clone
- print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken().'&object=scrumsprint', '', $permissiontoadd);
-
+ print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken().(!empty($projectstatic->id)?'&fk_project='.$projectstatic->id:''), '', $permissiontoadd);
// Delete (need delete permission, or if draft, just need create/modify permission)
- print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'', '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
+ print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().(!empty($projectstatic->id)?'&fk_project='.$projectstatic->id:''), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
}
print ''."\n";
}
diff --git a/htdocs/eventorganization/conferenceorboothattendee_list.php b/htdocs/eventorganization/conferenceorboothattendee_list.php
index 709d3255e13..8b263b32699 100644
--- a/htdocs/eventorganization/conferenceorboothattendee_list.php
+++ b/htdocs/eventorganization/conferenceorboothattendee_list.php
@@ -181,7 +181,9 @@ if (GETPOST('cancel', 'alpha')) {
$action = 'list';
$massaction = '';
}
-if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
+if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend'
+&& $massaction != 'presend_attendees'
+&& $massaction != 'confirm_presend_attendees') {
$massaction = '';
}
@@ -216,6 +218,7 @@ if (empty($reshook)) {
$objectclass = 'ConferenceOrBoothAttendee';
$objectlabel = 'ConferenceOrBoothAttendee';
$uploaddir = $conf->eventorganization->dir_output;
+ include DOL_DOCUMENT_ROOT.'/eventorganization/core/actions_massactions_mail.inc.php';
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
}
@@ -598,7 +601,7 @@ if ($projectstatic->id > 0 || $confOrBooth > 0) {
if (empty($confOrBooth->id)) {
$head = conferenceorboothProjectPrepareHead($projectstatic);
$tab = 'attendees';
- print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($project->public ? 'projectpub' : 'project'), 0, '', '');
+ print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($project->public ? 'projectpub' : 'project'), 0, '', 'reposition');
}
}
@@ -676,6 +679,7 @@ $arrayofmassactions = array(
//'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
+ 'presend_attendees'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail").' - '.$langs->trans("Attendees"),
);
if ($permissiontodelete) {
$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
@@ -699,7 +703,8 @@ print ' ';
print ' ';
print ' ';
-$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?action=create'.(!empty($confOrBooth->id)?'&conforboothid='.$confOrBooth->id:'').(!empty($projectstatic->id)?'&fk_project='.$projectstatic->id:'').$withProjectUrl.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?projectid='.$projectstatic->id.(empty($confOrBooth->id) ? '' : '&conforboothid='.$confOrBooth->id).$withProjectUrl), '', $permissiontoadd);
+$params = array('morecss'=>'reposition');
+$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?action=create'.(!empty($confOrBooth->id)?'&conforboothid='.$confOrBooth->id:'').(!empty($projectstatic->id)?'&fk_project='.$projectstatic->id:'').$withProjectUrl.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?projectid='.$projectstatic->id.(empty($confOrBooth->id) ? '' : '&conforboothid='.$confOrBooth->id).$withProjectUrl), '', $permissiontoadd, $params);
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
@@ -708,6 +713,7 @@ $topicmail = "SendConferenceOrBoothAttendeeRef";
$modelmail = "conferenceorboothattendee";
$objecttmp = new ConferenceOrBoothAttendee($db);
$trackid = 'xxxx'.$object->id;
+include DOL_DOCUMENT_ROOT.'/eventorganization/tpl/massactions_mail_pre.tpl.php';
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if ($search_all) {
diff --git a/htdocs/eventorganization/core/actions_massactions_mail.inc.php b/htdocs/eventorganization/core/actions_massactions_mail.inc.php
index 2f8e2959f2b..5fcada893f9 100644
--- a/htdocs/eventorganization/core/actions_massactions_mail.inc.php
+++ b/htdocs/eventorganization/core/actions_massactions_mail.inc.php
@@ -90,7 +90,7 @@ if (!$error && $massaction == 'confirm_presend_attendees') {
foreach ($toselect as $toselectid) {
$result = $objecttmp->fetch($toselectid);
if ($result > 0) {
- $attendees = $attendee->fetchAll('', '', 0, 0, array('t.fk_actioncomm' => $objecttmp->id));
+ $attendees = $attendee->fetchAll();
if (is_array($attendees) && count($attendees) > 0) {
foreach ($attendees as $attmail) {
if (!empty($attmail->email)) {
@@ -119,7 +119,7 @@ if (!$error && $massaction == 'confirm_presend_attendees') {
$receiver = array($receiver);
}
}
- if (!trim($_POST['sendto']) && count($receiver) == 0 && count($listofselectedid) == 1) { // if only one recipient, receiver is mandatory
+ if (!trim($_POST['sendto']) && count($receiver) == 0 && count($listofselectedid) == 0) { // if only one recipient, receiver is mandatory
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Recipient")), null, 'warnings');
$massaction = 'presend_attendees';
diff --git a/htdocs/eventorganization/tpl/massactions_mail_pre.tpl.php b/htdocs/eventorganization/tpl/massactions_mail_pre.tpl.php
index e4990da6424..8d0836b080e 100644
--- a/htdocs/eventorganization/tpl/massactions_mail_pre.tpl.php
+++ b/htdocs/eventorganization/tpl/massactions_mail_pre.tpl.php
@@ -37,7 +37,7 @@ if ($massaction == 'presend_attendees') {
foreach ($arrayofselected as $toselectid) {
$result = $objecttmp->fetch($toselectid);
if ($result > 0) {
- $attendees = $attendee->fetchAll('', '', 0, 0, array('t.fk_actioncomm'=>$objecttmp->id));
+ $attendees = $attendee->fetchAll();
if (is_array($attendees) && count($attendees)>0) {
foreach ($attendees as $attmail) {
if (!empty($attmail->email)) {
diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php
index c87d2fcc5ce..b9061b463ef 100644
--- a/htdocs/expedition/card.php
+++ b/htdocs/expedition/card.php
@@ -1160,10 +1160,16 @@ if ($action == 'create') {
print "\n";
}
+ // unit of order
+ $unit_order = '';
+ if (!empty($conf->global->PRODUCT_USE_UNITS)) {
+ $unit_order = measuringUnitString($line->fk_unit);
+ }
+
// Qty
print ''.$line->qty;
print ' ';
- print ' ';
+ print ''.$unit_order.'';
$qtyProdCom = $line->qty;
// Qty already shipped
@@ -1171,7 +1177,7 @@ if ($action == 'create') {
$quantityDelivered = $object->expeditions[$line->id];
print $quantityDelivered;
print ' ';
- print '';
+ print ''.$unit_order.'';
// Qty to ship
$quantityAsked = $line->qty;
@@ -2056,7 +2062,7 @@ if ($action == 'create') {
// Get list of products already sent for same source object into $alreadysent
$alreadysent = array();
if ($origin && $origin_id > 0) {
- $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end";
+ $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.fk_unit, obj.date_start, obj.date_end";
$sql .= ", ed.rowid as shipmentline_id, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line, ed.fk_entrepot";
$sql .= ", e.rowid as shipment_id, e.ref as shipment_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_expedition";
//if ($conf->delivery_note->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";
@@ -2176,8 +2182,13 @@ if ($action == 'create') {
print "\n";
}
+ $unit_order = '';
+ if ($conf->global->PRODUCT_USE_UNITS) {
+ $unit_order = measuringUnitString($lines[$i]->fk_unit);
+ }
+
// Qty ordered
- print ''.$lines[$i]->qty_asked.' ';
+ print ''.$lines[$i]->qty_asked.' '.$unit_order.' ';
// Qty in other shipments (with shipment and warehouse used)
if ($origin && $origin_id > 0) {
@@ -2241,7 +2252,7 @@ if ($action == 'create') {
print '';
print ' ';
// Qty to ship or shipped
- print ' ';
+ print ' '.$unit_order.' ';
// Warehouse source
print ''.$formproduct->selectWarehouses($lines[$i]->entrepot_id, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).' ';
// Batch number managment
@@ -2252,7 +2263,7 @@ if ($action == 'create') {
foreach ($lines[$i]->details_entrepot as $detail_entrepot) {
print ' ';
// Qty to ship or shipped
- print ' ';
+ print ' '.$unit_order.' ';
// Warehouse source
print ''.$formproduct->selectWarehouses($detail_entrepot->entrepot_id, 'entl'.$detail_entrepot->line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).' ';
// Batch number managment
@@ -2267,7 +2278,7 @@ if ($action == 'create') {
print '';
print ' ';
// Qty to ship or shipped
- print ' ';
+ print ' '.$unit_order.' ';
// Warehouse source
print ' ';
// Batch number managment
@@ -2289,7 +2300,7 @@ if ($action == 'create') {
print '
';
} else {
// Qty to ship or shipped
- print ''.$lines[$i]->qty_shipped.' ';
+ print ''.$lines[$i]->qty_shipped.' '.$unit_order.' ';
// Warehouse source
if (!empty($conf->stock->enabled)) {
diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php
index a6ab016ef7b..b8814450030 100644
--- a/htdocs/expedition/shipment.php
+++ b/htdocs/expedition/shipment.php
@@ -617,7 +617,7 @@ if ($id > 0 || !empty($ref)) {
$sql = "SELECT cd.rowid, cd.fk_product, cd.product_type as type, cd.label, cd.description,";
$sql .= " cd.price, cd.tva_tx, cd.subprice,";
- $sql .= " cd.qty,";
+ $sql .= " cd.qty, cd.fk_unit,";
$sql .= ' cd.date_start,';
$sql .= ' cd.date_end,';
$sql .= ' cd.special_code,';
@@ -625,8 +625,10 @@ if ($id > 0 || !empty($ref)) {
$sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units,';
$sql .= ' p.surface, p.surface_units, p.volume, p.volume_units';
$sql .= ', p.tobatch, p.tosell, p.tobuy, p.barcode';
+ $sql .= ', u.short_label as unit_order';
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units as u ON cd.fk_unit = u.rowid";
$sql .= " WHERE cd.fk_commande = ".((int) $object->id);
$sql .= " ORDER BY cd.rang, cd.rowid";
@@ -766,7 +768,7 @@ if ($id > 0 || !empty($ref)) {
}
// Qty ordered
- print ''.$objp->qty.' ';
+ print ''.$objp->qty.($objp->unit_order ? ' '.$objp->unit_order : '').' ';
// Qty already shipped
$qtyProdCom = $objp->qty;
@@ -774,7 +776,7 @@ if ($id > 0 || !empty($ref)) {
// Nb of sending products for this line of order
$qtyAlreadyShipped = (!empty($object->expeditions[$objp->rowid]) ? $object->expeditions[$objp->rowid] : 0);
print $qtyAlreadyShipped;
- print '';
+ print ($objp->unit_order ? ' '.$objp->unit_order : '').'';
// Qty remains to ship
print '';
@@ -785,7 +787,7 @@ if ($id > 0 || !empty($ref)) {
} else {
print '0 ('.$langs->trans("Service").')';
}
- print ' ';
+ print ($objp->unit_order ? ' '.$objp->unit_order : '').'';
if ($objp->fk_product > 0) {
$product = new Product($db);
diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php
index d5610c9153a..6e40b6b3a77 100644
--- a/htdocs/expensereport/card.php
+++ b/htdocs/expensereport/card.php
@@ -117,6 +117,8 @@ $permissiontoadd = $user->rights->expensereport->creer; // Used by the include o
$upload_dir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($object->ref);
+$projectRequired = $conf->projet->enabled && ! empty($conf->global->EXPENSEREPORT_PROJECT_IS_REQUIRED);
+
if ($object->id > 0) {
// Check current user can read this expense report
$canread = 0;
@@ -1147,6 +1149,12 @@ if (empty($reshook)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PriceUTTC")), null, 'errors');
}
+ // If no project entered
+ if ($projectRequired && $fk_project <= 0) {
+ $error++;
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors');
+ }
+
if (!$error) {
$type = 0; // TODO What if service ? We should take the type product/service from the type of expense report llx_c_type_fees
@@ -1280,6 +1288,12 @@ if (empty($reshook)) {
setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings');
}
+ // If no project entered
+ if ($projectRequired && $projet_id <= 0) {
+ $error++;
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors');
+ }
+
if (!$error) {
// TODO Use update method of ExpenseReportLine
$result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files);
@@ -2092,7 +2106,7 @@ if ($action == 'create') {
} else {
$tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $line->vatrate));
$pricenettoshow = price2num($line->value_unit / (1 + $tmpvat / 100), 'MU');
- print $pricenettoshow;
+ print price($pricenettoshow);
}
print '';
@@ -2269,7 +2283,7 @@ if ($action == 'create') {
// Select project
if (!empty($conf->projet->enabled)) {
print '';
- $formproject->select_projects(-1, $line->fk_project, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth300');
+ $formproject->select_projects(-1, $line->fk_project, 'fk_project', 0, 0, $projectRequired ? 0 : 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth300');
print ' ';
}
@@ -2445,7 +2459,7 @@ if ($action == 'create') {
// Select project
if (!empty($conf->projet->enabled)) {
print '';
- $formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, 1, -1, 0, 0, 0, '', 0, 0, 'maxwidth300');
+ $formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0, '', 0, 0, 'maxwidth300');
print ' ';
}
diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php
index 09a0326c6b5..c9ac19f9a23 100644
--- a/htdocs/fourn/card.php
+++ b/htdocs/fourn/card.php
@@ -212,7 +212,7 @@ if ($object->id > 0) {
print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
- print ' ('.$langs->trans("WrongSupplierCode").') ';
+ print ' ('.$langs->trans("WrongSupplierCode").') ';
}
print '';
print '';
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index ae6c271fec8..32150131314 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -144,6 +144,12 @@ $permissiondellink = $usercancreate; // Used by the include of actions_dellink.i
$permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php
$permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php
+// Project permission
+$caneditproject = false;
+if (!empty($conf->projet->enabled)) {
+ $caneditproject = empty($conf->global->SUPPLIER_ORDER_FORBID_EDIT_PROJECT) || ($object->statut == CommandeFournisseur::STATUS_DRAFT && preg_match('/^[\(]?PROV/i', $object->ref));
+}
+
/*
* Actions
@@ -239,7 +245,7 @@ if (empty($reshook)) {
}
// Set project
- if ($action == 'classin' && $usercancreate) {
+ if ($action == 'classin' && $usercancreate && $caneditproject) {
$result = $object->setProject($projectid);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
@@ -1988,7 +1994,7 @@ if ($action == 'create') {
$langs->load("projects");
$morehtmlref .= ' '.$langs->trans('Project').' ';
if ($usercancreate) {
- if ($action != 'classify') {
+ if ($action != 'classify' && $caneditproject) {
$morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : ';
}
if ($action == 'classify') {
@@ -2625,8 +2631,9 @@ if ($action == 'create') {
$urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
$genallowed = $usercanread;
$delallowed = $usercancreate;
+ $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF) ? '' : $conf->global->COMMANDE_SUPPLIER_ADDON_PDF));
- print $formfile->showdocuments('commande_fournisseur', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 0, 0, '', '', '', $object->thirdparty->default_lang);
+ print $formfile->showdocuments('commande_fournisseur', $objref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 0, 0, '', '', '', $object->thirdparty->default_lang);
$somethingshown = $formfile->numoffiles;
// Show links to link elements
diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php
index 26888851d45..bef5289c791 100644
--- a/htdocs/fourn/commande/list.php
+++ b/htdocs/fourn/commande/list.php
@@ -70,6 +70,23 @@ $search_date_delivery_endyear = GETPOST('search_date_delivery_endyear', 'int');
$search_date_delivery_start = dol_mktime(0, 0, 0, $search_date_delivery_startmonth, $search_date_delivery_startday, $search_date_delivery_startyear); // Use tzserver
$search_date_delivery_end = dol_mktime(23, 59, 59, $search_date_delivery_endmonth, $search_date_delivery_endday, $search_date_delivery_endyear);
+$search_date_valid_startday = GETPOST('search_date_valid_startday', 'int');
+$search_date_valid_startmonth = GETPOST('search_date_valid_startmonth', 'int');
+$search_date_valid_startyear = GETPOST('search_date_valid_startyear', 'int');
+$search_date_valid_endday = GETPOST('search_date_valid_endday', 'int');
+$search_date_valid_endmonth = GETPOST('search_date_valid_endmonth', 'int');
+$search_date_valid_endyear = GETPOST('search_date_valid_endyear', 'int');
+$search_date_valid_start = dol_mktime(0, 0, 0, $search_date_valid_startmonth, $search_date_valid_startday, $search_date_valid_startyear); // Use tzserver
+$search_date_valid_end = dol_mktime(23, 59, 59, $search_date_valid_endmonth, $search_date_valid_endday, $search_date_valid_endyear);
+$search_date_approve_startday = GETPOST('search_date_approve_startday', 'int');
+$search_date_approve_startmonth = GETPOST('search_date_approve_startmonth', 'int');
+$search_date_approve_startyear = GETPOST('search_date_approve_startyear', 'int');
+$search_date_approve_endday = GETPOST('search_date_approve_endday', 'int');
+$search_date_approve_endmonth = GETPOST('search_date_approve_endmonth', 'int');
+$search_date_approve_endyear = GETPOST('search_date_approve_endyear', 'int');
+$search_date_approve_start = dol_mktime(0, 0, 0, $search_date_approve_startmonth, $search_date_approve_startday, $search_date_approve_startyear); // Use tzserver
+$search_date_approve_end = dol_mktime(23, 59, 59, $search_date_approve_endmonth, $search_date_approve_endday, $search_date_approve_endyear);
+
$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
$search_product_category = GETPOST('search_product_category', 'int');
@@ -184,7 +201,9 @@ $arrayfields = array(
'cf.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
'cf.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
'cf.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
- 'cf.billed'=>array('label'=>"Billed", 'checked'=>1, 'position'=>1000, 'enabled'=>1)
+ 'cf.billed'=>array('label'=>"Billed", 'checked'=>1, 'position'=>1000, 'enabled'=>1),
+ 'cf.date_valid' =>array('label' => 'DateValidation', 'checked' => 0),
+ 'cf.date_approve' =>array('label' => 'DateApprove', 'checked' => 0)
);
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
@@ -258,6 +277,22 @@ if (empty($reshook)) {
$search_date_delivery_endyear = '';
$search_date_delivery_start = '';
$search_date_delivery_end = '';
+ $search_date_valid_startday = '';
+ $search_date_valid_startmonth = '';
+ $search_date_valid_startyear = '';
+ $search_date_valid_endday = '';
+ $search_date_valid_endmonth = '';
+ $search_date_valid_endyear = '';
+ $search_date_valid_start = '';
+ $search_date_valid_end = '';
+ $search_date_approve_startday = '';
+ $search_date_approve_startmonth = '';
+ $search_date_approve_startyear = '';
+ $search_date_approve_endday = '';
+ $search_date_approve_endmonth = '';
+ $search_date_approve_endyear = '';
+ $search_date_approve_start = '';
+ $search_date_approve_end = '';
$billed = '';
$search_billed = '';
$toselect = '';
@@ -580,6 +615,42 @@ if (empty($reshook)) {
if ($search_date_delivery_endyear) {
$param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
}
+ if ($search_date_valid_startday) {
+ $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
+ }
+ if ($search_date_valid_startmonth) {
+ $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
+ }
+ if ($search_date_valid_startyear) {
+ $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
+ }
+ if ($search_date_valid_endday) {
+ $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
+ }
+ if ($search_date_valid_endmonth) {
+ $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
+ }
+ if ($search_date_valid_endyear) {
+ $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
+ }
+ if ($search_date_approve_startday) {
+ $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
+ }
+ if ($search_date_approve_startmonth) {
+ $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
+ }
+ if ($search_date_approve_startyear) {
+ $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
+ }
+ if ($search_date_approve_endday) {
+ $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
+ }
+ if ($search_date_approve_endmonth) {
+ $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
+ }
+ if ($search_date_approve_endyear) {
+ $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
+ }
if ($search_ref) {
$param .= '&search_ref='.urlencode($search_ref);
}
@@ -673,7 +744,7 @@ if ($sall || $search_product_category > 0 || $search_user > 0) {
$sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, s.email,';
$sql .= " typent.code as typent_code,";
$sql .= " state.code_departement as state_code, state.nom as state_name,";
-$sql .= " cf.rowid, cf.ref, cf.ref_supplier, cf.fk_statut, cf.billed, cf.total_ht, cf.total_tva, cf.total_ttc, cf.fk_user_author, cf.date_commande as date_commande, cf.date_livraison as date_livraison,";
+$sql .= " cf.rowid, cf.ref, cf.ref_supplier, cf.fk_statut, cf.billed, cf.total_ht, cf.total_tva, cf.total_ttc, cf.fk_user_author, cf.date_commande as date_commande, cf.date_livraison as date_livraison,cf.date_valid, cf.date_approve,";
$sql .= ' cf.fk_multicurrency, cf.multicurrency_code, cf.multicurrency_tx, cf.multicurrency_total_ht, cf.multicurrency_total_tva, cf.multicurrency_total_ttc,';
$sql .= ' cf.date_creation as date_creation, cf.tms as date_update,';
$sql .= ' cf.note_public, cf.note_private,';
@@ -764,6 +835,18 @@ if ($search_date_delivery_start) {
if ($search_date_delivery_end) {
$sql .= " AND cf.date_livraison <= '".$db->idate($search_date_delivery_end)."'";
}
+if ($search_date_valid_start) {
+ $sql .= " AND cf.date_commande >= '".$db->idate($search_date_valid_start)."'";
+}
+if ($search_date_valid_end) {
+ $sql .= " AND cf.date_commande <= '".$db->idate($search_date_valid_end)."'";
+}
+if ($search_date_approve_start) {
+ $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_approve_start)."'";
+}
+if ($search_date_approve_end) {
+ $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_approve_end)."'";
+}
if ($search_town) {
$sql .= natural_search('s.town', $search_town);
}
@@ -905,6 +988,42 @@ if ($resql) {
if ($search_date_delivery_endyear) {
$param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
}
+ if ($search_date_valid_startday) {
+ $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
+ }
+ if ($search_date_valid_startmonth) {
+ $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
+ }
+ if ($search_date_valid_startyear) {
+ $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
+ }
+ if ($search_date_valid_endday) {
+ $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
+ }
+ if ($search_date_valid_endmonth) {
+ $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
+ }
+ if ($search_date_valid_endyear) {
+ $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
+ }
+ if ($search_date_approve_startday) {
+ $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
+ }
+ if ($search_date_approve_startmonth) {
+ $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
+ }
+ if ($search_date_approve_startyear) {
+ $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
+ }
+ if ($search_date_approve_endday) {
+ $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
+ }
+ if ($search_date_approve_endmonth) {
+ $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
+ }
+ if ($search_date_approve_endyear) {
+ $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
+ }
if ($search_ref) {
$param .= '&search_ref='.urlencode($search_ref);
}
@@ -1279,6 +1398,28 @@ if ($resql) {
print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1);
print '';
}
+ // Date valid
+ if (!empty($arrayfields['cf.date_valid']['checked'])) {
+ print '';
+ print '';
+ print $form->selectDate($search_date_valid_start ? $search_date_valid_start : -1, 'search_date_valid_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
+ print '
';
+ print '';
+ print $form->selectDate($search_date_valid_end ? $search_date_valid_end : -1, 'search_date_valid_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
+ print '
';
+ print ' ';
+ }
+ // Date approve
+ if (!empty($arrayfields['cf.date_approve']['checked'])) {
+ print '';
+ print '';
+ print $form->selectDate($search_date_approve_start ? $search_date_approve_start : -1, 'search_date_approve_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
+ print '
';
+ print '';
+ print $form->selectDate($search_date_approve_end ? $search_date_approve_end : -1, 'search_date_approve_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
+ print '
';
+ print ' ';
+ }
// Action column
print '';
$searchpicto = $form->showFilterButtons();
@@ -1370,6 +1511,12 @@ if ($resql) {
if (!empty($arrayfields['cf.billed']['checked'])) {
print_liste_field_titre($arrayfields['cf.billed']['label'], $_SERVER["PHP_SELF"], 'cf.billed', '', $param, '', $sortfield, $sortorder, 'center ');
}
+ if (!empty($arrayfields['cf.date_valid']['checked'])) {
+ print_liste_field_titre($arrayfields['cf.date_valid']['label'], $_SERVER["PHP_SELF"], "cf.date_valid", "", $param, '', $sortfield, $sortorder, 'center ');
+ }
+ if (!empty($arrayfields['cf.date_approve']['checked'])) {
+ print_liste_field_titre($arrayfields['cf.date_approve']['label'], $_SERVER["PHP_SELF"], 'cf.date_approve', '', $param, '', $sortfield, $sortorder, 'center ');
+ }
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
print "\n";
@@ -1668,6 +1815,25 @@ if ($resql) {
}
}
+ // valid date
+ if (!empty($arrayfields['cf.date_valid']['checked'])) {
+ print ' ';
+ print dol_print_date($db->jdate($obj->date_valid), 'day');
+ print ' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+ // approve date
+ if (!empty($arrayfields['cf.date_approve']['checked'])) {
+ print '';
+ print dol_print_date($db->jdate($obj->date_approve), 'day');
+ print ' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
// Action column
print '';
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index 21d6e73eb39..02e52c8164b 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -2377,7 +2377,7 @@ if ($action == 'create') {
print '';
- $objectsrc->printOriginLinesList();
+ $objectsrc->printOriginLinesList('', $selectedLines);
print '
';
}
diff --git a/htdocs/fourn/index.php b/htdocs/fourn/index.php
index 2b3017708dc..44a689fcd80 100644
--- a/htdocs/fourn/index.php
+++ b/htdocs/fourn/index.php
@@ -229,9 +229,17 @@ print '';
* List last modified supliers
*/
$max = 10;
-$sql = "SELECT s.rowid as socid, s.nom as name, s.town, s.datec, s.tms, s.prefix_comm, s.code_fournisseur, s.code_compta_fournisseur";
+$sql = "SELECT s.rowid as socid, s.nom as name, s.town, s.datec, s.tms, s.prefix_comm, s.code_fournisseur";
+if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
+ $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
+} else {
+ $sql .= ", s.code_compta_fournisseur";
+}
$sql .= ", st.libelle as stcomm";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
+if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
+ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
+}
$sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php
index e13d43c612d..55d92b7835b 100644
--- a/htdocs/holiday/class/holiday.class.php
+++ b/htdocs/holiday/class/holiday.class.php
@@ -1447,7 +1447,7 @@ class Holiday extends CommonObject
// Update each user counter
foreach ($users as $userCounter) {
- $nbDaysToAdd = (isset($typeleaves[$userCounter['type']]['newByMonth']) ? $typeleaves[$userCounter['type']]['newByMonth'] : 0);
+ $nbDaysToAdd = (isset($typeleaves[$userCounter['type']]['newbymonth']) ? $typeleaves[$userCounter['type']]['newbymonth'] : 0);
if (empty($nbDaysToAdd)) {
continue;
}
@@ -2081,7 +2081,7 @@ class Holiday extends CommonObject
{
global $mysoc;
- $sql = "SELECT rowid, code, label, affect, delay, newByMonth";
+ $sql = "SELECT rowid, code, label, affect, delay, newbymonth";
$sql .= " FROM ".MAIN_DB_PREFIX."c_holiday_types";
$sql .= " WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).')';
if ($active >= 0) {
@@ -2096,7 +2096,7 @@ class Holiday extends CommonObject
$num = $this->db->num_rows($result);
if ($num) {
while ($obj = $this->db->fetch_object($result)) {
- $types[$obj->rowid] = array('rowid'=> $obj->rowid, 'code'=> $obj->code, 'label'=>$obj->label, 'affect'=>$obj->affect, 'delay'=>$obj->delay, 'newByMonth'=>$obj->newByMonth);
+ $types[$obj->rowid] = array('rowid'=> $obj->rowid, 'code'=> $obj->code, 'label'=>$obj->label, 'affect'=>$obj->affect, 'delay'=>$obj->delay, 'newbymonth'=>$obj->newbymonth);
}
return $types;
diff --git a/htdocs/hrm/admin/admin_establishment.php b/htdocs/hrm/admin/admin_establishment.php
index f5baeee4027..dd17a2be4b0 100644
--- a/htdocs/hrm/admin/admin_establishment.php
+++ b/htdocs/hrm/admin/admin_establishment.php
@@ -21,7 +21,7 @@
* \brief HRM Establishment module setup page
*/
require '../../main.inc.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/hrm.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/hrm/lib/hrm.lib.php';
require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
// Load translation files required by the page
@@ -80,12 +80,12 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
// Subheader
$linkback = '
'.$langs->trans("BackToModuleList").' ';
-print load_fiche_titre($langs->trans("HRMSetup"), $linkback);
+print load_fiche_titre($langs->trans("HRMSetup"), $linkback, 'title_setup');
$newcardbutton = dolGetButtonTitle($langs->trans('NewEstablishment'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/hrm/establishment/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
// Configuration header
-$head = hrm_admin_prepare_head();
+$head = hrmAdminPrepareHead();
print dol_get_fiche_head($head, 'establishments', $langs->trans("HRM"), -1, "user", 0, $newcardbutton);
$sql = "SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
diff --git a/htdocs/hrm/class/evaluation.class.php b/htdocs/hrm/class/evaluation.class.php
new file mode 100644
index 00000000000..30e95e2d44e
--- /dev/null
+++ b/htdocs/hrm/class/evaluation.class.php
@@ -0,0 +1,1145 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 class/evaluation.class.php
+ * \ingroup hrm
+ * \brief This file is a CRUD class file for Evaluation (Create/Read/Update/Delete)
+ */
+
+// Put here all includes required by your class file
+require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/evaluationdet.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+
+/**
+ * Class for Evaluation
+ */
+class Evaluation extends CommonObject
+{
+ /**
+ * @var string ID of module.
+ */
+ public $module = 'hrm';
+
+ /**
+ * @var string ID to identify managed object.
+ */
+ public $element = 'evaluation';
+
+ /**
+ * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
+ */
+ public $table_element = 'hrm_evaluation';
+
+ /**
+ * @var int Does this object support multicompany module ?
+ * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
+ */
+ public $ismultientitymanaged = 0;
+
+ /**
+ * @var int Does object support extrafields ? 0=No, 1=Yes
+ */
+ public $isextrafieldmanaged = 1;
+
+ /**
+ * @var string String with name of icon for evaluation. Must be the part after the 'object_' into object_evaluation.png
+ */
+ public $picto = 'label';
+
+
+ const STATUS_DRAFT = 0;
+ const STATUS_VALIDATED = 1;
+ const STATUS_CANCELED = 9;
+ const STATUS_CLOSED = 6;
+
+
+ /**
+ * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
+ * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
+ * 'label' the translation key.
+ * 'picto' is code of a picto to show before value in forms
+ * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
+ * 'position' is the sort order of field.
+ * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
+ * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
+ * 'noteditable' says if field is not editable (1 or 0)
+ * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
+ * 'index' if we want an index in database.
+ * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
+ * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
+ * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
+ * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
+ * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
+ * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
+ * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
+ * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
+ * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
+ * 'comment' is not used. You can store here any text of your choice. It is not used by application.
+ *
+ * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
+ */
+
+ // BEGIN MODULEBUILDER PROPERTIES
+ /**
+ * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
+ */
+ public $fields=array(
+ 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
+ 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>4, 'noteditable'=>'1', 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"),
+ 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>0, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'showoncombobox'=>'2',),
+ 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>3,),
+ 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,),
+ 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,),
+ 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
+ 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
+ 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
+ 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
+ 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
+ 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'default'=>0, 'visible'=>5, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Brouillon', '1'=>'Validé'),),
+ 'date_eval' => array('type'=>'date', 'label'=>'DateEval', 'enabled'=>'1', 'position'=>502, 'notnull'=>1, 'visible'=>1,),
+ 'fk_user' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'User', 'enabled'=>'1', 'position'=>504, 'notnull'=>1, 'visible'=>1,),
+ 'fk_job' => array('type'=>'integer:Job:/hrm/class/job.class.php', 'label'=>'Job', 'enabled'=>'1', 'position'=>505, 'notnull'=>1, 'visible'=>1,),
+ );
+ public $rowid;
+ public $ref;
+ public $label;
+ public $description;
+ public $note_public;
+ public $note_private;
+ public $date_creation;
+ public $tms;
+ public $fk_user_creat;
+ public $fk_user_modif;
+ public $import_key;
+ public $status;
+ public $date_eval;
+ public $fk_user;
+ public $fk_job;
+ // END MODULEBUILDER PROPERTIES
+
+
+ // If this object has a subtable with lines
+
+ /**
+ * @var string Name of subtable line
+ */
+ public $table_element_line = 'hrm_evaluationdet';
+
+ /**
+ * @var string Field with ID of parent key if this object has a parent
+ */
+ public $fk_element = 'fk_evaluation';
+
+ /**
+ * @var string Name of subtable class that manage subtable lines
+ */
+ public $class_element_line = 'Evaluationline';
+
+ // /**
+ // * @var array List of child tables. To test if we can delete object.
+ // */
+ // protected $childtables = array();
+
+ // /**
+ // * @var array List of child tables. To know object to delete on cascade.
+ // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
+ // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
+ // */
+ protected $childtablesoncascade = array('@Evaluationline:hrm/class/evaluationdet.class.php:fk_evaluation');
+
+ /**
+ * @var Evaluationline[] Array of subtable lines
+ */
+ public $lines = array();
+
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDb $db Database handler
+ */
+ public function __construct(DoliDB $db)
+ {
+ global $conf, $langs;
+
+ $this->db = $db;
+
+ if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
+ $this->fields['rowid']['visible'] = 0;
+ }
+ if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
+ $this->fields['entity']['enabled'] = 0;
+ }
+
+ $this->date_eval = dol_now();
+
+ // Unset fields that are disabled
+ foreach ($this->fields as $key => $val) {
+ if (isset($val['enabled']) && empty($val['enabled'])) {
+ unset($this->fields[$key]);
+ }
+ }
+
+ // Translate some data of arrayofkeyval
+ if (is_object($langs)) {
+ foreach ($this->fields as $key => $val) {
+ if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
+ foreach ($val['arrayofkeyval'] as $key2 => $val2) {
+ $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Create object into database
+ *
+ * @param User $user User that creates
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, Id of created object if OK
+ */
+ public function create(User $user, $notrigger = false)
+ {
+ $resultcreate = $this->createCommon($user, $notrigger);
+
+ if ($resultcreate > 0) {
+ require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
+ $skillRank = new SkillRank($this->db);
+ $TRequiredRanks = $skillRank->fetchAll('ASC', 't.rowid', 0, 0, array('customsql' => 'fk_object='.$this->fk_job." AND objecttype='job'"));
+
+ if (is_array($TRequiredRanks) && !empty($TRequiredRanks)) {
+ $this->lines = array();
+ foreach ($TRequiredRanks as $required) {
+ $line = new Evaluationline($this->db);
+ $line->fk_evaluation = $resultcreate;
+ $line->fk_skill = $required->fk_skill;
+ $line->required_rank = $required->rank;
+ $line->fk_rank = 0;
+
+ $res = $line->create($user, $notrigger);
+ if ($res > 0) $this->lines[] = $line;
+ }
+ }
+ }
+
+ return $resultcreate;
+ }
+
+ /**
+ * Clone an object into another one
+ *
+ * @param User $user User that creates
+ * @param int $fromid Id of object to clone
+ * @return mixed New object created, <0 if KO
+ */
+ public function createFromClone(User $user, $fromid)
+ {
+ global $langs, $extrafields;
+ $error = 0;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $object = new self($this->db);
+
+ $this->db->begin();
+
+ // Load source object
+ $result = $object->fetchCommon($fromid);
+ if ($result > 0 && !empty($object->table_element_line)) {
+ $object->fetchLines();
+ }
+
+ // get lines so they will be clone
+ //foreach($this->lines as $line)
+ // $line->fetch_optionals();
+
+ // Reset some properties
+ unset($object->id);
+ unset($object->fk_user_creat);
+ unset($object->import_key);
+
+ // Clear fields
+ if (property_exists($object, 'ref')) {
+ $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
+ }
+ if (property_exists($object, 'label')) {
+ $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
+ }
+ if (property_exists($object, 'status')) {
+ $object->status = self::STATUS_DRAFT;
+ }
+ if (property_exists($object, 'date_creation')) {
+ $object->date_creation = dol_now();
+ }
+ if (property_exists($object, 'date_modification')) {
+ $object->date_modification = null;
+ }
+ // ...
+ // Clear extrafields that are unique
+ if (is_array($object->array_options) && count($object->array_options) > 0) {
+ $extrafields->fetch_name_optionals_label($this->table_element);
+ foreach ($object->array_options as $key => $option) {
+ $shortkey = preg_replace('/options_/', '', $key);
+ if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
+ //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
+ unset($object->array_options[$key]);
+ }
+ }
+ }
+
+ // Create clone
+ $object->context['createfromclone'] = 'createfromclone';
+ $result = $object->createCommon($user);
+ if ($result < 0) {
+ $error++;
+ $this->error = $object->error;
+ $this->errors = $object->errors;
+ }
+
+ if (!$error) {
+ // copy internal contacts
+ if ($this->copy_linked_contact($object, 'internal') < 0) {
+ $error++;
+ }
+ }
+
+ if (!$error) {
+ // copy external contacts if same company
+ if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
+ if ($this->copy_linked_contact($object, 'external') < 0) {
+ $error++;
+ }
+ }
+ }
+
+ unset($object->context['createfromclone']);
+
+ // End
+ if (!$error) {
+ $this->db->commit();
+ return $object;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+ /**
+ * Load object in memory from the database
+ *
+ * @param int $id Id object
+ * @param string $ref Ref
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetch($id, $ref = null)
+ {
+ $result = $this->fetchCommon($id, $ref);
+ if ($result > 0 && !empty($this->table_element_line)) {
+ $this->fetchLines();
+ }
+ return $result;
+ }
+
+ /**
+ * Load object lines in memory from the database
+ *
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetchLines()
+ {
+ $this->lines = array();
+
+ $result = $this->fetchLinesCommon();
+ return $result;
+ }
+
+
+ /**
+ * Load list of objects in memory from the database.
+ *
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit limit
+ * @param int $offset Offset
+ * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
+ */
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ {
+ global $conf;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $records = array();
+
+ $sql = 'SELECT ';
+ $sql .= $this->getFieldList('t');
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
+ $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
+ } else {
+ $sql .= ' WHERE 1 = 1';
+ }
+ // Manage filter
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sqlwhere[] = $key.'='.$value;
+ } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
+ $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
+ } elseif ($key == 'customsql') {
+ $sqlwhere[] = $value;
+ } elseif (strpos($value, '%') === false) {
+ $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
+ } else {
+ $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
+ }
+ }
+ }
+ if (count($sqlwhere) > 0) {
+ $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
+ }
+
+ if (!empty($sortfield)) {
+ $sql .= $this->db->order($sortfield, $sortorder);
+ }
+ if (!empty($limit)) {
+ $sql .= ' '.$this->db->plimit($limit, $offset);
+ }
+
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < ($limit ? min($limit, $num) : $num)) {
+ $obj = $this->db->fetch_object($resql);
+
+ $record = new self($this->db);
+ $record->setVarsFromFetchObj($obj);
+
+ $records[$record->id] = $record;
+
+ $i++;
+ }
+ $this->db->free($resql);
+
+ return $records;
+ } else {
+ $this->errors[] = 'Error '.$this->db->lasterror();
+ dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
+
+ return -1;
+ }
+ }
+
+ /**
+ * Update object into database
+ *
+ * @param User $user User that modifies
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function update(User $user, $notrigger = false)
+ {
+ return $this->updateCommon($user, $notrigger);
+ }
+
+ /**
+ * Delete object in database
+ *
+ * @param User $user User that deletes
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function delete(User $user, $notrigger = false)
+ {
+ return $this->deleteCommon($user, $notrigger);
+ //return $this->deleteCommon($user, $notrigger, 1);
+ }
+
+ /**
+ * Delete a line of object in database
+ *
+ * @param User $user User that delete
+ * @param int $idline Id of line to delete
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int >0 if OK, <0 if KO
+ */
+ public function deleteLine(User $user, $idline, $notrigger = false)
+ {
+ if ($this->status < 0) {
+ $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
+ return -2;
+ }
+
+ return $this->deleteLineCommon($user, $idline, $notrigger);
+ }
+
+
+ /**
+ * Validate object
+ *
+ * @param User $user User making status change
+ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
+ * @return int <=0 if OK, 0=Nothing done, >0 if KO
+ */
+ public function validate($user, $notrigger = 0)
+ {
+ global $conf, $langs;
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ $error = 0;
+
+ // Protection
+ if ($this->status == self::STATUS_VALIDATED) {
+ dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
+ return 0;
+ }
+
+
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // Define new ref
+ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
+ $num = $this->getNextNumRef();
+ } else {
+ $num = $this->ref;
+ }
+ $this->newref = $num;
+
+ if (!empty($num)) {
+ // Validate
+ $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
+ $sql .= " SET ref = '".$this->db->escape($num)."',";
+ $sql .= " status = ".self::STATUS_VALIDATED;
+ if (!empty($this->fields['date_validation'])) {
+ $sql .= ", date_validation = '".$this->db->idate($now)."'";
+ }
+ if (!empty($this->fields['fk_user_valid'])) {
+ $sql .= ", fk_user_valid = ".((int) $user->id);
+ }
+ $sql .= " WHERE rowid = ".((int) $this->id);
+
+ dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ dol_print_error($this->db);
+ $this->error = $this->db->lasterror();
+ $error++;
+ }
+
+ if (!$error && !$notrigger) {
+ // Call trigger
+ $result = $this->call_trigger('EVALUATION_VALIDATE', $user);
+ if ($result < 0) {
+ $error++;
+ }
+ // End call triggers
+ }
+ }
+
+ if (!$error) {
+ $this->oldref = $this->ref;
+
+ // Rename directory if dir was a temporary ref
+ if (preg_match('/^[\(]?PROV/i', $this->ref)) {
+ // Now we rename also files into index
+ $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'evaluation/".$this->db->escape($this->newref)."'";
+ $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $error++; $this->error = $this->db->lasterror();
+ }
+
+ // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
+ $oldref = dol_sanitizeFileName($this->ref);
+ $newref = dol_sanitizeFileName($num);
+ $dirsource = $conf->hrm->dir_output.'/evaluation/'.$oldref;
+ $dirdest = $conf->hrm->dir_output.'/evaluation/'.$newref;
+ if (!$error && file_exists($dirsource)) {
+ dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
+
+ if (@rename($dirsource, $dirdest)) {
+ dol_syslog("Rename ok");
+ // Rename docs starting with $oldref with $newref
+ $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluation/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
+ foreach ($listoffiles as $fileentry) {
+ $dirsource = $fileentry['name'];
+ $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
+ $dirsource = $fileentry['path'].'/'.$dirsource;
+ $dirdest = $fileentry['path'].'/'.$dirdest;
+ @rename($dirsource, $dirdest);
+ }
+ }
+ }
+ }
+ }
+
+ // Set new ref and current status
+ if (!$error) {
+ $this->ref = $num;
+ $this->status = self::STATUS_VALIDATED;
+ }
+
+ if (!$error) {
+ $this->db->commit();
+ return 1;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+ /**
+ * Get the last evaluation by date for the user assigned
+ *
+ * @param int $fk_user ID of user we need to get last eval
+ * @return Evaluation|null
+ */
+ public function getLastEvaluationForUser($fk_user)
+ {
+ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."hrm_evaluation ";
+ $sql.= "WHERE fk_user=".((int) $fk_user)." ";
+ $sql.= "ORDER BY date_eval DESC ";
+ $sql.= "LIMIT 1 ";
+
+ $res = $this->db->query($sql);
+ if (!$res) { dol_print_error($this->db);}
+
+ $Tab = $this->db->fetch_object($res);
+
+ if (empty($Tab)) return null;
+ else {
+ $evaluation = new Evaluation($this->db);
+ $evaluation->fetch($Tab->rowid);
+
+ return $evaluation;
+ }
+ }
+
+
+ /**
+ * Set draft status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function setDraft($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status <= self::STATUS_DRAFT) {
+ return 0;
+ }
+
+
+
+ return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'EVALUATION_UNVALIDATE');
+ }
+
+ /**
+ * Set cancel status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function cancel($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_VALIDATED) {
+ return 0;
+ }
+
+
+
+ return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'EVALUATION_CANCEL');
+ }
+
+ /**
+ * Set back to validated status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function reopen($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_CANCELED) {
+ return 0;
+ }
+
+
+
+ return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'EVALUATION_REOPEN');
+ }
+
+ /**
+ * Return a link to the object card (with optionaly the picto)
+ *
+ * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
+ * @param string $option On what the link point to ('nolink', ...)
+ * @param int $notooltip 1=Disable tooltip
+ * @param string $morecss Add more css on link
+ * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
+ * @return string String with URL
+ */
+ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
+ {
+ global $conf, $langs, $hookmanager;
+
+ if (!empty($conf->dol_no_mouse_hover)) {
+ $notooltip = 1; // Force disable tooltips
+ }
+
+ $result = '';
+
+ $label = img_picto('', $this->picto).' '.$langs->trans("Evaluation").' ';
+ if (isset($this->status)) {
+ $label .= ' '.$this->getLibStatut(5);
+ }
+ $label .= ' ';
+ $label .= ''.$langs->trans('Ref').': '.$this->ref;
+
+ $url = dol_buildpath('/hrm/evaluation_card.php', 1).'?id='.$this->id;
+
+ if ($option != 'nolink') {
+ // Add param to save lastsearch_values or not
+ $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
+ }
+
+ $linkclose = '';
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
+ $label = $langs->trans("ShowEvaluation");
+ $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
+ }
+ $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
+ $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
+ } else {
+ $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
+ }
+
+ if ($option == 'nolink') {
+ $linkstart = '';
+ if ($option == 'nolink') {
+ $linkend = ' ';
+ } else {
+ $linkend = '';
+ }
+
+ $result .= $linkstart;
+
+ if (empty($this->showphoto_on_popup)) {
+ if ($withpicto) {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ } else {
+ if ($withpicto) {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ list($class, $module) = explode('@', $this->picto);
+ $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
+ $filearray = dol_dir_list($upload_dir, "files");
+ $filename = $filearray[0]['name'];
+ if (!empty($filename)) {
+ $pospoint = strpos($filearray[0]['name'], '.');
+
+ $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
+ if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
+ $result .= '';
+ } else {
+ $result .= '';
+ }
+
+ $result .= ' ';
+ } else {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ }
+ }
+
+ if ($withpicto != 2) {
+ $result .= $this->ref;
+ }
+
+ $result .= $linkend;
+ //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
+
+ global $action, $hookmanager;
+ $hookmanager->initHooks(array('evaluationdao'));
+ $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
+ $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ if ($reshook > 0) {
+ $result = $hookmanager->resPrint;
+ } else {
+ $result .= $hookmanager->resPrint;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Return the label of the status
+ *
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function getLibStatut($mode = 0)
+ {
+ return $this->LibStatut($this->status, $mode);
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Return the status
+ *
+ * @param int $status Id status
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function LibStatut($status, $mode = 0)
+ {
+ // phpcs:enable
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
+ global $langs;
+ //$langs->load("hrm");
+ $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated');
+ $this->labelStatus[self::STATUS_CLOSED] = $langs->trans('Closed');
+ $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated');
+ $this->labelStatus[self::STATUS_CLOSED] = $langs->trans('Closed');
+ }
+
+ $statusType = 'status'.$status;
+ //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
+ if ($status == self::STATUS_CANCELED) {
+ $statusType = 'status6';
+ }
+
+ return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
+ }
+
+ /**
+ * Load the info information in the object
+ *
+ * @param int $id Id of object
+ * @return void
+ */
+ public function info($id)
+ {
+ $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
+ $sql .= ' fk_user_creat, fk_user_modif';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ $sql .= ' WHERE t.rowid = '.((int) $id);
+ $result = $this->db->query($sql);
+ if ($result) {
+ if ($this->db->num_rows($result)) {
+ $obj = $this->db->fetch_object($result);
+ $this->id = $obj->rowid;
+ if ($obj->fk_user_author) {
+ $cuser = new User($this->db);
+ $cuser->fetch($obj->fk_user_author);
+ $this->user_creation = $cuser;
+ }
+
+ if ($obj->fk_user_valid) {
+ $vuser = new User($this->db);
+ $vuser->fetch($obj->fk_user_valid);
+ $this->user_validation = $vuser;
+ }
+
+ if ($obj->fk_user_cloture) {
+ $cluser = new User($this->db);
+ $cluser->fetch($obj->fk_user_cloture);
+ $this->user_cloture = $cluser;
+ }
+
+ $this->date_creation = $this->db->jdate($obj->datec);
+ $this->date_modification = $this->db->jdate($obj->datem);
+ $this->date_validation = $this->db->jdate($obj->datev);
+ }
+
+ $this->db->free($result);
+ } else {
+ dol_print_error($this->db);
+ }
+ }
+
+ /**
+ * Initialise object with example values
+ * Id must be 0 if object instance is a specimen
+ *
+ * @return void
+ */
+ public function initAsSpecimen()
+ {
+ // Set here init that are not commonf fields
+ // $this->property1 = ...
+ // $this->property2 = ...
+
+ $this->initAsSpecimenCommon();
+ }
+
+ /**
+ * Create an array of lines
+ *
+ * @return array|int array of lines if OK, <0 if KO
+ */
+ public function getLinesArray()
+ {
+ $this->lines = array();
+
+ $objectline = new Evaluationline($this->db);
+ $result = $objectline->fetchAll('ASC', '', 0, 0, array('customsql'=>'fk_evaluation = '.$this->id));
+
+ if (is_numeric($result)) {
+ $this->error = $this->error;
+ $this->errors = $this->errors;
+ return $result;
+ } else {
+ $this->lines = $result;
+ return $this->lines;
+ }
+ }
+
+ /**
+ * Returns the reference to the following non used object depending on the active numbering module.
+ *
+ * @return string Object free reference
+ */
+ public function getNextNumRef()
+ {
+ global $langs, $conf;
+ $langs->load("hrm");
+
+ if (empty($conf->global->HRMTEST_EVALUATION_ADDON)) {
+ $conf->global->HRMTEST_EVALUATION_ADDON = 'mod_evaluation_standard';
+ }
+
+ if (!empty($conf->global->HRMTEST_EVALUATION_ADDON)) {
+ $mybool = false;
+
+ $file = $conf->global->HRMTEST_EVALUATION_ADDON.".php";
+ $classname = $conf->global->HRMTEST_EVALUATION_ADDON;
+
+ // Include file with class
+ $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+ foreach ($dirmodels as $reldir) {
+ $dir = dol_buildpath($reldir."core/modules/hrm/");
+
+ // Load file with numbering class (if found)
+ $mybool |= @include_once $dir.$file;
+ }
+
+ if ($mybool === false) {
+ dol_print_error('', "Failed to include file ".$file);
+ return '';
+ }
+
+ if (class_exists($classname)) {
+ $obj = new $classname();
+ $numref = $obj->getNextValue($this);
+
+ if ($numref != '' && $numref != '-1') {
+ return $numref;
+ } else {
+ $this->error = $obj->error;
+ //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
+ return "";
+ }
+ } else {
+ print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
+ return "";
+ }
+ } else {
+ print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
+ return "";
+ }
+ }
+
+ /**
+ * Create a document onto disk according to template module.
+ *
+ * @param string $modele Force template to use ('' to not force)
+ * @param Translate $outputlangs objet lang a utiliser pour traduction
+ * @param int $hidedetails Hide details of lines
+ * @param int $hidedesc Hide description
+ * @param int $hideref Hide ref
+ * @param null|array $moreparams Array to provide more information
+ * @return int 0 if KO, 1 if OK
+ */
+ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
+ {
+ global $conf, $langs;
+
+ $result = 0;
+ $includedocgeneration = 0;
+
+ $langs->load("hrm");
+
+ if (!dol_strlen($modele)) {
+ $modele = 'standard_evaluation';
+
+ if (!empty($this->model_pdf)) {
+ $modele = $this->model_pdf;
+ } elseif (!empty($conf->global->EVALUATION_ADDON_PDF)) {
+ $modele = $conf->global->EVALUATION_ADDON_PDF;
+ }
+ }
+
+ $modelpath = "core/modules/hrm/doc/";
+
+ if ($includedocgeneration && !empty($modele)) {
+ $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Action executed by scheduler
+ * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
+ * Use public function doScheduledJob($param1, $param2, ...) to get parameters
+ *
+ * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
+ */
+ public function doScheduledJob()
+ {
+ global $conf, $langs;
+
+ //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
+
+ $error = 0;
+ $this->output = '';
+ $this->error = '';
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // ...
+
+ $this->db->commit();
+
+ return $error;
+ }
+
+ /**
+ * @param string $action
+ * @param int $selected
+ */
+ // public function printObjectLines($action, $selected = 0)
+ // {
+ // global $conf, $hookmanager, $langs, $user, $extrafields, $object;
+ // // TODO We should not use global var for this
+ // global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax;
+ //
+ // // Define usemargins
+ //// $usemargins = 0;
+ //// if (!empty($conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'facturerec', 'propal', 'commande'))) {
+ //// $usemargins = 1;
+ //// }
+ //
+ // $num = count($this->lines);
+ //
+ // // Line extrafield
+ // if (!is_object($extrafields)) {
+ // require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+ // $extrafields = new ExtraFields($this->db);
+ // }
+ // $extrafields->fetch_name_optionals_label($this->table_element_line);
+ //
+ // $parameters = array('num'=>$num, 'selected'=>$selected, 'table_element_line'=>$this->table_element_line);
+ // $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ // if (empty($reshook)) {
+ // // Output template part (modules that overwrite templates must declare this into descriptor)
+ // // Note: This is deprecated. If you need to overwrite the tpl file, use instead the hook.
+ // include dol_buildpath('hrm/core/tpl/objectline_title.tpl.php');
+ // }
+ //
+ // $i = 0;
+ //
+ // print "
\n";
+ // foreach ($this->lines as $line) {
+ // //Line extrafield
+ // $line->fetch_optionals();
+ //
+ // //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line)))
+ // if (is_object($hookmanager)) { // Old code is commented on preceding line.
+ // if (empty($line->fk_parent_line)) {
+ // $parameters = array('line'=>$line, 'num'=>$num, 'i'=>$i, 'selected'=>$selected, 'table_element_line'=>$line->table_element);
+ // $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ // } else {
+ // $parameters = array('line'=>$line, 'num'=>$num, 'i'=>$i, 'selected'=>$selected, 'table_element_line'=>$line->table_element, 'fk_parent_line'=>$line->fk_parent_line);
+ // $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ // }
+ // }
+ // if (empty($reshook)) {
+ // $this->printObjectLine($action, $line);
+ // }
+ //
+ // $i++;
+ // }
+ // print " \n";
+ // }
+
+ // public function printObjectLine($action, $line)
+ // {
+ // global $conf, $langs, $user, $object, $hookmanager;
+ // global $form;
+ // global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this !
+ //
+ // $object_rights = $this->getRights();
+ //
+ // $element = $this->element;
+ //
+ // $text = '';
+ // $description = '';
+ //
+ // include dol_buildpath('hrm/tpl/objectline_view.tpl.php');
+ // }
+}
diff --git a/htdocs/hrm/class/evaluationdet.class.php b/htdocs/hrm/class/evaluationdet.class.php
new file mode 100644
index 00000000000..83a4c5a387b
--- /dev/null
+++ b/htdocs/hrm/class/evaluationdet.class.php
@@ -0,0 +1,1045 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 class/evaluationdet.class.php
+ * \ingroup hrm
+ * \brief This file is a CRUD class file for Evaluationdet (Create/Read/Update/Delete)
+ */
+
+// Put here all includes required by your class file
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+
+/**
+ * Class for Evaluationline
+ */
+class Evaluationline extends CommonObject
+{
+ /**
+ * @var string ID of module.
+ */
+ public $module = 'hrm';
+
+ /**
+ * @var string ID to identify managed object.
+ */
+ public $element = 'evaluationdet';
+
+ /**
+ * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
+ */
+ public $table_element = 'hrm_evaluationdet';
+
+ /**
+ * @var int Does this object support multicompany module ?
+ * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
+ */
+ public $ismultientitymanaged = 0;
+
+ /**
+ * @var int Does object support extrafields ? 0=No, 1=Yes
+ */
+ public $isextrafieldmanaged = 1;
+
+ /**
+ * @var string String with name of icon for evaluationdet. Must be the part after the 'object_' into object_evaluationdet.png
+ */
+ public $picto = 'evaluationdet@hrm';
+
+
+ const STATUS_DRAFT = 0;
+ const STATUS_VALIDATED = 1;
+ const STATUS_CANCELED = 9;
+
+
+ /**
+ * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
+ * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
+ * 'label' the translation key.
+ * 'picto' is code of a picto to show before value in forms
+ * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
+ * 'position' is the sort order of field.
+ * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
+ * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
+ * 'noteditable' says if field is not editable (1 or 0)
+ * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
+ * 'index' if we want an index in database.
+ * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
+ * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
+ * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
+ * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
+ * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
+ * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
+ * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
+ * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
+ * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
+ * 'comment' is not used. You can store here any text of your choice. It is not used by application.
+ *
+ * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
+ */
+
+ // BEGIN MODULEBUILDER PROPERTIES
+ /**
+ * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
+ */
+ public $fields=array(
+ 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
+ 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
+ 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
+ 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
+ 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
+ 'fk_skill' => array('type'=>'integer:Skill:hrm/class/skill.class.php:1', 'label'=>'Skill', 'enabled'=>'1', 'position'=>3, 'notnull'=>1, 'visible'=>1, 'index'=>1,),
+ 'fk_evaluation' => array('type'=>'integer:Evaluation:hrm/class/evaluation.class.php:1', 'label'=>'Evaluation', 'enabled'=>'1', 'position'=>3, 'notnull'=>1, 'visible'=>1, 'index'=>1,),
+ 'rank' => array('type'=>'integer', 'label'=>'Rank', 'enabled'=>'1', 'position'=>4, 'notnull'=>1, 'visible'=>1,),
+ 'required_rank' => array('type'=>'integer', 'label'=>'requiredRank', 'enabled'=>'1', 'position'=>5, 'notnull'=>1, 'visible'=>1,),
+ 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
+ );
+ public $rowid;
+ public $date_creation;
+ public $tms;
+ public $fk_user_creat;
+ public $fk_user_modif;
+ public $fk_skill;
+ public $fk_evaluation;
+ public $fk_rank;
+ public $required_rank;
+ public $import_key;
+ // END MODULEBUILDER PROPERTIES
+
+
+ // If this object has a subtable with lines
+
+ // /**
+ // * @var string Name of subtable line
+ // */
+ // public $table_element_line = 'hrm_evaluationline';
+
+ // /**
+ // * @var string Field with ID of parent key if this object has a parent
+ // */
+ // public $fk_element = 'fk_evaluationdet';
+
+ // /**
+ // * @var string Name of subtable class that manage subtable lines
+ // */
+ // public $class_element_line = 'Evaluationline';
+
+ // /**
+ // * @var array List of child tables. To test if we can delete object.
+ // */
+ // protected $childtables = array();
+
+ // /**
+ // * @var array List of child tables. To know object to delete on cascade.
+ // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
+ // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
+ // */
+ // protected $childtablesoncascade = array('hrm_evaluationdetdet');
+
+ // /**
+ // * @var EvaluationLine[] Array of subtable lines
+ // */
+ // public $lines = array();
+
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDb $db Database handler
+ */
+ public function __construct(DoliDB $db)
+ {
+ global $conf, $langs;
+
+ $this->db = $db;
+
+ if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
+ $this->fields['rowid']['visible'] = 0;
+ }
+ if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
+ $this->fields['entity']['enabled'] = 0;
+ }
+
+ // Example to show how to set values of fields definition dynamically
+ /*if ($user->rights->hrm->evaluationdet->read) {
+ $this->fields['myfield']['visible'] = 1;
+ $this->fields['myfield']['noteditable'] = 0;
+ }*/
+
+ // Unset fields that are disabled
+ foreach ($this->fields as $key => $val) {
+ if (isset($val['enabled']) && empty($val['enabled'])) {
+ unset($this->fields[$key]);
+ }
+ }
+
+ // Translate some data of arrayofkeyval
+ if (is_object($langs)) {
+ foreach ($this->fields as $key => $val) {
+ if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
+ foreach ($val['arrayofkeyval'] as $key2 => $val2) {
+ $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Create object into database
+ *
+ * @param User $user User that creates
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, Id of created object if OK
+ */
+ public function create(User $user, $notrigger = false)
+ {
+ $resultcreate = $this->createCommon($user, $notrigger);
+
+ return $resultcreate;
+ }
+
+ /**
+ * Clone an object into another one
+ *
+ * @param User $user User that creates
+ * @param int $fromid Id of object to clone
+ * @return mixed New object created, <0 if KO
+ */
+ public function createFromClone(User $user, $fromid)
+ {
+ global $langs, $extrafields;
+ $error = 0;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $object = new self($this->db);
+
+ $this->db->begin();
+
+ // Load source object
+ $result = $object->fetchCommon($fromid);
+ if ($result > 0 && !empty($object->table_element_line)) {
+ $object->fetchLines();
+ }
+
+ // get lines so they will be clone
+ //foreach($this->lines as $line)
+ // $line->fetch_optionals();
+
+ // Reset some properties
+ unset($object->id);
+ unset($object->fk_user_creat);
+ unset($object->import_key);
+
+ // Clear fields
+ if (property_exists($object, 'ref')) {
+ $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
+ }
+ if (property_exists($object, 'label')) {
+ $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
+ }
+ if (property_exists($object, 'status')) {
+ $object->status = self::STATUS_DRAFT;
+ }
+ if (property_exists($object, 'date_creation')) {
+ $object->date_creation = dol_now();
+ }
+ if (property_exists($object, 'date_modification')) {
+ $object->date_modification = null;
+ }
+ // ...
+ // Clear extrafields that are unique
+ if (is_array($object->array_options) && count($object->array_options) > 0) {
+ $extrafields->fetch_name_optionals_label($this->table_element);
+ foreach ($object->array_options as $key => $option) {
+ $shortkey = preg_replace('/options_/', '', $key);
+ if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
+ //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
+ unset($object->array_options[$key]);
+ }
+ }
+ }
+
+ // Create clone
+ $object->context['createfromclone'] = 'createfromclone';
+ $result = $object->createCommon($user);
+ if ($result < 0) {
+ $error++;
+ $this->error = $object->error;
+ $this->errors = $object->errors;
+ }
+
+ if (!$error) {
+ // copy internal contacts
+ if ($this->copy_linked_contact($object, 'internal') < 0) {
+ $error++;
+ }
+ }
+
+ if (!$error) {
+ // copy external contacts if same company
+ if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
+ if ($this->copy_linked_contact($object, 'external') < 0) {
+ $error++;
+ }
+ }
+ }
+
+ unset($object->context['createfromclone']);
+
+ // End
+ if (!$error) {
+ $this->db->commit();
+ return $object;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+ /**
+ * Load object in memory from the database
+ *
+ * @param int $id Id object
+ * @param string $ref Ref
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetch($id, $ref = null)
+ {
+ $result = $this->fetchCommon($id, $ref);
+ if ($result > 0 && !empty($this->table_element_line)) {
+ $this->fetchLines();
+ }
+ return $result;
+ }
+
+ /**
+ * Load object lines in memory from the database
+ *
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetchLines()
+ {
+ $this->lines = array();
+
+ $result = $this->fetchLinesCommon();
+ return $result;
+ }
+
+
+ /**
+ * Load list of objects in memory from the database.
+ *
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit limit
+ * @param int $offset Offset
+ * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
+ */
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ {
+ global $conf;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $records = array();
+
+ $sql = 'SELECT ';
+ $sql .= $this->getFieldList('t');
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
+ $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
+ } else {
+ $sql .= ' WHERE 1 = 1';
+ }
+ // Manage filter
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sqlwhere[] = $key.'='.$value;
+ } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
+ $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
+ } elseif ($key == 'customsql') {
+ $sqlwhere[] = $value;
+ } elseif (strpos($value, '%') === false) {
+ $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
+ } else {
+ $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
+ }
+ }
+ }
+ if (count($sqlwhere) > 0) {
+ $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
+ }
+
+ if (!empty($sortfield)) {
+ $sql .= $this->db->order($sortfield, $sortorder);
+ }
+ if (!empty($limit)) {
+ $sql .= ' '.$this->db->plimit($limit, $offset);
+ }
+
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < ($limit ? min($limit, $num) : $num)) {
+ $obj = $this->db->fetch_object($resql);
+
+ $record = new self($this->db);
+ $record->setVarsFromFetchObj($obj);
+
+ $records[$record->id] = $record;
+
+ $i++;
+ }
+ $this->db->free($resql);
+
+ return $records;
+ } else {
+ $this->errors[] = 'Error '.$this->db->lasterror();
+ dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
+
+ return -1;
+ }
+ }
+
+ /**
+ * Update object into database
+ *
+ * @param User $user User that modifies
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function update(User $user, $notrigger = false)
+ {
+ return $this->updateCommon($user, $notrigger);
+ }
+
+ /**
+ * Delete object in database
+ *
+ * @param User $user User that deletes
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function delete(User $user, $notrigger = false)
+ {
+ if ($this->fk_rank) {
+ $skillRank = new SkillRank($this->db);
+ $skillRank->fetch($this->fk_rank);
+ $skillRank->delete($user, $notrigger);
+ }
+ return $this->deleteCommon($user, $notrigger);
+ //return $this->deleteCommon($user, $notrigger, 1);
+ }
+
+ /**
+ * Delete a line of object in database
+ *
+ * @param User $user User that delete
+ * @param int $idline Id of line to delete
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int >0 if OK, <0 if KO
+ */
+ public function deleteLine(User $user, $idline, $notrigger = false)
+ {
+ if ($this->status < 0) {
+ $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
+ return -2;
+ }
+
+ return $this->deleteLineCommon($user, $idline, $notrigger);
+ }
+
+
+ /**
+ * Validate object
+ *
+ * @param User $user User making status change
+ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
+ * @return int <=0 if OK, 0=Nothing done, >0 if KO
+ */
+ public function validate($user, $notrigger = 0)
+ {
+ global $conf, $langs;
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ $error = 0;
+
+ // Protection
+ if ($this->status == self::STATUS_VALIDATED) {
+ dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->evaluationdet->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->evaluationdet->evaluationdet_advance->validate))))
+ {
+ $this->error='NotEnoughPermissions';
+ dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
+ return -1;
+ }*/
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // Define new ref
+ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
+ $num = $this->getNextNumRef();
+ } else {
+ $num = $this->ref;
+ }
+ $this->newref = $num;
+
+ if (!empty($num)) {
+ // Validate
+ $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
+ $sql .= " SET ref = '".$this->db->escape($num)."',";
+ $sql .= " status = ".self::STATUS_VALIDATED;
+ if (!empty($this->fields['date_validation'])) {
+ $sql .= ", date_validation = '".$this->db->idate($now)."'";
+ }
+ if (!empty($this->fields['fk_user_valid'])) {
+ $sql .= ", fk_user_valid = ".((int) $user->id);
+ }
+ $sql .= " WHERE rowid = ".((int) $this->id);
+
+ dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ dol_print_error($this->db);
+ $this->error = $this->db->lasterror();
+ $error++;
+ }
+
+ if (!$error && !$notrigger) {
+ // Call trigger
+ $result = $this->call_trigger('EVALUATIONLINE_VALIDATE', $user);
+ if ($result < 0) {
+ $error++;
+ }
+ // End call triggers
+ }
+ }
+
+ if (!$error) {
+ $this->oldref = $this->ref;
+
+ // Rename directory if dir was a temporary ref
+ if (preg_match('/^[\(]?PROV/i', $this->ref)) {
+ // Now we rename also files into index
+ $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'evaluationline/".$this->db->escape($this->newref)."'";
+ $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluationline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $error++; $this->error = $this->db->lasterror();
+ }
+
+ // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
+ $oldref = dol_sanitizeFileName($this->ref);
+ $newref = dol_sanitizeFileName($num);
+ $dirsource = $conf->hrm->dir_output.'/evaluationline/'.$oldref;
+ $dirdest = $conf->hrm->dir_output.'/evaluationline/'.$newref;
+ if (!$error && file_exists($dirsource)) {
+ dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
+
+ if (@rename($dirsource, $dirdest)) {
+ dol_syslog("Rename ok");
+ // Rename docs starting with $oldref with $newref
+ $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluationline/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
+ foreach ($listoffiles as $fileentry) {
+ $dirsource = $fileentry['name'];
+ $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
+ $dirsource = $fileentry['path'].'/'.$dirsource;
+ $dirdest = $fileentry['path'].'/'.$dirdest;
+ @rename($dirsource, $dirdest);
+ }
+ }
+ }
+ }
+ }
+
+ // Set new ref and current status
+ if (!$error) {
+ $this->ref = $num;
+ $this->status = self::STATUS_VALIDATED;
+ }
+
+ if (!$error) {
+ $this->db->commit();
+ return 1;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+
+ /**
+ * Set draft status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function setDraft($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status <= self::STATUS_DRAFT) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'EVALUATIONLINE_UNVALIDATE');
+ }
+
+ /**
+ * Set cancel status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function cancel($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_VALIDATED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'EVALUATIONLINE_CANCEL');
+ }
+
+ /**
+ * Set back to validated status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function reopen($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_CANCELED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'EVALUATIONLINE_REOPEN');
+ }
+
+ /**
+ * Return a link to the object card (with optionaly the picto)
+ *
+ * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
+ * @param string $option On what the link point to ('nolink', ...)
+ * @param int $notooltip 1=Disable tooltip
+ * @param string $morecss Add more css on link
+ * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
+ * @return string String with URL
+ */
+ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
+ {
+ global $conf, $langs, $hookmanager;
+
+ if (!empty($conf->dol_no_mouse_hover)) {
+ $notooltip = 1; // Force disable tooltips
+ }
+
+ $result = '';
+
+ $label = img_picto('', $this->picto).' '.$langs->trans("Evaluationdet").' ';
+ if (isset($this->status)) {
+ $label .= ' '.$this->getLibStatut(5);
+ }
+ $label .= ' ';
+ $label .= ''.$langs->trans('Ref').': '.$this->ref;
+
+ $url = dol_buildpath('/hrm/evaluationdet_card.php', 1).'?id='.$this->id;
+
+ if ($option != 'nolink') {
+ // Add param to save lastsearch_values or not
+ $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
+ }
+
+ $linkclose = '';
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
+ $label = $langs->trans("ShowEvaluationdet");
+ $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
+ }
+ $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
+ $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
+ } else {
+ $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
+ }
+
+ if ($option == 'nolink') {
+ $linkstart = '';
+ if ($option == 'nolink') {
+ $linkend = ' ';
+ } else {
+ $linkend = '';
+ }
+
+ $result .= $linkstart;
+
+ if (empty($this->showphoto_on_popup)) {
+ if ($withpicto) {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ } else {
+ if ($withpicto) {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ list($class, $module) = explode('@', $this->picto);
+ $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
+ $filearray = dol_dir_list($upload_dir, "files");
+ $filename = $filearray[0]['name'];
+ if (!empty($filename)) {
+ $pospoint = strpos($filearray[0]['name'], '.');
+
+ $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
+ if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
+ $result .= '';
+ } else {
+ $result .= '';
+ }
+
+ $result .= ' ';
+ } else {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ }
+ }
+
+ if ($withpicto != 2) {
+ $result .= $this->ref;
+ }
+
+ $result .= $linkend;
+ //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
+
+ global $action, $hookmanager;
+ $hookmanager->initHooks(array('evaluationlinedao'));
+ $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
+ $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ if ($reshook > 0) {
+ $result = $hookmanager->resPrint;
+ } else {
+ $result .= $hookmanager->resPrint;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Return the label of the status
+ *
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function getLibStatut($mode = 0)
+ {
+ return $this->LibStatut($this->status, $mode);
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Return the status
+ *
+ * @param int $status Id status
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function LibStatut($status, $mode = 0)
+ {
+ // phpcs:enable
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
+ global $langs;
+ //$langs->load("hrm");
+ $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ }
+
+ $statusType = 'status'.$status;
+ //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
+ if ($status == self::STATUS_CANCELED) {
+ $statusType = 'status6';
+ }
+
+ return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
+ }
+
+ /**
+ * Load the info information in the object
+ *
+ * @param int $id Id of object
+ * @return void
+ */
+ public function info($id)
+ {
+ $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
+ $sql .= ' fk_user_creat, fk_user_modif';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ $sql .= ' WHERE t.rowid = '.((int) $id);
+ $result = $this->db->query($sql);
+ if ($result) {
+ if ($this->db->num_rows($result)) {
+ $obj = $this->db->fetch_object($result);
+ $this->id = $obj->rowid;
+ if ($obj->fk_user_author) {
+ $cuser = new User($this->db);
+ $cuser->fetch($obj->fk_user_author);
+ $this->user_creation = $cuser;
+ }
+
+ if ($obj->fk_user_valid) {
+ $vuser = new User($this->db);
+ $vuser->fetch($obj->fk_user_valid);
+ $this->user_validation = $vuser;
+ }
+
+ if ($obj->fk_user_cloture) {
+ $cluser = new User($this->db);
+ $cluser->fetch($obj->fk_user_cloture);
+ $this->user_cloture = $cluser;
+ }
+
+ $this->date_creation = $this->db->jdate($obj->datec);
+ $this->date_modification = $this->db->jdate($obj->datem);
+ $this->date_validation = $this->db->jdate($obj->datev);
+ }
+
+ $this->db->free($result);
+ } else {
+ dol_print_error($this->db);
+ }
+ }
+
+ /**
+ * Initialise object with example values
+ * Id must be 0 if object instance is a specimen
+ *
+ * @return void
+ */
+ public function initAsSpecimen()
+ {
+ // Set here init that are not commonf fields
+ // $this->property1 = ...
+ // $this->property2 = ...
+
+ $this->initAsSpecimenCommon();
+ }
+
+ /**
+ * Create an array of lines
+ *
+ * @return array|int array of lines if OK, <0 if KO
+ */
+ public function getLinesArray()
+ {
+ $this->lines = array();
+
+ $objectline = new EvaluationLine($this->db);
+ $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_evaluationdet = '.$this->id));
+
+ if (is_numeric($result)) {
+ $this->error = $this->error;
+ $this->errors = $this->errors;
+ return $result;
+ } else {
+ $this->lines = $result;
+ return $this->lines;
+ }
+ }
+
+ /**
+ * Returns the reference to the following non used object depending on the active numbering module.
+ *
+ * @return string Object free reference
+ */
+ public function getNextNumRef()
+ {
+ global $langs, $conf;
+ $langs->load("hrm");
+
+ if (empty($conf->global->hrm_EVALUATIONLINE_ADDON)) {
+ $conf->global->hrm_EVALUATIONLINE_ADDON = 'mod_evaluationdet_standard';
+ }
+
+ if (!empty($conf->global->hrm_EVALUATIONLINE_ADDON)) {
+ $mybool = false;
+
+ $file = $conf->global->hrm_EVALUATIONLINE_ADDON.".php";
+ $classname = $conf->global->hrm_EVALUATIONLINE_ADDON;
+
+ // Include file with class
+ $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+ foreach ($dirmodels as $reldir) {
+ $dir = dol_buildpath($reldir."core/modules/hrm/");
+
+ // Load file with numbering class (if found)
+ $mybool |= @include_once $dir.$file;
+ }
+
+ if ($mybool === false) {
+ dol_print_error('', "Failed to include file ".$file);
+ return '';
+ }
+
+ if (class_exists($classname)) {
+ $obj = new $classname();
+ $numref = $obj->getNextValue($this);
+
+ if ($numref != '' && $numref != '-1') {
+ return $numref;
+ } else {
+ $this->error = $obj->error;
+ //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
+ return "";
+ }
+ } else {
+ print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
+ return "";
+ }
+ } else {
+ print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
+ return "";
+ }
+ }
+
+ /**
+ * Create a document onto disk according to template module.
+ *
+ * @param string $modele Force template to use ('' to not force)
+ * @param Translate $outputlangs objet lang a utiliser pour traduction
+ * @param int $hidedetails Hide details of lines
+ * @param int $hidedesc Hide description
+ * @param int $hideref Hide ref
+ * @param null|array $moreparams Array to provide more information
+ * @return int 0 if KO, 1 if OK
+ */
+ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
+ {
+ global $conf, $langs;
+
+ $result = 0;
+ $includedocgeneration = 0;
+
+ $langs->load("hrm");
+
+ if (!dol_strlen($modele)) {
+ $modele = 'standard_evaluationdet';
+
+ if (!empty($this->model_pdf)) {
+ $modele = $this->model_pdf;
+ } elseif (!empty($conf->global->EVALUATIONLINE_ADDON_PDF)) {
+ $modele = $conf->global->EVALUATIONLINE_ADDON_PDF;
+ }
+ }
+
+ $modelpath = "core/modules/hrm/doc/";
+
+ if ($includedocgeneration && !empty($modele)) {
+ $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Action executed by scheduler
+ * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
+ * Use public function doScheduledJob($param1, $param2, ...) to get parameters
+ *
+ * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
+ */
+ public function doScheduledJob()
+ {
+ global $conf, $langs;
+
+ //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
+
+ $error = 0;
+ $this->output = '';
+ $this->error = '';
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // ...
+
+ $this->db->commit();
+
+ return $error;
+ }
+}
+
+
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
diff --git a/htdocs/hrm/class/job.class.php b/htdocs/hrm/class/job.class.php
new file mode 100644
index 00000000000..4ff5ccbe303
--- /dev/null
+++ b/htdocs/hrm/class/job.class.php
@@ -0,0 +1,1103 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 class/job.class.php
+ * \ingroup hrm
+ * \brief This file is a CRUD class file for Job (Create/Read/Update/Delete)
+ */
+
+// Put here all includes required by your class file
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+
+/**
+ * Class for Job
+ */
+class Job extends CommonObject
+{
+ /**
+ * @var string ID of module.
+ */
+ public $module = 'hrm';
+
+ /**
+ * @var string ID to identify managed object.
+ */
+ public $element = 'job';
+
+ /**
+ * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
+ */
+ public $table_element = 'hrm_job';
+
+ /**
+ * @var int Does this object support multicompany module ?
+ * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
+ */
+ public $ismultientitymanaged = 0;
+
+ /**
+ * @var int Does object support extrafields ? 0=No, 1=Yes
+ */
+ public $isextrafieldmanaged = 1;
+
+ /**
+ * @var string String with name of icon for job. Must be the part after the 'object_' into object_job.png
+ */
+ public $picto = 'technic';
+
+
+ const STATUS_DRAFT = 0;
+ const STATUS_VALIDATED = 1;
+ const STATUS_CANCELED = 9;
+
+
+ /**
+ * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
+ * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
+ * 'label' the translation key.
+ * 'picto' is code of a picto to show before value in forms
+ * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
+ * 'position' is the sort order of field.
+ * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
+ * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
+ * 'noteditable' says if field is not editable (1 or 0)
+ * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
+ * 'index' if we want an index in database.
+ * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
+ * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
+ * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
+ * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
+ * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
+ * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
+ * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
+ * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
+ * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
+ * 'comment' is not used. You can store here any text of your choice. It is not used by application.
+ *
+ * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
+ */
+
+ // BEGIN MODULEBUILDER PROPERTIES
+ /**
+ * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
+ */
+ public $fields=array(
+ 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
+ 'label' => array('type'=>'varchar(128)', 'label'=>'Label', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Label of object"),
+ 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>21, 'notnull'=>0, 'visible'=>1,),
+ 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>2,),
+ 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>2,),
+ 'deplacement' => array('type'=>'select', 'required'=> 1,'label'=> 'deplacement', 'enabled'=> 1, 'position'=> 90, 'notnull'=> 1, 'visible'=> 1, 'arrayofkeyval'=> array(0 =>"No", 1=>"Yes"), 'default'=>0),
+ 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>70, 'notnull'=>0, 'visible'=>0,),
+ 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>71, 'notnull'=>0, 'visible'=>0,),
+ 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
+ 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
+ );
+ public $rowid;
+ public $ref;
+ public $description;
+ public $date_creation;
+ public $tms;
+ public $deplacement;
+ public $note_public;
+ public $note_private;
+ public $fk_user_creat;
+ public $fk_user_modif;
+ // END MODULEBUILDER PROPERTIES
+
+
+ // If this object has a subtable with lines
+
+ // /**
+ // * @var string Name of subtable line
+ // */
+ // public $table_element_line = 'hrm_jobline';
+
+ // /**
+ // * @var string Field with ID of parent key if this object has a parent
+ // */
+ public $fk_element = 'fk_job';
+
+ // /**
+ // * @var string Name of subtable class that manage subtable lines
+ // */
+ // public $class_element_line = 'Jobline';
+
+ // /**
+ // * @var array List of child tables. To test if we can delete object.
+ // */
+ protected $childtables = array('hrm_evaluation', 'hrm_job_user');
+
+ // /**
+ // * @var array List of child tables. To know object to delete on cascade.
+ // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
+ // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
+ // */
+ // protected $childtablesoncascade = array('hrm_jobdet');
+
+ // /**
+ // * @var JobLine[] Array of subtable lines
+ // */
+ // public $lines = array();
+
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDb $db Database handler
+ */
+ public function __construct(DoliDB $db)
+ {
+ global $conf, $langs;
+
+ $this->db = $db;
+
+ if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
+ $this->fields['rowid']['visible'] = 0;
+ }
+ if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
+ $this->fields['entity']['enabled'] = 0;
+ }
+
+ // Example to show how to set values of fields definition dynamically
+ /*if ($user->rights->hrm->job->read) {
+ $this->fields['myfield']['visible'] = 1;
+ $this->fields['myfield']['noteditable'] = 0;
+ }*/
+
+ // Unset fields that are disabled
+ foreach ($this->fields as $key => $val) {
+ if (isset($val['enabled']) && empty($val['enabled'])) {
+ unset($this->fields[$key]);
+ }
+ }
+
+ // Translate some data of arrayofkeyval
+ if (is_object($langs)) {
+ foreach ($this->fields as $key => $val) {
+ if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
+ foreach ($val['arrayofkeyval'] as $key2 => $val2) {
+ $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Create object into database
+ *
+ * @param User $user User that creates
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, Id of created object if OK
+ */
+ public function create(User $user, $notrigger = false)
+ {
+ $resultcreate = $this->createCommon($user, $notrigger);
+
+ //$resultvalidate = $this->validate($user, $notrigger);
+
+ return $resultcreate;
+ }
+
+ /**
+ * Clone an object into another one
+ *
+ * @param User $user User that creates
+ * @param int $fromid Id of object to clone
+ * @return mixed New object created, <0 if KO
+ */
+ public function createFromClone(User $user, $fromid)
+ {
+ global $langs, $extrafields;
+ $error = 0;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $object = new self($this->db);
+
+ $this->db->begin();
+
+ // Load source object
+ $result = $object->fetchCommon($fromid);
+ if ($result > 0 && !empty($object->table_element_line)) {
+ $object->fetchLines();
+ }
+
+ // get lines so they will be clone
+ //foreach($this->lines as $line)
+ // $line->fetch_optionals();
+
+ // Reset some properties
+ unset($object->id);
+ unset($object->fk_user_creat);
+ unset($object->import_key);
+
+ // Clear fields
+ if (property_exists($object, 'ref')) {
+ $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
+ }
+ if (property_exists($object, 'label')) {
+ $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
+ }
+ if (property_exists($object, 'status')) {
+ $object->status = self::STATUS_DRAFT;
+ }
+ if (property_exists($object, 'date_creation')) {
+ $object->date_creation = dol_now();
+ }
+ if (property_exists($object, 'date_modification')) {
+ $object->date_modification = null;
+ }
+ // ...
+ // Clear extrafields that are unique
+ if (is_array($object->array_options) && count($object->array_options) > 0) {
+ $extrafields->fetch_name_optionals_label($this->table_element);
+ foreach ($object->array_options as $key => $option) {
+ $shortkey = preg_replace('/options_/', '', $key);
+ if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
+ //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
+ unset($object->array_options[$key]);
+ }
+ }
+ }
+
+ // Create clone
+ $object->context['createfromclone'] = 'createfromclone';
+ $result = $object->createCommon($user);
+ if ($result < 0) {
+ $error++;
+ $this->error = $object->error;
+ $this->errors = $object->errors;
+ }
+
+ if (!$error) {
+ // copy internal contacts
+ if ($this->copy_linked_contact($object, 'internal') < 0) {
+ $error++;
+ }
+ }
+
+ if (!$error) {
+ // copy external contacts if same company
+ if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
+ if ($this->copy_linked_contact($object, 'external') < 0) {
+ $error++;
+ }
+ }
+ }
+
+ unset($object->context['createfromclone']);
+
+ // End
+ if (!$error) {
+ $this->db->commit();
+ return $object;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+ /**
+ * Load object in memory from the database
+ *
+ * @param int $id Id object
+ * @param string $ref Ref
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetch($id, $ref = null)
+ {
+ $result = $this->fetchCommon($id, $ref);
+ if ($result > 0 && !empty($this->table_element_line)) {
+ $this->fetchLines();
+ }
+ return $result;
+ }
+
+ /**
+ * Load object lines in memory from the database
+ *
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetchLines()
+ {
+ $this->lines = array();
+
+ $result = $this->fetchLinesCommon();
+ return $result;
+ }
+
+
+ /**
+ * Load list of objects in memory from the database.
+ *
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit limit
+ * @param int $offset Offset
+ * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
+ */
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ {
+ global $conf;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $records = array();
+
+ $sql = 'SELECT ';
+ $sql .= $this->getFieldList('t');
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
+ $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
+ } else {
+ $sql .= ' WHERE 1 = 1';
+ }
+ // Manage filter
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sqlwhere[] = $key.'='.$value;
+ } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
+ $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
+ } elseif ($key == 'customsql') {
+ $sqlwhere[] = $value;
+ } elseif (strpos($value, '%') === false) {
+ $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
+ } else {
+ $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
+ }
+ }
+ }
+ if (count($sqlwhere) > 0) {
+ $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
+ }
+
+ if (!empty($sortfield)) {
+ $sql .= $this->db->order($sortfield, $sortorder);
+ }
+ if (!empty($limit)) {
+ $sql .= ' '.$this->db->plimit($limit, $offset);
+ }
+
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < ($limit ? min($limit, $num) : $num)) {
+ $obj = $this->db->fetch_object($resql);
+
+ $record = new self($this->db);
+ $record->setVarsFromFetchObj($obj);
+
+ $records[$record->id] = $record;
+
+ $i++;
+ }
+ $this->db->free($resql);
+
+ return $records;
+ } else {
+ $this->errors[] = 'Error '.$this->db->lasterror();
+ dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
+
+ return -1;
+ }
+ }
+
+ /**
+ * Update object into database
+ *
+ * @param User $user User that modifies
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function update(User $user, $notrigger = false)
+ {
+ return $this->updateCommon($user, $notrigger);
+ }
+
+ /**
+ * Delete object in database
+ *
+ * @param User $user User that deletes
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function delete(User $user, $notrigger = false)
+ {
+ return $this->deleteCommon($user, $notrigger);
+ //return $this->deleteCommon($user, $notrigger, 1);
+ }
+
+ /**
+ * Delete a line of object in database
+ *
+ * @param User $user User that delete
+ * @param int $idline Id of line to delete
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int >0 if OK, <0 if KO
+ */
+ public function deleteLine(User $user, $idline, $notrigger = false)
+ {
+ if ($this->status < 0) {
+ $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
+ return -2;
+ }
+
+ return $this->deleteLineCommon($user, $idline, $notrigger);
+ }
+
+
+ /**
+ * Validate object
+ *
+ * @param User $user User making status change
+ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
+ * @return int <=0 if OK, 0=Nothing done, >0 if KO
+ */
+ public function validate($user, $notrigger = 0)
+ {
+ global $conf, $langs;
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ $error = 0;
+
+ // Protection
+ if ($this->status == self::STATUS_VALIDATED) {
+ dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->job->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->job->job_advance->validate))))
+ {
+ $this->error='NotEnoughPermissions';
+ dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
+ return -1;
+ }*/
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // Define new ref
+ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
+ $num = $this->getNextNumRef();
+ } else {
+ $num = $this->ref;
+ }
+ $this->newref = $num;
+
+ if (!empty($num)) {
+ // Validate
+ $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
+ $sql .= " SET ref = '".$this->db->escape($num)."',";
+ $sql .= " status = ".self::STATUS_VALIDATED;
+ if (!empty($this->fields['date_validation'])) {
+ $sql .= ", date_validation = '".$this->db->idate($now)."'";
+ }
+ if (!empty($this->fields['fk_user_valid'])) {
+ $sql .= ", fk_user_valid = ".((int) $user->id);
+ }
+ $sql .= " WHERE rowid = ".((int) $this->id);
+
+ dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ dol_print_error($this->db);
+ $this->error = $this->db->lasterror();
+ $error++;
+ }
+
+ if (!$error && !$notrigger) {
+ // Call trigger
+ $result = $this->call_trigger('JOB_VALIDATE', $user);
+ if ($result < 0) {
+ $error++;
+ }
+ // End call triggers
+ }
+ }
+
+ if (!$error) {
+ $this->oldref = $this->ref;
+
+ // Rename directory if dir was a temporary ref
+ if (preg_match('/^[\(]?PROV/i', $this->ref)) {
+ // Now we rename also files into index
+ $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'job/".$this->db->escape($this->newref)."'";
+ $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'job/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $error++; $this->error = $this->db->lasterror();
+ }
+
+ // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
+ $oldref = dol_sanitizeFileName($this->ref);
+ $newref = dol_sanitizeFileName($num);
+ $dirsource = $conf->hrm->dir_output.'/job/'.$oldref;
+ $dirdest = $conf->hrm->dir_output.'/job/'.$newref;
+ if (!$error && file_exists($dirsource)) {
+ dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
+
+ if (@rename($dirsource, $dirdest)) {
+ dol_syslog("Rename ok");
+ // Rename docs starting with $oldref with $newref
+ $listoffiles = dol_dir_list($conf->hrm->dir_output.'/job/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
+ foreach ($listoffiles as $fileentry) {
+ $dirsource = $fileentry['name'];
+ $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
+ $dirsource = $fileentry['path'].'/'.$dirsource;
+ $dirdest = $fileentry['path'].'/'.$dirdest;
+ @rename($dirsource, $dirdest);
+ }
+ }
+ }
+ }
+ }
+
+ // Set new ref and current status
+ if (!$error) {
+ $this->ref = $num;
+ $this->status = self::STATUS_VALIDATED;
+ }
+
+ if (!$error) {
+ $this->db->commit();
+ return 1;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+ /**
+ * Get last job for user
+ *
+ * @param int $fk_user id of user we need to get last job
+ * @return mixed|string|null
+ */
+ public function getLastJobForUser($fk_user)
+ {
+ global $db;
+
+ $j = new Job($db);
+ $Tab = $j->getForUser($fk_user);
+
+ if (empty($Tab)) return '';
+
+ $job = array_shift($Tab);
+
+ return $job;
+ }
+
+ /**
+ * Get jobs for user
+ *
+ * @param int $userid id of user we need to get job list
+ * @return array of jobs
+ */
+ public function getForUser($userid)
+ {
+ global $db;
+
+ $TReturn = array();
+ $position = new Position($db);
+ $TPosition = $position->getForUser($userid);
+ foreach ($TPosition as $UPosition) {
+ $TReturn[$UPosition->Job->rowid] = $UPosition->Job->ref;
+ }
+ return $TReturn;
+ }
+
+ /**
+ * Set draft status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function setDraft($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status <= self::STATUS_DRAFT) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'JOB_UNVALIDATE');
+ }
+
+ /**
+ * Set cancel status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function cancel($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_VALIDATED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'JOB_CANCEL');
+ }
+
+ /**
+ * Set back to validated status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function reopen($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_CANCELED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'JOB_REOPEN');
+ }
+
+ /**
+ * Return a link to the object card (with optionaly the picto)
+ *
+ * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
+ * @param string $option On what the link point to ('nolink', ...)
+ * @param int $notooltip 1=Disable tooltip
+ * @param string $morecss Add more css on link
+ * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
+ * @return string String with URL
+ */
+ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
+ {
+ global $conf, $langs, $hookmanager;
+
+ if (!empty($conf->dol_no_mouse_hover)) {
+ $notooltip = 1; // Force disable tooltips
+ }
+
+ $result = '';
+
+ $label = img_picto('', $this->picto).' '.$langs->trans("Job").' ';
+ if (isset($this->status)) {
+ $label .= ' '.$this->getLibStatut(5);
+ }
+ $label .= ' ';
+ $label .= ''.$langs->trans('Label').': '.$this->label;
+
+ $url = dol_buildpath('/hrm/job_card.php', 1).'?id='.$this->id;
+
+ if ($option != 'nolink') {
+ // Add param to save lastsearch_values or not
+ $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
+ }
+
+ $linkclose = '';
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
+ $label = $langs->trans("ShowJob");
+ $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
+ }
+ $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
+ $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
+ } else {
+ $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
+ }
+
+ if ($option == 'nolink') {
+ $linkstart = '';
+ if ($option == 'nolink') {
+ $linkend = ' ';
+ } else {
+ $linkend = '';
+ }
+
+ $result .= $linkstart;
+
+ if (empty($this->showphoto_on_popup)) {
+ if ($withpicto) {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ } else {
+ if ($withpicto) {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ list($class, $module) = explode('@', $this->picto);
+ $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->label);
+ $filearray = dol_dir_list($upload_dir, "files");
+ $filename = $filearray[0]['name'];
+ if (!empty($filename)) {
+ $pospoint = strpos($filearray[0]['name'], '.');
+
+ $pathtophoto = $class.'/'.$this->label.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
+ if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
+ $result .= '';
+ } else {
+ $result .= ' ';
+ }
+
+ $result .= '';
+ } else {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ }
+ }
+
+ if ($withpicto != 2) {
+ $result .= $this->label;
+ }
+
+ $result .= $linkend;
+ //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
+
+ global $action, $hookmanager;
+ $hookmanager->initHooks(array('jobdao'));
+ $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
+ $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ if ($reshook > 0) {
+ $result = $hookmanager->resPrint;
+ } else {
+ $result .= $hookmanager->resPrint;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Return the label of the status
+ *
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function getLibStatut($mode = 0)
+ {
+ return $this->LibStatut($this->status, $mode);
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Return the status
+ *
+ * @param int $status Id status
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function LibStatut($status, $mode = 0)
+ {
+ // phpcs:enable
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
+ global $langs;
+ //$langs->load("hrm");
+ $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ }
+
+ $statusType = 'status'.$status;
+ //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
+ if ($status == self::STATUS_CANCELED) {
+ $statusType = 'status6';
+ }
+
+ return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
+ }
+
+ /**
+ * Load the info information in the object
+ *
+ * @param int $id Id of object
+ * @return void
+ */
+ public function info($id)
+ {
+ $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
+ $sql .= ' fk_user_creat, fk_user_modif';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ $sql .= ' WHERE t.rowid = '.((int) $id);
+ $result = $this->db->query($sql);
+ if ($result) {
+ if ($this->db->num_rows($result)) {
+ $obj = $this->db->fetch_object($result);
+ $this->id = $obj->rowid;
+ if ($obj->fk_user_author) {
+ $cuser = new User($this->db);
+ $cuser->fetch($obj->fk_user_author);
+ $this->user_creation = $cuser;
+ }
+
+ if ($obj->fk_user_valid) {
+ $vuser = new User($this->db);
+ $vuser->fetch($obj->fk_user_valid);
+ $this->user_validation = $vuser;
+ }
+
+ if ($obj->fk_user_cloture) {
+ $cluser = new User($this->db);
+ $cluser->fetch($obj->fk_user_cloture);
+ $this->user_cloture = $cluser;
+ }
+
+ $this->date_creation = $this->db->jdate($obj->datec);
+ $this->date_modification = $this->db->jdate($obj->datem);
+ $this->date_validation = $this->db->jdate($obj->datev);
+ }
+
+ $this->db->free($result);
+ } else {
+ dol_print_error($this->db);
+ }
+ }
+
+ /**
+ * Initialise object with example values
+ * Id must be 0 if object instance is a specimen
+ *
+ * @return void
+ */
+ public function initAsSpecimen()
+ {
+ // Set here init that are not commonf fields
+ // $this->property1 = ...
+ // $this->property2 = ...
+
+ $this->initAsSpecimenCommon();
+ }
+
+ /**
+ * Create an array of lines
+ *
+ * @return array|int array of lines if OK, <0 if KO
+ */
+ public function getLinesArray()
+ {
+ $this->lines = array();
+
+ $objectline = new JobLine($this->db);
+ $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_job = '.$this->id));
+
+ if (is_numeric($result)) {
+ $this->error = $this->error;
+ $this->errors = $this->errors;
+ return $result;
+ } else {
+ $this->lines = $result;
+ return $this->lines;
+ }
+ }
+
+ /**
+ * Returns the reference to the following non used object depending on the active numbering module.
+ *
+ * @return string Object free reference
+ */
+ public function getNextNumRef()
+ {
+ global $langs, $conf;
+ $langs->load("hrm");
+
+ if (empty($conf->global->hrm_JOB_ADDON)) {
+ $conf->global->hrm_JOB_ADDON = 'mod_job_standard';
+ }
+
+ if (!empty($conf->global->hrm_JOB_ADDON)) {
+ $mybool = false;
+
+ $file = $conf->global->hrm_JOB_ADDON.".php";
+ $classname = $conf->global->hrm_JOB_ADDON;
+
+ // Include file with class
+ $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+ foreach ($dirmodels as $reldir) {
+ $dir = dol_buildpath($reldir."core/modules/hrm/");
+
+ // Load file with numbering class (if found)
+ $mybool |= @include_once $dir.$file;
+ }
+
+ if ($mybool === false) {
+ dol_print_error('', "Failed to include file ".$file);
+ return '';
+ }
+
+ if (class_exists($classname)) {
+ $obj = new $classname();
+ $numref = $obj->getNextValue($this);
+
+ if ($numref != '' && $numref != '-1') {
+ return $numref;
+ } else {
+ $this->error = $obj->error;
+ //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
+ return "";
+ }
+ } else {
+ print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
+ return "";
+ }
+ } else {
+ print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
+ return "";
+ }
+ }
+
+ /**
+ * Create a document onto disk according to template module.
+ *
+ * @param string $modele Force template to use ('' to not force)
+ * @param Translate $outputlangs objet lang a utiliser pour traduction
+ * @param int $hidedetails Hide details of lines
+ * @param int $hidedesc Hide description
+ * @param int $hideref Hide ref
+ * @param null|array $moreparams Array to provide more information
+ * @return int 0 if KO, 1 if OK
+ */
+ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
+ {
+ global $conf, $langs;
+
+ $result = 0;
+ $includedocgeneration = 0;
+
+ $langs->load("hrm");
+
+ if (!dol_strlen($modele)) {
+ $modele = 'standard_job';
+
+ if (!empty($this->model_pdf)) {
+ $modele = $this->model_pdf;
+ } elseif (!empty($conf->global->JOB_ADDON_PDF)) {
+ $modele = $conf->global->JOB_ADDON_PDF;
+ }
+ }
+
+ $modelpath = "core/modules/hrm/doc/";
+
+ if ($includedocgeneration && !empty($modele)) {
+ $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Action executed by scheduler
+ * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
+ * Use public function doScheduledJob($param1, $param2, ...) to get parameters
+ *
+ * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
+ */
+ public function doScheduledJob()
+ {
+ global $conf, $langs;
+
+ //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
+
+ $error = 0;
+ $this->output = '';
+ $this->error = '';
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // ...
+
+ $this->db->commit();
+
+ return $error;
+ }
+}
+
+
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
+
+/**
+ * Class JobLine. You can also remove this and generate a CRUD class for lines objects.
+ */
+class JobLine extends CommonObjectLine
+{
+ // To complete with content of an object JobLine
+ // We should have a field rowid, fk_job and position
+
+ /**
+ * @var int Does object support extrafields ? 0=No, 1=Yes
+ */
+ public $isextrafieldmanaged = 0;
+
+ /**
+ * Constructor
+ *
+ * @param DoliDb $db Database handler
+ */
+ public function __construct(DoliDB $db)
+ {
+ $this->db = $db;
+ }
+}
diff --git a/htdocs/hrm/class/position.class.php b/htdocs/hrm/class/position.class.php
new file mode 100644
index 00000000000..f349514b69a
--- /dev/null
+++ b/htdocs/hrm/class/position.class.php
@@ -0,0 +1,1091 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 class/position.class.php
+ * \ingroup hrm
+ * \brief This file is a CRUD class file for Position (Create/Read/Update/Delete)
+ */
+
+// Put here all includes required by your class file
+require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+
+/**
+ * Class for Position
+ */
+class Position extends CommonObject
+{
+ /**
+ * @var string ID of module.
+ */
+ public $module = 'hrm';
+
+ /**
+ * @var string ID to identify managed object.
+ */
+ public $element = 'position';
+
+ /**
+ * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
+ */
+ public $table_element = 'hrm_job_user';
+
+ /**
+ * @var int Does this object support multicompany module ?
+ * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
+ */
+ public $ismultientitymanaged = 0;
+
+ /**
+ * @var int Does object support extrafields ? 0=No, 1=Yes
+ */
+ public $isextrafieldmanaged = 1;
+
+ /**
+ * @var string String with name of icon for position. Must be the part after the 'object_' into object_position.png
+ */
+ public $picto = 'user-cog';
+
+
+ const STATUS_DRAFT = 0;
+ const STATUS_VALIDATED = 1;
+ const STATUS_CANCELED = 9;
+
+
+ /**
+ * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
+ * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
+ * 'label' the translation key.
+ * 'picto' is code of a picto to show before value in forms
+ * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
+ * 'position' is the sort order of field.
+ * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
+ * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
+ * 'noteditable' says if field is not editable (1 or 0)
+ * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
+ * 'index' if we want an index in database.
+ * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
+ * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
+ * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
+ * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
+ * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
+ * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
+ * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
+ * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
+ * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
+ * 'comment' is not used. You can store here any text of your choice. It is not used by application.
+ *
+ * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
+ */
+
+ // BEGIN MODULEBUILDER PROPERTIES
+ /**
+ * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
+ */
+ public $fields=array(
+ 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>2, 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
+ //'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"),
+ 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>3,),
+ 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
+ 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
+ 'fk_contrat' => array('type'=>'integer:Contrat:contrat/class/contrat.class.php', 'label'=>'fk_contrat', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>0,),
+ 'fk_user' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Employee', 'enabled'=>'1', 'position'=>55, 'notnull'=>1, 'visible'=>1,),
+ 'fk_job' => array('type'=>'integer:Job:/hrm/class/job.class.php', 'label'=>'Job', 'enabled'=>'1', 'position'=>56, 'notnull'=>1, 'visible'=>1,),
+ 'date_start' => array('type'=>'date', 'label'=>'DateStart', 'enabled'=>'1', 'position'=>51, 'notnull'=>1, 'visible'=>1,),
+ 'date_end' => array('type'=>'date', 'label'=>'DateEnd', 'enabled'=>'1', 'position'=>52, 'notnull'=>0, 'visible'=>1,),
+ 'commentaire_abandon' => array('type'=>'varchar(255)', 'label'=>'AbandonmentComment', 'enabled'=>'1', 'position'=>502, 'notnull'=>0, 'visible'=>1,),
+ 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>70, 'notnull'=>0, 'visible'=>0,),
+ 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>71, 'notnull'=>0, 'visible'=>0,),
+ 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
+ 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
+ );
+ public $rowid;
+ public $ref;
+ public $description;
+ public $date_creation;
+ public $tms;
+ public $fk_contrat;
+ public $fk_user;
+ public $fk_job;
+ public $date_start;
+ public $date_end;
+ public $commentaire_abandon;
+ public $note_public;
+ public $note_private;
+ public $fk_user_creat;
+ public $fk_user_modif;
+
+
+ // END MODULEBUILDER PROPERTIES
+
+
+ // If this object has a subtable with lines
+
+ // /**
+ // * @var string Name of subtable line
+ // */
+ // public $table_element_line = 'hrm_job_userline';
+
+ // /**
+ // * @var string Field with ID of parent key if this object has a parent
+ // */
+ // public $fk_element = 'fk_position';
+
+ // /**
+ // * @var string Name of subtable class that manage subtable lines
+ // */
+ // public $class_element_line = 'Positionline';
+
+ // /**
+ // * @var array List of child tables. To test if we can delete object.
+ // */
+ // protected $childtables = array();
+
+ // /**
+ // * @var array List of child tables. To know object to delete on cascade.
+ // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
+ // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
+ // */
+ // protected $childtablesoncascade = array('hrm_job_userdet');
+
+ // /**
+ // * @var PositionLine[] Array of subtable lines
+ // */
+ // public $lines = array();
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDb $db Database handler
+ */
+ public function __construct(DoliDB $db)
+ {
+ global $conf, $langs;
+
+ $this->db = $db;
+
+ if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
+ //$this->fields['rowid']['visible'] = 0;
+ }
+ if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
+ $this->fields['entity']['enabled'] = 0;
+ }
+
+ // Example to show how to set values of fields definition dynamically
+ /*if ($user->rights->hrm->position->read) {
+ $this->fields['myfield']['visible'] = 1;
+ $this->fields['myfield']['noteditable'] = 0;
+ }*/
+
+ // Unset fields that are disabled
+ foreach ($this->fields as $key => $val) {
+ if (isset($val['enabled']) && empty($val['enabled'])) {
+ unset($this->fields[$key]);
+ }
+ }
+
+ // Translate some data of arrayofkeyval
+ if (is_object($langs)) {
+ foreach ($this->fields as $key => $val) {
+ if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
+ foreach ($val['arrayofkeyval'] as $key2 => $val2) {
+ $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Create object into database
+ *
+ * @param User $user User that creates
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, Id of created object if OK
+ */
+ public function create(User $user, $notrigger = false)
+ {
+ $resultcreate = $this->createCommon($user, $notrigger);
+
+ //$resultvalidate = $this->validate($user, $notrigger);
+
+ return $resultcreate;
+ }
+
+ /**
+ * Clone an object into another one
+ *
+ * @param User $user User that creates
+ * @param int $fromid Id of object to clone
+ * @return mixed New object created, <0 if KO
+ */
+ public function createFromClone(User $user, $fromid)
+ {
+ global $langs, $extrafields;
+ $error = 0;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $object = new self($this->db);
+
+ $this->db->begin();
+
+ // Load source object
+ $result = $object->fetchCommon($fromid);
+ if ($result > 0 && !empty($object->table_element_line)) {
+ $object->fetchLines();
+ }
+
+ // get lines so they will be clone
+ //foreach($this->lines as $line)
+ // $line->fetch_optionals();
+
+ // Reset some properties
+ unset($object->id);
+ unset($object->fk_user_creat);
+ unset($object->import_key);
+
+ // Clear fields
+ if (property_exists($object, 'ref')) {
+ $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_" . $object->ref : $this->fields['ref']['default'];
+ }
+ if (property_exists($object, 'label')) {
+ $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf") . " " . $object->label : $this->fields['label']['default'];
+ }
+ if (property_exists($object, 'status')) {
+ $object->status = self::STATUS_DRAFT;
+ }
+ if (property_exists($object, 'date_creation')) {
+ $object->date_creation = dol_now();
+ }
+ if (property_exists($object, 'date_modification')) {
+ $object->date_modification = null;
+ }
+ // ...
+ // Clear extrafields that are unique
+ if (is_array($object->array_options) && count($object->array_options) > 0) {
+ $extrafields->fetch_name_optionals_label($this->table_element);
+ foreach ($object->array_options as $key => $option) {
+ $shortkey = preg_replace('/options_/', '', $key);
+ if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
+ //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
+ unset($object->array_options[$key]);
+ }
+ }
+ }
+
+ // Create clone
+ $object->context['createfromclone'] = 'createfromclone';
+ $result = $object->createCommon($user);
+ if ($result < 0) {
+ $error++;
+ $this->error = $object->error;
+ $this->errors = $object->errors;
+ }
+
+ if (!$error) {
+ // copy internal contacts
+ if ($this->copy_linked_contact($object, 'internal') < 0) {
+ $error++;
+ }
+ }
+
+ if (!$error) {
+ // copy external contacts if same company
+ if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
+ if ($this->copy_linked_contact($object, 'external') < 0) {
+ $error++;
+ }
+ }
+ }
+
+ unset($object->context['createfromclone']);
+
+ // End
+ if (!$error) {
+ $this->db->commit();
+ return $object;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+ /**
+ * Load object in memory from the database
+ *
+ * @param int $id Id object
+ * @param string $ref Ref
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetch($id, $ref = null)
+ {
+ $result = $this->fetchCommon($id, $ref);
+ if ($result > 0 && !empty($this->table_element_line)) {
+ $this->fetchLines();
+ }
+ return $result;
+ }
+
+ /**
+ * Load object lines in memory from the database
+ *
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetchLines()
+ {
+ $this->lines = array();
+
+ $result = $this->fetchLinesCommon();
+ return $result;
+ }
+
+
+ /**
+ * Load list of objects in memory from the database.
+ *
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit limit
+ * @param int $offset Offset
+ * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
+ */
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ {
+ global $conf;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $records = array();
+
+ $sql = 'SELECT ';
+ $sql .= $this->getFieldList('t');
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
+ $sql .= ' WHERE t.entity IN (' . getEntity($this->table_element) . ')';
+ } else {
+ $sql .= ' WHERE 1 = 1';
+ }
+ // Manage filter
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sqlwhere[] = $key . '=' . $value;
+ } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
+ $sqlwhere[] = $key . ' = \'' . $this->db->idate($value) . '\'';
+ } elseif ($key == 'customsql') {
+ $sqlwhere[] = $value;
+ } elseif (strpos($value, '%') === false) {
+ $sqlwhere[] = $key . ' IN (' . $this->db->sanitize($this->db->escape($value)) . ')';
+ } else {
+ $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
+ }
+ }
+ }
+ if (count($sqlwhere) > 0) {
+ $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
+ }
+
+ if (!empty($sortfield)) {
+ $sql .= $this->db->order($sortfield, $sortorder);
+ }
+ if (!empty($limit)) {
+ $sql .= ' ' . $this->db->plimit($limit, $offset);
+ }
+
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < ($limit ? min($limit, $num) : $num)) {
+ $obj = $this->db->fetch_object($resql);
+
+ $record = new self($this->db);
+ $record->setVarsFromFetchObj($obj);
+
+ $records[$record->id] = $record;
+
+ $i++;
+ }
+ $this->db->free($resql);
+
+ return $records;
+ } else {
+ $this->errors[] = 'Error ' . $this->db->lasterror();
+ dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
+
+ return -1;
+ }
+ }
+
+ /**
+ * Update object into database
+ *
+ * @param User $user User that modifies
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function update(User $user, $notrigger = false)
+ {
+ return $this->updateCommon($user, $notrigger);
+ }
+
+ /**
+ * Delete object in database
+ *
+ * @param User $user User that deletes
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function delete(User $user, $notrigger = false)
+ {
+ return $this->deleteCommon($user, $notrigger);
+ //return $this->deleteCommon($user, $notrigger, 1);
+ }
+
+ /**
+ * Delete a line of object in database
+ *
+ * @param User $user User that delete
+ * @param int $idline Id of line to delete
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int >0 if OK, <0 if KO
+ */
+ public function deleteLine(User $user, $idline, $notrigger = false)
+ {
+ if ($this->status < 0) {
+ $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
+ return -2;
+ }
+
+ return $this->deleteLineCommon($user, $idline, $notrigger);
+ }
+
+
+ /**
+ * Validate object
+ *
+ * @param User $user User making status change
+ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
+ * @return int <=0 if OK, 0=Nothing done, >0 if KO
+ */
+ public function validate($user, $notrigger = 0)
+ {
+ global $conf, $langs;
+
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+
+ $error = 0;
+
+ // Protection
+ if ($this->status == self::STATUS_VALIDATED) {
+ dol_syslog(get_class($this) . "::validate action abandonned: already validated", LOG_WARNING);
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->position->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->position->position_advance->validate))))
+ {
+ $this->error='NotEnoughPermissions';
+ dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
+ return -1;
+ }*/
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // Define new ref
+ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
+ $num = $this->getNextNumRef();
+ } else {
+ $num = $this->ref;
+ }
+ $this->newref = $num;
+
+ if (!empty($num)) {
+ // Validate
+ $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element;
+ $sql .= " SET ref = '" . $this->db->escape($num) . "',";
+ $sql .= " status = " . self::STATUS_VALIDATED;
+ if (!empty($this->fields['date_validation'])) {
+ $sql .= ", date_validation = '" . $this->db->idate($now) . "'";
+ }
+ if (!empty($this->fields['fk_user_valid'])) {
+ $sql .= ", fk_user_valid = " . ((int) $user->id);
+ }
+ $sql .= " WHERE rowid = " . ((int) $this->id);
+
+ dol_syslog(get_class($this) . "::validate()", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ dol_print_error($this->db);
+ $this->error = $this->db->lasterror();
+ $error++;
+ }
+
+ if (!$error && !$notrigger) {
+ // Call trigger
+ $result = $this->call_trigger('POSITION_VALIDATE', $user);
+ if ($result < 0) {
+ $error++;
+ }
+ // End call triggers
+ }
+ }
+
+ if (!$error) {
+ $this->oldref = $this->ref;
+
+ // Rename directory if dir was a temporary ref
+ if (preg_match('/^[\(]?PROV/i', $this->ref)) {
+ // Now we rename also files into index
+ $sql = 'UPDATE ' . MAIN_DB_PREFIX . "ecm_files set filename = CONCAT('" . $this->db->escape($this->newref) . "', SUBSTR(filename, " . (strlen($this->ref) + 1) . ")), filepath = 'position/" . $this->db->escape($this->newref) . "'";
+ $sql .= " WHERE filename LIKE '" . $this->db->escape($this->ref) . "%' AND filepath = 'position/" . $this->db->escape($this->ref) . "' and entity = " . $conf->entity;
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $error++;
+ $this->error = $this->db->lasterror();
+ }
+
+ // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
+ $oldref = dol_sanitizeFileName($this->ref);
+ $newref = dol_sanitizeFileName($num);
+ $dirsource = $conf->hrm->dir_output . '/position/' . $oldref;
+ $dirdest = $conf->hrm->dir_output . '/position/' . $newref;
+ if (!$error && file_exists($dirsource)) {
+ dol_syslog(get_class($this) . "::validate() rename dir " . $dirsource . " into " . $dirdest);
+
+ if (@rename($dirsource, $dirdest)) {
+ dol_syslog("Rename ok");
+ // Rename docs starting with $oldref with $newref
+ $listoffiles = dol_dir_list($conf->hrm->dir_output . '/position/' . $newref, 'files', 1, '^' . preg_quote($oldref, '/'));
+ foreach ($listoffiles as $fileentry) {
+ $dirsource = $fileentry['name'];
+ $dirdest = preg_replace('/^' . preg_quote($oldref, '/') . '/', $newref, $dirsource);
+ $dirsource = $fileentry['path'] . '/' . $dirsource;
+ $dirdest = $fileentry['path'] . '/' . $dirdest;
+ @rename($dirsource, $dirdest);
+ }
+ }
+ }
+ }
+ }
+
+ // Set new ref and current status
+ if (!$error) {
+ $this->ref = $num;
+ $this->status = self::STATUS_VALIDATED;
+ }
+
+ if (!$error) {
+ $this->db->commit();
+ return 1;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+
+ /**
+ * Set draft status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function setDraft($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status <= self::STATUS_DRAFT) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'POSITION_UNVALIDATE');
+ }
+
+ /**
+ * Set cancel status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function cancel($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_VALIDATED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'POSITION_CANCEL');
+ }
+
+ /**
+ * Set back to validated status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function reopen($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_CANCELED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'POSITION_REOPEN');
+ }
+
+ /**
+ * Return a link to the object card (with optionaly the picto)
+ *
+ * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
+ * @param string $option On what the link point to ('nolink', ...)
+ * @param int $notooltip 1=Disable tooltip
+ * @param string $morecss Add more css on link
+ * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
+ * @return string String with URL
+ */
+ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
+ {
+ global $conf, $langs, $hookmanager;
+
+ if (!empty($conf->dol_no_mouse_hover)) {
+ $notooltip = 1; // Force disable tooltips
+ }
+
+ $result = '';
+
+ $label = img_picto('', $this->picto) . ' ' . $langs->trans("Position") . ' ';
+ if (isset($this->status)) {
+ $label .= ' ' . $this->getLibStatut(5);
+ }
+ $label .= ' ';
+ $label .= '' . $langs->trans('Ref') . ': ' . $this->ref;
+
+ $url = dol_buildpath('/hrm/position_card.php', 1) . '?id=' . $this->id;
+
+ if ($option != 'nolink') {
+ // Add param to save lastsearch_values or not
+ $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
+ }
+
+ $linkclose = '';
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
+ $label = $langs->trans("ShowPosition");
+ $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"';
+ }
+ $linkclose .= ' title="' . dol_escape_htmltag($label, 1) . '"';
+ $linkclose .= ' class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"';
+ } else {
+ $linkclose = ($morecss ? ' class="' . $morecss . '"' : '');
+ }
+
+ if ($option == 'nolink') {
+ $linkstart = '';
+ if ($option == 'nolink') {
+ $linkend = ' ';
+ } else {
+ $linkend = '';
+ }
+
+ $result .= $linkstart;
+
+ if (empty($this->showphoto_on_popup)) {
+ if ($withpicto) {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ } else {
+ if ($withpicto) {
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+
+ list($class, $module) = explode('@', $this->picto);
+ $upload_dir = $conf->$module->multidir_output[$conf->entity] . "/$class/" . dol_sanitizeFileName($this->ref);
+ $filearray = dol_dir_list($upload_dir, "files");
+ $filename = $filearray[0]['name'];
+ if (!empty($filename)) {
+ $pospoint = strpos($filearray[0]['name'], '.');
+
+ $pathtophoto = $class . '/' . $this->ref . '/thumbs/' . substr($filename, 0, $pospoint) . '_mini' . substr($filename, $pospoint);
+ if (empty($conf->global->{strtoupper($module . '_' . $class) . '_FORMATLISTPHOTOSASUSERS'})) {
+ $result .= '';
+ } else {
+ $result .= ' ';
+ }
+
+ $result .= '';
+ } else {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ }
+ }
+
+ if ($withpicto != 2) {
+ $result .= $this->ref;
+ }
+
+ $result .= $linkend;
+ //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
+
+ global $action, $hookmanager;
+ $hookmanager->initHooks(array('positiondao'));
+ $parameters = array('id' => $this->id, 'getnomurl' => $result);
+ $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ if ($reshook > 0) {
+ $result = $hookmanager->resPrint;
+ } else {
+ $result .= $hookmanager->resPrint;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Return the label of the status
+ *
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function getLibStatut($mode = 0)
+ {
+ return $this->LibStatut($this->status, $mode);
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+
+ /**
+ * Return the status
+ *
+ * @param int $status Id status
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function LibStatut($status, $mode = 0)
+ {
+ // phpcs:enable
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
+ global $langs;
+ //$langs->load("hrm");
+ $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ }
+
+ $statusType = 'status' . $status;
+ //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
+ if ($status == self::STATUS_CANCELED) {
+ $statusType = 'status6';
+ }
+
+ return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
+ }
+
+ /**
+ * Load the info information in the object
+ *
+ * @param int $id Id of object
+ * @return void
+ */
+ public function info($id)
+ {
+ $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
+ $sql .= ' fk_user_creat, fk_user_modif';
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
+ $sql .= ' WHERE t.rowid = ' . ((int) $id);
+ $result = $this->db->query($sql);
+ if ($result) {
+ if ($this->db->num_rows($result)) {
+ $obj = $this->db->fetch_object($result);
+ $this->id = $obj->rowid;
+ if ($obj->fk_user_author) {
+ $cuser = new User($this->db);
+ $cuser->fetch($obj->fk_user_author);
+ $this->user_creation = $cuser;
+ }
+
+ if ($obj->fk_user_valid) {
+ $vuser = new User($this->db);
+ $vuser->fetch($obj->fk_user_valid);
+ $this->user_validation = $vuser;
+ }
+
+ if ($obj->fk_user_cloture) {
+ $cluser = new User($this->db);
+ $cluser->fetch($obj->fk_user_cloture);
+ $this->user_cloture = $cluser;
+ }
+
+ $this->date_creation = $this->db->jdate($obj->datec);
+ $this->date_modification = $this->db->jdate($obj->datem);
+ $this->date_validation = $this->db->jdate($obj->datev);
+ }
+
+ $this->db->free($result);
+ } else {
+ dol_print_error($this->db);
+ }
+ }
+
+ /**
+ * Initialise object with example values
+ * Id must be 0 if object instance is a specimen
+ *
+ * @return void
+ */
+ public function initAsSpecimen()
+ {
+ // Set here init that are not commonf fields
+ // $this->property1 = ...
+ // $this->property2 = ...
+
+ $this->initAsSpecimenCommon();
+ }
+
+ /**
+ * Create an array of lines
+ *
+ * @return array|int array of lines if OK, <0 if KO
+ */
+ public function getLinesArray()
+ {
+ $this->lines = array();
+
+ $objectline = new PositionLine($this->db);
+ $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql' => 'fk_position = ' . $this->id));
+
+ if (is_numeric($result)) {
+ $this->error = $this->error;
+ $this->errors = $this->errors;
+ return $result;
+ } else {
+ $this->lines = $result;
+ return $this->lines;
+ }
+ }
+
+ /**
+ * Returns the reference to the following non used object depending on the active numbering module.
+ *
+ * @return string Object free reference
+ */
+ public function getNextNumRef()
+ {
+ global $langs, $conf;
+ $langs->load("hrm");
+
+ if (empty($conf->global->hrm_POSITION_ADDON)) {
+ $conf->global->hrm_POSITION_ADDON = 'mod_position_standard';
+ }
+
+ if (!empty($conf->global->hrm_POSITION_ADDON)) {
+ $mybool = false;
+
+ $file = $conf->global->hrm_POSITION_ADDON . ".php";
+ $classname = $conf->global->hrm_POSITION_ADDON;
+
+ // Include file with class
+ $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+ foreach ($dirmodels as $reldir) {
+ $dir = dol_buildpath($reldir . "core/modules/hrm/");
+
+ // Load file with numbering class (if found)
+ $mybool |= @include_once $dir . $file;
+ }
+
+ if ($mybool === false) {
+ dol_print_error('', "Failed to include file " . $file);
+ return '';
+ }
+
+ if (class_exists($classname)) {
+ $obj = new $classname();
+ $numref = $obj->getNextValue($this);
+
+ if ($numref != '' && $numref != '-1') {
+ return $numref;
+ } else {
+ $this->error = $obj->error;
+ //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
+ return "";
+ }
+ } else {
+ print $langs->trans("Error") . " " . $langs->trans("ClassNotFound") . ' ' . $classname;
+ return "";
+ }
+ } else {
+ print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
+ return "";
+ }
+ }
+
+ /**
+ * @param int $userid id of user we need to get position list
+ * @return array|int of positions of user with for each of them the job fetched into that array
+ */
+ public function getForUser($userid)
+ {
+ $TPosition = array();
+
+ $TPosition = $this->fetchAll('ASC', 't.rowid', 0, 0, array('customsql' => 'fk_user=' . $userid));
+
+ return $TPosition;
+ }
+
+ /**
+ * Create a document onto disk according to template module.
+ *
+ * @param string $modele Force template to use ('' to not force)
+ * @param Translate $outputlangs objet lang a utiliser pour traduction
+ * @param int $hidedetails Hide details of lines
+ * @param int $hidedesc Hide description
+ * @param int $hideref Hide ref
+ * @param null|array $moreparams Array to provide more information
+ * @return int 0 if KO, 1 if OK
+ */
+ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
+ {
+ global $conf, $langs;
+
+ $result = 0;
+ $includedocgeneration = 0;
+
+ $langs->load("hrm");
+
+ if (!dol_strlen($modele)) {
+ $modele = 'standard_position';
+
+ if (!empty($this->model_pdf)) {
+ $modele = $this->model_pdf;
+ } elseif (!empty($conf->global->POSITION_ADDON_PDF)) {
+ $modele = $conf->global->POSITION_ADDON_PDF;
+ }
+ }
+
+ $modelpath = "core/modules/hrm/doc/";
+
+ if ($includedocgeneration && !empty($modele)) {
+ $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Action executed by scheduler
+ * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
+ * Use public function doScheduledJob($param1, $param2, ...) to get parameters
+ *
+ * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
+ */
+ public function doScheduledJob()
+ {
+ global $conf, $langs;
+
+ //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
+
+ $error = 0;
+ $this->output = '';
+ $this->error = '';
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // ...
+
+ $this->db->commit();
+
+ return $error;
+ }
+}
+
+
+require_once DOL_DOCUMENT_ROOT . '/core/class/commonobjectline.class.php';
+
+/**
+ * Class PositionLine. You can also remove this and generate a CRUD class for lines objects.
+ */
+class PositionLine extends CommonObjectLine
+{
+ // To complete with content of an object PositionLine
+ // We should have a field rowid, fk_position and position
+
+ /**
+ * @var int Does object support extrafields ? 0=No, 1=Yes
+ */
+ public $isextrafieldmanaged = 0;
+
+ /**
+ * Constructor
+ *
+ * @param DoliDb $db Database handler
+ */
+ public function __construct(DoliDB $db)
+ {
+ $this->db = $db;
+ }
+}
diff --git a/htdocs/hrm/class/skill.class.php b/htdocs/hrm/class/skill.class.php
new file mode 100644
index 00000000000..ba7d0f43d3c
--- /dev/null
+++ b/htdocs/hrm/class/skill.class.php
@@ -0,0 +1,1109 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 class/skill.class.php
+ * \ingroup hrm
+ * \brief This file is a CRUD class file for Skill (Create/Read/Update/Delete)
+ */
+
+// Put here all includes required by your class file
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+
+/**
+ * Class for Skill
+ */
+class Skill extends CommonObject
+{
+ /**
+ * @var string ID of module.
+ */
+ public $module = 'hrm';
+
+ /**
+ * @var string ID to identify managed object.
+ */
+ public $element = 'skill';
+
+ /**
+ * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
+ */
+ public $table_element = 'hrm_skill';
+
+
+ /**
+ * @var string Name of subtable line
+ */
+ public $table_element_line = 'skilldet';
+
+ /**
+ * @var int Does this object support multicompany module ?
+ * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
+ */
+ public $ismultientitymanaged = 0;
+
+ /**
+ * @var int Does object support extrafields ? 0=No, 1=Yes
+ */
+ public $isextrafieldmanaged = 1;
+
+ /**
+ * @var string String with name of icon for skill. Must be the part after the 'object_' into object_skill.png
+ */
+ public $picto = 'shapes';
+
+
+ const STATUS_DRAFT = 0;
+ const STATUS_VALIDATED = 1;
+ const STATUS_CANCELED = 9;
+ const DEFAULT_MAX_RANK_PER_SKILL = 5;
+
+ /**
+ * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
+ * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
+ * 'label' the translation key.
+ * 'picto' is code of a picto to show before value in forms
+ * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
+ * 'position' is the sort order of field.
+ * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
+ * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
+ * 'noteditable' says if field is not editable (1 or 0)
+ * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
+ * 'index' if we want an index in database.
+ * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
+ * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
+ * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
+ * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
+ * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
+ * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
+ * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
+ * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
+ * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
+ * 'comment' is not used. You can store here any text of your choice. It is not used by application.
+ *
+ * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
+ */
+
+ // BEGIN MODULEBUILDER PROPERTIES
+ /**
+ * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
+ */
+ public $fields=array(
+ 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
+ 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'showoncombobox'=>'2',),
+ 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>3,),
+ 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
+ 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
+ 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
+ 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
+ 'required_level' => array('type'=>'integer', 'label'=>'requiredLevel', 'enabled'=>'1', 'position'=>50, 'notnull'=>1, 'visible'=>0,),
+ 'date_validite' => array('type'=>'integer', 'label'=>'date_validite', 'enabled'=>'1', 'position'=>52, 'notnull'=>1, 'visible'=>0,),
+ 'temps_theorique' => array('type'=>'double(24,8)', 'label'=>'temps_theorique', 'enabled'=>'1', 'position'=>54, 'notnull'=>1, 'visible'=>0,),
+ 'skill_type' => array('type'=>'integer', 'label'=>'SkillType', 'enabled'=>'1', 'position'=>55, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'knowHow', '1'=>'HowToBe', '9'=>'knowledge'), 'default'=>0),
+ 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>70, 'notnull'=>0, 'visible'=>0,),
+ 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>71, 'notnull'=>0, 'visible'=>0,),
+ );
+ public $rowid;
+ public $label;
+ public $description;
+ public $date_creation;
+ public $tms;
+ public $fk_user_creat;
+ public $fk_user_modif;
+ public $required_level;
+ public $date_validite;
+ public $temps_theorique;
+ public $skill_type;
+ public $note_public;
+ public $note_private;
+ // END MODULEBUILDER PROPERTIES
+
+
+ // If this object has a subtable with lines
+
+ // /**
+ // * @var string Name of subtable line
+ // */
+ // public $table_element_line = 'hrm_skillline';
+
+ // /**
+ // * @var string Field with ID of parent key if this object has a parent
+ // */
+ public $fk_element = 'fk_skill';
+
+ // /**
+ // * @var string Name of subtable class that manage subtable lines
+ // */
+ // public $class_element_line = 'Skillline';
+
+ // /**
+ // * @var array List of child tables. To test if we can delete object.
+ // */
+ protected $childtables = array('hrm_skillrank', 'hrm_evaluationdet');
+
+ // /**
+ // * @var array List of child tables. To know object to delete on cascade.
+ // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
+ // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
+ // */
+ protected $childtablesoncascade = array('hrm_skilldet');
+
+ // /**
+ // * @var SkillLine[] Array of subtable lines
+ // */
+ // public $lines = array();
+
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDb $db Database handler
+ */
+ public function __construct(DoliDB $db)
+ {
+ global $conf, $langs;
+
+ $this->db = $db;
+
+ if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
+ $this->fields['rowid']['visible'] = 0;
+ }
+ if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
+ $this->fields['entity']['enabled'] = 0;
+ }
+
+ // Example to show how to set values of fields definition dynamically
+ /*if ($user->rights->hrm->skill->read) {
+ $this->fields['myfield']['visible'] = 1;
+ $this->fields['myfield']['noteditable'] = 0;
+ }*/
+
+ // Unset fields that are disabled
+ foreach ($this->fields as $key => $val) {
+ if (isset($val['enabled']) && empty($val['enabled'])) {
+ unset($this->fields[$key]);
+ }
+ }
+
+ // Translate some data of arrayofkeyval
+ if (is_object($langs)) {
+ foreach ($this->fields as $key => $val) {
+ if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
+ foreach ($val['arrayofkeyval'] as $key2 => $val2) {
+ $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Create object into database
+ *
+ * @param User $user User that creates
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, Id of created object if OK
+ */
+ public function create(User $user, $notrigger = false)
+ {
+ global $langs,$conf;
+
+ $resultcreate = $this->createCommon($user, $notrigger);
+
+
+ if ($resultcreate > 0) {
+ // skillDet create
+ $this->createSkills();
+ }
+
+ return $resultcreate;
+ }
+
+ /**
+ * @param int $i rank from which we want to create skilldets
+ * @return null
+ */
+ public function createSkills($i = 1)
+ {
+
+ global $conf, $user, $langs;
+
+ $MaxNumberSkill = isset($conf->global->HRM_MAXRANK) ? $conf->global->HRM_MAXRANK : self::DEFAULT_MAX_RANK_PER_SKILL;
+ $defaultSkillDesc = !empty($conf->global->HRM_DEFAULT_SKILL_DESCRIPTION) ? $conf->global->HRM_DEFAULT_SKILL_DESCRIPTION : 'no Description';
+ require_once __DIR__ . '/skilldet.class.php';
+ for ($i; $i <= $MaxNumberSkill ; $i++) {
+ $skilldet = new Skilldet($this->db);
+ $skilldet->description = $defaultSkillDesc . " " . $i ;
+ $skilldet->rank = $i;
+ $skilldet->fk_skill = $this->id;
+
+ $result = $skilldet->create($user);
+
+ if ($result > 0) {
+ setEventMessage($langs->trans('TraductionCreadted'), $i);
+ }
+ }
+ }
+
+ /**
+ * Clone an object into another one
+ *
+ * @param User $user User that creates
+ * @param int $fromid Id of object to clone
+ * @return mixed New object created, <0 if KO
+ */
+ public function createFromClone(User $user, $fromid)
+ {
+ global $langs, $extrafields;
+ $error = 0;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $object = new self($this->db);
+
+ $this->db->begin();
+
+ // Load source object
+ $result = $object->fetchCommon($fromid);
+ if ($result > 0 && !empty($object->table_element_line)) {
+ $object->fetchLines();
+ }
+
+ // get lines so they will be clone
+ //foreach($this->lines as $line)
+ // $line->fetch_optionals();
+
+ // Reset some properties
+ unset($object->id);
+ unset($object->fk_user_creat);
+ unset($object->import_key);
+
+ // Clear fields
+ if (property_exists($object, 'ref')) {
+ $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
+ }
+ if (property_exists($object, 'label')) {
+ $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
+ }
+ if (property_exists($object, 'status')) {
+ $object->status = self::STATUS_DRAFT;
+ }
+ if (property_exists($object, 'date_creation')) {
+ $object->date_creation = dol_now();
+ }
+ if (property_exists($object, 'date_modification')) {
+ $object->date_modification = null;
+ }
+ // ...
+ // Clear extrafields that are unique
+ if (is_array($object->array_options) && count($object->array_options) > 0) {
+ $extrafields->fetch_name_optionals_label($this->table_element);
+ foreach ($object->array_options as $key => $option) {
+ $shortkey = preg_replace('/options_/', '', $key);
+ if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
+ //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
+ unset($object->array_options[$key]);
+ }
+ }
+ }
+
+ // Create clone
+ $object->context['createfromclone'] = 'createfromclone';
+ $result = $object->createCommon($user);
+ if ($result < 0) {
+ $error++;
+ $this->error = $object->error;
+ $this->errors = $object->errors;
+ }
+
+ if (!$error) {
+ // copy internal contacts
+ if ($this->copy_linked_contact($object, 'internal') < 0) {
+ $error++;
+ }
+ }
+
+ if (!$error) {
+ // copy external contacts if same company
+ if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
+ if ($this->copy_linked_contact($object, 'external') < 0) {
+ $error++;
+ }
+ }
+ }
+
+ unset($object->context['createfromclone']);
+
+ // End
+ if (!$error) {
+ $this->db->commit();
+ return $object;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+ /**
+ * Load object in memory from the database
+ *
+ * @param int $id Id object
+ * @param string $ref Ref
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetch($id, $ref = null)
+ {
+ $result = $this->fetchCommon($id, $ref);
+ if ($result > 0 && !empty($this->table_element_line)) {
+ $this->fetchLines();
+ }
+ return $result;
+ }
+
+ /**
+ * Load object lines in memory from the database
+ *
+ * @return int | array <0 if KO, 0 if not found, array if OK
+ */
+ public function fetchLines()
+ {
+ $this->lines = array();
+ require_once __DIR__ . '/skilldet.class.php';
+ $skilldet = new Skilldet($this->db);
+ $this->lines = $skilldet->fetchAll('ASC', '', '', '', array('fk_skill' => $this->id), '');
+
+ return (count($this->lines) > 0 ) ? $this->lines : 0;
+ }
+
+
+ /**
+ * Load list of objects in memory from the database.
+ *
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit limit
+ * @param int $offset Offset
+ * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
+ */
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ {
+ global $conf;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $records = array();
+
+ $sql = 'SELECT ';
+ $sql .= $this->getFieldList('t');
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
+ $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
+ } else {
+ $sql .= ' WHERE 1 = 1';
+ }
+ // Manage filter
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sqlwhere[] = $key.'='.$value;
+ } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
+ $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
+ } elseif ($key == 'customsql') {
+ $sqlwhere[] = $value;
+ } elseif (strpos($value, '%') === false) {
+ $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
+ } else {
+ $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
+ }
+ }
+ }
+ if (count($sqlwhere) > 0) {
+ $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
+ }
+
+ if (!empty($sortfield)) {
+ $sql .= $this->db->order($sortfield, $sortorder);
+ }
+ if (!empty($limit)) {
+ $sql .= ' '.$this->db->plimit($limit, $offset);
+ }
+
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < ($limit ? min($limit, $num) : $num)) {
+ $obj = $this->db->fetch_object($resql);
+
+ $record = new self($this->db);
+ $record->setVarsFromFetchObj($obj);
+
+ $records[$record->id] = $record;
+
+ $i++;
+ }
+ $this->db->free($resql);
+
+ return $records;
+ } else {
+ $this->errors[] = 'Error '.$this->db->lasterror();
+ dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
+
+ return -1;
+ }
+ }
+
+ /**
+ * Update object into database
+ *
+ * @param User $user User that modifies
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function update(User $user, $notrigger = false)
+ {
+ return $this->updateCommon($user, $notrigger);
+ }
+
+ /**
+ * Delete object in database
+ *
+ * @param User $user User that deletes
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function delete(User $user, $notrigger = false)
+ {
+ return $this->deleteCommon($user, $notrigger);;
+ }
+
+ /**
+ * Delete a line of object in database
+ *
+ * @param User $user User that delete
+ * @param int $idline Id of line to delete
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int >0 if OK, <0 if KO
+ */
+ public function deleteLine(User $user, $idline, $notrigger = false)
+ {
+ if ($this->status < 0) {
+ $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
+ return -2;
+ }
+
+ return $this->deleteLineCommon($user, $idline, $notrigger);
+ }
+
+
+ /**
+ * Validate object
+ *
+ * @param User $user User making status change
+ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
+ * @return int <=0 if OK, 0=Nothing done, >0 if KO
+ */
+ public function validate($user, $notrigger = 0)
+ {
+ global $conf, $langs;
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ $error = 0;
+
+ // Protection
+ if ($this->status == self::STATUS_VALIDATED) {
+ dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->skill->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->skill->skill_advance->validate))))
+ {
+ $this->error='NotEnoughPermissions';
+ dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
+ return -1;
+ }*/
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // Define new ref
+ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
+ $num = $this->getNextNumRef();
+ } else {
+ $num = $this->ref;
+ }
+ $this->newref = $num;
+
+ if (!empty($num)) {
+ // Validate
+ $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
+ $sql .= " SET ref = '".$this->db->escape($num)."',";
+ $sql .= " status = ".self::STATUS_VALIDATED;
+ if (!empty($this->fields['date_validation'])) {
+ $sql .= ", date_validation = '".$this->db->idate($now)."'";
+ }
+ if (!empty($this->fields['fk_user_valid'])) {
+ $sql .= ", fk_user_valid = ".((int) $user->id);
+ }
+ $sql .= " WHERE rowid = ".((int) $this->id);
+
+ dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ dol_print_error($this->db);
+ $this->error = $this->db->lasterror();
+ $error++;
+ }
+
+ if (!$error && !$notrigger) {
+ // Call trigger
+ $result = $this->call_trigger('SKILL_VALIDATE', $user);
+ if ($result < 0) {
+ $error++;
+ }
+ // End call triggers
+ }
+ }
+
+ if (!$error) {
+ $this->oldref = $this->ref;
+
+ // Rename directory if dir was a temporary ref
+ if (preg_match('/^[\(]?PROV/i', $this->ref)) {
+ // Now we rename also files into index
+ $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'skill/".$this->db->escape($this->newref)."'";
+ $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $error++; $this->error = $this->db->lasterror();
+ }
+
+ // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
+ $oldref = dol_sanitizeFileName($this->ref);
+ $newref = dol_sanitizeFileName($num);
+ $dirsource = $conf->hrm->dir_output.'/skill/'.$oldref;
+ $dirdest = $conf->hrm->dir_output.'/skill/'.$newref;
+ if (!$error && file_exists($dirsource)) {
+ dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
+
+ if (@rename($dirsource, $dirdest)) {
+ dol_syslog("Rename ok");
+ // Rename docs starting with $oldref with $newref
+ $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skill/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
+ foreach ($listoffiles as $fileentry) {
+ $dirsource = $fileentry['name'];
+ $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
+ $dirsource = $fileentry['path'].'/'.$dirsource;
+ $dirdest = $fileentry['path'].'/'.$dirdest;
+ @rename($dirsource, $dirdest);
+ }
+ }
+ }
+ }
+ }
+
+ // Set new ref and current status
+ if (!$error) {
+ $this->ref = $num;
+ $this->status = self::STATUS_VALIDATED;
+ }
+
+ if (!$error) {
+ $this->db->commit();
+ return 1;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+
+ /**
+ * Set draft status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function setDraft($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status <= self::STATUS_DRAFT) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILL_UNVALIDATE');
+ }
+
+ /**
+ * Set cancel status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function cancel($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_VALIDATED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILL_CANCEL');
+ }
+
+ /**
+ * Set back to validated status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function reopen($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_CANCELED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILL_REOPEN');
+ }
+
+ /**
+ * Return a link to the object card (with optionaly the picto)
+ *
+ * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
+ * @param string $option On what the link point to ('nolink', ...)
+ * @param int $notooltip 1=Disable tooltip
+ * @param string $morecss Add more css on link
+ * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
+ * @return string String with URL
+ */
+ /**
+ * Return a link to the object card (with optionaly the picto)
+ *
+ * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
+ * @param string $option On what the link point to ('nolink', ...)
+ * @param int $notooltip 1=Disable tooltip
+ * @param string $morecss Add more css on link
+ * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
+ * @return string String with URL
+ */
+ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
+ {
+ global $conf, $langs, $hookmanager;
+
+ if (!empty($conf->dol_no_mouse_hover)) {
+ $notooltip = 1; // Force disable tooltips
+ }
+
+ $result = '';
+
+ $label = img_picto('', $this->picto).' '.$langs->trans("Skill").' ';
+ if (isset($this->status)) {
+ $label .= ' '.$this->getLibStatut(5);
+ }
+ $label .= ' ';
+ $label .= ''.$langs->trans('Label').': '.$this->label;
+
+ $url = dol_buildpath('/hrm/skill_card.php', 1).'?id='.$this->id;
+
+ if ($option != 'nolink') {
+ // Add param to save lastsearch_values or not
+ $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
+ }
+
+ $linkclose = '';
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
+ $label = $langs->trans("ShowSkill");
+ $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
+ }
+ $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
+ $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
+ } else {
+ $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
+ }
+
+ if ($option == 'nolink') {
+ $linkstart = '';
+ if ($option == 'nolink') {
+ $linkend = ' ';
+ } else {
+ $linkend = '';
+ }
+
+ $result .= $linkstart;
+
+ if (empty($this->showphoto_on_popup)) {
+ if ($withpicto) {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ } else {
+ if ($withpicto) {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ list($class, $module) = explode('@', $this->picto);
+ $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
+ $filearray = dol_dir_list($upload_dir, "files");
+ $filename = $filearray[0]['name'];
+ if (!empty($filename)) {
+ $pospoint = strpos($filearray[0]['name'], '.');
+
+ $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
+ if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
+ $result .= '';
+ } else {
+ $result .= ' ';
+ }
+
+ $result .= '';
+ } else {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ }
+ }
+
+ if ($withpicto != 2) {
+ $result .= $this->label;
+ }
+
+ $result .= $linkend;
+ //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
+
+ global $action, $hookmanager;
+ $hookmanager->initHooks(array('jobdao'));
+ $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
+ $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ if ($reshook > 0) {
+ $result = $hookmanager->resPrint;
+ } else {
+ $result .= $hookmanager->resPrint;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Return the label of the status
+ *
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function getLibStatut($mode = 0)
+ {
+ return $this->LibStatut($this->status, $mode);
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Return the status
+ *
+ * @param int $status Id status
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function LibStatut($status, $mode = 0)
+ {
+ // phpcs:enable
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
+ global $langs;
+ //$langs->load("hrm");
+ $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ }
+
+ $statusType = 'status'.$status;
+ //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
+ if ($status == self::STATUS_CANCELED) {
+ $statusType = 'status6';
+ }
+
+ return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
+ }
+
+ /**
+ * Load the info information in the object
+ *
+ * @param int $id Id of object
+ * @return void
+ */
+ public function info($id)
+ {
+ $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
+ $sql .= ' fk_user_creat, fk_user_modif';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ $sql .= ' WHERE t.rowid = '.((int) $id);
+ $result = $this->db->query($sql);
+ if ($result) {
+ if ($this->db->num_rows($result)) {
+ $obj = $this->db->fetch_object($result);
+ $this->id = $obj->rowid;
+ if ($obj->fk_user_author) {
+ $cuser = new User($this->db);
+ $cuser->fetch($obj->fk_user_author);
+ $this->user_creation = $cuser;
+ }
+
+ if ($obj->fk_user_valid) {
+ $vuser = new User($this->db);
+ $vuser->fetch($obj->fk_user_valid);
+ $this->user_validation = $vuser;
+ }
+
+ if ($obj->fk_user_cloture) {
+ $cluser = new User($this->db);
+ $cluser->fetch($obj->fk_user_cloture);
+ $this->user_cloture = $cluser;
+ }
+
+ $this->date_creation = $this->db->jdate($obj->datec);
+ $this->date_modification = $this->db->jdate($obj->datem);
+ $this->date_validation = $this->db->jdate($obj->datev);
+ }
+
+ $this->db->free($result);
+ } else {
+ dol_print_error($this->db);
+ }
+ }
+
+ /**
+ * Initialise object with example values
+ * Id must be 0 if object instance is a specimen
+ *
+ * @return void
+ */
+ public function initAsSpecimen()
+ {
+ // Set here init that are not commonf fields
+ // $this->property1 = ...
+ // $this->property2 = ...
+
+ $this->initAsSpecimenCommon();
+ }
+
+ /**
+ * Create an array of lines
+ *
+ * @return array|int array of lines if OK, <0 if KO
+ */
+ public function getLinesArray()
+ {
+ $this->lines = array();
+
+ $objectline = new SkillLine($this->db);
+ $result = $objectline->fetchAll('ASC', 'rank', 0, 0, array('customsql'=>'fk_skill = '.$this->id));
+
+ if (is_numeric($result)) {
+ $this->error = $this->error;
+ $this->errors = $this->errors;
+ return $result;
+ } else {
+ $this->lines = $result;
+ return $this->lines;
+ }
+ }
+
+ /**
+ * Returns the reference to the following non used object depending on the active numbering module.
+ *
+ * @return string Object free reference
+ */
+ public function getNextNumRef()
+ {
+ global $langs, $conf;
+ $langs->load("hrm");
+
+ if (empty($conf->global->hrm_SKILL_ADDON)) {
+ $conf->global->hrm_SKILL_ADDON = 'mod_skill_standard';
+ }
+
+ if (!empty($conf->global->hrm_SKILL_ADDON)) {
+ $mybool = false;
+
+ $file = $conf->global->hrm_SKILL_ADDON.".php";
+ $classname = $conf->global->hrm_SKILL_ADDON;
+
+ // Include file with class
+ $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+ foreach ($dirmodels as $reldir) {
+ $dir = dol_buildpath($reldir."core/modules/hrm/");
+
+ // Load file with numbering class (if found)
+ $mybool |= @include_once $dir.$file;
+ }
+
+ if ($mybool === false) {
+ dol_print_error('', "Failed to include file ".$file);
+ return '';
+ }
+
+ if (class_exists($classname)) {
+ $obj = new $classname();
+ $numref = $obj->getNextValue($this);
+
+ if ($numref != '' && $numref != '-1') {
+ return $numref;
+ } else {
+ $this->error = $obj->error;
+ //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
+ return "";
+ }
+ } else {
+ print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
+ return "";
+ }
+ } else {
+ print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
+ return "";
+ }
+ }
+
+ /**
+ * Create a document onto disk according to template module.
+ *
+ * @param string $modele Force template to use ('' to not force)
+ * @param Translate $outputlangs objet lang a utiliser pour traduction
+ * @param int $hidedetails Hide details of lines
+ * @param int $hidedesc Hide description
+ * @param int $hideref Hide ref
+ * @param null|array $moreparams Array to provide more information
+ * @return int 0 if KO, 1 if OK
+ */
+ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
+ {
+ global $conf, $langs;
+
+ $result = 0;
+ $includedocgeneration = 0;
+
+ $langs->load("hrm");
+
+ if (!dol_strlen($modele)) {
+ $modele = 'standard_skill';
+
+ if (!empty($this->model_pdf)) {
+ $modele = $this->model_pdf;
+ } elseif (!empty($conf->global->SKILL_ADDON_PDF)) {
+ $modele = $conf->global->SKILL_ADDON_PDF;
+ }
+ }
+
+ $modelpath = "core/modules/hrm/doc/";
+
+ if ($includedocgeneration && !empty($modele)) {
+ $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Action executed by scheduler
+ * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
+ * Use public function doScheduledJob($param1, $param2, ...) to get parameters
+ *
+ * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
+ */
+ public function doScheduledJob()
+ {
+ global $conf, $langs;
+
+ //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
+
+ $error = 0;
+ $this->output = '';
+ $this->error = '';
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // ...
+
+ $this->db->commit();
+
+ return $error;
+ }
+
+ /**
+ * @param int $code number of code label
+ * @return int|string
+ */
+ public static function typeCodeToLabel($code)
+ {
+ global $langs;
+ $result = '';
+ switch ($code) {
+ case 0 : $result = $langs->trans("knowHow"); break; //"Savoir Faire"
+ case 1 : $result = $langs->trans("HowToBe"); break; // "Savoir être"
+ case 9 : $result = $langs->trans("knowledge"); break; //"Savoir"
+ }
+ return $result;
+ }
+}
diff --git a/htdocs/hrm/class/skilldet.class.php b/htdocs/hrm/class/skilldet.class.php
new file mode 100644
index 00000000000..e4ac293c297
--- /dev/null
+++ b/htdocs/hrm/class/skilldet.class.php
@@ -0,0 +1,1030 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 class/skilldet.class.php
+ * \ingroup hrm
+ * \brief This file is a CRUD class file for Skilldet (Create/Read/Update/Delete)
+ */
+
+// Put here all includes required by your class file
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
+//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+
+/**
+ * Class for Skilldet
+ */
+class Skilldet extends CommonObject
+{
+ /**
+ * @var string ID of module.
+ */
+ public $module = 'hrm';
+
+ /**
+ * @var string ID to identify managed object.
+ */
+ public $element = 'skilldet';
+
+ /**
+ * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
+ */
+ public $table_element = 'hrm_skilldet';
+
+ /**
+ * @var int Does this object support multicompany module ?
+ * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
+ */
+ public $ismultientitymanaged = 0;
+
+ /**
+ * @var int Does object support extrafields ? 0=No, 1=Yes
+ */
+ public $isextrafieldmanaged = 1;
+
+ /**
+ * @var string String with name of icon for skilldet. Must be the part after the 'object_' into object_skilldet.png
+ */
+ public $picto = 'skilldet@hrm';
+
+
+ const STATUS_DRAFT = 0;
+ const STATUS_VALIDATED = 1;
+ const STATUS_CANCELED = 9;
+
+
+ /**
+ * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
+ * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
+ * 'label' the translation key.
+ * 'picto' is code of a picto to show before value in forms
+ * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
+ * 'position' is the sort order of field.
+ * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
+ * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
+ * 'noteditable' says if field is not editable (1 or 0)
+ * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
+ * 'index' if we want an index in database.
+ * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
+ * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
+ * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
+ * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
+ * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
+ * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
+ * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
+ * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
+ * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
+ * 'comment' is not used. You can store here any text of your choice. It is not used by application.
+ *
+ * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
+ */
+
+ // BEGIN MODULEBUILDER PROPERTIES
+ /**
+ * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
+ */
+ public $fields=array(
+ 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
+ 'rank' => array('type'=>'integer', 'label'=>'rank', 'enabled'=>'1', 'position'=>2, 'notnull'=>0, 'visible'=>2,),
+ 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>1,),
+ 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
+ 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>0,),
+ 'fk_skill' => array('type'=>'integer:Skill:/hrm/class/skill.class.php', 'label'=>'fk_skill', 'enabled'=>'1', 'position'=>513, 'notnull'=>1, 'visible'=>0,),
+ );
+ public $rowid;
+ public $description;
+ public $fk_user_creat;
+ public $fk_user_modif;
+ public $fk_skill;
+ public $rank;
+ // END MODULEBUILDER PROPERTIES
+
+
+ // If this object has a subtable with lines
+
+ // /**
+ // * @var string Name of subtable line
+ // */
+ // public $table_element_line = 'hrm_skilldetline';
+
+ // /**
+ // * @var string Field with ID of parent key if this object has a parent
+ // */
+ // public $fk_element = 'fk_skilldet';
+
+ // /**
+ // * @var string Name of subtable class that manage subtable lines
+ // */
+ // public $class_element_line = 'Skilldetline';
+
+ // /**
+ // * @var array List of child tables. To test if we can delete object.
+ // */
+ // protected $childtables = array();
+
+ // /**
+ // * @var array List of child tables. To know object to delete on cascade.
+ // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
+ // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
+ // */
+ // protected $childtablesoncascade = array('hrm_skilldetdet');
+
+ // /**
+ // * @var SkilldetLine[] Array of subtable lines
+ // */
+ // public $lines = array();
+
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDb $db Database handler
+ */
+ public function __construct(DoliDB $db)
+ {
+ global $conf, $langs;
+
+ $this->db = $db;
+
+ if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
+ $this->fields['rowid']['visible'] = 0;
+ }
+ if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
+ $this->fields['entity']['enabled'] = 0;
+ }
+
+ // Example to show how to set values of fields definition dynamically
+ /*if ($user->rights->hrm->skilldet->read) {
+ $this->fields['myfield']['visible'] = 1;
+ $this->fields['myfield']['noteditable'] = 0;
+ }*/
+
+ // Unset fields that are disabled
+ foreach ($this->fields as $key => $val) {
+ if (isset($val['enabled']) && empty($val['enabled'])) {
+ unset($this->fields[$key]);
+ }
+ }
+
+ // Translate some data of arrayofkeyval
+ if (is_object($langs)) {
+ foreach ($this->fields as $key => $val) {
+ if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
+ foreach ($val['arrayofkeyval'] as $key2 => $val2) {
+ $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Create object into database
+ *
+ * @param User $user User that creates
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, Id of created object if OK
+ */
+ public function create(User $user, $notrigger = false)
+ {
+ $resultcreate = $this->createCommon($user, $notrigger);
+
+ //$resultvalidate = $this->validate($user, $notrigger);
+
+ return $resultcreate;
+ }
+
+ /**
+ * Clone an object into another one
+ *
+ * @param User $user User that creates
+ * @param int $fromid Id of object to clone
+ * @return mixed New object created, <0 if KO
+ */
+ public function createFromClone(User $user, $fromid)
+ {
+ global $langs, $extrafields;
+ $error = 0;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $object = new self($this->db);
+
+ $this->db->begin();
+
+ // Load source object
+ $result = $object->fetchCommon($fromid);
+ if ($result > 0 && !empty($object->table_element_line)) {
+ $object->fetchLines();
+ }
+
+ // get lines so they will be clone
+ //foreach($this->lines as $line)
+ // $line->fetch_optionals();
+
+ // Reset some properties
+ unset($object->id);
+ unset($object->fk_user_creat);
+ unset($object->import_key);
+
+ // Clear fields
+ if (property_exists($object, 'ref')) {
+ $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
+ }
+ if (property_exists($object, 'label')) {
+ $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
+ }
+ if (property_exists($object, 'status')) {
+ $object->status = self::STATUS_DRAFT;
+ }
+ if (property_exists($object, 'date_creation')) {
+ $object->date_creation = dol_now();
+ }
+ if (property_exists($object, 'date_modification')) {
+ $object->date_modification = null;
+ }
+ // ...
+ // Clear extrafields that are unique
+ if (is_array($object->array_options) && count($object->array_options) > 0) {
+ $extrafields->fetch_name_optionals_label($this->table_element);
+ foreach ($object->array_options as $key => $option) {
+ $shortkey = preg_replace('/options_/', '', $key);
+ if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
+ //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
+ unset($object->array_options[$key]);
+ }
+ }
+ }
+
+ // Create clone
+ $object->context['createfromclone'] = 'createfromclone';
+ $result = $object->createCommon($user);
+ if ($result < 0) {
+ $error++;
+ $this->error = $object->error;
+ $this->errors = $object->errors;
+ }
+
+ if (!$error) {
+ // copy internal contacts
+ if ($this->copy_linked_contact($object, 'internal') < 0) {
+ $error++;
+ }
+ }
+
+ if (!$error) {
+ // copy external contacts if same company
+ if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
+ if ($this->copy_linked_contact($object, 'external') < 0) {
+ $error++;
+ }
+ }
+ }
+
+ unset($object->context['createfromclone']);
+
+ // End
+ if (!$error) {
+ $this->db->commit();
+ return $object;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+ /**
+ * Load object in memory from the database
+ *
+ * @param int $id Id object
+ * @param string $ref Ref
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetch($id, $ref = null)
+ {
+ $result = $this->fetchCommon($id, $ref);
+ if ($result > 0 && !empty($this->table_element_line)) {
+ $this->fetchLines();
+ }
+ return $result;
+ }
+
+ /**
+ * Load object lines in memory from the database
+ *
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetchLines()
+ {
+ $this->lines = array();
+
+ $result = $this->fetchLinesCommon();
+ return $result;
+ }
+
+
+ /**
+ * Load list of objects in memory from the database.
+ *
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit limit
+ * @param int $offset Offset
+ * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
+ */
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ {
+ global $conf;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $records = array();
+
+ $sql = 'SELECT ';
+ $sql .= $this->getFieldList('t');
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
+ $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
+ } else {
+ $sql .= ' WHERE 1 = 1';
+ }
+ // Manage filter
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sqlwhere[] = $key.'='.$value;
+ } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
+ $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
+ } elseif ($key == 'customsql') {
+ $sqlwhere[] = $value;
+ } elseif (strpos($value, '%') === false) {
+ $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
+ } else {
+ $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
+ }
+ }
+ }
+ if (count($sqlwhere) > 0) {
+ $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
+ }
+
+ if (!empty($sortfield)) {
+ $sql .= $this->db->order($sortfield, $sortorder);
+ }
+ if (!empty($limit)) {
+ $sql .= ' '.$this->db->plimit($limit, $offset);
+ }
+
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < ($limit ? min($limit, $num) : $num)) {
+ $obj = $this->db->fetch_object($resql);
+
+ $record = new self($this->db);
+ $record->setVarsFromFetchObj($obj);
+
+ $records[$record->id] = $record;
+
+ $i++;
+ }
+ $this->db->free($resql);
+
+ return $records;
+ } else {
+ $this->errors[] = 'Error '.$this->db->lasterror();
+ dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
+
+ return -1;
+ }
+ }
+
+ /**
+ * Update object into database
+ *
+ * @param User $user User that modifies
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function update(User $user, $notrigger = false)
+ {
+ return $this->updateCommon($user, $notrigger);
+ }
+
+ /**
+ * Delete object in database
+ *
+ * @param User $user User that deletes
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function delete(User $user, $notrigger = false)
+ {
+ return $this->deleteCommon($user, $notrigger);
+ //return $this->deleteCommon($user, $notrigger, 1);
+ }
+
+ /**
+ * Delete a line of object in database
+ *
+ * @param User $user User that delete
+ * @param int $idline Id of line to delete
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int >0 if OK, <0 if KO
+ */
+ public function deleteLine(User $user, $idline, $notrigger = false)
+ {
+ if ($this->status < 0) {
+ $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
+ return -2;
+ }
+
+ return $this->deleteLineCommon($user, $idline, $notrigger);
+ }
+
+
+ /**
+ * Validate object
+ *
+ * @param User $user User making status change
+ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
+ * @return int <=0 if OK, 0=Nothing done, >0 if KO
+ */
+ public function validate($user, $notrigger = 0)
+ {
+ global $conf, $langs;
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ $error = 0;
+
+ // Protection
+ if ($this->status == self::STATUS_VALIDATED) {
+ dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->skilldet->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->skilldet->skilldet_advance->validate))))
+ {
+ $this->error='NotEnoughPermissions';
+ dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
+ return -1;
+ }*/
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // Define new ref
+ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
+ $num = $this->getNextNumRef();
+ } else {
+ $num = $this->ref;
+ }
+ $this->newref = $num;
+
+ if (!empty($num)) {
+ // Validate
+ $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
+ $sql .= " SET ref = '".$this->db->escape($num)."',";
+ $sql .= " status = ".self::STATUS_VALIDATED;
+ if (!empty($this->fields['date_validation'])) {
+ $sql .= ", date_validation = '".$this->db->idate($now)."'";
+ }
+ if (!empty($this->fields['fk_user_valid'])) {
+ $sql .= ", fk_user_valid = ".((int) $user->id);
+ }
+ $sql .= " WHERE rowid = ".((int) $this->id);
+
+ dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ dol_print_error($this->db);
+ $this->error = $this->db->lasterror();
+ $error++;
+ }
+
+ if (!$error && !$notrigger) {
+ // Call trigger
+ $result = $this->call_trigger('SKILLDET_VALIDATE', $user);
+ if ($result < 0) {
+ $error++;
+ }
+ // End call triggers
+ }
+ }
+
+ if (!$error) {
+ $this->oldref = $this->ref;
+
+ // Rename directory if dir was a temporary ref
+ if (preg_match('/^[\(]?PROV/i', $this->ref)) {
+ // Now we rename also files into index
+ $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'skilldet/".$this->db->escape($this->newref)."'";
+ $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skilldet/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $error++; $this->error = $this->db->lasterror();
+ }
+
+ // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
+ $oldref = dol_sanitizeFileName($this->ref);
+ $newref = dol_sanitizeFileName($num);
+ $dirsource = $conf->hrm->dir_output.'/skilldet/'.$oldref;
+ $dirdest = $conf->hrm->dir_output.'/skilldet/'.$newref;
+ if (!$error && file_exists($dirsource)) {
+ dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
+
+ if (@rename($dirsource, $dirdest)) {
+ dol_syslog("Rename ok");
+ // Rename docs starting with $oldref with $newref
+ $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skilldet/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
+ foreach ($listoffiles as $fileentry) {
+ $dirsource = $fileentry['name'];
+ $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
+ $dirsource = $fileentry['path'].'/'.$dirsource;
+ $dirdest = $fileentry['path'].'/'.$dirdest;
+ @rename($dirsource, $dirdest);
+ }
+ }
+ }
+ }
+ }
+
+ // Set new ref and current status
+ if (!$error) {
+ $this->ref = $num;
+ $this->status = self::STATUS_VALIDATED;
+ }
+
+ if (!$error) {
+ $this->db->commit();
+ return 1;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+
+ /**
+ * Set draft status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function setDraft($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status <= self::STATUS_DRAFT) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILLDET_UNVALIDATE');
+ }
+
+ /**
+ * Set cancel status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function cancel($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_VALIDATED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILLDET_CANCEL');
+ }
+
+ /**
+ * Set back to validated status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function reopen($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_CANCELED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLDET_REOPEN');
+ }
+
+ /**
+ * Return a link to the object card (with optionaly the picto)
+ *
+ * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
+ * @param string $option On what the link point to ('nolink', ...)
+ * @param int $notooltip 1=Disable tooltip
+ * @param string $morecss Add more css on link
+ * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
+ * @return string String with URL
+ */
+ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
+ {
+ global $conf, $langs, $hookmanager;
+
+ if (!empty($conf->dol_no_mouse_hover)) {
+ $notooltip = 1; // Force disable tooltips
+ }
+
+ $result = '';
+
+ $label = img_picto('', $this->picto).' '.$langs->trans("Skilldet").' ';
+ if (isset($this->status)) {
+ $label .= ' '.$this->getLibStatut(5);
+ }
+ $label .= ' ';
+ $label .= ''.$langs->trans('Ref').': '.$this->ref;
+
+ $url = dol_buildpath('/hrm/skilldet_card.php', 1).'?id='.$this->id;
+
+ if ($option != 'nolink') {
+ // Add param to save lastsearch_values or not
+ $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
+ }
+
+ $linkclose = '';
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
+ $label = $langs->trans("ShowSkilldet");
+ $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
+ }
+ $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
+ $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
+ } else {
+ $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
+ }
+
+ if ($option == 'nolink') {
+ $linkstart = '';
+ if ($option == 'nolink') {
+ $linkend = ' ';
+ } else {
+ $linkend = '';
+ }
+
+ $result .= $linkstart;
+
+ if (empty($this->showphoto_on_popup)) {
+ if ($withpicto) {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ } else {
+ if ($withpicto) {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ list($class, $module) = explode('@', $this->picto);
+ $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
+ $filearray = dol_dir_list($upload_dir, "files");
+ $filename = $filearray[0]['name'];
+ if (!empty($filename)) {
+ $pospoint = strpos($filearray[0]['name'], '.');
+
+ $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
+ if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
+ $result .= '';
+ } else {
+ $result .= ' ';
+ }
+
+ $result .= '';
+ } else {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ }
+ }
+
+ if ($withpicto != 2) {
+ $result .= $this->ref;
+ }
+
+ $result .= $linkend;
+ //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
+
+ global $action, $hookmanager;
+ $hookmanager->initHooks(array('skilldetdao'));
+ $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
+ $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ if ($reshook > 0) {
+ $result = $hookmanager->resPrint;
+ } else {
+ $result .= $hookmanager->resPrint;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Return the label of the status
+ *
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function getLibStatut($mode = 0)
+ {
+ return $this->LibStatut($this->status, $mode);
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Return the status
+ *
+ * @param int $status Id status
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function LibStatut($status, $mode = 0)
+ {
+ // phpcs:enable
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
+ global $langs;
+ //$langs->load("hrm");
+ $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ }
+
+ $statusType = 'status'.$status;
+ //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
+ if ($status == self::STATUS_CANCELED) {
+ $statusType = 'status6';
+ }
+
+ return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
+ }
+
+ /**
+ * Load the info information in the object
+ *
+ * @param int $id Id of object
+ * @return void
+ */
+ public function info($id)
+ {
+ $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
+ $sql .= ' fk_user_creat, fk_user_modif';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ $sql .= ' WHERE t.rowid = '.((int) $id);
+ $result = $this->db->query($sql);
+ if ($result) {
+ if ($this->db->num_rows($result)) {
+ $obj = $this->db->fetch_object($result);
+ $this->id = $obj->rowid;
+ if ($obj->fk_user_author) {
+ $cuser = new User($this->db);
+ $cuser->fetch($obj->fk_user_author);
+ $this->user_creation = $cuser;
+ }
+
+ if ($obj->fk_user_valid) {
+ $vuser = new User($this->db);
+ $vuser->fetch($obj->fk_user_valid);
+ $this->user_validation = $vuser;
+ }
+
+ if ($obj->fk_user_cloture) {
+ $cluser = new User($this->db);
+ $cluser->fetch($obj->fk_user_cloture);
+ $this->user_cloture = $cluser;
+ }
+
+ $this->date_creation = $this->db->jdate($obj->datec);
+ $this->date_modification = $this->db->jdate($obj->datem);
+ $this->date_validation = $this->db->jdate($obj->datev);
+ }
+
+ $this->db->free($result);
+ } else {
+ dol_print_error($this->db);
+ }
+ }
+
+ /**
+ * Initialise object with example values
+ * Id must be 0 if object instance is a specimen
+ *
+ * @return void
+ */
+ public function initAsSpecimen()
+ {
+ // Set here init that are not commonf fields
+ // $this->property1 = ...
+ // $this->property2 = ...
+
+ $this->initAsSpecimenCommon();
+ }
+
+ /**
+ * Create an array of lines
+ *
+ * @return array|int array of lines if OK, <0 if KO
+ */
+ public function getLinesArray()
+ {
+ $this->lines = array();
+
+ $objectline = new SkilldetLine($this->db);
+ $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_skilldet = '.$this->id));
+
+ if (is_numeric($result)) {
+ $this->error = $this->error;
+ $this->errors = $this->errors;
+ return $result;
+ } else {
+ $this->lines = $result;
+ return $this->lines;
+ }
+ }
+
+ /**
+ * Returns the reference to the following non used object depending on the active numbering module.
+ *
+ * @return string Object free reference
+ */
+ public function getNextNumRef()
+ {
+ global $langs, $conf;
+ $langs->load("hrm");
+
+ if (empty($conf->global->hrm_SKILLDET_ADDON)) {
+ $conf->global->hrm_SKILLDET_ADDON = 'mod_skilldet_standard';
+ }
+
+ if (!empty($conf->global->hrm_SKILLDET_ADDON)) {
+ $mybool = false;
+
+ $file = $conf->global->hrm_SKILLDET_ADDON.".php";
+ $classname = $conf->global->hrm_SKILLDET_ADDON;
+
+ // Include file with class
+ $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+ foreach ($dirmodels as $reldir) {
+ $dir = dol_buildpath($reldir."core/modules/hrm/");
+
+ // Load file with numbering class (if found)
+ $mybool |= @include_once $dir.$file;
+ }
+
+ if ($mybool === false) {
+ dol_print_error('', "Failed to include file ".$file);
+ return '';
+ }
+
+ if (class_exists($classname)) {
+ $obj = new $classname();
+ $numref = $obj->getNextValue($this);
+
+ if ($numref != '' && $numref != '-1') {
+ return $numref;
+ } else {
+ $this->error = $obj->error;
+ //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
+ return "";
+ }
+ } else {
+ print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
+ return "";
+ }
+ } else {
+ print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
+ return "";
+ }
+ }
+
+ /**
+ * Create a document onto disk according to template module.
+ *
+ * @param string $modele Force template to use ('' to not force)
+ * @param Translate $outputlangs objet lang a utiliser pour traduction
+ * @param int $hidedetails Hide details of lines
+ * @param int $hidedesc Hide description
+ * @param int $hideref Hide ref
+ * @param null|array $moreparams Array to provide more information
+ * @return int 0 if KO, 1 if OK
+ */
+ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
+ {
+ global $conf, $langs;
+
+ $result = 0;
+ $includedocgeneration = 0;
+
+ $langs->load("hrm");
+
+ if (!dol_strlen($modele)) {
+ $modele = 'standard_skilldet';
+
+ if (!empty($this->model_pdf)) {
+ $modele = $this->model_pdf;
+ } elseif (!empty($conf->global->SKILLDET_ADDON_PDF)) {
+ $modele = $conf->global->SKILLDET_ADDON_PDF;
+ }
+ }
+
+ $modelpath = "core/modules/hrm/doc/";
+
+ if ($includedocgeneration && !empty($modele)) {
+ $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Action executed by scheduler
+ * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
+ * Use public function doScheduledJob($param1, $param2, ...) to get parameters
+ *
+ * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
+ */
+ public function doScheduledJob()
+ {
+ global $conf, $langs;
+
+ //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
+
+ $error = 0;
+ $this->output = '';
+ $this->error = '';
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // ...
+
+ $this->db->commit();
+
+ return $error;
+ }
+}
diff --git a/htdocs/hrm/class/skillrank.class.php b/htdocs/hrm/class/skillrank.class.php
new file mode 100644
index 00000000000..97fcd7edab4
--- /dev/null
+++ b/htdocs/hrm/class/skillrank.class.php
@@ -0,0 +1,1086 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 class/skillrank.class.php
+ * \ingroup hrm
+ * \brief This file is a CRUD class file for SkillRank (Create/Read/Update/Delete)
+ */
+
+// Put here all includes required by your class file
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_skillrank.lib.php';
+
+/**
+ * Class for SkillRank
+ */
+class SkillRank extends CommonObject
+{
+ /**
+ * @var string ID of module.
+ */
+ public $module = 'hrm';
+
+ /**
+ * @var string ID to identify managed object.
+ */
+ public $element = 'skillrank';
+
+ /**
+ * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
+ */
+ public $table_element = 'hrm_skillrank';
+
+ /**
+ * @var int Does this object support multicompany module ?
+ * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
+ */
+ public $ismultientitymanaged = 0;
+
+ /**
+ * @var int Does object support extrafields ? 0=No, 1=Yes
+ */
+ public $isextrafieldmanaged = 0;
+
+ /**
+ * @var string String with name of icon for skillrank. Must be the part after the 'object_' into object_skillrank.png
+ */
+ public $picto = 'skillrank@hrm';
+
+
+ const STATUS_DRAFT = 0;
+ const STATUS_VALIDATED = 1;
+ const STATUS_CANCELED = 9;
+
+ const SKILLRANK_TYPE_JOB = "job";
+ const SKILLRANK_TYPE_USER = "user";
+ const SKILLRANK_TYPE_EVALDET = "evaluationdet";
+
+ /**
+ * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
+ * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
+ * 'label' the translation key.
+ * 'picto' is code of a picto to show before value in forms
+ * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
+ * 'position' is the sort order of field.
+ * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
+ * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
+ * 'noteditable' says if field is not editable (1 or 0)
+ * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
+ * 'index' if we want an index in database.
+ * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
+ * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
+ * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
+ * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
+ * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
+ * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
+ * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
+ * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
+ * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
+ * 'comment' is not used. You can store here any text of your choice. It is not used by application.
+ *
+ * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
+ */
+
+ // BEGIN MODULEBUILDER PROPERTIES
+ /**
+ * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
+ */
+ public $fields=array(
+ 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
+ 'fk_skill' => array('type'=>'integer:Skill:hrm/class/skill.class.php:1', 'label'=>'Skill', 'enabled'=>'1', 'position'=>3, 'notnull'=>1, 'visible'=>1, 'index'=>1,),
+ 'rank' => array('type'=>'integer', 'label'=>'Rank', 'enabled'=>'1', 'position'=>4, 'notnull'=>1, 'visible'=>1, 'default' => 0),
+ 'fk_object' => array('type'=>'integer', 'label'=>'object', 'enabled'=>'1', 'position'=>5, 'notnull'=>1, 'visible'=>0,),
+ 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
+ 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
+ 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
+ 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
+ 'objecttype' => array('type'=>'varchar(128)', 'label'=>'objecttype', 'enabled'=>'1', 'position'=>6, 'notnull'=>1, 'visible'=>0,),
+ );
+ public $rowid;
+ public $fk_skill;
+ public $rank;
+ public $fk_object;
+ public $date_creation;
+ public $tms;
+ public $fk_user_creat;
+ public $fk_user_modif;
+ public $objecttype;
+ // END MODULEBUILDER PROPERTIES
+
+
+ // If this object has a subtable with lines
+
+ // /**
+ // * @var string Name of subtable line
+ // */
+ // public $table_element_line = 'hrm_skillrankline';
+
+ // /**
+ // * @var string Field with ID of parent key if this object has a parent
+ // */
+ // public $fk_element = 'fk_skillrank';
+
+ // /**
+ // * @var string Name of subtable class that manage subtable lines
+ // */
+ // public $class_element_line = 'SkillRankline';
+
+ // /**
+ // * @var array List of child tables. To test if we can delete object.
+ // */
+ // protected $childtables = array();
+
+ // /**
+ // * @var array List of child tables. To know object to delete on cascade.
+ // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
+ // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
+ // */
+ // protected $childtablesoncascade = array('hrm_skillrankdet');
+
+ // /**
+ // * @var SkillRankLine[] Array of subtable lines
+ // */
+ // public $lines = array();
+
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDb $db Database handler
+ */
+ public function __construct(DoliDB $db)
+ {
+ global $conf, $langs;
+
+ $this->db = $db;
+
+ if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
+ $this->fields['rowid']['visible'] = 0;
+ }
+ if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
+ $this->fields['entity']['enabled'] = 0;
+ }
+
+ // Example to show how to set values of fields definition dynamically
+ /*if ($user->rights->hrm->skillrank->read) {
+ $this->fields['myfield']['visible'] = 1;
+ $this->fields['myfield']['noteditable'] = 0;
+ }*/
+
+ // Unset fields that are disabled
+ foreach ($this->fields as $key => $val) {
+ if (isset($val['enabled']) && empty($val['enabled'])) {
+ unset($this->fields[$key]);
+ }
+ }
+
+ // Translate some data of arrayofkeyval
+ if (is_object($langs)) {
+ foreach ($this->fields as $key => $val) {
+ if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
+ foreach ($val['arrayofkeyval'] as $key2 => $val2) {
+ $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Create object into database
+ *
+ * @param User $user User that creates
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, Id of created object if OK
+ */
+ public function create(User $user, $notrigger = false)
+ {
+ global $langs;
+
+ $sqlfilter = 'fk_object='.((int) $this->fk_object)." AND objecttype='".$this->db->escape($this->objecttype)."' AND fk_skill = ".((int) $this->fk_skill);
+ $alreadyLinked = $this->fetchAll('ASC', 'rowid', 0, 0, array('customsql' => $sqlfilter));
+ if (!empty($alreadyLinked)) {
+ $this->error = $langs->trans('ErrSkillAlreadyAdded');
+ return -1;
+ }
+
+ $resultcreate = $this->createCommon($user, $notrigger);
+
+ return $resultcreate;
+ }
+
+ /**
+ * Clone an object into another one
+ *
+ * @param User $user User that creates
+ * @param int $fromid Id of object to clone
+ * @return mixed New object created, <0 if KO
+ */
+ public function createFromClone(User $user, $fromid)
+ {
+ global $langs, $extrafields;
+ $error = 0;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $object = new self($this->db);
+
+ $this->db->begin();
+
+ // Load source object
+ $result = $object->fetchCommon($fromid);
+ if ($result > 0 && !empty($object->table_element_line)) {
+ $object->fetchLines();
+ }
+
+ // get lines so they will be clone
+ //foreach($this->lines as $line)
+ // $line->fetch_optionals();
+
+ // Reset some properties
+ unset($object->id);
+ unset($object->fk_user_creat);
+ unset($object->import_key);
+
+ // Clear fields
+ if (property_exists($object, 'ref')) {
+ $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
+ }
+ if (property_exists($object, 'label')) {
+ $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
+ }
+ if (property_exists($object, 'status')) {
+ $object->status = self::STATUS_DRAFT;
+ }
+ if (property_exists($object, 'date_creation')) {
+ $object->date_creation = dol_now();
+ }
+ if (property_exists($object, 'date_modification')) {
+ $object->date_modification = null;
+ }
+ // ...
+ // Clear extrafields that are unique
+ if (is_array($object->array_options) && count($object->array_options) > 0) {
+ $extrafields->fetch_name_optionals_label($this->table_element);
+ foreach ($object->array_options as $key => $option) {
+ $shortkey = preg_replace('/options_/', '', $key);
+ if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
+ //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
+ unset($object->array_options[$key]);
+ }
+ }
+ }
+
+ // Create clone
+ $object->context['createfromclone'] = 'createfromclone';
+ $result = $object->createCommon($user);
+ if ($result < 0) {
+ $error++;
+ $this->error = $object->error;
+ $this->errors = $object->errors;
+ }
+
+ if (!$error) {
+ // copy internal contacts
+ if ($this->copy_linked_contact($object, 'internal') < 0) {
+ $error++;
+ }
+ }
+
+ if (!$error) {
+ // copy external contacts if same company
+ if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
+ if ($this->copy_linked_contact($object, 'external') < 0) {
+ $error++;
+ }
+ }
+ }
+
+ unset($object->context['createfromclone']);
+
+ // End
+ if (!$error) {
+ $this->db->commit();
+ return $object;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+ /**
+ * Load object in memory from the database
+ *
+ * @param int $id Id object
+ * @param string $ref Ref
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetch($id, $ref = null)
+ {
+ $result = $this->fetchCommon($id, $ref);
+ if ($result > 0 && !empty($this->table_element_line)) {
+ $this->fetchLines();
+ }
+ return $result;
+ }
+
+ /**
+ * Load object lines in memory from the database
+ *
+ * @return int <0 if KO, 0 if not found, >0 if OK
+ */
+ public function fetchLines()
+ {
+ $this->lines = array();
+
+ $result = $this->fetchLinesCommon();
+ return $result;
+ }
+
+ /**
+ * Clone skillrank Object linked to job with user id
+ * The skillrank table is a join table that is marked for multiple objects
+ *
+ * @param SkillRank $currentSkill line of evaluation (skill) we need to clone and add to user skills list
+ * @param int $fk_user id of user linked to skillrank
+ * @return int > 0 if ok, < 0 if ko
+ */
+ public function cloneFromCurrentSkill($currentSkill, $fk_user)
+ {
+
+ global $user;
+
+ $this->fk_skill = $currentSkill->fk_skill;
+ $this->rank = $currentSkill->rank;
+ $this->fk_object = $fk_user;
+ $this->date_creation = dol_now();
+ $this->fk_user_creat = $user->id;
+ $this->fk_user_modif = $user->id;
+ $this->objecttype = self::SKILLRANK_TYPE_USER;
+ $result = $this->create($user);
+
+ return $result;
+ }
+
+ /**
+ * Load list of objects in memory from the database.
+ *
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit limit
+ * @param int $offset Offset
+ * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
+ */
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ {
+ global $conf;
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $records = array();
+
+ $sql = 'SELECT ';
+ $sql .= $this->getFieldList('t');
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
+ $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
+ } else {
+ $sql .= ' WHERE 1 = 1';
+ }
+ // Manage filter
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sqlwhere[] = $key.'='.$value;
+ } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
+ $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
+ } elseif ($key == 'customsql') {
+ $sqlwhere[] = $value;
+ } elseif (strpos($value, '%') === false) {
+ $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
+ } else {
+ $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
+ }
+ }
+ }
+ if (count($sqlwhere) > 0) {
+ $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
+ }
+
+ if (!empty($sortfield)) {
+ $sql .= $this->db->order($sortfield, $sortorder);
+ }
+ if (!empty($limit)) {
+ $sql .= ' '.$this->db->plimit($limit, $offset);
+ }
+
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < ($limit ? min($limit, $num) : $num)) {
+ $obj = $this->db->fetch_object($resql);
+
+ $record = new self($this->db);
+ $record->setVarsFromFetchObj($obj);
+
+ $records[$record->id] = $record;
+
+ $i++;
+ }
+ $this->db->free($resql);
+
+ return $records;
+ } else {
+ $this->errors[] = 'Error '.$this->db->lasterror();
+ dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
+
+ return -1;
+ }
+ }
+
+ /**
+ * Update object into database
+ *
+ * @param User $user User that modifies
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function update(User $user, $notrigger = false)
+ {
+ return $this->updateCommon($user, $notrigger);
+ }
+
+ /**
+ * Delete object in database
+ *
+ * @param User $user User that deletes
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function delete(User $user, $notrigger = false)
+ {
+ return $this->deleteCommon($user, $notrigger);
+ //return $this->deleteCommon($user, $notrigger, 1);
+ }
+
+ /**
+ * Delete a line of object in database
+ *
+ * @param User $user User that delete
+ * @param int $idline Id of line to delete
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int >0 if OK, <0 if KO
+ */
+ public function deleteLine(User $user, $idline, $notrigger = false)
+ {
+ if ($this->status < 0) {
+ $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
+ return -2;
+ }
+
+ return $this->deleteLineCommon($user, $idline, $notrigger);
+ }
+
+
+ /**
+ * Validate object
+ *
+ * @param User $user User making status change
+ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
+ * @return int <=0 if OK, 0=Nothing done, >0 if KO
+ */
+ public function validate($user, $notrigger = 0)
+ {
+ global $conf, $langs;
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ $error = 0;
+
+ // Protection
+ if ($this->status == self::STATUS_VALIDATED) {
+ dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->skillrank->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->skillrank->skillrank_advance->validate))))
+ {
+ $this->error='NotEnoughPermissions';
+ dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
+ return -1;
+ }*/
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // Define new ref
+ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
+ $num = $this->getNextNumRef();
+ } else {
+ $num = $this->ref;
+ }
+ $this->newref = $num;
+
+ if (!empty($num)) {
+ // Validate
+ $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
+ $sql .= " SET ref = '".$this->db->escape($num)."',";
+ $sql .= " status = ".self::STATUS_VALIDATED;
+ if (!empty($this->fields['date_validation'])) {
+ $sql .= ", date_validation = '".$this->db->idate($now)."'";
+ }
+ if (!empty($this->fields['fk_user_valid'])) {
+ $sql .= ", fk_user_valid = ".((int) $user->id);
+ }
+ $sql .= " WHERE rowid = ".((int) $this->id);
+
+ dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ dol_print_error($this->db);
+ $this->error = $this->db->lasterror();
+ $error++;
+ }
+
+ if (!$error && !$notrigger) {
+ // Call trigger
+ $result = $this->call_trigger('SKILLRANK_VALIDATE', $user);
+ if ($result < 0) {
+ $error++;
+ }
+ // End call triggers
+ }
+ }
+
+ if (!$error) {
+ $this->oldref = $this->ref;
+
+ // Rename directory if dir was a temporary ref
+ if (preg_match('/^[\(]?PROV/i', $this->ref)) {
+ // Now we rename also files into index
+ $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'skillrank/".$this->db->escape($this->newref)."'";
+ $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $error++; $this->error = $this->db->lasterror();
+ }
+
+ // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
+ $oldref = dol_sanitizeFileName($this->ref);
+ $newref = dol_sanitizeFileName($num);
+ $dirsource = $conf->hrm->dir_output.'/skillrank/'.$oldref;
+ $dirdest = $conf->hrm->dir_output.'/skillrank/'.$newref;
+ if (!$error && file_exists($dirsource)) {
+ dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
+
+ if (@rename($dirsource, $dirdest)) {
+ dol_syslog("Rename ok");
+ // Rename docs starting with $oldref with $newref
+ $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skillrank/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
+ foreach ($listoffiles as $fileentry) {
+ $dirsource = $fileentry['name'];
+ $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
+ $dirsource = $fileentry['path'].'/'.$dirsource;
+ $dirdest = $fileentry['path'].'/'.$dirdest;
+ @rename($dirsource, $dirdest);
+ }
+ }
+ }
+ }
+ }
+
+ // Set new ref and current status
+ if (!$error) {
+ $this->ref = $num;
+ $this->status = self::STATUS_VALIDATED;
+ }
+
+ if (!$error) {
+ $this->db->commit();
+ return 1;
+ } else {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+
+ /**
+ * Set draft status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function setDraft($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status <= self::STATUS_DRAFT) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILLRANK_UNVALIDATE');
+ }
+
+ /**
+ * Set cancel status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function cancel($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_VALIDATED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILLRANK_CANCEL');
+ }
+
+ /**
+ * Set back to validated status
+ *
+ * @param User $user Object user that modify
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
+ */
+ public function reopen($user, $notrigger = 0)
+ {
+ // Protection
+ if ($this->status != self::STATUS_CANCELED) {
+ return 0;
+ }
+
+ /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
+ {
+ $this->error='Permission denied';
+ return -1;
+ }*/
+
+ return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLRANK_REOPEN');
+ }
+
+ /**
+ * Return a link to the object card (with optionaly the picto)
+ *
+ * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
+ * @param string $option On what the link point to ('nolink', ...)
+ * @param int $notooltip 1=Disable tooltip
+ * @param string $morecss Add more css on link
+ * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
+ * @return string String with URL
+ */
+ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
+ {
+ global $conf, $langs, $hookmanager;
+
+ if (!empty($conf->dol_no_mouse_hover)) {
+ $notooltip = 1; // Force disable tooltips
+ }
+
+ $result = '';
+
+ $label = img_picto('', $this->picto).' '.$langs->trans("SkillRank").' ';
+ if (isset($this->status)) {
+ $label .= ' '.$this->getLibStatut(5);
+ }
+ $label .= ' ';
+ $label .= ''.$langs->trans('Ref').': '.$this->ref;
+
+ $url = dol_buildpath('/hrm/skillrank_card.php', 1).'?id='.$this->id;
+
+ if ($option != 'nolink') {
+ // Add param to save lastsearch_values or not
+ $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
+ }
+
+ $linkclose = '';
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
+ $label = $langs->trans("ShowSkillRank");
+ $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
+ }
+ $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
+ $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
+ } else {
+ $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
+ }
+
+ if ($option == 'nolink') {
+ $linkstart = '';
+ if ($option == 'nolink') {
+ $linkend = ' ';
+ } else {
+ $linkend = '';
+ }
+
+ $result .= $linkstart;
+
+ if (empty($this->showphoto_on_popup)) {
+ if ($withpicto) {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ } else {
+ if ($withpicto) {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ list($class, $module) = explode('@', $this->picto);
+ $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
+ $filearray = dol_dir_list($upload_dir, "files");
+ $filename = $filearray[0]['name'];
+ if (!empty($filename)) {
+ $pospoint = strpos($filearray[0]['name'], '.');
+
+ $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
+ if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
+ $result .= '';
+ } else {
+ $result .= ' ';
+ }
+
+ $result .= '';
+ } else {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ }
+ }
+
+ if ($withpicto != 2) {
+ $result .= $this->ref;
+ }
+
+ $result .= $linkend;
+ //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
+
+ global $action, $hookmanager;
+ $hookmanager->initHooks(array('skillrankdao'));
+ $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
+ $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ if ($reshook > 0) {
+ $result = $hookmanager->resPrint;
+ } else {
+ $result .= $hookmanager->resPrint;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Return the label of the status
+ *
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function getLibStatut($mode = 0)
+ {
+ return $this->LibStatut($this->status, $mode);
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Return the status
+ *
+ * @param int $status Id status
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
+ * @return string Label of status
+ */
+ public function LibStatut($status, $mode = 0)
+ {
+ // phpcs:enable
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
+ global $langs;
+ //$langs->load("hrm");
+ $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
+ $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled');
+ $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
+ }
+
+ $statusType = 'status'.$status;
+ //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
+ if ($status == self::STATUS_CANCELED) {
+ $statusType = 'status6';
+ }
+
+ return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
+ }
+
+ /**
+ * Load the info information in the object
+ *
+ * @param int $id Id of object
+ * @return void
+ */
+ public function info($id)
+ {
+ $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
+ $sql .= ' fk_user_creat, fk_user_modif';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ $sql .= ' WHERE t.rowid = '.((int) $id);
+ $result = $this->db->query($sql);
+ if ($result) {
+ if ($this->db->num_rows($result)) {
+ $obj = $this->db->fetch_object($result);
+ $this->id = $obj->rowid;
+ if ($obj->fk_user_author) {
+ $cuser = new User($this->db);
+ $cuser->fetch($obj->fk_user_author);
+ $this->user_creation = $cuser;
+ }
+
+ if ($obj->fk_user_valid) {
+ $vuser = new User($this->db);
+ $vuser->fetch($obj->fk_user_valid);
+ $this->user_validation = $vuser;
+ }
+
+ if ($obj->fk_user_cloture) {
+ $cluser = new User($this->db);
+ $cluser->fetch($obj->fk_user_cloture);
+ $this->user_cloture = $cluser;
+ }
+
+ $this->date_creation = $this->db->jdate($obj->datec);
+ $this->date_modification = $this->db->jdate($obj->datem);
+ $this->date_validation = $this->db->jdate($obj->datev);
+ }
+
+ $this->db->free($result);
+ } else {
+ dol_print_error($this->db);
+ }
+ }
+
+ /**
+ * Initialise object with example values
+ * Id must be 0 if object instance is a specimen
+ *
+ * @return void
+ */
+ public function initAsSpecimen()
+ {
+ // Set here init that are not commonf fields
+ // $this->property1 = ...
+ // $this->property2 = ...
+
+ $this->initAsSpecimenCommon();
+ }
+
+ /**
+ * Create an array of lines
+ *
+ * @return array|int array of lines if OK, <0 if KO
+ */
+ public function getLinesArray()
+ {
+ $this->lines = array();
+
+ $objectline = new SkillRankLine($this->db);
+ $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_skillrank = '.((int) $this->id)));
+
+ if (is_numeric($result)) {
+ $this->error = $this->error;
+ $this->errors = $this->errors;
+ return $result;
+ } else {
+ $this->lines = $result;
+ return $this->lines;
+ }
+ }
+
+ /**
+ * Returns the reference to the following non used object depending on the active numbering module.
+ *
+ * @return string Object free reference
+ */
+ public function getNextNumRef()
+ {
+ global $langs, $conf;
+ $langs->load("hrm");
+
+ if (empty($conf->global->hrm_SKILLRANK_ADDON)) {
+ $conf->global->hrm_SKILLRANK_ADDON = 'mod_skillrank_standard';
+ }
+
+ if (!empty($conf->global->hrm_SKILLRANK_ADDON)) {
+ $mybool = false;
+
+ $file = $conf->global->hrm_SKILLRANK_ADDON.".php";
+ $classname = $conf->global->hrm_SKILLRANK_ADDON;
+
+ // Include file with class
+ $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+ foreach ($dirmodels as $reldir) {
+ $dir = dol_buildpath($reldir."core/modules/hrm/");
+
+ // Load file with numbering class (if found)
+ $mybool |= @include_once $dir.$file;
+ }
+
+ if ($mybool === false) {
+ dol_print_error('', "Failed to include file ".$file);
+ return '';
+ }
+
+ if (class_exists($classname)) {
+ $obj = new $classname();
+ $numref = $obj->getNextValue($this);
+
+ if ($numref != '' && $numref != '-1') {
+ return $numref;
+ } else {
+ $this->error = $obj->error;
+ //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
+ return "";
+ }
+ } else {
+ print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
+ return "";
+ }
+ } else {
+ print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
+ return "";
+ }
+ }
+
+ /**
+ * Create a document onto disk according to template module.
+ *
+ * @param string $modele Force template to use ('' to not force)
+ * @param Translate $outputlangs objet lang a utiliser pour traduction
+ * @param int $hidedetails Hide details of lines
+ * @param int $hidedesc Hide description
+ * @param int $hideref Hide ref
+ * @param null|array $moreparams Array to provide more information
+ * @return int 0 if KO, 1 if OK
+ */
+ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
+ {
+ global $conf, $langs;
+
+ $result = 0;
+ $includedocgeneration = 0;
+
+ $langs->load("hrm");
+
+ if (!dol_strlen($modele)) {
+ $modele = 'standard_skillrank';
+
+ if (!empty($this->model_pdf)) {
+ $modele = $this->model_pdf;
+ } elseif (!empty($conf->global->SKILLRANK_ADDON_PDF)) {
+ $modele = $conf->global->SKILLRANK_ADDON_PDF;
+ }
+ }
+
+ $modelpath = "core/modules/hrm/doc/";
+
+ if ($includedocgeneration && !empty($modele)) {
+ $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Action executed by scheduler
+ * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
+ * Use public function doScheduledJob($param1, $param2, ...) to get parameters
+ *
+ * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
+ */
+ public function doScheduledJob()
+ {
+ global $conf, $langs;
+
+ //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
+
+ $error = 0;
+ $this->output = '';
+ $this->error = '';
+
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $now = dol_now();
+
+ $this->db->begin();
+
+ // ...
+
+ $this->db->commit();
+
+ return $error;
+ }
+
+ /**
+ * @param array $val
+ * @param string $key
+ * @param string $value
+ * @param string $moreparam
+ * @param string $keysuffix
+ * @param string $keyprefix
+ * @param string $morecss
+ * @return string
+ */
+ // public function showOutputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
+ // {
+ // if ($key == "rank") {
+ // return displayRankInfos($this);
+ // } else return parent::showOutputField($val, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
+ // }
+}
diff --git a/htdocs/hrm/compare.php b/htdocs/hrm/compare.php
new file mode 100644
index 00000000000..13b83af9737
--- /dev/null
+++ b/htdocs/hrm/compare.php
@@ -0,0 +1,566 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 class/compare.php
+ * \ingroup hrm
+ * \brief This file compares skills of user groups
+ *
+ * Displays a table in three parts.
+ * 1- the left part displays the list of users of the selected group 1.
+ *
+ * 2- the central part displays the skills. display of the maximum score for this group and the number of occurrences.
+ *
+ * 3- the right part displays the members of group 2 or the job to be compared
+ *
+ *
+ *
+ */
+
+require_once '../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
+
+ini_set('display_errors', 1);
+
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/skill.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/evaluation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/position.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm.lib.php';
+
+$permissiontoread = $user->rights->hrm->compare->read;
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
+
+$langs->load('hrm');
+
+$css = array();
+$css[] = '/hrm/css/style.css';
+llxHeader('', $langs->trans('SkillComparison'), '', '', 0, 0, '', $css);
+
+$head = array();
+
+$h = 0;
+$head[$h][0] = $_SERVER["PHP_SELF"];
+$head[$h][1] = $langs->trans("SkillComparison");
+$head[$h][2] = 'compare';
+
+print dol_get_fiche_head($head, 'compare', '', 1);
+
+//$PDOdb = new TPDOdb;
+$form = new Form($db);
+?>
+
+
+
+
+
+
+
+
+';
+
+ foreach ($TMergedSkills as $id => &$sk) {
+ $class = 'diffnote';
+
+ if (empty($sk->rate2)) $class .= ' toohappy';
+ elseif (empty($sk->rate1)) $class .= ' toosad';
+ elseif ($sk->rate1 == $sk->rate2) $class .= ' happy';
+ elseif ($sk->rate2 < $sk->rate1) $class .= ' veryhappy';
+ elseif ($sk->rate2 > $sk->rate1) $class .= ' sad';
+
+ $out .= '
+
+ ';
+ }
+
+ $out .= '';
+
+ return $out;
+}
+
+/**
+ * Return a html list with rank informations
+ * @param array $TMergedSkills skill list for display
+ * @param string $field which column of comparison we are working with
+ * @return string
+ */
+function rate(&$TMergedSkills, $field)
+{
+ global $langs, $fk_job;
+
+ $out = '';
+
+ return $out;
+}
+
+/**
+ * return a html ul list of skills
+ *
+ * @param array $TMergedSkills skill list for display
+ * @return string (ul list in html )
+ */
+function skillList(&$TMergedSkills)
+{
+
+ $out = '';
+
+ foreach ($TMergedSkills as $id => &$sk) {
+ $out .= '
+ ' . $sk->label . '
+ ' . $sk->description . '
+ ';
+ }
+
+ $out .= ' ';
+
+ return $out;
+}
+
+/**
+ * create an array of lines [ skillLabel,dscription, maxrank on group1 , minrank needed for this skill ]
+ *
+ * @param array $TSkill1 skill list of first column
+ * @param array $TSkill2 skill list of second column
+ * @return array
+ */
+function mergeSkills($TSkill1, $TSkill2)
+{
+
+ $Tab = array();
+
+ foreach ($TSkill1 as &$sk) {
+ if (empty($Tab[$sk->fk_skill])) $Tab[$sk->fk_skill] = new stdClass;
+
+ $Tab[$sk->fk_skill]->rate1 = $sk->rank;
+ $Tab[$sk->fk_skill]->how_many_max1 = $sk->how_many_max;
+ $Tab[$sk->fk_skill]->label = $sk->label;
+ $Tab[$sk->fk_skill]->description = $sk->description;
+ }
+
+ foreach ($TSkill2 as &$sk) {
+ if (empty($Tab[$sk->fk_skill])) $Tab[$sk->fk_skill] = new stdClass;
+ $Tab[$sk->fk_skill]->rate2 = $sk->rank;
+ $Tab[$sk->fk_skill]->label = $sk->label;
+ $Tab[$sk->fk_skill]->description = $sk->description;
+ $Tab[$sk->fk_skill]->how_many_max2 = $sk->how_many_max;
+ }
+
+ return $Tab;
+}
+
+/**
+ * Display a list of User with picto
+ * @param array $TUser list of users (employees) in selected usergroup of a column
+ * @param int $fk_usergroup selected usergroup id
+ * @param string $namelist html name
+ * @return string
+ */
+function displayUsersListWithPicto(&$TUser, $fk_usergroup = 0, $namelist = 'list-user')
+{
+ global $db, $langs, $conf, $form;
+
+ $out = '';
+ if ($fk_usergroup > 0) {
+ $list = $namelist . '_excluded_id';
+
+ $excludedIdsList = GETPOST($list);
+
+
+ $sql = "SELECT DISTINCT u.rowid FROM " . MAIN_DB_PREFIX . "user u
+ LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ugu ON (u.rowid = ugu.fk_user)
+ WHERE u.statut > 0
+ AND ugu.fk_usergroup=" . ((int) $fk_usergroup);
+
+ $res = $db->query($sql);
+ $out .= '';
+
+ $TExcludedId = explode(',', $excludedIdsList);
+
+ $form = new Form($db);
+ $out .= ' ';
+
+ while ($obj = $db->fetch_object($res)) {
+ $class = '';
+
+ $user = new User($db);
+ $user->fetch($obj->rowid);
+
+ $name = $user->getFullName($langs);
+ if (empty($name)) $name = $user->login;
+
+ if (in_array($user->id, $TExcludedId)) {
+ $class .= ' disabled';
+ } else {
+ if (!in_array($user->id, $TUser)) $TUser[] = $user->id;
+ }
+
+
+ $desc = '';
+
+ $job = Job::getLastJobForUser($user->id);
+ $desc .= $job;
+
+ $static_eval = new Evaluation($db);
+ $evaluation = $static_eval->getLastEvaluationForUser($user->id);
+
+ if (!empty($evaluation) && !empty($evaluation->date_eval)) {
+ $desc .= $langs->trans('DateLastEval') . ' : ' . dol_print_date($evaluation->date_eval);
+ } else {
+ $desc .= $langs->trans('NoEval');
+ }
+
+ if (!empty($user->array_options['options_DDA'])) $desc .= ' ' . $langs->trans('Anciennete') . ' : ' . dol_print_date(strtotime($user->array_options['options_DDA']));
+
+ $out .= '
+ ' . $form->showphoto('userphoto', $user, 0, 0, 0, 'photoref', 'small', 1, 0, 1) . '
+ ' . $name . '
+ ' . $desc . '
+ ';
+ }
+
+ $out .= ' ';
+ }
+
+ return $out;
+}
+
+
+/**
+ *
+ * Allow to get skill(s) of a user
+ *
+ * @param array $TUser array of employees we need to get skills
+ * @return array|int
+ */
+function getSkillForUsers($TUser)
+{
+ global $db;
+
+ //I go back to the user with the highest score in a given group for all the skills assessed in that group
+ if (empty($TUser)) return array();
+
+ $sql = 'SELECT sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill, ';
+ $sql.= ' MAX(sr.rank) as "rank"';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'hrm_skill sk';
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'hrm_skillrank sr ON (sk.rowid = sr.fk_skill)';
+ $sql.= " WHERE sr.objecttype = '".SkillRank::SKILLRANK_TYPE_USER."'";
+ $sql.= ' AND sr.fk_object IN ('.$db->sanitize(implode(',', $TUser)).')';
+ $sql.= " GROUP BY sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill "; // group par competence
+
+ $resql = $db->query($sql);
+ $Tab = array();
+
+ if ($resql) {
+ //For each skill, we count the number of times that the max score has been reached within a given group
+ $num = 0;
+ while ($obj = $db->fetch_object($resql) ) {
+ $sql1 = "SELECT count(*) as how_many_max FROM ".MAIN_DB_PREFIX."hrm_skillrank sr";
+ $sql1.=" WHERE sr.rank = ".((int) $obj->rank);
+ $sql1.=" AND sr.objecttype = '".Skillrank::SKILLRANK_TYPE_USER."'";
+ $sql1.=" AND sr.fk_skill = ".((int) $obj->fk_skill);
+ $sql1.=" AND sr.fk_object IN (".$db->sanitize(implode(',', $TUser)).")";
+ $resql1 = $db->query($sql1);
+
+ $objMax = $db->fetch_object($resql1);
+
+ $Tab[$num] = new stdClass();
+ $Tab[$num]->fk_skill = $obj->fk_skill;
+ $Tab[$num]->label = $obj->label;
+ $Tab[$num]->description = $obj->description;
+ $Tab[$num]->skill_type = $obj->skill_type;
+ $Tab[$num]->fk_object = $obj->fk_object;
+ $Tab[$num]->objectType = SkillRank::SKILLRANK_TYPE_USER;
+ $Tab[$num]->rank = $obj->rank;
+ $Tab[$num]->how_many_max = $objMax->how_many_max;
+
+ $num++;
+ }
+ } else {
+ dol_print_error($db);
+ }
+
+ return $Tab;
+}
+
+/**
+ * Allow to get skill(s) of a job
+ *
+ * @param int $fk_job job we need to get required skills
+ * @return array|int
+ */
+function getSkillForJob($fk_job)
+{
+ global $db;
+
+ if (empty($fk_job)) return array();
+
+ $sql = 'SELECT sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill, ';
+ $sql.= ' MAX(sr.rank) as "rank"';
+ $sql.=' FROM '.MAIN_DB_PREFIX.'hrm_skill sk';
+ $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'hrm_skillrank sr ON (sk.rowid = sr.fk_skill)';
+ $sql.=" WHERE sr.objecttype = '".SkillRank::SKILLRANK_TYPE_JOB."'";
+ $sql.=' AND sr.fk_object = '.((int) $fk_job);
+ $sql.=' GROUP BY sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill '; // group par competence*/
+
+ $resql = $db->query($sql);
+ $Tab = array();
+
+
+ if ($resql) {
+ $num = 0;
+ while ($obj = $db->fetch_object($resql) ) {
+ $Tab[$num] = new stdClass();
+ $Tab[$num]->fk_skill = $obj->fk_skill;
+ $Tab[$num]->label = $obj->label;
+ $Tab[$num]->description = $obj->description;
+ $Tab[$num]->skill_type = $obj->skill_type;
+ //$Tab[$num]->date_start = '';// du poste
+ //$Tab[$num]->date_end = ''; // du poste
+ $Tab[$num]->fk_object = $obj->fk_object;
+ $Tab[$num]->objectType = SkillRank::SKILLRANK_TYPE_JOB;
+ $Tab[$num]->rank = $obj->rank;
+ $Tab[$num]->how_many_max = $obj->how_many_max;
+
+ $num++;
+ }
+ } else {
+ dol_print_error($db);
+ }
+
+
+ return $Tab;
+}
diff --git a/htdocs/hrm/core/tpl/objectline_title.tpl.php b/htdocs/hrm/core/tpl/objectline_title.tpl.php
new file mode 100644
index 00000000000..3801288543a
--- /dev/null
+++ b/htdocs/hrm/core/tpl/objectline_title.tpl.php
@@ -0,0 +1,80 @@
+
+ * Copyright (C) 2010-2011 Laurent Destailleur
+ * Copyright (C) 2012-2013 Christophe Battarel
+ * Copyright (C) 2012 Cédric Salvador
+ * Copyright (C) 2012-2014 Raphaël Doursenaud
+ * Copyright (C) 2013 Florian Henry
+ * Copyright (C) 2017 Juanjo Menent
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 .
+ *
+ * Need to have following variables defined:
+ * $object (invoice, order, ...)
+ * $conf
+ * $langs
+ * $element (used to test $user->rights->$element->creer)
+ * $permtoedit (used to replace test $user->rights->$element->creer)
+ * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
+ * $outputalsopricetotalwithtax
+ * $usemargins (0 to disable all margins columns, 1 to show according to margin setup)
+ *
+ * $type, $text, $description, $line
+ */
+
+// Protection to avoid direct call of template
+if (empty($object) || !is_object($object)) {
+ print "Error, template page can't be called as URL";
+ exit;
+}
+
+print "\n";
+
+// Title line
+print "\n";
+
+print '';
+
+// Adds a line numbering column
+if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
+ print ' ';
+}
+
+// Skill type
+print ''.$langs->trans('SkillType').' ';
+
+// Label skill
+print ''.$langs->trans('Label').' ';
+
+// Description
+print ''.$langs->trans('Description').' ';
+
+// Note
+print ''.$langs->trans('EmployeeRank').' ';
+
+
+//print ' '; // No width to allow autodim
+
+//print ' ';
+
+//print ' ';
+
+print " \n";
+print " \n";
+
+print "\n";
diff --git a/htdocs/hrm/core/tpl/objectline_view.tpl.php b/htdocs/hrm/core/tpl/objectline_view.tpl.php
new file mode 100644
index 00000000000..9be74a5f38f
--- /dev/null
+++ b/htdocs/hrm/core/tpl/objectline_view.tpl.php
@@ -0,0 +1,165 @@
+
+ * Copyright (C) 2010-2011 Laurent Destailleur
+ * Copyright (C) 2012-2013 Christophe Battarel
+ * Copyright (C) 2012 Cédric Salvador
+ * Copyright (C) 2012-2014 Raphaël Doursenaud
+ * Copyright (C) 2013 Florian Henry
+ * Copyright (C) 2017 Juanjo Menent
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 .
+ *
+ * Need to have following variables defined:
+ * $object (invoice, order, ...)
+ * $conf
+ * $langs
+ * $dateSelector
+ * $forceall (0 by default, 1 for supplier invoices/orders)
+ * $element (used to test $user->rights->$element->creer)
+ * $permtoedit (used to replace test $user->rights->$element->creer)
+ * $senderissupplier (0 by default, 1 for supplier invoices/orders)
+ * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
+ * $outputalsopricetotalwithtax
+ * $usemargins (0 to disable all margins columns, 1 to show according to margin setup)
+ * $object_rights->creer initialized from = $object->getRights()
+ * $disableedit, $disablemove, $disableremove
+ *
+ * $text, $description, $line
+ */
+
+// Protection to avoid direct call of template
+if (empty($object) || !is_object($object)) {
+ print "Error, template page can't be called as URL";
+ exit;
+}
+
+global $mysoc;
+global $forceall, $senderissupplier, $inputalsopricewithtax, $outputalsopricetotalwithtax;
+
+// add html5 elements
+$domData = ' data-element="'.$line->element.'"';
+$domData .= ' data-id="'.$line->id.'"';
+$domData .= ' data-qty="'.$line->qty.'"';
+$domData .= ' data-product_type="'.$line->product_type.'"';
+
+$sign = 1;
+if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && in_array($object->element, array('facture', 'invoice_supplier')) && $object->type == $object::TYPE_CREDIT_NOTE) {
+ $sign = -1;
+}
+
+$coldisplay = 0;
+?>
+
+ >
+global->MAIN_VIEW_LINE_NUMBER)) { ?>
+
+
+
+fk_skill > 0) {
+ $skill = new Skill($this->db);
+ $resSkill = $skill->fetch($line->fk_skill);
+ if ($resSkill > 0) {
+ print Skill::typeCodeToLabel($skill->skill_type).' ';
+ print ''.$skill->getNomUrl(1);
+ }
+}
+?>
+
+
+
+fk_skill > 0 && $resSkill > 0) {
+ print $skill->description;
+}
+
+print ' ';
+
+?>
+
+
+rank, $line->fk_skill, 'TNote', ($this->status == 0 && $permissiontoadd) ? 'edit' : 'view');
+
+?>
+
+
+
+statut == 0 && !empty($object_rights->creer) && $action != 'selectlines') {
+ $situationinvoicelinewithparent = 0;
+ if ($line->fk_prev_id != null && in_array($object->element, array('facture', 'facturedet'))) {
+ if ($object->type == $object::TYPE_SITUATION) { // The constant TYPE_SITUATION exists only for object invoice
+ // Set constant to disallow editing during a situation cycle
+ $situationinvoicelinewithparent = 1;
+ }
+ }
+
+ print '';
+ $coldisplay++;
+ if (($line->info_bits & 2) == 2 || !empty($disableedit)) {
+ } else { ?>
+ id.'&action=editline&lineid='.$line->id.'#line_'.$line->id; ?>">
+ ';
+ }
+ print ' ';
+
+ /*print '';
+ $coldisplay++;
+ if (!$situationinvoicelinewithparent && empty($disableremove)) { // For situation invoice, deletion is not possible if there is a parent company.
+ print 'id.'&action=ask_deleteline&lineid='.$line->id.'">';
+ print img_delete();
+ print ' ';
+ }
+ print ' ';
+
+ if ($num > 1 && $conf->browser->layout != 'phone' && ($this->situation_counter == 1 || !$this->situation_cycle_ref) && empty($disablemove)) {
+ print '';
+ $coldisplay++;
+ if ($i > 0) { ?>
+ id.'&action=up&rowid='.$line->id; ?>">
+
+
+
+ id.'&action=down&rowid='.$line->id; ?>">
+
+
+ ';
+ } else {
+ print ' browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'> ';
+ $coldisplay++;
+ }*/
+} else {
+ //print ' ';
+ $coldisplay = $coldisplay + 3;
+}
+
+if ($action == 'selectlines') { ?>
+
+\n";
+
+print "\n";
diff --git a/htdocs/hrm/core/tpl/skilldet.fiche.tpl.php b/htdocs/hrm/core/tpl/skilldet.fiche.tpl.php
new file mode 100644
index 00000000000..60bb56ff173
--- /dev/null
+++ b/htdocs/hrm/core/tpl/skilldet.fiche.tpl.php
@@ -0,0 +1,113 @@
+rights->module->create
+// $cssclass must be defined by caller. For example $cssclass='fieldtitle'
+$module = $object->element;
+$note_public = 'note_public';
+$note_private = 'note_private';
+
+$colwidth = (isset($colwidth) ? $colwidth : (empty($cssclass) ? '25' : ''));
+// Set $permission from the $permissionnote var defined on calling page
+$permission = (isset($permissionnote) ? $permissionnote : (isset($permission) ? $permission : (isset($user->rights->$module->create) ? $user->rights->$module->create : (isset($user->rights->$module->creer) ? $user->rights->$module->creer : 0))));
+$moreparam = (isset($moreparam) ? $moreparam : '');
+$value_public = $object->note_public;
+$value_private = $object->note_private;
+if (!empty($conf->global->MAIN_AUTO_TIMESTAMP_IN_PUBLIC_NOTES)) {
+$stringtoadd = dol_print_date(dol_now(), 'dayhour').' '.$user->getFullName($langs).' --';
+if (GETPOST('action', 'aZ09') == 'edit'.$note_public) {
+$value_public = dol_concatdesc($value_public, ($value_public ? "\n" : "")."-- ".$stringtoadd);
+if (dol_textishtml($value_public)) {
+$value_public .= " \n";
+} else {
+$value_public .= "\n";
+}
+}
+}
+if (!empty($conf->global->MAIN_AUTO_TIMESTAMP_IN_PRIVATE_NOTES)) {
+$stringtoadd = dol_print_date(dol_now(), 'dayhour').' '.$user->getFullName($langs).' --';
+if (GETPOST('action', 'aZ09') == 'edit'.$note_private) {
+$value_private = dol_concatdesc($value_private, ($value_private ? "\n" : "")."-- ".$stringtoadd);
+if (dol_textishtml($value_private)) {
+$value_private .= " \n";
+} else {
+$value_private .= "\n";
+}
+}
+}*/
+/*
+// Special cases
+if ($module == 'propal') {
+$permission = $user->rights->propale->creer;
+} elseif ($module == 'supplier_proposal') {
+$permission = $user->rights->supplier_proposal->creer;
+} elseif ($module == 'fichinter') {
+$permission = $user->rights->ficheinter->creer;
+} elseif ($module == 'project') {
+$permission = $user->rights->projet->creer;
+} elseif ($module == 'project_task') {
+$permission = $user->rights->projet->creer;
+} elseif ($module == 'invoice_supplier') {
+if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
+$permission = $user->rights->fournisseur->facture->creer;
+} else {
+$permission = $user->rights->supplier_invoice->creer;
+}
+} elseif ($module == 'order_supplier') {
+if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
+$permission = $user->rights->fournisseur->commande->creer;
+} else {
+$permission = $user->rights->supplier_order->creer;
+}
+} elseif ($module == 'societe') {
+$permission = $user->rights->societe->creer;
+} elseif ($module == 'contact') {
+$permission = $user->rights->societe->creer;
+} elseif ($module == 'shipping') {
+$permission = $user->rights->expedition->creer;
+} elseif ($module == 'product') {
+$permission = $user->rights->produit->creer;
+} elseif ($module == 'ecmfiles') {
+$permission = $user->rights->ecm->setup;
+}*/
+//else dol_print_error('','Bad value '.$module.' for param module');
+
+if (!empty($object->table_element_line)) {
+ // Show object lines
+ $result = $object->getLinesArray();
+}
+
+
+
+print ''."\n";
+
+print ''."\n";
+ print '
'."\n";
+ $editmode = (GETPOST('action', 'aZ09') == 'edit'.$note_public);
+ print '
'."\n";
+ print $form->editfieldkey("NotePublic", $note_public, $value_public, $object, $permission, $typeofdata, $moreparam, '', 0);
+ print '
'."\n";
+ print '
'."\n";
+ print $form->editfieldval("NotePublic", $note_public, $value_public, $object, $permission, $typeofdata, '', null, null, $moreparam, 1)."\n";
+ print '
'."\n";
+ print '
'."\n";
+if (empty($user->socid)) {
+ // Private notes (always hidden to external users)
+ print '
'."\n";
+ $editmode = (GETPOST('action', 'aZ09') == 'edit'.$note_private);
+ print '
'."\n";
+ print $form->editfieldkey("NotePrivate", $note_private, $value_private, $object, $permission, $typeofdata, $moreparam, '', 0);
+ print '
'."\n";
+ print '
'."\n";
+ print $form->editfieldval("NotePrivate", $note_private, $value_private, $object, $permission, $typeofdata, '', null, null, $moreparam, 1);
+ print '
'."\n";
+ print '
'."\n";
+}
+print '
'."\n";
+?>
+
diff --git a/htdocs/hrm/css/radio_js_number.css b/htdocs/hrm/css/radio_js_number.css
new file mode 100644
index 00000000000..320b0ddc1f2
--- /dev/null
+++ b/htdocs/hrm/css/radio_js_number.css
@@ -0,0 +1,18 @@
+.radio_js_bloc_number {
+ display:inline-block;
+ padding:5px 7px;
+ min-width:20px;
+ border-radius:3px;
+ border:1px solid #ccc;
+ background:#eee;
+ color:#555;
+ cursor:pointer;
+ margin:2px;
+ text-align:center;
+}
+.radio_js_bloc_number.selected {
+ transition:0.2s ease background;
+ background:#888;
+ color:#fff;
+ border-color:#555;
+}
\ No newline at end of file
diff --git a/htdocs/hrm/css/style.css b/htdocs/hrm/css/style.css
new file mode 100644
index 00000000000..0c8ba81d827
--- /dev/null
+++ b/htdocs/hrm/css/style.css
@@ -0,0 +1,130 @@
+#compare ul,#compare li,#compare h3 {margin: 0; padding: 0;}
+
+#compare div {
+ margin: 20px;
+}
+
+#compare ul {
+ list-style-type: none;
+ width: 100%;
+}
+
+#compare h3 {
+ font: bold 20px/1.5 Helvetica, Verdana, sans-serif;
+}
+
+#compare li img {
+ float: left;
+ margin: 0 15px 0 0;
+ max-width:80px;
+}
+
+#compare li p {
+ font: 200 12px/1.5 Georgia, Times New Roman, serif;
+}
+
+#compare li {
+ padding: 10px;
+ overflow: auto;
+ border-bottom: 2px solid #98b880;
+}
+#compare ul.competence li,#compare ul.note li {
+ height:48px;
+ overflow: hidden;
+ border-bottom: 2px solid #6C286C;
+}
+
+#compare li:hover {
+ background: #eee;
+ cursor: pointer;
+}
+
+#compare li.disabled {
+ color:#999;
+ border-bottom: 2px solid #ff0000;
+}
+
+#compare li.disabled img,#compare li.disabled p {
+ display:none;
+}
+
+span.note {
+ font: bold Helvetica, Verdana, sans-serif;
+ background: #eee none repeat scroll 0 0;
+ border: 1px solid #ccc;
+ border-radius: 3px;
+ color: #555;
+ cursor: pointer;
+ display: inline-block;
+ margin: 2px;
+ min-width: 20px;
+ padding: 5px 7px;
+ text-align: center;
+ font-weight: bold;
+}
+span.note.none {
+ background: #BA7777 none repeat scroll 0 0;
+}
+#compare ul.diff li {
+ text-align: center;
+ border-bottom:0 none;
+ height:48px;
+ overflow: hidden;
+ border-bottom: 2px solid #77BABA;
+}
+span.diffnote {
+ display: inline-block;
+ background: #c3e6cb;
+ width:42px;
+ height: 42px;
+ overflow: hidden;
+ border:none;
+ box-sizing: border-box;
+}
+span.diffnote.little {
+ width:25px;
+ height: 25px;
+ border-width:3px;
+}
+span.toohappy {
+ background: #3097D1;
+ border:5px solid #3097D1;
+}
+span.veryhappy {
+ border:5px solid #3097D1;
+}
+span.toosad {
+ background: #ccc;
+ border:5px solid #ccc;
+}
+span.sad {
+ background:#bd4147;
+}
+/*span.diffnote {
+ display: inline-block;
+ background: url(img/smiley.png);
+ width:42px;
+ height: 42px;
+ overflow: hidden;
+}
+span.toohappy {
+ background-position: -105px 0px;
+}
+span.veryhappy {
+ background-position: -53px 0px;
+}
+span.toosad {
+ background-position: -105px -52px;
+}
+span.sad {
+ background-position: 0px -52px;
+}*/
+
+span.bubble {
+ background-color: #ccc;
+ border:1px;
+ display:inline-block;
+ width:20px;
+ height:20px;
+ border-radius:20px;
+}
\ No newline at end of file
diff --git a/htdocs/hrm/evaluation_agenda.php b/htdocs/hrm/evaluation_agenda.php
new file mode 100644
index 00000000000..8524f6df3d9
--- /dev/null
+++ b/htdocs/hrm/evaluation_agenda.php
@@ -0,0 +1,282 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 evaluation_agenda.php
+ * \ingroup hr
+ * \brief Tab of events on Evaluation
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/hrm/class/evaluation.class.php';
+require_once DOL_DOCUMENT_ROOT.'/hrm/lib/hrm_evaluation.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/hrm/class/job.class.php';
+
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "other"));
+
+// Get parameters
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'aZ09');
+$cancel = GETPOST('cancel', 'aZ09');
+$backtopage = GETPOST('backtopage', 'alpha');
+
+if (GETPOST('actioncode', 'array')) {
+ $actioncode = GETPOST('actioncode', 'array', 3);
+ if (!count($actioncode)) {
+ $actioncode = '0';
+ }
+} else {
+ $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
+}
+$search_agenda_label = GETPOST('search_agenda_label');
+
+$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
+$sortfield = GETPOST("sortfield", 'alpha');
+$sortorder = GETPOST("sortorder", 'alpha');
+$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
+if (empty($page) || $page == -1) {
+ $page = 0;
+} // If $page is not defined, or '' or -1
+$offset = $limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+if (!$sortfield) {
+ $sortfield = 'a.datep,a.id';
+}
+if (!$sortorder) {
+ $sortorder = 'DESC,DESC';
+}
+
+// Initialize technical objects
+$object = new Evaluation($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('evaluationagenda', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+if ($id > 0 || !empty($ref)) {
+ $upload_dir = $conf->hrm->multidir_output[$object->entity]."/".$object->id;
+}
+
+$permissiontoadd = $user->rights->hrm->evaluation->write; // Used by the include of actions_addupdatedelete.inc.php
+$permissiontoread = $user->rights->hrm->evaluation->read; // Used by the include of actions_addupdatedelete.inc.php
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+$parameters = array('id'=>$id);
+$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)) {
+ // Cancel
+ if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
+ header("Location: ".$backtopage);
+ exit;
+ }
+
+ // Purge search criteria
+ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
+ $actioncode = '';
+ $search_agenda_label = '';
+ }
+}
+
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+if ($object->id > 0) {
+ $title = $langs->trans("Agenda");
+ //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
+ $help_url = 'EN:Module_Agenda_En';
+ llxHeader('', $title, $help_url);
+
+ if (!empty($conf->notification->enabled)) {
+ $langs->load("mails");
+ }
+ $head = evaluationPrepareHead($object);
+
+
+ print dol_get_fiche_head($head, 'agenda', $langs->trans("Agenda"), -1, $object->picto);
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = ''.$langs->trans("BackToList").' ';
+
+ $morehtmlref = '';
+ $morehtmlref .= $langs->trans('Label').' : '.$object->label;
+ $u_position = new User(($db));
+ $u_position->fetch($object->fk_user);
+ $morehtmlref .= ' '.$langs->trans('Employee').' : '.$u_position->getNomUrl(1);
+ $job = new Job($db);
+ $job->fetch($object->fk_job);
+ $morehtmlref .= ' '.$langs->trans('Job').' : '.$job->getNomUrl(1);
+ $morehtmlref .= '
';
+
+
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
+
+ print '';
+ print '
';
+
+ $object->info($object->id);
+ dol_print_object_info($object, 1);
+
+ print '
';
+
+ print dol_get_fiche_end();
+
+
+
+ // Actions buttons
+
+ $objthirdparty = $object;
+ $objcon = new stdClass();
+
+ $out = '&origin='.urlencode($object->element.'@'.$object->module).'&originid='.urlencode($object->id);
+ $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
+ $out .= '&backtopage='.urlencode($urlbacktopage);
+ $permok = $user->rights->agenda->myactions->create;
+ if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
+ //$out.='trans("AddAnAction"),'filenew');
+ //$out.=" ";
+ }
+
+
+ print '';
+
+ if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
+ $param = '&id='.$object->id.'&socid='.$socid;
+ if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+ $param .= '&contextpage='.urlencode($contextpage);
+ }
+ if ($limit > 0 && $limit != $conf->liste_limit) {
+ $param .= '&limit='.urlencode($limit);
+ }
+
+
+ //print load_fiche_titre($langs->trans("ActionsOnEvaluation"), '', '');
+
+ // List of all actions
+ $filters = array();
+ $filters['search_agenda_label'] = $search_agenda_label;
+
+ // TODO Replace this with same code than into list.php
+ show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, $object->module);
+ }
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/evaluation_card.php b/htdocs/hrm/evaluation_card.php
new file mode 100644
index 00000000000..64b54b4c80b
--- /dev/null
+++ b/htdocs/hrm/evaluation_card.php
@@ -0,0 +1,766 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 evaluation_card.php
+ * \ingroup hrm
+ * \brief Page to create/edit/view evaluation
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+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.'/hrm/class/evaluation.class.php';
+require_once DOL_DOCUMENT_ROOT.'/hrm/class/skill.class.php';
+require_once DOL_DOCUMENT_ROOT.'/hrm/class/skillrank.class.php';
+require_once DOL_DOCUMENT_ROOT.'/hrm/lib/hrm_evaluation.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/hrm/lib/hrm_skillrank.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "other", 'products'));
+
+// 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') : 'evaluationcard'; // To manage different context of search
+$backtopage = GETPOST('backtopage', 'alpha');
+$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
+//$lineid = GETPOST('lineid', 'int');
+
+// Initialize technical objects
+$object = new Evaluation($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('evaluationcard', '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 = 'view';
+}
+
+// Load object
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
+
+
+$permissiontoread = $user->rights->hrm->evaluation->read;
+$permissiontoadd = $user->rights->hrm->evaluation->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
+$permissiontovalidate = $user->rights->hrm->evaluation->validate;
+$permissiontoClose = $user->rights->hrm->evaluation->write;
+$permissiontodelete = $user->rights->hrm->evaluation->delete/* || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT)*/;
+$permissiondellink = $user->rights->hrm->evaluation->write; // Used by the include of actions_dellink.inc.php
+$upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1].'/evaluation';
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
+
+
+/*
+ * 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('/hrm/evaluation_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('/hrm/evaluation_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
+ }
+ }
+ }
+
+ $triggermodname = 'hrm_EVALUATION_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
+ include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
+
+ // 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 == 'set_thirdparty' && $permissiontoadd) {
+ $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
+ }
+ if ($action == 'classin' && $permissiontoadd) {
+ $object->setProject(GETPOST('projectid', 'int'));
+ }
+
+ // Actions to send emails
+ $triggersendname = 'hrm_EVALUATION_SENTBYMAIL';
+ $autocopy = 'MAIN_MAIL_AUTOCOPY_EVALUATION_TO';
+ $trackid = 'evaluation'.$object->id;
+ include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
+
+ if ($action == 'saveSkill') {
+ $TNote = GETPOST('TNote', 'array');
+ if (!empty($TNote)) {
+ foreach ($object->lines as $line) {
+ $line->rank = $TNote[$line->fk_skill];
+ $line->update($user);
+ }
+ }
+ }
+
+ if ($action == 'close') {
+ // save evaldet lines to user;
+ $sk = new SkillRank($db);
+ $SkillrecordsForActiveUser = $sk->fetchAll('ASC', 'fk_skill', 0, 0, array("customsql"=>"fk_object = ".$object->fk_user ." AND objecttype ='".SkillRank::SKILLRANK_TYPE_USER."'"), 'AND');
+
+ $errors = 0;
+ // we go through the evaldets of the eval
+ foreach ($object->lines as $key => $line) {
+ // no reference .. we add the line to use it
+ if (count($SkillrecordsForActiveUser) == 0) {
+ if ($res > 0) {
+ $newSkill = new SkillRank($db);
+ $resCreate = $newSkill->cloneFromCurrentSkill($line, $object->fk_user);
+
+ if ($resCreate <= 0) {
+ $errors++;
+ setEventMessage($langs->trans('ErrorCreateUserSkill'), $line->fk_skill);
+ }
+ } else {
+ setEventMessage($langs->trans('NoSkilRankLoaded'));
+ }
+ } else {
+ //check if the skill is present to use it
+ $find = false;
+ $keyFind = 0;
+ foreach ($SkillrecordsForActiveUser as $k => $sr) {
+ if ($sr->fk_skill == $line->fk_skill) {
+ $keyFind = $k;
+ $find = true;
+ break;
+ }
+ }
+ //we update the skill user
+ if ($find) {
+ $updSkill = $SkillrecordsForActiveUser[$k];
+
+ $updSkill->rank = $line->rank;
+ $updSkill->update($user);
+ } else { // sinon on ajoute la skill
+ $newSkill = new SkillRank($db);
+ $resCreate = $newSkill->cloneFromCurrentSkill($line, $object->fk_user);
+ }
+ }
+ }
+ if (empty($errors)) {
+ $object->setStatut(Evaluation::STATUS_CLOSED);
+ setEventMessage('EmployeeSkillsUpdated');
+ }
+ }
+
+ if ($action == 'reopen' ) {
+ // no update here we just change the evaluation status
+ $object->setStatut(Evaluation::STATUS_VALIDATED);
+ }
+}
+
+
+
+
+/*
+ * View
+ *
+ * Put here all code to build page
+ */
+
+$form = new Form($db);
+$formfile = new FormFile($db);
+$formproject = new FormProjets($db);
+
+$title = $langs->trans("Evaluation");
+$help_url = '';
+$css = array();
+$css[] = '/hrm/css/style.css';
+llxHeader('', $title, $help_url, '', 0, 0, '', $css);
+
+print '';
+
+// Part to create
+if ($action == 'create') {
+ print load_fiche_titre($langs->trans("NewEval"), '', 'object_' . $object->picto);
+
+ print '';
+}
+
+// Part to edit record
+if (($id || $ref) && $action == 'edit') {
+ print load_fiche_titre($langs->trans("Evaluation"), '', 'object_'.$object->picto);
+
+ print '';
+}
+
+// Part to show record
+if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
+ $res = $object->fetch_optionals();
+
+ $head = evaluationPrepareHead($object);
+ print dol_get_fiche_head($head, 'card', $langs->trans("Workstation"), -1, $object->picto);
+
+ $formconfirm = '';
+
+ if ($action == 'validate' && $permissiontovalidate) {
+ // Confirm validate proposal
+ $error = 0;
+
+ // We verify whether the object is provisionally numbering
+ $ref = substr($object->ref, 1, 4);
+ if ($ref == 'PROV') {
+ $numref = $object->getNextNumRef();
+ if (empty($numref)) {
+ $error++;
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
+ } else {
+ $numref = $object->ref;
+ }
+
+ $text = $langs->trans('ConfirmValidateEvaluation', $numref);
+ if (!empty($conf->notification->enabled)) {
+ require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
+ $notify = new Notify($db);
+ $text .= ' ';
+ $text .= $notify->confirmMessage('HRM_EVALUATION_VALIDATE', $object->socid, $object);
+ }
+
+ if (!$error) {
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateEvaluation'), $text, 'confirm_validate', '', 0, 1);
+ }
+ }
+
+ // Confirmation to delete
+ if ($action == 'delete') {
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteEvaluation'), $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);
+ }
+
+ // Confirmation of action xxxx
+ if ($action == 'xxx') {
+ $formquestion = array();
+
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
+ }
+
+ // 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 = '';
+ $morehtmlref .= $langs->trans('Label').' : '.$object->label;
+ $u_position = new User(($db));
+ $u_position->fetch($object->fk_user);
+ $morehtmlref .= ' '.$langs->trans('Employee').' : '.$u_position->getNomUrl(1);
+ $job = new Job($db);
+ $job->fetch($object->fk_job);
+ $morehtmlref .= ' '.$langs->trans('Job').' : '.$job->getNomUrl(1);
+ $morehtmlref .= '
';
+
+
+
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
+
+
+ print '';
+ print '
';
+ print '
';
+ print '
'."\n";
+
+ $object->fields['label']['visible']=0; // Already in banner
+ $object->fields['fk_user']['visible']=0; // Already in banner
+ $object->fields['fk_job']['visible']=0; // Already 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();
+
+
+ /*
+ * Lines
+ */
+
+ if (!empty($object->table_element_line)) {
+ if ($object->status == Evaluation::STATUS_DRAFT) {
+ $result = $object->getLinesArray();
+
+ print ' \n";
+ print " ";
+ }
+ }
+
+ // list of comparison
+ if ($object->status != Evaluation::STATUS_DRAFT) {
+ // Recovery of skills related to this evaluation
+
+ $sql = 'select';
+ $sql .= ' e.ref,';
+ $sql .= ' e.date_creation,';
+ $sql .= ' e.fk_job,';
+ $sql .= ' j.label as "refjob",';
+ $sql .= ' ed.fk_skill,';
+
+ $sql .= ' sk.label as "skilllabel",';
+ $sql .= ' sk.skill_type,';
+ $sql .= ' sk.description,';
+ $sql .= ' ed.rank,';
+ $sql .= ' ed.required_rank,';
+ $sql .= ' ed.rank as "userRankForSkill",';
+ $sql .= ' skdet_user.description as "userRankForSkillDesc",';
+ $sql .= ' skdet_required.description as "required_rank_desc"';
+
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . 'hrm_evaluation as e';
+ $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'hrm_evaluationdet as ed ON e.rowid = ed.fk_evaluation';
+ $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'hrm_job as j ON e.fk_job = j.rowid';
+ $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'hrm_skill as sk ON ed.fk_skill = sk.rowid';
+ $sql .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'hrm_skilldet as skdet_user ON (skdet_user.fk_skill = sk.rowid AND skdet_user.rank = ed.rank)';
+ //$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "hrm_skillrank as skr ON (j.rowid = skr.fk_object AND skr.fk_skill = ed.fk_skill AND skr.objecttype = 'job')";
+ $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'hrm_skilldet as skdet_required ON (skdet_required.fk_skill = sk.rowid AND skdet_required.rank = ed.required_rank)';
+ $sql .= " WHERE e.rowid =" . ((int) $object->id);
+
+ // echo $sql;
+
+ $resql = $db->query($sql);
+ $Tab = array();
+
+ if ($resql) {
+ $num = 0;
+ while ($obj = $db->fetch_object($resql)) {
+ $Tab[$num] = new stdClass();
+ $class = '';
+ $Tab[$num]->skill_type = $obj->skill_type;
+ $Tab[$num]->skill_id = $obj->fk_skill;
+ $Tab[$num]->skilllabel = $obj->skilllabel;
+ $Tab[$num]->description = $obj->description;
+ $Tab[$num]->userRankForSkill = '' . $obj->userRankForSkill . ' ';
+ $Tab[$num]->required_rank = '' . $obj->required_rank . ' ';
+
+ if ($obj->userRankForSkill > $obj->required_rank) {
+ $title=$langs->trans('MaxlevelGreaterThanShort');
+ $class .= 'veryhappy diffnote';
+ } elseif ($obj->userRankForSkill == $obj->required_rank) {
+ $title=$langs->trans('MaxLevelEqualToShort');
+ $class .= 'happy diffnote';
+ } elseif ($obj->userRankForSkill < $obj->required_rank) {
+ $title=$langs->trans('MaxLevelLowerThanShort');
+ $class .= 'sad';
+ }
+
+ $Tab[$num]->result = ' ';
+
+ $num++;
+ }
+
+ print '
';
+ print '';
+
+ print '';
+ print '' . $langs->trans("TypeSkill") . ' ';
+ print '' . $langs->trans("Label") . ' ';
+ print '' . $langs->trans("Description") . ' ';
+ print '' . $langs->trans("EmployeeRank") . ' ';
+ print '' . $langs->trans("RequiredRank") . ' ';
+ print '' . $langs->trans("Result") . ' ';
+ print ' ';
+
+ $sk = new Skill($db);
+ foreach ($Tab as $t) {
+ $sk->fetch($t->skill_id);
+ print '';
+ print ' ' . Skill::typeCodeToLabel($t->skill_type) . ' ';
+ print ' ' . $sk->getNomUrl(1) . ' ';
+ print ' ' . $t->description . ' ';
+ print ' ' . $t->userRankForSkill . ' ';
+ print ' ' . $t->required_rank . ' ';
+ print ' ' . $t->result . ' ';
+ print ' ';
+ }
+
+ 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 dolGetButtonAction($langs->trans('SendMail'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init&token='.newToken().'#formmailbeforetitle');
+ }
+
+ // Back to draft
+ if ($object->status == $object::STATUS_VALIDATED) {
+ print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken(), '', $permissiontoadd);
+ print dolGetButtonAction($langs->trans('Close'), '', 'close', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_CLOSED && $permissiontoclose));
+ } elseif ($object->status != $object::STATUS_CLOSED) {
+ print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
+ }
+
+ if ($object->status == $object::STATUS_CLOSED) {
+ print dolGetButtonAction($langs->trans('ReOpen'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), '', $permissiontoadd);
+ }
+
+
+ // Validate
+ if ($object->status == $object::STATUS_DRAFT) {
+ if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
+ print dolGetButtonAction($langs->trans('Save').' '.$langs->trans('and').' '.$langs->trans('Valid'), '', 'default', '#', 'btn_valid', $permissiontovalidate);
+ } else {
+ $langs->load("errors");
+ print dolGetButtonAction($langs->trans("ErrorAddAtLeastOneLineFirst"), $langs->trans("Validate"), 'default', '#', '', 0);
+ }
+ }
+
+
+ // Delete (need delete permission, or if draft, just need create/modify permission)
+ print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete);
+ }
+
+
+ print ''."\n";
+ }
+
+ // Select mail models is same action as presend
+ if (GETPOST('modelselected')) {
+ $action = 'presend';
+ }
+
+ if ($action != 'presend') {
+ print '';
+ print '
'; // ancre
+
+ $includedocgeneration = 0;
+
+ // Documents
+ if ($includedocgeneration) {
+ $objref = dol_sanitizeFileName($object->ref);
+ $relativepath = $objref.'/'.$objref.'.pdf';
+ $filedir = $conf->hrm->dir_output.'/'.$object->element.'/'.$objref;
+ $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
+ $genallowed = $user->rights->hrm->evaluation->read; // If you can read, you can build the PDF to read content
+ $delallowed = $user->rights->hrm->evaluation->write; // If you can create/edit, you can remove a file on card
+ print $formfile->showdocuments('hrm:Evaluation', $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('evaluation'));
+ $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
+
+
+ print '
';
+
+ $MAXEVENT = 10;
+
+ $morehtmlright = '
';
+ $morehtmlright .= $langs->trans("SeeAll");
+ $morehtmlright .= ' ';
+
+ // 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.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlright);
+
+ print '
';
+ }
+
+ //Select mail models is same action as presend
+ if (GETPOST('modelselected')) {
+ $action = 'presend';
+ }
+
+ // Presend form
+ $modelmail = 'evaluation';
+ $defaulttopic = 'InformationMessage';
+ $diroutput = $conf->hrm->dir_output;
+ $trackid = 'evaluation'.$object->id;
+
+ include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/evaluation_contact.php b/htdocs/hrm/evaluation_contact.php
new file mode 100644
index 00000000000..540154b77ef
--- /dev/null
+++ b/htdocs/hrm/evaluation_contact.php
@@ -0,0 +1,220 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 evaluation_contact.php
+ * \ingroup hrm
+ * \brief Tab for contacts linked to Evaluation
+ */
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/evaluation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_evaluation.lib.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "companies", "other", "mails"));
+
+$id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
+$ref = GETPOST('ref', 'alpha');
+$lineid = GETPOST('lineid', 'int');
+$socid = GETPOST('socid', 'int');
+$action = GETPOST('action', 'aZ09');
+
+// Initialize technical objects
+$object = new Evaluation($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('evaluationcontact', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+
+$permission = $user->rights->hrm->evaluation->write;
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+//if (empty($conf->hrm->enabled)) accessforbidden();
+//if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Add a new contact
+ */
+
+if ($action == 'addcontact' && $permission) {
+ $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
+ $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
+ $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
+
+ if ($result >= 0) {
+ header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+ exit;
+ } else {
+ if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
+ $langs->load("errors");
+ setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
+ } else {
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
+ }
+} elseif ($action == 'swapstatut' && $permission) {
+ // Toggle the status of a contact
+ $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
+} elseif ($action == 'deletecontact' && $permission) {
+ // Deletes a contact
+ $result = $object->delete_contact($lineid);
+
+ if ($result >= 0) {
+ header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+ exit;
+ } else {
+ dol_print_error($db);
+ }
+}
+
+
+/*
+ * View
+ */
+
+$title = $langs->trans('Evaluation')." - ".$langs->trans('ContactsAddresses');
+$help_url = '';
+//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
+llxHeader('', $title, $help_url);
+
+$form = new Form($db);
+$formcompany = new FormCompany($db);
+$contactstatic = new Contact($db);
+$userstatic = new User($db);
+
+
+/* *************************************************************************** */
+/* */
+/* View and edit mode */
+/* */
+/* *************************************************************************** */
+
+if ($object->id) {
+ /*
+ * Show tabs
+ */
+ $head = evaluationPrepareHead($object);
+
+ print dol_get_fiche_head($head, 'contact', '', -1, $object->picto);
+
+ $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->projet->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, 1, 1);
+ $morehtmlref.='
';
+ } else {
+ $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
+ }
+ } else {
+ if (! empty($object->fk_project)) {
+ $proj = new Project($db);
+ $proj->fetch($object->fk_project);
+ $morehtmlref .= ': '.$proj->getNomUrl();
+ } else {
+ $morehtmlref .= '';
+ }
+ }
+ }*/
+ $morehtmlref .= '
';
+
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
+
+ print dol_get_fiche_end();
+
+ print ' ';
+
+ // Contacts lines (modules that overwrite templates must declare this into descriptor)
+ $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
+ foreach ($dirtpls as $reldir) {
+ $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
+ if ($res) {
+ break;
+ }
+ }
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/evaluation_document.php b/htdocs/hrm/evaluation_document.php
new file mode 100644
index 00000000000..06cbd7a621a
--- /dev/null
+++ b/htdocs/hrm/evaluation_document.php
@@ -0,0 +1,224 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 evaluation_document.php
+ * \ingroup hrm
+ * \brief Tab for documents linked to Evaluation
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/evaluation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_evaluation.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "companies", "other", "mails"));
+
+
+$action = GETPOST('action', 'aZ09');
+$confirm = GETPOST('confirm');
+$id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int'));
+$ref = GETPOST('ref', 'alpha');
+
+// Get parameters
+$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
+$sortfield = GETPOST("sortfield", 'alpha');
+$sortorder = GETPOST("sortorder", 'alpha');
+$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
+if (empty($page) || $page == -1) {
+ $page = 0;
+} // If $page is not defined, or '' or -1
+$offset = $liste_limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+if (!$sortorder) {
+ $sortorder = "ASC";
+}
+if (!$sortfield) {
+ $sortfield = "name";
+}
+//if (! $sortfield) $sortfield="position_name";
+
+// Initialize technical objects
+$object = new Evaluation($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('evaluationdocument', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+
+if ($id > 0 || !empty($ref)) {
+ $upload_dir = $conf->hrm->multidir_output[$object->entity ? $object->entity : $conf->entity]."/evaluation/".get_exdir(0, 0, 0, 1, $object);
+}
+
+$permissiontoadd = $user->rights->hrm->evaluation->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
+$permissiontoread = $user->rights->hrm->evaluation->read;
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+$title = $langs->trans("Evaluation").' - '.$langs->trans("Files");
+$help_url = '';
+//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
+llxHeader('', $title, $help_url);
+
+if ($object->id) {
+ /*
+ * Show tabs
+ */
+ $head = evaluationPrepareHead($object);
+
+ print dol_get_fiche_head($head, 'document', $langs->trans("Documents"), -1, $object->picto);
+
+
+ // Build file list
+ $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
+ $totalsize = 0;
+ foreach ($filearray as $key => $file) {
+ $totalsize += $file['size'];
+ }
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = ''.$langs->trans("BackToList").' ';
+
+ $morehtmlref = '';
+ $morehtmlref .= $langs->trans('Label').' : '.$object->label;
+ $u_position = new User(($db));
+ $u_position->fetch($object->fk_user);
+ $morehtmlref .= ' '.$langs->trans('Employee').' : '.$u_position->getNomUrl(1);
+ $job = new Job($db);
+ $job->fetch($object->fk_job);
+ $morehtmlref .= ' '.$langs->trans('Job').' : '.$job->getNomUrl(1);
+ $morehtmlref .= '
';
+
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
+
+ print '';
+
+ print '
';
+ print '
';
+
+ // Number of files
+ print ''.$langs->trans("NbOfAttachedFiles").' '.count($filearray).' ';
+
+ // Total size
+ print ''.$langs->trans("TotalSizeOfAttachedFiles").' '.$totalsize.' '.$langs->trans("bytes").' ';
+
+ print '
';
+
+ print '
';
+
+ print dol_get_fiche_end();
+
+ $modulepart = 'hrm';
+ $permtoedit = $permissiontoadd;
+ $param = '&id='.$object->id;
+
+ //$relativepathwithnofile='evaluation/' . dol_sanitizeFileName($object->id).'/';
+ $relativepathwithnofile = 'evaluation/'.dol_sanitizeFileName($object->ref).'/';
+
+ include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
+} else {
+ accessforbidden('', 0, 1);
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/evaluation_list.php b/htdocs/hrm/evaluation_list.php
new file mode 100644
index 00000000000..9ec102c45ea
--- /dev/null
+++ b/htdocs/hrm/evaluation_list.php
@@ -0,0 +1,731 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 evaluation_list.php
+ * \ingroup hrm
+ * \brief List page for evaluation
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
+
+// load hrm libraries
+require_once __DIR__.'/class/evaluation.class.php';
+
+// for other modules
+//dol_include_once('/othermodule/class/otherobject.class.php');
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "other"));
+
+$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
+$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
+$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
+$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
+$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
+$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
+$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'evaluationlist'; // To manage different context of search
+$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
+$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
+
+$id = GETPOST('id', 'int');
+
+// Load variable for pagination
+$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
+$sortfield = GETPOST('sortfield', 'aZ09comma');
+$sortorder = GETPOST('sortorder', 'aZ09comma');
+$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
+if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
+ // If $page is not defined, or '' or -1 or if we click on clear filters
+ $page = 0;
+}
+$offset = $limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+
+// Initialize technical objects
+$object = new Evaluation($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('evaluationlist')); // Note that conf->hooks_modules contains array
+
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+//$extrafields->fetch_name_optionals_label($object->table_element_line);
+
+$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
+
+// Default sort order (if not yet defined by previous GETPOST)
+if (!$sortfield) {
+ reset($object->fields); // Reset is required to avoid key() to return null.
+ $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
+}
+if (!$sortorder) {
+ $sortorder = "ASC";
+}
+
+// Initialize array of search criterias
+$search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
+$search = array();
+foreach ($object->fields as $key => $val) {
+ if (GETPOST('search_'.$key, 'alpha') !== '') {
+ $search[$key] = GETPOST('search_'.$key, 'alpha');
+ }
+ if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
+ $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
+ $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
+ }
+}
+
+// List of fields to search into when doing a "search in all"
+$fieldstosearchall = array();
+foreach ($object->fields as $key => $val) {
+ if (!empty($val['searchall'])) {
+ $fieldstosearchall['t.'.$key] = $val['label'];
+ }
+}
+
+// Definition of array of fields for columns
+$arrayfields = array();
+foreach ($object->fields as $key => $val) {
+ // If $val['visible']==0, then we never show the field
+ if (!empty($val['visible'])) {
+ $visible = (int) dol_eval($val['visible'], 1);
+ $arrayfields['t.'.$key] = array(
+ 'label'=>$val['label'],
+ 'checked'=>(($visible < 0) ? 0 : 1),
+ 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)),
+ 'position'=>$val['position'],
+ 'help'=> isset($val['help']) ? $val['help'] : ''
+ );
+ }
+}
+// Extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
+
+$object->fields = dol_sort_array($object->fields, 'position');
+$arrayfields = dol_sort_array($arrayfields, 'position');
+
+$permissiontoread = $user->rights->hrm->evaluation->read;
+$permissiontoadd = $user->rights->hrm->evaluation->write;
+$permissiontodelete = $user->rights->hrm->evaluation->delete;
+
+// Security check
+if (empty($conf->hrm->enabled)) {
+ accessforbidden('Module not enabled');
+}
+
+// Security check (enable the most restrictive one)
+if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) accessforbidden();
+//$socid = 0; if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+//if (empty($conf->hrm->enabled)) accessforbidden();
+//if (!$permissiontoread) accessforbidden();
+
+
+
+/*
+ * Actions
+ */
+
+if (GETPOST('cancel', 'alpha')) {
+ $action = 'list';
+ $massaction = '';
+}
+if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
+ $massaction = '';
+}
+
+$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)) {
+ // Selection of new fields
+ include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
+
+ // Purge search criteria
+ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
+ foreach ($object->fields as $key => $val) {
+ $search[$key] = '';
+ if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
+ $search[$key.'_dtstart'] = '';
+ $search[$key.'_dtend'] = '';
+ }
+ }
+ $toselect = array();
+ $search_array_options = array();
+ }
+ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
+ || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
+ $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
+ }
+
+ // Mass actions
+ $objectclass = 'Evaluation';
+ $objectlabel = 'Evaluation';
+ $uploaddir = $conf->hrm->dir_output;
+ include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
+}
+
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+$now = dol_now();
+
+//$help_url="EN:Module_Evaluation|FR:Module_Evaluation_FR|ES:Módulo_Evaluation";
+$help_url = '';
+$title = $langs->trans("List").' '.$langs->trans('Evaluations');
+$morejs = array();
+$morecss = array();
+
+
+// Build and execute select
+// --------------------------------------------------------------------
+$sql = 'SELECT ';
+$sql .= $object->getFieldList('t');
+// Add fields from extrafields
+if (!empty($extrafields->attributes[$object->table_element]['label'])) {
+ foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
+ $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key.', ' : '');
+ }
+}
+// Add fields from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
+$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
+$sql = preg_replace('/,\s*$/', '', $sql);
+$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
+if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
+}
+// Add table from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
+$sql .= $hookmanager->resPrint;
+if ($object->ismultientitymanaged == 1) {
+ $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
+} else {
+ $sql .= " WHERE 1 = 1";
+}
+foreach ($search as $key => $val) {
+ if (array_key_exists($key, $object->fields)) {
+ if ($key == 'status' && $search[$key] == -1) {
+ continue;
+ }
+ $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
+ if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
+ if ($search[$key] == '-1' || $search[$key] === '0') {
+ $search[$key] = '';
+ }
+ $mode_search = 2;
+ }
+ if ($search[$key] != '') {
+ $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
+ }
+ } else {
+ if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
+ $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
+ if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
+ if (preg_match('/_dtstart$/', $key)) {
+ $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
+ }
+ if (preg_match('/_dtend$/', $key)) {
+ $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
+ }
+ }
+ }
+ }
+}
+if ($search_all) {
+ $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
+}
+//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
+// Add where from extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
+// Add where from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
+$sql .= $hookmanager->resPrint;
+
+/* If a group by is required
+$sql .= " GROUP BY ";
+foreach($object->fields as $key => $val) {
+ $sql .= "t.".$key.", ";
+}
+// Add fields from extrafields
+if (!empty($extrafields->attributes[$object->table_element]['label'])) {
+ foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
+ $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
+ }
+}
+// Add where from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
+$sql .= $hookmanager->resPrint;
+$sql = preg_replace('/,\s*$/', '', $sql);
+*/
+
+$sql .= $db->order($sortfield, $sortorder);
+
+// Count total nb of records
+$nbtotalofrecords = '';
+if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+ $resql = $db->query($sql);
+ $nbtotalofrecords = $db->num_rows($resql);
+ if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
+ $page = 0;
+ $offset = 0;
+ }
+}
+// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
+if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
+ $num = $nbtotalofrecords;
+} else {
+ if ($limit) {
+ $sql .= $db->plimit($limit + 1, $offset);
+ }
+
+ $resql = $db->query($sql);
+ if (!$resql) {
+ dol_print_error($db);
+ exit;
+ }
+
+ $num = $db->num_rows($resql);
+}
+
+// Direct jump if only one record found
+if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
+ $obj = $db->fetch_object($resql);
+ $id = $obj->rowid;
+ header("Location: ".dol_buildpath('/hrm/evaluation_card.php', 1).'?id='.$id);
+ exit;
+}
+
+
+// Output page
+// --------------------------------------------------------------------
+
+llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
+
+// Example : Adding jquery code
+// print '';
+
+$arrayofselected = is_array($toselect) ? $toselect : array();
+
+$param = '';
+if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+ $param .= '&contextpage='.urlencode($contextpage);
+}
+if ($limit > 0 && $limit != $conf->liste_limit) {
+ $param .= '&limit='.urlencode($limit);
+}
+foreach ($search as $key => $val) {
+ if (is_array($search[$key]) && count($search[$key])) {
+ foreach ($search[$key] as $skey) {
+ $param .= '&search_'.$key.'[]='.urlencode($skey);
+ }
+ } else {
+ $param .= '&search_'.$key.'='.urlencode($search[$key]);
+ }
+}
+if ($optioncss != '') {
+ $param .= '&optioncss='.urlencode($optioncss);
+}
+// Add $param from extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
+// Add $param from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
+$param .= $hookmanager->resPrint;
+
+// List of mass actions available
+$arrayofmassactions = array(
+ //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
+ //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
+ //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
+ //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
+);
+if ($permissiontodelete) {
+ $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
+}
+if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
+ $arrayofmassactions = array();
+}
+$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
+
+print ''."\n";
+
+if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
+ $hidegeneratedfilelistifempty = 1;
+ if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
+ $hidegeneratedfilelistifempty = 0;
+ }
+
+ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
+ $formfile = new FormFile($db);
+
+ // Show list of available documents
+ $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
+ $urlsource .= str_replace('&', '&', $param);
+
+ $filedir = $diroutputmassaction;
+ $genallowed = $permissiontoread;
+ $delallowed = $permissiontoadd;
+
+ print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/evaluation_note.php b/htdocs/hrm/evaluation_note.php
new file mode 100644
index 00000000000..aae7b56acaf
--- /dev/null
+++ b/htdocs/hrm/evaluation_note.php
@@ -0,0 +1,182 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 evaluation_note.php
+ * \ingroup hrm
+ * \brief Tab for notes on Evaluation
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/evaluation.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_evaluation.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "companies"));
+
+// Get parameters
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'aZ09');
+$cancel = GETPOST('cancel', 'aZ09');
+$backtopage = GETPOST('backtopage', 'alpha');
+
+// Initialize technical objects
+$object = new Evaluation($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('evaluationnote', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+if ($id > 0 || !empty($ref)) {
+ $upload_dir = $conf->hrm->multidir_output[$object->entity]."/".$object->id;
+}
+
+$permissionnote = $user->rights->hrm->evaluation->write; // Used by the include of actions_setnotes.inc.php
+$permissiontoread = $user->rights->hrm->evaluation->read; // Used by the include of actions_addupdatedelete.inc.php
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+//if (empty($conf->hrm->enabled)) accessforbidden();
+//if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+$reshook = $hookmanager->executeHooks('doActions', array(), $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)) {
+ include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
+}
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+//$help_url='EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes';
+$help_url = '';
+llxHeader('', $langs->trans('Evaluation'), $help_url);
+
+if ($id > 0 || !empty($ref)) {
+ $object->fetch_thirdparty();
+
+ $head = evaluationPrepareHead($object);
+
+ print dol_get_fiche_head($head, 'note', $langs->trans('Notes'), -1, $object->picto);
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = ''.$langs->trans("BackToList").' ';
+
+ $morehtmlref = '';
+ $morehtmlref .= $langs->trans('Label').' : '.$object->label;
+ $u_position = new User(($db));
+ $u_position->fetch($object->fk_user);
+ $morehtmlref .= ' '.$langs->trans('Employee').' : '.$u_position->getNomUrl(1);
+ $job = new Job($db);
+ $job->fetch($object->fk_job);
+ $morehtmlref .= ' '.$langs->trans('Job').' : '.$job->getNomUrl(1);
+ $morehtmlref .= '
';
+
+
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
+
+
+ print '';
+ print '
';
+
+
+ $cssclass = "titlefield";
+ include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
+
+ print '
';
+
+ print dol_get_fiche_end();
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/job_agenda.php b/htdocs/hrm/job_agenda.php
new file mode 100644
index 00000000000..77dd464a7f0
--- /dev/null
+++ b/htdocs/hrm/job_agenda.php
@@ -0,0 +1,275 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 job_agenda.php
+ * \ingroup hrm
+ * \brief Tab of events on Job
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
+
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "other"));
+
+// Get parameters
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'aZ09');
+$cancel = GETPOST('cancel', 'aZ09');
+$backtopage = GETPOST('backtopage', 'alpha');
+
+if (GETPOST('actioncode', 'array')) {
+ $actioncode = GETPOST('actioncode', 'array', 3);
+ if (!count($actioncode)) {
+ $actioncode = '0';
+ }
+} else {
+ $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
+}
+$search_agenda_label = GETPOST('search_agenda_label');
+
+$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
+$sortfield = GETPOST("sortfield", 'alpha');
+$sortorder = GETPOST("sortorder", 'alpha');
+$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
+if (empty($page) || $page == -1) {
+ $page = 0;
+} // If $page is not defined, or '' or -1
+$offset = $limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+if (!$sortfield) {
+ $sortfield = 'a.datep,a.id';
+}
+if (!$sortorder) {
+ $sortorder = 'DESC,DESC';
+}
+
+// Initialize technical objects
+$object = new Job($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('jobagenda', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+if ($id > 0 || !empty($ref)) {
+ $upload_dir = $conf->hrm->multidir_output[$object->entity]."/".$object->id;
+}
+
+$permissiontoread = $user->rights->hrm->all->read;
+$permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+$parameters = array('id'=>$id);
+$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)) {
+ // Cancel
+ if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
+ header("Location: ".$backtopage);
+ exit;
+ }
+
+ // Purge search criteria
+ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
+ $actioncode = '';
+ $search_agenda_label = '';
+ }
+}
+
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+if ($object->id > 0) {
+ $title = $langs->trans("Agenda");
+ //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
+ $help_url = 'EN:Module_Agenda_En';
+ llxHeader('', $title, $help_url);
+
+ if (!empty($conf->notification->enabled)) {
+ $langs->load("mails");
+ }
+ $head = jobPrepareHead($object);
+
+
+ print dol_get_fiche_head($head, 'agenda', $langs->trans("Agenda"), -1, $object->picto);
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = ''.$langs->trans("BackToList").' ';
+
+ $morehtmlref = '';
+ $morehtmlref.= $object->label;
+ $morehtmlref .= '
';
+
+
+ dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
+
+ print '';
+ print '
';
+
+ $object->info($object->id);
+ dol_print_object_info($object, 1);
+
+ print '
';
+
+ print dol_get_fiche_end();
+
+
+
+ // Actions buttons
+
+ $objthirdparty = $object;
+ $objcon = new stdClass();
+
+ $out = '&origin='.urlencode($object->element.'@'.$object->module).'&originid='.urlencode($object->id);
+ $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
+ $out .= '&backtopage='.urlencode($urlbacktopage);
+ $permok = $user->rights->agenda->myactions->create;
+ if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
+ //$out.='trans("AddAnAction"),'filenew');
+ //$out.=" ";
+ }
+
+
+ print '';
+
+ if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
+ $param = '&id='.$object->id.'&socid='.$socid;
+ if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+ $param .= '&contextpage='.urlencode($contextpage);
+ }
+ if ($limit > 0 && $limit != $conf->liste_limit) {
+ $param .= '&limit='.urlencode($limit);
+ }
+
+
+ //print load_fiche_titre($langs->trans("ActionsOnJob"), '', '');
+
+ // List of all actions
+ $filters = array();
+ $filters['search_agenda_label'] = $search_agenda_label;
+
+ // TODO Replace this with same code than into list.php
+ show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, $object->module);
+ }
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/job_card.php b/htdocs/hrm/job_card.php
new file mode 100644
index 00000000000..19b40048f7b
--- /dev/null
+++ b/htdocs/hrm/job_card.php
@@ -0,0 +1,532 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 job_card.php
+ * \ingroup hrm
+ * \brief Page to create/edit/view job
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
+$tmp2 = realpath(__FILE__);
+$i = strlen($tmp) - 1;
+$j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--;
+ $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+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 . '/hrm/class/job.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "other", 'products'));
+
+// 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') : 'jobcard'; // To manage different context of search
+$backtopage = GETPOST('backtopage', 'alpha');
+$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
+//$lineid = GETPOST('lineid', 'int');
+
+// Initialize technical objects
+$object = new Job($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
+$hookmanager->initHooks(array('jobcard', '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 = 'view';
+}
+
+// Load object
+include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
+
+
+$permissiontoread = $user->rights->hrm->all->read;
+$permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
+$permissiontodelete = $user->rights->hrm->all->delete;
+$upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1] . '/job';
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
+
+
+/*
+ * 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('/hrm/job_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('/hrm/job_card.php', 1) . '?id=' . ($id > 0 ? $id : '__ID__');
+ }
+ }
+ }
+
+ $triggermodname = 'hrm_JOB_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
+ include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
+
+ // 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 == 'set_thirdparty' && $permissiontoadd) {
+ $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
+ }
+ if ($action == 'classin' && $permissiontoadd) {
+ $object->setProject(GETPOST('projectid', 'int'));
+ }
+
+ // Actions to send emails
+ $triggersendname = 'hrm_JOB_SENTBYMAIL';
+ $autocopy = 'MAIN_MAIL_AUTOCOPY_JOB_TO';
+ $trackid = 'job' . $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);
+
+$title = $langs->trans("Job");
+$help_url = '';
+llxHeader('', $title, $help_url);
+
+// Example : Adding jquery code
+// print '';
+
+
+// Part to create
+if ($action == 'create') {
+ print load_fiche_titre($langs->trans("NewObject", $langs->transnoentities('Job')), '', 'object_' . $object->picto);
+
+ print '';
+
+ //dol_set_focus('input[name="ref"]');
+}
+
+// Part to edit record
+if (($id || $ref) && $action == 'edit') {
+ print load_fiche_titre($langs->trans("Job"), '', 'object_' . $object->picto);
+
+ print '';
+}
+
+// Part to show record
+if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
+ $res = $object->fetch_optionals();
+
+ $head = jobPrepareHead($object);
+ $picto = 'company.png';
+ print dol_get_fiche_head($head, 'job_card', $langs->trans("Workstation"), -1, $object->picto);
+
+ $formconfirm = '';
+
+ // Confirmation to delete
+ if ($action == 'delete') {
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteJob'), $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);
+ }
+
+ // Confirmation of action xxxx
+ if ($action == 'xxx') {
+ $formquestion = array();
+ /*
+ $forcecombo=0;
+ if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
+ $formquestion = array(
+ // 'text' => $langs->trans("ConfirmClone"),
+ // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
+ // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
+ // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
+ );
+ */
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
+ }
+
+ // 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 = '';
+ $morehtmlref.= $object->label;
+ $morehtmlref .= '
';
+
+
+ dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
+
+
+ print '';
+ print '
';
+ print '
';
+ print '
' . "\n";
+
+ // Common attributes
+ //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
+ //unset($object->fields['fk_project']); // Hide field already shown in banner
+ //unset($object->fields['fk_soc']); // Hide field already shown in banner
+ $object->fields['label']['visible']=0; // Already 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();
+
+
+ /*
+ * Lines
+ */
+
+ if (!empty($object->table_element_line)) {
+ // Show object lines
+ $result = $object->getLinesArray();
+
+ print ' \n";
+ }
+
+
+ // 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)) {
+ // Back to draft
+ if ($object->status == $object::STATUS_VALIDATED) {
+ print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=confirm_setdraft&confirm=yes&token=' . newToken(), '', $permissiontoadd);
+ }
+
+ print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
+
+ // Delete (need delete permission, or if draft, just need create/modify permission)
+ print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete);
+ }
+ print '
' . "\n";
+ }
+
+
+ // Select mail models is same action as presend
+ if (GETPOST('modelselected')) {
+ $action = 'presend';
+ }
+
+ if ($action != 'presend') {
+ print '';
+ print '
'; // ancre
+
+ $includedocgeneration = 0;
+
+ // Documents
+ if ($includedocgeneration) {
+ $objref = dol_sanitizeFileName($object->ref);
+ $relativepath = $objref . '/' . $objref . '.pdf';
+ $filedir = $conf->hrm->dir_output . '/' . $object->element . '/' . $objref;
+ $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
+ $genallowed = $user->rights->hrm->job->read; // If you can read, you can build the PDF to read content
+ $delallowed = $user->rights->hrm->job->write; // If you can create/edit, you can remove a file on card
+ print $formfile->showdocuments('hrm:Job', $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('job'));
+ $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
+
+
+ print '
';
+
+ $MAXEVENT = 10;
+
+ $morehtmlright = '
';
+ $morehtmlright .= $langs->trans("SeeAll");
+ $morehtmlright .= ' ';
+
+ // 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 . '@' . $object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlright);
+
+ print '
';
+ }
+
+ // Presend form
+ $modelmail = 'job';
+ $defaulttopic = 'InformationMessage';
+ $diroutput = $conf->hrm->dir_output;
+ $trackid = 'job' . $object->id;
+
+ include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php';
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/job_contact.php b/htdocs/hrm/job_contact.php
new file mode 100644
index 00000000000..cbc961d3f9e
--- /dev/null
+++ b/htdocs/hrm/job_contact.php
@@ -0,0 +1,220 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 job_contact.php
+ * \ingroup hrm
+ * \brief Tab for contacts linked to Job
+ */
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "companies", "other", "mails"));
+
+$id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
+$ref = GETPOST('ref', 'alpha');
+$lineid = GETPOST('lineid', 'int');
+$socid = GETPOST('socid', 'int');
+$action = GETPOST('action', 'aZ09');
+
+// Initialize technical objects
+$object = new Job($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('jobcontact', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+
+$permission = $user->rights->hrm->job->write;
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+//if (empty($conf->hrm->enabled)) accessforbidden();
+//if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Add a new contact
+ */
+
+if ($action == 'addcontact' && $permission) {
+ $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
+ $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
+ $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
+
+ if ($result >= 0) {
+ header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+ exit;
+ } else {
+ if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
+ $langs->load("errors");
+ setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
+ } else {
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
+ }
+} elseif ($action == 'swapstatut' && $permission) {
+ // Toggle the status of a contact
+ $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
+} elseif ($action == 'deletecontact' && $permission) {
+ // Deletes a contact
+ $result = $object->delete_contact($lineid);
+
+ if ($result >= 0) {
+ header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+ exit;
+ } else {
+ dol_print_error($db);
+ }
+}
+
+
+/*
+ * View
+ */
+
+$title = $langs->trans('Job')." - ".$langs->trans('ContactsAddresses');
+$help_url = '';
+//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
+llxHeader('', $title, $help_url);
+
+$form = new Form($db);
+$formcompany = new FormCompany($db);
+$contactstatic = new Contact($db);
+$userstatic = new User($db);
+
+
+/* *************************************************************************** */
+/* */
+/* View and edit mode */
+/* */
+/* *************************************************************************** */
+
+if ($object->id) {
+ /*
+ * Show tabs
+ */
+ $head = jobPrepareHead($object);
+
+ print dol_get_fiche_head($head, 'contact', '', -1, $object->picto);
+
+ $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->projet->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, 1, 1);
+ $morehtmlref.='
';
+ } else {
+ $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
+ }
+ } else {
+ if (! empty($object->fk_project)) {
+ $proj = new Project($db);
+ $proj->fetch($object->fk_project);
+ $morehtmlref .= ': '.$proj->getNomUrl();
+ } else {
+ $morehtmlref .= '';
+ }
+ }
+ }*/
+ $morehtmlref .= '
';
+
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
+
+ print dol_get_fiche_end();
+
+ print ' ';
+
+ // Contacts lines (modules that overwrite templates must declare this into descriptor)
+ $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
+ foreach ($dirtpls as $reldir) {
+ $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
+ if ($res) {
+ break;
+ }
+ }
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/job_document.php b/htdocs/hrm/job_document.php
new file mode 100644
index 00000000000..a32f02915e9
--- /dev/null
+++ b/htdocs/hrm/job_document.php
@@ -0,0 +1,219 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 job_document.php
+ * \ingroup hrm
+ * \brief Tab for documents linked to Job
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "companies", "other", "mails"));
+
+
+$action = GETPOST('action', 'aZ09');
+$confirm = GETPOST('confirm');
+$id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int'));
+$ref = GETPOST('ref', 'alpha');
+
+// Get parameters
+$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
+$sortfield = GETPOST("sortfield", 'alpha');
+$sortorder = GETPOST("sortorder", 'alpha');
+$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
+if (empty($page) || $page == -1) {
+ $page = 0;
+} // If $page is not defined, or '' or -1
+$offset = $liste_limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+if (!$sortorder) {
+ $sortorder = "ASC";
+}
+if (!$sortfield) {
+ $sortfield = "name";
+}
+//if (! $sortfield) $sortfield="position_name";
+
+// Initialize technical objects
+$object = new Job($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('jobdocument', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+
+if ($id > 0 || !empty($ref)) {
+ $upload_dir = $conf->hrm->multidir_output[$object->entity ? $object->entity : $conf->entity]."/job/".get_exdir(0, 0, 0, 1, $object);
+}
+
+$permissiontoread = $user->rights->hrm->all->read;
+$permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+$title = $langs->trans("Job").' - '.$langs->trans("Files");
+$help_url = '';
+//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
+llxHeader('', $title, $help_url);
+
+if ($object->id) {
+ /*
+ * Show tabs
+ */
+ $head = jobPrepareHead($object);
+
+ print dol_get_fiche_head($head, 'document', $langs->trans("Document"), -1, $object->picto);
+
+
+ // Build file list
+ $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
+ $totalsize = 0;
+ foreach ($filearray as $key => $file) {
+ $totalsize += $file['size'];
+ }
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = ''.$langs->trans("BackToList").' ';
+
+ $morehtmlref = '';
+ $morehtmlref.= $object->label;
+ $morehtmlref .= '
';
+
+ dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
+
+ print '';
+
+ print '
';
+ print '
';
+
+ // Number of files
+ print ''.$langs->trans("NbOfAttachedFiles").' '.count($filearray).' ';
+
+ // Total size
+ print ''.$langs->trans("TotalSizeOfAttachedFiles").' '.$totalsize.' '.$langs->trans("bytes").' ';
+
+ print '
';
+
+ print '
';
+
+ print dol_get_fiche_end();
+
+ $modulepart = 'hrm';
+ //$permissiontoadd = $user->rights->hrm->job->write;
+ //$permtoedit = $user->rights->hrm->job->write;
+ $permtoedit = $permissiontoadd;
+ $param = '&id='.$object->id;
+
+ //$relativepathwithnofile='job/' . dol_sanitizeFileName($object->id).'/';
+ $relativepathwithnofile = 'job/'.dol_sanitizeFileName($object->ref).'/';
+
+ include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
+} else {
+ accessforbidden('', 0, 1);
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/job_list.php b/htdocs/hrm/job_list.php
new file mode 100644
index 00000000000..fdf2de51d45
--- /dev/null
+++ b/htdocs/hrm/job_list.php
@@ -0,0 +1,733 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 job_list.php
+ * \ingroup hrm
+ * \brief List page for job
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
+
+// load hrm libraries
+require_once __DIR__.'/class/job.class.php';
+
+// for other modules
+//dol_include_once('/othermodule/class/otherobject.class.php');
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "other"));
+
+$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
+$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
+$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
+$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
+$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
+$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
+$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'joblist'; // To manage different context of search
+$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
+$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
+
+$id = GETPOST('id', 'int');
+
+// Load variable for pagination
+$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
+$sortfield = GETPOST('sortfield', 'aZ09comma');
+$sortorder = GETPOST('sortorder', 'aZ09comma');
+$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
+if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
+ // If $page is not defined, or '' or -1 or if we click on clear filters
+ $page = 0;
+}
+$offset = $limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+
+// Initialize technical objects
+$object = new Job($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('joblist')); // Note that conf->hooks_modules contains array
+
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+//$extrafields->fetch_name_optionals_label($object->table_element_line);
+
+$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
+
+// Default sort order (if not yet defined by previous GETPOST)
+if (!$sortfield) {
+ reset($object->fields); // Reset is required to avoid key() to return null.
+ $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
+}
+if (!$sortorder) {
+ $sortorder = "ASC";
+}
+
+// Initialize array of search criterias
+$search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
+$search = array();
+foreach ($object->fields as $key => $val) {
+ if (GETPOST('search_'.$key, 'alpha') !== '') {
+ $search[$key] = GETPOST('search_'.$key, 'alpha');
+ }
+ if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
+ $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
+ $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
+ }
+}
+
+// List of fields to search into when doing a "search in all"
+$fieldstosearchall = array();
+foreach ($object->fields as $key => $val) {
+ if (!empty($val['searchall'])) {
+ $fieldstosearchall['t.'.$key] = $val['label'];
+ }
+}
+
+// Definition of array of fields for columns
+$arrayfields = array();
+foreach ($object->fields as $key => $val) {
+ // If $val['visible']==0, then we never show the field
+ if (!empty($val['visible'])) {
+ $visible = (int) dol_eval($val['visible'], 1);
+ $arrayfields['t.'.$key] = array(
+ 'label'=>$val['label'],
+ 'checked'=>(($visible < 0) ? 0 : 1),
+ 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)),
+ 'position'=>$val['position'],
+ 'help'=> isset($val['help']) ? $val['help'] : ''
+ );
+ }
+}
+// Extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
+
+$object->fields = dol_sort_array($object->fields, 'position');
+$arrayfields = dol_sort_array($arrayfields, 'position');
+
+$permissiontoread = $user->rights->hrm->all->read;
+$permissiontoadd = $user->rights->hrm->all->write;
+$permissiontodelete = $user->rights->hrm->all->delete;
+
+// Security check
+if (empty($conf->hrm->enabled)) {
+ accessforbidden('Module not enabled');
+}
+
+// Security check (enable the most restrictive one)
+if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) accessforbidden();
+//$socid = 0; if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+
+
+/*
+ * Actions
+ */
+
+if (GETPOST('cancel', 'alpha')) {
+ $action = 'list';
+ $massaction = '';
+}
+if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
+ $massaction = '';
+}
+
+$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)) {
+ // Selection of new fields
+ include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
+
+ // Purge search criteria
+ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
+ foreach ($object->fields as $key => $val) {
+ $search[$key] = '';
+ if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
+ $search[$key.'_dtstart'] = '';
+ $search[$key.'_dtend'] = '';
+ }
+ }
+ $toselect = array();
+ $search_array_options = array();
+ }
+ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
+ || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
+ $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
+ }
+
+ // Mass actions
+ $objectclass = 'Job';
+ $objectlabel = 'Job';
+ $uploaddir = $conf->hrm->dir_output;
+ include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
+}
+
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+$now = dol_now();
+
+//$help_url="EN:Module_Job|FR:Module_Job_FR|ES:Módulo_Job";
+$help_url = '';
+$title = $langs->trans("ListOf", $langs->transnoentities('Jobs'));
+$morejs = array();
+$morecss = array();
+
+
+// Build and execute select
+// --------------------------------------------------------------------
+$sql = 'SELECT ';
+$sql .= $object->getFieldList('t');
+// Add fields from extrafields
+if (!empty($extrafields->attributes[$object->table_element]['label'])) {
+ foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
+ $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key.', ' : '');
+ }
+}
+// Add fields from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
+$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
+$sql = preg_replace('/,\s*$/', '', $sql);
+$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
+if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
+}
+// Add table from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
+$sql .= $hookmanager->resPrint;
+if ($object->ismultientitymanaged == 1) {
+ $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
+} else {
+ $sql .= " WHERE 1 = 1";
+}
+foreach ($search as $key => $val) {
+ if (array_key_exists($key, $object->fields)) {
+ if ($key == 'status' && $search[$key] == -1) {
+ continue;
+ }
+ $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
+ if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
+ if ($search[$key] == '-1' || $search[$key] === '0') {
+ $search[$key] = '';
+ }
+ $mode_search = 2;
+ }
+ if ($search[$key] != '') {
+ $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
+ }
+ } else {
+ if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
+ $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
+ if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
+ if (preg_match('/_dtstart$/', $key)) {
+ $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
+ }
+ if (preg_match('/_dtend$/', $key)) {
+ $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
+ }
+ }
+ }
+ }
+}
+if ($search_all) {
+ $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
+}
+//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
+// Add where from extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
+// Add where from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
+$sql .= $hookmanager->resPrint;
+
+/* If a group by is required
+$sql .= " GROUP BY ";
+foreach($object->fields as $key => $val) {
+ $sql .= "t.".$key.", ";
+}
+// Add fields from extrafields
+if (!empty($extrafields->attributes[$object->table_element]['label'])) {
+ foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
+ $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
+ }
+}
+// Add where from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
+$sql .= $hookmanager->resPrint;
+$sql = preg_replace('/,\s*$/', '', $sql);
+*/
+
+$sql .= $db->order($sortfield, $sortorder);
+
+// Count total nb of records
+$nbtotalofrecords = '';
+if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+ $resql = $db->query($sql);
+ $nbtotalofrecords = $db->num_rows($resql);
+ if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
+ $page = 0;
+ $offset = 0;
+ }
+}
+// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
+if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
+ $num = $nbtotalofrecords;
+} else {
+ if ($limit) {
+ $sql .= $db->plimit($limit + 1, $offset);
+ }
+
+ $resql = $db->query($sql);
+ if (!$resql) {
+ dol_print_error($db);
+ exit;
+ }
+
+ $num = $db->num_rows($resql);
+}
+
+// Direct jump if only one record found
+if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
+ $obj = $db->fetch_object($resql);
+ $id = $obj->rowid;
+ header("Location: ".dol_buildpath('/hrm/job_card.php', 1).'?id='.$id);
+ exit;
+}
+
+
+// Output page
+// --------------------------------------------------------------------
+
+llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
+
+// Example : Adding jquery code
+// print '';
+
+$arrayofselected = is_array($toselect) ? $toselect : array();
+
+$param = '';
+if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+ $param .= '&contextpage='.urlencode($contextpage);
+}
+if ($limit > 0 && $limit != $conf->liste_limit) {
+ $param .= '&limit='.urlencode($limit);
+}
+foreach ($search as $key => $val) {
+ if (is_array($search[$key]) && count($search[$key])) {
+ foreach ($search[$key] as $skey) {
+ $param .= '&search_'.$key.'[]='.urlencode($skey);
+ }
+ } else {
+ $param .= '&search_'.$key.'='.urlencode($search[$key]);
+ }
+}
+if ($optioncss != '') {
+ $param .= '&optioncss='.urlencode($optioncss);
+}
+// Add $param from extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
+// Add $param from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
+$param .= $hookmanager->resPrint;
+
+// List of mass actions available
+$arrayofmassactions = array(
+ //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
+ //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
+ //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
+ //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
+);
+if ($permissiontodelete) {
+ $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
+}
+if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
+ $arrayofmassactions = array();
+}
+$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
+
+print ''."\n";
+
+if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
+ $hidegeneratedfilelistifempty = 1;
+ if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
+ $hidegeneratedfilelistifempty = 0;
+ }
+
+ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
+ $formfile = new FormFile($db);
+
+ // Show list of available documents
+ $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
+ $urlsource .= str_replace('&', '&', $param);
+
+ $filedir = $diroutputmassaction;
+ $genallowed = $permissiontoread;
+ $delallowed = $permissiontoadd;
+
+ print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/job_note.php b/htdocs/hrm/job_note.php
new file mode 100644
index 00000000000..85a1cd1dc84
--- /dev/null
+++ b/htdocs/hrm/job_note.php
@@ -0,0 +1,175 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 job_note.php
+ * \ingroup hrm
+ * \brief Tab for notes on Job
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "companies"));
+
+// Get parameters
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'aZ09');
+$cancel = GETPOST('cancel', 'aZ09');
+$backtopage = GETPOST('backtopage', 'alpha');
+
+// Initialize technical objects
+$object = new Job($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('jobnote', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+if ($id > 0 || !empty($ref)) {
+ $upload_dir = $conf->hrm->multidir_output[$object->entity]."/".$object->id;
+}
+
+$permissiontoread = $user->rights->hrm->all->read;
+$permissionnote = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+$reshook = $hookmanager->executeHooks('doActions', array(), $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)) {
+ include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
+}
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+//$help_url='EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes';
+$help_url = '';
+llxHeader('', $langs->trans('Job'), $help_url);
+
+if ($id > 0 || !empty($ref)) {
+ $object->fetch_thirdparty();
+
+ $head = jobPrepareHead($object);
+
+ print dol_get_fiche_head($head, 'note', $langs->trans("Notes"), -1, $object->picto);
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = ''.$langs->trans("BackToList").' ';
+
+ $morehtmlref = '';
+ $morehtmlref.= $object->label;
+ $morehtmlref .= '
';
+
+
+ dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
+
+
+ print '';
+ print '
';
+
+
+ $cssclass = "titlefield";
+ include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
+
+ print '
';
+
+ print dol_get_fiche_end();
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/lib/hrm.lib.php b/htdocs/hrm/lib/hrm.lib.php
new file mode 100644
index 00000000000..e875f61b9e4
--- /dev/null
+++ b/htdocs/hrm/lib/hrm.lib.php
@@ -0,0 +1,76 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 hrm/lib/hrm.lib.php
+ * \ingroup hr
+ * \brief Library files with common functions for Workstation
+ */
+
+/**
+ * Prepare admin pages header
+ *
+ * @return array
+ */
+function hrmAdminPrepareHead()
+{
+ global $langs, $conf;
+
+ $langs->load("hrm");
+
+ $h = 0;
+ $head = array();
+ $head[$h][0] = DOL_URL_ROOT . "/admin/hrm.php";
+ $head[$h][1] = $langs->trans("Settings");
+ $head[$h][2] = 'settings';
+ $h++;
+
+ $head[$h][0] = DOL_URL_ROOT.'/hrm/admin/admin_establishment.php';
+ $head[$h][1] = $langs->trans("Establishments");
+ $head[$h][2] = 'establishments';
+ $h++;
+
+ /*
+ $head[$h][0] = dol_buildpath("/workstation/admin/myobject_extrafields.php", 1);
+ $head[$h][1] = $langs->trans("ExtraFields");
+ $head[$h][2] = 'myobject_extrafields';
+ $h++;
+ */
+
+ /*$head[$h][0] = require_once "/admin/about.php";
+ $head[$h][1] = $langs->trans("About");
+ $head[$h][2] = 'about';
+ $h++;*/
+
+ // Show more tabs from modules
+ // Entries must be declared in modules descriptor with line
+ //$this->tabs = array(
+ // 'entity:+tabname:Title:@workstation:/workstation/mypage.php?id=__ID__'
+ //); // to add new tab
+ //$this->tabs = array(
+ // 'entity:-tabname:Title:@workstation:/workstation/mypage.php?id=__ID__'
+ //); // to remove a tab
+ complete_head_from_modules($conf, $langs, null, $head, $h, 'hrm_admin');
+
+ complete_head_from_modules($conf, $langs, null, $head, $h, 'hrm_admin', 'remove');
+
+ return $head;
+}
diff --git a/htdocs/hrm/lib/hrm_evaluation.lib.php b/htdocs/hrm/lib/hrm_evaluation.lib.php
new file mode 100644
index 00000000000..87e6b80adaa
--- /dev/null
+++ b/htdocs/hrm/lib/hrm_evaluation.lib.php
@@ -0,0 +1,95 @@
+
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 lib/hrm_evaluation.lib.php
+ * \ingroup hrm
+ * \brief Library files with common functions for Evaluation
+ */
+
+/**
+ * Prepare array of tabs for Evaluation
+ *
+ * @param Evaluation $object Evaluation
+ * @return array Array of tabs
+ */
+function evaluationPrepareHead($object)
+{
+ global $db, $langs, $conf;
+
+ $langs->load("hrm");
+
+ $h = 0;
+ $head = array();
+
+ $head[$h][0] = dol_buildpath("/hrm/evaluation_card.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("EvaluationCard");
+ $head[$h][2] = 'card';
+ $h++;
+
+ if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
+ $nbNote = 0;
+ if (!empty($object->note_private)) {
+ $nbNote++;
+ }
+ if (!empty($object->note_public)) {
+ $nbNote++;
+ }
+ $head[$h][0] = dol_buildpath('/hrm/evaluation_note.php', 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Notes');
+ if ($nbNote > 0) {
+ $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ''.$nbNote.' ' : '');
+ }
+ $head[$h][2] = 'note';
+ $h++;
+ }
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
+ $upload_dir = $conf->hrm->dir_output."/evaluation/".dol_sanitizeFileName($object->ref);
+ $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
+ $nbLinks = Link::count($db, $object->element, $object->id);
+ $head[$h][0] = dol_buildpath("/hrm/evaluation_document.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Documents');
+ if (($nbFiles + $nbLinks) > 0) {
+ $head[$h][1] .= ''.($nbFiles + $nbLinks).' ';
+ }
+ $head[$h][2] = 'document';
+ $h++;
+
+ $head[$h][0] = dol_buildpath("/hrm/evaluation_agenda.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("Events");
+ $head[$h][2] = 'agenda';
+ $h++;
+
+ // Show more tabs from modules
+ // Entries must be declared in modules descriptor with line
+ //$this->tabs = array(
+ // 'entity:+tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to add new tab
+ //$this->tabs = array(
+ // 'entity:-tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to remove a tab
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'evaluation@hrm');
+
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'evaluation@hrm', 'remove');
+
+ return $head;
+}
diff --git a/htdocs/hrm/lib/hrm_job.lib.php b/htdocs/hrm/lib/hrm_job.lib.php
new file mode 100644
index 00000000000..f465d934b0f
--- /dev/null
+++ b/htdocs/hrm/lib/hrm_job.lib.php
@@ -0,0 +1,106 @@
+
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 lib/hrm_job.lib.php
+ * \ingroup hrm
+ * \brief Library files with common functions for Job
+ */
+
+/**
+ * Prepare array of tabs for Job
+ *
+ * @param Job $object Job
+ * @return array Array of tabs
+ */
+function jobPrepareHead($object)
+{
+ global $db, $langs, $conf;
+
+ $langs->load("hrm");
+
+ $h = 0;
+ $head = array();
+
+ $head[$h][0] = dol_buildpath("/hrm/job_card.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("JobCard");
+ $head[$h][2] = 'job_card';
+ $h++;
+
+ $head[$h][0] = dol_buildpath("/hrm/skill_tab.php", 1).'?id='.$object->id.'&objecttype=job';
+ $head[$h][1] = $langs->trans("RequiredSkills");
+ $head[$h][2] = 'skill_tab';
+ $h++;
+
+ $head[$h][0] = dol_buildpath("/hrm/position.php", 1).'?fk_job='.$object->id;
+ $head[$h][1] = $langs->trans("EmployeesInThisPosition");
+ $head[$h][2] = 'position';
+ $h++;
+
+
+ if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
+ $nbNote = 0;
+ if (!empty($object->note_private)) {
+ $nbNote++;
+ }
+ if (!empty($object->note_public)) {
+ $nbNote++;
+ }
+ $head[$h][0] = dol_buildpath('/hrm/job_note.php', 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Notes');
+ if ($nbNote > 0) {
+ $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ''.$nbNote.' ' : '');
+ }
+ $head[$h][2] = 'note';
+ $h++;
+ }
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
+ $upload_dir = $conf->hrm->dir_output."/job/".dol_sanitizeFileName($object->label);
+ $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
+ $nbLinks = Link::count($db, $object->element, $object->id);
+ $head[$h][0] = dol_buildpath("/hrm/job_document.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Documents');
+ if (($nbFiles + $nbLinks) > 0) {
+ $head[$h][1] .= ''.($nbFiles + $nbLinks).' ';
+ }
+ $head[$h][2] = 'document';
+ $h++;
+
+ $head[$h][0] = dol_buildpath("/hrm/job_agenda.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("Events");
+ $head[$h][2] = 'agenda';
+ $h++;
+
+ // Show more tabs from modules
+ // Entries must be declared in modules descriptor with line
+ //$this->tabs = array(
+ // 'entity:+tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to add new tab
+ //$this->tabs = array(
+ // 'entity:-tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to remove a tab
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'job@hrm');
+
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'job@hrm', 'remove');
+
+ return $head;
+}
diff --git a/htdocs/hrm/lib/hrm_position.lib.php b/htdocs/hrm/lib/hrm_position.lib.php
new file mode 100644
index 00000000000..da9a7b3123a
--- /dev/null
+++ b/htdocs/hrm/lib/hrm_position.lib.php
@@ -0,0 +1,96 @@
+
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 lib/hrm_position.lib.php
+ * \ingroup hrm
+ * \brief Library files with common functions for Position
+ */
+
+
+/**
+ * Prepare array of tabs for positions
+ *
+ * @param Position $object Position
+ * @return array Array of tabs
+ */
+function PositionCardPrepareHead($object)
+{
+ global $db, $langs, $conf;
+
+ $langs->load("hrm");
+
+ $h = 0;
+ $head = array();
+
+ $head[$h][0] = dol_buildpath("/hrm/position_card.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("PositionCard");
+ $head[$h][2] = 'position';
+ $h++;
+
+ if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
+ $nbNote = 0;
+ if (!empty($object->note_private)) {
+ $nbNote++;
+ }
+ if (!empty($object->note_public)) {
+ $nbNote++;
+ }
+ $head[$h][0] = dol_buildpath('/hrm/position_note.php', 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Notes');
+ if ($nbNote > 0) {
+ $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ''.$nbNote.' ' : '');
+ }
+ $head[$h][2] = 'note';
+ $h++;
+ }
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
+ $upload_dir = $conf->hrm->dir_output."/position/".dol_sanitizeFileName($object->ref);
+ $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
+ $nbLinks = Link::count($db, $object->element, $object->id);
+ $head[$h][0] = dol_buildpath("/hrm/position_document.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Documents');
+ if (($nbFiles + $nbLinks) > 0) {
+ $head[$h][1] .= ''.($nbFiles + $nbLinks).' ';
+ }
+ $head[$h][2] = 'document';
+ $h++;
+
+ $head[$h][0] = dol_buildpath("/hrm/position_agenda.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("Events");
+ $head[$h][2] = 'agenda';
+ $h++;
+
+ // Show more tabs from modules
+ // Entries must be declared in modules descriptor with line
+ //$this->tabs = array(
+ // 'entity:+tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to add new tab
+ //$this->tabs = array(
+ // 'entity:-tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to remove a tab
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'position@hrm');
+
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'position@hrm', 'remove');
+
+ return $head;
+}
diff --git a/htdocs/hrm/lib/hrm_skill.lib.php b/htdocs/hrm/lib/hrm_skill.lib.php
new file mode 100644
index 00000000000..c9c83fa6411
--- /dev/null
+++ b/htdocs/hrm/lib/hrm_skill.lib.php
@@ -0,0 +1,95 @@
+
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 lib/hrm_skill.lib.php
+ * \ingroup hrm
+ * \brief Library files with common functions for Skill
+ */
+
+/**
+ * Prepare array of tabs for Skill
+ *
+ * @param Skill $object Skill
+ * @return array Array of tabs
+ */
+function skillPrepareHead($object)
+{
+ global $db, $langs, $conf;
+
+ $langs->load("hrm");
+
+ $h = 0;
+ $head = array();
+
+ $head[$h][0] = dol_buildpath("/hrm/skill_card.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("SkillCard");
+ $head[$h][2] = 'card';
+ $h++;
+
+ if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
+ $nbNote = 0;
+ if (!empty($object->note_private)) {
+ $nbNote++;
+ }
+ if (!empty($object->note_public)) {
+ $nbNote++;
+ }
+ $head[$h][0] = dol_buildpath('/hrm/skill_note.php', 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Notes');
+ if ($nbNote > 0) {
+ $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ''.$nbNote.' ' : '');
+ }
+ $head[$h][2] = 'note';
+ $h++;
+ }
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
+ $upload_dir = $conf->hrm->dir_output."/skill/".dol_sanitizeFileName($object->ref);
+ $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
+ $nbLinks = Link::count($db, $object->element, $object->id);
+ $head[$h][0] = dol_buildpath("/hrm/skill_document.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Documents');
+ if (($nbFiles + $nbLinks) > 0) {
+ $head[$h][1] .= ''.($nbFiles + $nbLinks).' ';
+ }
+ $head[$h][2] = 'document';
+ $h++;
+
+ $head[$h][0] = dol_buildpath("/hrm/skill_agenda.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("Events");
+ $head[$h][2] = 'agenda';
+ $h++;
+
+ // Show more tabs from modules
+ // Entries must be declared in modules descriptor with line
+ //$this->tabs = array(
+ // 'entity:+tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to add new tab
+ //$this->tabs = array(
+ // 'entity:-tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to remove a tab
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'skill@hrm');
+
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'skill@hrm', 'remove');
+
+ return $head;
+}
diff --git a/htdocs/hrm/lib/hrm_skilldet.lib.php b/htdocs/hrm/lib/hrm_skilldet.lib.php
new file mode 100644
index 00000000000..df7e1af45fc
--- /dev/null
+++ b/htdocs/hrm/lib/hrm_skilldet.lib.php
@@ -0,0 +1,95 @@
+
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 lib/hrm_skilldet.lib.php
+ * \ingroup hrm
+ * \brief Library files with common functions for Skilldet
+ */
+
+/**
+ * Prepare array of tabs for Skilldet
+ *
+ * @param Skilldet $object Skilldet
+ * @return array Array of tabs
+ */
+function skilldetPrepareHead($object)
+{
+ global $db, $langs, $conf;
+
+ $langs->load("hrm");
+
+ $h = 0;
+ $head = array();
+
+ $head[$h][0] = dol_buildpath("/hrm/skilldet_card.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("Card");
+ $head[$h][2] = 'card';
+ $h++;
+
+ if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
+ $nbNote = 0;
+ if (!empty($object->note_private)) {
+ $nbNote++;
+ }
+ if (!empty($object->note_public)) {
+ $nbNote++;
+ }
+ $head[$h][0] = dol_buildpath('/hrm/skilldet_note.php', 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Notes');
+ if ($nbNote > 0) {
+ $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ''.$nbNote.' ' : '');
+ }
+ $head[$h][2] = 'note';
+ $h++;
+ }
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
+ $upload_dir = $conf->hrm->dir_output."/skilldet/".dol_sanitizeFileName($object->ref);
+ $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
+ $nbLinks = Link::count($db, $object->element, $object->id);
+ $head[$h][0] = dol_buildpath("/hrm/skilldet_document.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Documents');
+ if (($nbFiles + $nbLinks) > 0) {
+ $head[$h][1] .= ''.($nbFiles + $nbLinks).' ';
+ }
+ $head[$h][2] = 'document';
+ $h++;
+
+ $head[$h][0] = dol_buildpath("/hrm/skilldet_agenda.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("Events");
+ $head[$h][2] = 'agenda';
+ $h++;
+
+ // Show more tabs from modules
+ // Entries must be declared in modules descriptor with line
+ //$this->tabs = array(
+ // 'entity:+tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to add new tab
+ //$this->tabs = array(
+ // 'entity:-tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to remove a tab
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'skilldet@hrm');
+
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'skilldet@hrm', 'remove');
+
+ return $head;
+}
diff --git a/htdocs/hrm/lib/hrm_skillrank.lib.php b/htdocs/hrm/lib/hrm_skillrank.lib.php
new file mode 100644
index 00000000000..2aca41504ad
--- /dev/null
+++ b/htdocs/hrm/lib/hrm_skillrank.lib.php
@@ -0,0 +1,159 @@
+
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 lib/hrm_skillrank.lib.php
+ * \ingroup hrm
+ * \brief Library files with common functions for SkillRank
+ */
+
+/**
+ * Prepare array of tabs for SkillRank
+ *
+ * @param SkillRank $object SkillRank
+ * @return array Array of tabs
+ */
+function skillrankPrepareHead($object)
+{
+ global $db, $langs, $conf;
+
+ $langs->load("hrm");
+
+ $h = 0;
+ $head = array();
+
+ $head[$h][0] = dol_buildpath("/hrm/skillrank_card.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("Card");
+ $head[$h][2] = 'card';
+ $h++;
+
+ if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
+ $nbNote = 0;
+ if (!empty($object->note_private)) {
+ $nbNote++;
+ }
+ if (!empty($object->note_public)) {
+ $nbNote++;
+ }
+ $head[$h][0] = dol_buildpath('/hrm/skillrank_note.php', 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Notes');
+ if ($nbNote > 0) {
+ $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ''.$nbNote.' ' : '');
+ }
+ $head[$h][2] = 'note';
+ $h++;
+ }
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
+ $upload_dir = $conf->hrm->dir_output."/skillrank/".dol_sanitizeFileName($object->ref);
+ $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
+ $nbLinks = Link::count($db, $object->element, $object->id);
+ $head[$h][0] = dol_buildpath("/hrm/skillrank_document.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans('Documents');
+ if (($nbFiles + $nbLinks) > 0) {
+ $head[$h][1] .= ''.($nbFiles + $nbLinks).' ';
+ }
+ $head[$h][2] = 'document';
+ $h++;
+
+ $head[$h][0] = dol_buildpath("/hrm/skillrank_agenda.php", 1).'?id='.$object->id;
+ $head[$h][1] = $langs->trans("Events");
+ $head[$h][2] = 'agenda';
+ $h++;
+
+ // Show more tabs from modules
+ // Entries must be declared in modules descriptor with line
+ //$this->tabs = array(
+ // 'entity:+tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to add new tab
+ //$this->tabs = array(
+ // 'entity:-tabname:Title:@hrm:/hrm/mypage.php?id=__ID__'
+ //); // to remove a tab
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'skillrank@hrm');
+
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'skillrank@hrm', 'remove');
+
+ return $head;
+}
+
+/**
+ * Used to print ranks of a skill into several case, view or edit pour js necessary to select a rank
+ *
+ * @param int $selected_rank rank we want to preselect
+ * @param int $fk_skill id of skill we display ranks
+ * @param string $inputname html name of input
+ * @param string $mode view or edit
+ *
+ * @return string string result
+ */
+function displayRankInfos($selected_rank, $fk_skill, $inputname = 'TNote', $mode = 'view')
+{
+ global $db, $conf, $langs;
+
+ require_once DOL_DOCUMENT_ROOT . '/hrm/class/skill.class.php';
+ require_once DOL_DOCUMENT_ROOT . '/hrm/class/skilldet.class.php';
+
+ // On charge les différentes notes possibles pour la compétence $fk_skill
+ $skilldet = new Skilldet($db);
+ $Lines = $skilldet->fetchAll('ASC', 'rank', 0, 0, array('customsql'=>'fk_skill = '.$fk_skill));
+
+ if (empty($Lines)) return $langs->trans('SkillHasNoLines');
+
+ $ret = '0 ';
+
+ foreach ($Lines as $line) {
+ $MaxNumberSkill = isset($conf->global->HRM_MAXRANK) ? $conf->global->HRM_MAXRANK : Skill::DEFAULT_MAX_RANK_PER_SKILL;
+ if ($line->rank > $MaxNumberSkill) {
+ continue;
+ }
+
+ $ret.= ''.$line->rank.' ';
+ }
+
+ if ($mode == 'edit') {
+ $ret.= '
+
+ ';
+ }
+
+ return $ret;
+}
diff --git a/htdocs/hrm/modulebuilder.txt b/htdocs/hrm/modulebuilder.txt
new file mode 100644
index 00000000000..670a1774929
--- /dev/null
+++ b/htdocs/hrm/modulebuilder.txt
@@ -0,0 +1,3 @@
+# DO NOT DELETE THIS FILE MANUALLY
+# File to flag module built using official module template.
+# When this file is present into a module directory, you can edit it with the module builder tool.
\ No newline at end of file
diff --git a/htdocs/hrm/position.php b/htdocs/hrm/position.php
new file mode 100644
index 00000000000..8eec7d0e660
--- /dev/null
+++ b/htdocs/hrm/position.php
@@ -0,0 +1,948 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 position.php
+ * \ingroup hrm
+ * \brief Page to create/edit/view position
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
+$tmp2 = realpath(__FILE__);
+$i = strlen($tmp) - 1;
+$j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--;
+ $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+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 . '/hrm/class/position.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_position.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
+
+$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
+$backtopage = GETPOST('backtopage', 'alpha');
+$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
+$fk_job = GETPOST('fk_job', 'int');
+
+// Get parameters
+$id = GETPOST('fk_job', 'int');
+$fk_job = GETPOST('fk_job', 'int');
+$fk_user = GETPOST('fk_user', 'int');
+//$start_date = date('Y-m-d', GETPOST('date_startyear', 'int').'-'.GETPOST('date_startmonth', 'int').'-'.GETPOST('date_startday', 'int'));
+$start_date = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
+
+$ref = GETPOST('ref', 'alpha');
+$confirm = GETPOST('confirm', 'alpha');
+$cancel = GETPOST('cancel', 'aZ09');
+$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positioncard'; // To manage different context of search
+
+// Initialize technical objects
+$object = new Job($db);
+
+$extrafields = new ExtraFields($db);
+
+$diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
+$hookmanager->initHooks(array('positiontab', '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');
+ }
+}
+
+// Load object
+include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
+
+$permissiontoread = $user->rights->hrm->all->read;
+$permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
+$permissiontodelete = $user->rights->hrm->all->delete;
+$upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1] . '/position';
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
+
+
+/*
+ * 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('/hrm/position_list.php', 1);
+ //$backtopage = dol_buildpath('/hrm/position.php', 1) . '?fk_job=' . ($fk_job > 0 ? $fk_job : '__ID__');
+
+ if (empty($backtopage) || ($cancel && empty($fk_job))) {
+ if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
+ if (empty($fk_job) && (($action != 'add' && $action != 'create') || $cancel)) {
+ $backtopage = $backurlforlist;
+ } else {
+ if ($fk_job > 0) {
+ $backtopage = dol_buildpath('/hrm/position.php', 1) . '?fk_job=' . ($fk_job > 0 ? $fk_job : '__ID__');
+ } else {
+ $backtopage = dol_buildpath('/hrm/position_card.php', 1) . '?id=__ID__';
+ }
+ }
+ }
+ }
+
+ $triggermodname = 'hrm_POSITION_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
+ $job = $object;
+ $object = new Position($db);
+ include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
+}
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "other", 'products'));
+
+$title = $langs->trans("Position");
+$help_url = '';
+llxHeader('', $title, $help_url);
+
+if ($job->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
+ DisplayJob($job);
+ DisplayPositionList();
+}
+
+
+/**
+ * Show the top of the page including informations of a job
+ *
+ * @param Job $object Job object
+ *
+ * @return void
+ */
+function DisplayJob($object)
+{
+ global $conf, $langs, $db, $extrafields, $hookmanager, $action, $backtopage, $backtopageforcancel, $permissiontoadd;
+
+ /*
+ * View
+ *
+ * Put here all code to build page
+ */
+
+ $form = new Form($db);
+ $formfile = new FormFile($db);
+ $formproject = new FormProjets($db);
+
+ if ($backtopage) {
+ print ' ';
+ }
+ if ($backtopageforcancel) {
+ print ' ';
+ }
+
+ // Part to show record
+
+ $res = $object->fetch_optionals();
+
+ $head = jobPrepareHead($object);
+ print dol_get_fiche_head($head, 'position', $langs->trans("Workstation"), -1, $object->picto);
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = '' . $langs->trans("BackToList") . ' ';
+
+ $morehtmlref = '';
+ $morehtmlref.= $object->label;
+ $morehtmlref .= '
';
+
+ dol_banner_tab($object, 'fk_job', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
+
+
+ print '';
+ print '
';
+ print '
';
+ print '
' . "\n";
+
+ // Common attributes
+ //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
+ //unset($object->fields['fk_project']); // Hide field already shown in banner
+ //unset($object->fields['fk_soc']); // Hide field already shown in banner
+ $object->fields['label']['visible']=0; // Already 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();
+}
+
+
+/**
+ * Show a list of positions for the current job
+ *
+ * @return void
+ */
+function DisplayPositionList()
+{
+ global $user, $langs, $db, $conf, $extrafields, $hookmanager, $permissiontoadd, $permissiontodelete;
+
+ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
+
+ // load hrm libraries
+ require_once __DIR__ . '/class/position.class.php';
+
+ // for other modules
+ //dol_include_once('/othermodule/class/otherobject.class.php');
+
+ $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
+ $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
+ $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
+ $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
+ $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
+ $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
+ $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positionlist'; // To manage different context of search
+ $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
+ $id = GETPOST('id', 'int');
+ $fk_job = GETPOST('fk_job', 'int');
+
+ // Load variable for pagination
+ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
+ $sortfield = GETPOST('sortfield', 'aZ09comma');
+ $sortorder = GETPOST('sortorder', 'aZ09comma');
+ $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
+ if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
+ // If $page is not defined, or '' or -1 or if we click on clear filters
+ $page = 0;
+ }
+ $offset = $limit * $page;
+ $pageprev = $page - 1;
+ $pagenext = $page + 1;
+
+ // Initialize technical objects
+ $object = new Position($db);
+
+ $extrafields = new ExtraFields($db);
+ $diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
+ $hookmanager->initHooks(array('positiontablist')); // Note that conf->hooks_modules contains array
+
+ // Fetch optionals attributes and labels
+ $extrafields->fetch_name_optionals_label($object->table_element);
+ //$extrafields->fetch_name_optionals_label($object->table_element_line);
+
+ $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
+
+ // Default sort order (if not yet defined by previous GETPOST)
+ if (!$sortfield) {
+ reset($object->fields); // Reset is required to avoid key() to return null.
+ $sortfield = "t." . key($object->fields); // Set here default search field. By default 1st field in definition.
+ }
+ if (!$sortorder) {
+ $sortorder = "ASC";
+ }
+
+ // Initialize array of search criterias
+ $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
+ $search = array();
+ foreach ($object->fields as $key => $val) {
+ if (GETPOST('search_' . $key, 'alpha') !== '') {
+ $search[$key] = GETPOST('search_' . $key, 'alpha');
+ }
+ if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
+ $search[$key . '_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_' . $key . '_dtstartmonth', 'int'), GETPOST('search_' . $key . '_dtstartday', 'int'), GETPOST('search_' . $key . '_dtstartyear', 'int'));
+ $search[$key . '_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_' . $key . '_dtendmonth', 'int'), GETPOST('search_' . $key . '_dtendday', 'int'), GETPOST('search_' . $key . '_dtendyear', 'int'));
+ }
+ }
+
+ // List of fields to search into when doing a "search in all"
+ $fieldstosearchall = array();
+ foreach ($object->fields as $key => $val) {
+ if (!empty($val['searchall'])) {
+ $fieldstosearchall['t.' . $key] = $val['label'];
+ }
+ }
+
+ // Definition of array of fields for columns
+ $arrayfields = array();
+ foreach ($object->fields as $key => $val) {
+ // If $val['visible']==0, then we never show the field
+ if (!empty($val['visible'])) {
+ $visible = (int) dol_eval($val['visible'], 1);
+ $arrayfields['t.' . $key] = array(
+ 'label' => $val['label'],
+ 'checked' => (($visible < 0) ? 0 : 1),
+ 'enabled' => ($visible != 3 && dol_eval($val['enabled'], 1)),
+ 'position' => $val['position'],
+ 'help' => isset($val['help']) ? $val['help'] : ''
+ );
+ }
+ }
+ // Extra fields
+ include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
+
+ $object->fields = dol_sort_array($object->fields, 'position');
+ $arrayfields = dol_sort_array($arrayfields, 'position');
+
+ // Security check
+ if (empty($conf->hrm->enabled)) {
+ accessforbidden('Module not enabled');
+ }
+
+ // Security check (enable the most restrictive one)
+ if ($user->socid > 0) accessforbidden();
+ //if ($user->socid > 0) accessforbidden();
+ //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
+ //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+ //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+ //if (empty($conf->hrm->enabled)) accessforbidden();
+ //if (!$permissiontoread) accessforbidden();
+
+
+ /*
+ * Actions
+ */
+
+ if (GETPOST('cancel', 'alpha')) {
+ $action = 'list';
+ $massaction = '';
+ }
+ if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
+ $massaction = '';
+ }
+
+ $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)) {
+ // Selection of new fields
+ include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
+
+ // Purge search criteria
+ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
+ foreach ($object->fields as $key => $val) {
+ $search[$key] = '';
+ if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
+ $search[$key . '_dtstart'] = '';
+ $search[$key . '_dtend'] = '';
+ }
+ }
+ $toselect = array();
+ $search_array_options = array();
+ }
+ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
+ || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
+ $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
+ }
+
+ // Mass actions
+ $objectclass = 'Position';
+ $objectlabel = 'Position';
+ $uploaddir = $conf->hrm->dir_output;
+ include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php';
+ }
+
+
+ /*
+ * View
+ */
+
+ $form = new Form($db);
+
+ $now = dol_now();
+
+ //$help_url="EN:Module_Position|FR:Module_Position_FR|ES:Módulo_Position";
+ $help_url = '';
+ $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("Positions"));
+ $morejs = array();
+ $morecss = array();
+
+
+ // Build and execute select
+ // --------------------------------------------------------------------
+ $sql = 'SELECT ';
+ $sql .= $object->getFieldList('t');
+ // Add fields from extrafields
+ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
+ foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
+ $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef." . $key . " as options_" . $key . ', ' : '');
+ }
+ }
+ // Add fields from hooks
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
+ $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
+ $sql = preg_replace('/,\s*$/', '', $sql);
+ $sql .= " FROM " . MAIN_DB_PREFIX . $object->table_element . " as t";
+ if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
+ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
+ }
+ // Add table from hooks
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
+ $sql .= $hookmanager->resPrint;
+ if ($object->ismultientitymanaged == 1) {
+ $sql .= " WHERE t.entity IN (" . getEntity($object->element) . ")";
+ } else {
+ $sql .= " WHERE 1 = 1";
+ }
+ $sql .= " AND t.fk_job = " . ((int) $fk_job) . " ";
+
+ foreach ($search as $key => $val) {
+ if (array_key_exists($key, $object->fields)) {
+ if ($key == 'status' && $search[$key] == -1) {
+ continue;
+ }
+ $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
+ if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
+ if ($search[$key] == '-1' || $search[$key] === '0') {
+ $search[$key] = '';
+ }
+ $mode_search = 2;
+ }
+ if ($search[$key] != '') {
+ $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
+ }
+ } else {
+ if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
+ $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
+ if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
+ if (preg_match('/_dtstart$/', $key)) {
+ $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
+ }
+ if (preg_match('/_dtend$/', $key)) {
+ $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
+ }
+ }
+ }
+ }
+ }
+ if ($search_all) {
+ $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
+ }
+ //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
+ // Add where from extra fields
+ include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
+ // Add where from hooks
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
+ $sql .= $hookmanager->resPrint;
+
+ /* If a group by is required
+ $sql .= " GROUP BY ";
+ foreach($object->fields as $key => $val) {
+ $sql .= "t.".$key.", ";
+ }
+ // Add fields from extrafields
+ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
+ foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
+ $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
+ }
+ }
+ // Add where from hooks
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
+ $sql .= $hookmanager->resPrint;
+ $sql = preg_replace('/,\s*$/', '', $sql);
+ */
+
+ $sql .= $db->order($sortfield, $sortorder);
+
+ // Count total nb of records
+ $nbtotalofrecords = '';
+ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+ $resql = $db->query($sql);
+ $nbtotalofrecords = $db->num_rows($resql);
+ if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
+ $page = 0;
+ $offset = 0;
+ }
+ }
+ // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
+ if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
+ $num = $nbtotalofrecords;
+ } else {
+ if ($limit) {
+ $sql .= $db->plimit($limit + 1, $offset);
+ }
+
+ $resql = $db->query($sql);
+ if (!$resql) {
+ dol_print_error($db);
+ exit;
+ }
+
+ $num = $db->num_rows($resql);
+ }
+
+ // Direct jump if only one record found
+ if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
+ $obj = $db->fetch_object($resql);
+ $id = $obj->rowid;
+ header("Location: " . dol_buildpath('/hrm/position.php', 1) . '?id=' . $id);
+ exit;
+ }
+
+ $arrayofselected = is_array($toselect) ? $toselect : array();
+
+ $param = 'fk_job=' . $fk_job;
+ if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+ $param .= '&contextpage=' . urlencode($contextpage);
+ }
+ if ($limit > 0 && $limit != $conf->liste_limit) {
+ $param .= '&limit=' . urlencode($limit);
+ }
+ foreach ($search as $key => $val) {
+ if (is_array($search[$key]) && count($search[$key])) {
+ foreach ($search[$key] as $skey) {
+ $param .= '&search_' . $key . '[]=' . urlencode($skey);
+ }
+ } else {
+ $param .= '&search_' . $key . '=' . urlencode($search[$key]);
+ }
+ }
+ if ($optioncss != '') {
+ $param .= '&optioncss=' . urlencode($optioncss);
+ }
+ // Add $param from extra fields
+ include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
+ // Add $param from hooks
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
+ $param .= $hookmanager->resPrint;
+
+ // List of mass actions available
+ $arrayofmassactions = array(
+ //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
+ //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
+ //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
+ //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
+ );
+ if ($permissiontodelete) {
+ $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"') . $langs->trans("Delete");
+ }
+ if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
+ $arrayofmassactions = array();
+ }
+ $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
+
+ print '' . "\n";
+
+ if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
+ $hidegeneratedfilelistifempty = 1;
+ if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
+ $hidegeneratedfilelistifempty = 0;
+ }
+
+ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
+ $formfile = new FormFile($db);
+
+ // Show list of available documents
+ $urlsource = $_SERVER['PHP_SELF'] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder;
+ $urlsource .= str_replace('&', '&', $param);
+
+ $filedir = $diroutputmassaction;
+ $genallowed = $permissiontoread;
+ $delallowed = $permissiontoadd;
+
+ print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
+ }
+}
+
+// Part to create
+if ($action == 'create') {
+ $object = new Position($db);
+ print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Position")), '', 'object_' . $object->picto);
+
+ print '';
+
+ //dol_set_focus('input[name="ref"]');
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/position_agenda.php b/htdocs/hrm/position_agenda.php
new file mode 100644
index 00000000000..670ec51304b
--- /dev/null
+++ b/htdocs/hrm/position_agenda.php
@@ -0,0 +1,282 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 position_agenda.php
+ * \ingroup hrm
+ * \brief Tab of events on Position
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--; $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/hrm/class/position.class.php';
+require_once DOL_DOCUMENT_ROOT.'/hrm/lib/hrm_position.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
+
+
+// Load translation files required by the page
+$langs->loadLangs(array("hrm", "other"));
+
+// Get parameters
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'aZ09');
+$cancel = GETPOST('cancel', 'aZ09');
+$backtopage = GETPOST('backtopage', 'alpha');
+
+if (GETPOST('actioncode', 'array')) {
+ $actioncode = GETPOST('actioncode', 'array', 3);
+ if (!count($actioncode)) {
+ $actioncode = '0';
+ }
+} else {
+ $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
+}
+$search_agenda_label = GETPOST('search_agenda_label');
+
+$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
+$sortfield = GETPOST("sortfield", 'alpha');
+$sortorder = GETPOST("sortorder", 'alpha');
+$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
+if (empty($page) || $page == -1) {
+ $page = 0;
+} // If $page is not defined, or '' or -1
+$offset = $limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+if (!$sortfield) {
+ $sortfield = 'a.datep,a.id';
+}
+if (!$sortorder) {
+ $sortorder = 'DESC,DESC';
+}
+
+// Initialize technical objects
+$object = new Position($db);
+$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('positionagenda', 'globalcard')); // Note that conf->hooks_modules contains array
+// Fetch optionals attributes and labels
+$extrafields->fetch_name_optionals_label($object->table_element);
+
+// Load object
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
+if ($id > 0 || !empty($ref)) {
+ $upload_dir = $conf->hrm->multidir_output[$object->entity]."/".$object->id;
+}
+
+$permissiontoread = $user->rights->hrm->all->read;
+$permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+$parameters = array('id'=>$id);
+$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)) {
+ // Cancel
+ if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
+ header("Location: ".$backtopage);
+ exit;
+ }
+
+ // Purge search criteria
+ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
+ $actioncode = '';
+ $search_agenda_label = '';
+ }
+}
+
+
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+
+if ($object->id > 0) {
+ $title = $langs->trans("Agenda");
+ //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
+ $help_url = 'EN:Module_Agenda_En';
+ llxHeader('', $title, $help_url);
+
+ if (!empty($conf->notification->enabled)) {
+ $langs->load("mails");
+ }
+ $head = PositionCardPrepareHead($object);
+
+
+ print dol_get_fiche_head($head, 'agenda', $langs->trans("Agenda"), -1, $object->picto);
+
+ // Object card
+ // ------------------------------------------------------------
+ $linkback = ''.$langs->trans("BackToList").' ';
+
+ $morehtmlref = '';
+ $u_position = new User(($db));
+ $u_position->fetch($object->fk_user);
+ $morehtmlref .= $langs->trans('Employee').' : '.$u_position->getNomUrl(1);
+ $job = new Job($db);
+ $job->fetch($object->fk_job);
+ $morehtmlref .= ' '.$langs->trans('Job').' : '.$job->getNomUrl(1);
+ $morehtmlref .= '
';
+
+
+ dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
+
+ print '';
+ print '
';
+
+ $object->info($object->id);
+ dol_print_object_info($object, 1);
+
+ print '
';
+
+ print dol_get_fiche_end();
+
+
+
+ // Actions buttons
+
+ $objthirdparty = $object;
+ $objcon = new stdClass();
+
+ $out = '&origin='.urlencode($object->element.'@'.$object->module).'&originid='.urlencode($object->id);
+ $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
+ $out .= '&backtopage='.urlencode($urlbacktopage);
+ $permok = $user->rights->agenda->myactions->create;
+ if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
+ //$out.='trans("AddAnAction"),'filenew');
+ //$out.=" ";
+ }
+
+
+ print '';
+
+ if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
+ $param = '&id='.$object->id.'&socid='.$socid;
+ if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+ $param .= '&contextpage='.urlencode($contextpage);
+ }
+ if ($limit > 0 && $limit != $conf->liste_limit) {
+ $param .= '&limit='.urlencode($limit);
+ }
+
+
+ //print load_fiche_titre($langs->trans("ActionsOnPosition"), '', '');
+
+ // List of all actions
+ $filters = array();
+ $filters['search_agenda_label'] = $search_agenda_label;
+ $object->fields['label']=array(); // Usefull to get only get agenda events linked to position (this object doesn't need label of ref field, but show_actions_done() needs it to work correctly)
+
+ // TODO Replace this with same code than into list.php
+ show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, $object->module);
+ }
+}
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/hrm/position_card.php b/htdocs/hrm/position_card.php
new file mode 100644
index 00000000000..8cb8ba9de8c
--- /dev/null
+++ b/htdocs/hrm/position_card.php
@@ -0,0 +1,446 @@
+
+ * Copyright (C) 2021 Gauthier VERDOL
+ * Copyright (C) 2021 Greg Rastklan
+ * Copyright (C) 2021 Jean-Pascal BOUDET
+ * Copyright (C) 2021 Grégory BLEMAND
+ *
+ * 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 position_card.php
+ * \ingroup hrm
+ * \brief Page to create/edit/view position
+ */
+
+//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies
+//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
+//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
+
+// Load Dolibarr environment
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
+$tmp2 = realpath(__FILE__);
+$i = strlen($tmp) - 1;
+$j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--;
+ $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+ $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+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 . '/hrm/class/position.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_position.lib.php';
+//dol_include_once('/hrm/position.php');
+
+$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
+$backtopage = GETPOST('backtopage', 'alpha');
+$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
+$id = GETPOST('id', 'int');
+
+// Initialize technical objects
+$form = new Form($db);
+$object = new Position($db);
+$res = $object->fetch($id);
+if ($res < 0) {
+ dol_print_error($db, $object->error);
+}
+
+$permissiontoread = $user->rights->hrm->all->read;
+$permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
+$permissiontodelete = $user->rights->hrm->all->delete;
+$permissiondellink = $user->rights->hrm->all->write; // Used by the include of actions_dellink.inc.php
+$upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1] . '/position';
+
+// Security check (enable the most restrictive one)
+//if ($user->socid > 0) accessforbidden();
+//if ($user->socid > 0) $socid = $user->socid;
+//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
+//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
+if (empty($conf->hrm->enabled)) accessforbidden();
+if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
+
+$langs->loadLangs(array("hrm", "other"));
+
+
+
+// Get parameters
+$id = GETPOST('id', 'int');
+$fk_job = GETPOST('fk_job', 'int');
+
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'aZ09');
+$confirm = GETPOST('confirm', 'alpha');
+$cancel = GETPOST('cancel', 'aZ09');
+$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positioncard'; // To manage different context of search
+$backtopage = GETPOST('backtopage', 'alpha');
+$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
+// $lineid = GETPOST('lineid', 'int');
+
+// Initialize technical objects
+//$object = new Position($db);
+//$res = $object->fetch($id);
+/*if ($res < 0) {
+ dol_print_error($db, &$object->error);
+}*/
+
+$extrafields = new ExtraFields($db);
+
+$diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
+$hookmanager->initHooks(array('positioncard', '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 = 'view';
+}
+
+// Load object
+include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
+
+
+/*
+ * 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('/hrm/position_list.php', 1);
+
+ if (empty($backtopage) || ($cancel && empty($fk_job))) {
+ if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
+ if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
+ $backtopage = $backurlforlist;
+ } else {
+ $backtopage = dol_buildpath('/hrm/position_card.php', 1) . '?id=' . ($id > 0 ? $id : '__ID__');
+ }
+ }
+ }
+
+ $triggermodname = 'hrm_POSITION_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
+ include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
+
+ // 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 == 'set_thirdparty' && $permissiontoadd) {
+ $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
+ }
+ if ($action == 'classin' && $permissiontoadd) {
+ $object->setProject(GETPOST('projectid', 'int'));
+ }
+
+ // Actions to send emails
+ $triggersendname = 'hrm_POSITION_SENTBYMAIL';
+ $autocopy = 'MAIN_MAIL_AUTOCOPY_POSITION_TO';
+ $trackid = 'position' . $object->id;
+ include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
+}
+
+DisplayPositionCard($object);
+
+/**
+ * Show the card of a position
+ *
+ * @param Position $object Position object
+ *
+ * @return void
+ */
+function DisplayPositionCard(&$object)
+{
+
+ global $user, $langs, $db, $conf, $extrafields, $hookmanager, $action, $permissiontoadd, $permissiontodelete;
+
+ $id = $object->id;
+
+ /*
+ * View
+ *
+ * Put here all code to build page
+ */
+
+ $form = new Form($db);
+ $formfile = new FormFile($db);
+ $formproject = new FormProjets($db);
+
+ $title = $langs->trans("Position");
+ $help_url = '';
+ llxHeader('', $title, $help_url);
+
+
+ // Part to edit record
+ if (($id || $ref) && $action == 'edit') {
+ print load_fiche_titre($langs->trans("Position"), '', 'object_' . $object->picto);
+
+ print '';
+ }
+
+
+ // Part to show record
+ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
+ $res = $object->fetch_optionals();
+
+
+ $head = PositionCardPrepareHead($object);
+ print dol_get_fiche_head($head, 'position', $langs->trans("Workstation"), -1, $object->picto);
+
+ $formconfirm = '';
+
+ // Confirmation to delete
+ if ($action == 'delete') {
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeletePosition'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
+ }
+
+ // 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") . ' ';
+ $linkback = '' . $langs->trans("BackToList") . ' ';
+
+ $morehtmlref = '';
+ $u_position = new User(($db));
+ $u_position->fetch($object->fk_user);
+ $morehtmlref .= $langs->trans('Employee').' : '.$u_position->getNomUrl(1);
+ $job = new Job($db);
+ $job->fetch($object->fk_job);
+ $morehtmlref .= ' '.$langs->trans('Job').' : '.$job->getNomUrl(1);
+ $morehtmlref .= '
';
+
+ dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
+
+
+ print '';
+ print '
';
+ print '
';
+ print '
' . "\n";
+
+ // Common attributes
+ //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
+ //unset($object->fields['fk_project']); // Hide field already shown in banner
+ //unset($object->fields['fk_soc']); // Hide field already shown in banner
+ $object->fields['fk_user']['visible']=0; // Already in banner
+ $object->fields['fk_job']['visible']=0; // Already 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();
+
+ /*
+ * Action bar
+ */
+ print '';
+
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
+
+
+ print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
+
+ // Delete (need delete permission, or if draft, just need create/modify permission)
+ print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete);
+ }
+}
+
+//if ($action != 'presend') {
+// $formfile = new FormFile($db);
+// print '
';
+//
+// if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) {
+// print '
'; // ancre
+//
+// /*
+// * Generated documents
+// */
+// $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
+// $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
+// $genallowed = $user->rights->societe->lire;
+// $delallowed = $user->rights->societe->creer;
+//
+// print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
+// }
+//
+//
+// print '
';
+//
+// $MAXEVENT = 10;
+//
+// $morehtmlright = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-list-alt imgforviewmode', DOL_URL_ROOT.'/societe/agenda.php?socid='.$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->id, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
+//
+// print '
';
+//}
+
+
+print '
' . "\n";
+print '