Skip to content

Commit

Permalink
#337 [Certificat] clean: view and lib
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Jul 21, 2023
1 parent 4f2b85a commit 9d51543
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 120 deletions.
45 changes: 38 additions & 7 deletions core/modules/modDoliSIRH.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public function __construct($db)

// Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
$this->familyinfo = ['Evarisk' => ['position' => '01', 'label' => $langs->trans('Evarisk')]];
// Module label (no space allowed), used if translation string 'ModuleDoliSMQName' not found (DoliSMQ is name of module).
// Module label (no space allowed), used if translation string 'ModuleDoliSIRHName' not found (DoliSIRH is name of module).
$this->name = preg_replace('/^mod/i', '', get_class($this));

// Module description, used if translation string 'ModuleDoliSMQDesc' not found (DoliSMQ is name of module).
// Module description, used if translation string 'ModuleDoliSIRHDesc' not found (DoliSIRH is name of module).
$this->description = $langs->trans('DoliSIRHDescription');
// Used only if file README.md and README-LL.md not found.
$this->descriptionlong = $langs->trans('DoliSIRHDescriptionLong');
Expand All @@ -83,7 +83,7 @@ public function __construct($db)
// Url to the file with your last numberversion of this module.
//$this->url_last_version = 'http://www.example.com/versionmodule.txt';

// Key used in llx_const table to save module status enabled/disabled (where DOLISMQ is value of property name of module in uppercase).
// Key used in llx_const table to save module status enabled/disabled (where DoliSIRH is value of property name of module in uppercase).
$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);

// Name of image file used for this module.
Expand Down Expand Up @@ -178,8 +178,8 @@ public function __construct($db)

// Constants.
// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive).
// Example: $this->const=array(1 => array('DOLISMQ_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
// 2 => array('DOLISMQ_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
// Example: $this->const=array(1 => array('DoliSIRH_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
// 2 => array('DoliSIRH_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
// );
$i = 0;
$this->const = [
Expand Down Expand Up @@ -244,7 +244,7 @@ public function __construct($db)

// Array to add new pages in new tabs.
// Example:
// $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@dolimeet:$user->rights->othermodule->read:/dolimeet/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
// $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@dolisirh:$user->rights->othermodule->read:/dolisirh/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
// $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove');
$this->tabs = [];
$pictoPath = dol_buildpath('/custom/dolisirh/img/dolisirh_color.png', 1);
Expand Down Expand Up @@ -302,7 +302,7 @@ public function __construct($db)
];

// Boxes/Widgets
// Add here list of php file(s) stored in dolismq/core/boxes that contains a class to show a widget.
// Add here list of php file(s) stored in dolisirh/core/boxes that contains a class to show a widget.
$this->boxes = [];

// Cronjobs (List of cron jobs entries to add when module is enabled).
Expand Down Expand Up @@ -443,6 +443,37 @@ public function __construct($db)
'user' => 0,
];

$this->menu[$r++] = [
'fk_menu' => 'fk_mainmenu=dolisirh',
'type' => 'left',
'titre' => $langs->trans('Certificate'),
'prefix' => '<i class="fas fa-user-graduate pictofixedwidth"></i>',
'mainmenu' => 'dolisirh',
'leftmenu' => 'certificate',
'url' => '/dolisirh/view/certificate/certificate_list.php',
'langs' => 'dolisirh@dolisirh',
'position' => 1000 + $r,
'enabled' => '$conf->dolisirh->enabled',
'perms' => '$user->rights->dolisirh->certificate->read',
'target' => '',
'user' => 0,
];

$this->menu[$r++] = [
'fk_menu' => 'fk_mainmenu=dolisirh,fk_leftmenu=certificate',
'type' => 'left',
'titre' => '<i class="fas fa-tags pictofixedwidth" style="padding-right: 4px;"></i>' . $langs->transnoentities('Categories'),
'mainmenu' => 'dolisirh',
'leftmenu' => 'certificatetags',
'url' => '/categories/index.php?type=certificate',
'langs' => 'dolisirh@dolisirh',
'position' => 1000 + $r,
'enabled' => '$conf->dolisirh->enabled && $conf->categorie->enabled',
'perms' => '$user->rights->dolisirh->lire && $user->rights->dolisirh->certificate->read && $user->rights->categorie->lire',
'target' => '',
'user' => 0,
];

$this->menu[$r++] = [
'fk_menu' => 'fk_mainmenu=dolisirh',
'type' => 'left',
Expand Down
7 changes: 5 additions & 2 deletions lib/dolisirh_certificate.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* \file lib/dolisirh_certificate.lib.php
* \ingroup dolimeet
* \ingroup dolisirh
* \brief Library files with common functions for Certificate.
*/

Expand All @@ -33,5 +33,8 @@
*/
function certificate_prepare_head(Certificate $object): array
{
return saturne_object_prepare_head($object, [], [], true);
$moreParams['documentType'] = 'CertificateDocument';
$moreParams['attendantTableMode'] = 'simple';

return saturne_object_prepare_head($object, [], $moreParams, true);
}
135 changes: 24 additions & 111 deletions view/certificate/certificate_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
die('Include of dolisirh main fails');
}

// Load Saturne Libraries.
// Load Saturne libraries.
require_once __DIR__ . '/../../../saturne/class/saturnesignature.class.php';

// load DoliSIRH libraries.
require_once __DIR__ . '/../../lib/dolisirh_certificate.lib.php';
require_once __DIR__ . '/../../class/certificate.class.php';
require_once __DIR__ . '/../../class/dolisirhdocuments/certificatedocument.class.php';
require_once __DIR__ . '/../../lib/dolisirh_certificate.lib.php';

// Global variables definitions.
global $conf, $db, $hookmanager, $langs, $mysoc, $user;
Expand All @@ -55,10 +55,10 @@
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');

// Initialize technical objects.
$object = new Certificate($db);
$signatory = new SaturneSignature($db);
$certificatedocument = new CertificateDocument($db);
$extrafields = new ExtraFields($db);
$object = new Certificate($db);
$signatory = new SaturneSignature($db, 'dolisirh', $object->element);
$document = new CertificateDocument($db);
$extrafields = new ExtraFields($db);

// Initialize view objects.
$form = new Form($db);
Expand All @@ -72,7 +72,7 @@

// Initialize array of search criterias.
$search_all = GETPOST('search_all', 'alpha');
$search = [];
$search = [];
foreach ($object->fields as $key => $val) {
if (GETPOST('search_'.$key, 'alpha')) {
$search[$key] = GETPOST('search_'.$key, 'alpha');
Expand Down Expand Up @@ -123,99 +123,16 @@
$conf->global->MAIN_DISABLE_PDF_AUTOUPDATE = 1;
include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';

// Action to build doc.
if (($action == 'builddoc' || GETPOST('forcebuilddoc')) && $permissiontoadd) {
$outputlangs = $langs;
$newlang = '';

if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
$newlang = GETPOST('lang_id', 'aZ09');
}
if (!empty($newlang)) {
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($newlang);
}

// To be sure vars is defined
if (empty($hidedetails)){
$hidedetails = 0;
}
if (empty($hidedesc)) {
$hidedesc = 0;
}
if (empty($hideref)) {
$hideref = 0;
}
if (empty($moreparams)) {
$moreparams = null;
}

if (GETPOST('forcebuilddoc')) {
$model = '';
$modellist = saturne_get_list_of_models($db, $object->element . 'document');
if (!empty($modellist)) {
asort($modellist);
$modellist = array_filter($modellist, 'saturne_remove_index');
if (is_array($modellist)) {
$models = array_keys($modellist);
}
}
} else {
$model = GETPOST('model', 'alpha');
}

$moreparams['object'] = $object;
$moreparams['user'] = $user;

if ($object->status < SaturneCertificate::STATUS_ARCHIVED) {
$moreparams['specimen'] = 1;
$moreparams['zone'] = 'private';
} else {
$moreparams['specimen'] = 0;
}
// Actions save_project.
include __DIR__ . '/../../../saturne/core/tpl/actions/edit_project_action.tpl.php';

$result = $certificatedocument->generateDocument((!empty($models) ? $models[0] : $model), $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
if ($result <= 0) {
setEventMessages($certificatedocument->error, $certificatedocument->errors, 'errors');
$action = '';
} elseif (empty($donotredirect)) {
setEventMessages($langs->trans('FileGenerated') . ' - ' . $certificatedocument->last_main_doc, []);
$urltoredirect = $_SERVER['REQUEST_URI'];
$urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect);
$urltoredirect = preg_replace('/action=builddoc&?/', '', $urltoredirect); // To avoid infinite loop
$urltoredirect = preg_replace('/forcebuilddoc=1&?/', '', $urltoredirect); // To avoid infinite loop
header('Location: ' . $urltoredirect . '#builddoc');
exit;
}
}
// Actions builddoc, forcebuilddoc, remove_file.
require_once __DIR__ . '/../../../saturne/core/tpl/documents/documents_action.tpl.php';

// Delete file in doc form.
if ($action == 'remove_file' && $permissiontodelete) {
if (!empty($upload_dir)) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';

$langs->load('other');
$fileToDelete = GETPOST('file', 'alpha');
$file = $upload_dir . '/' . $fileToDelete;
$ret = dol_delete_file($file, 0, 0, 0, $object);
if ($ret) {
setEventMessages($langs->trans('FileWasRemoved', $fileToDelete), []);
} else {
setEventMessages($langs->trans('ErrorFailToDeleteFile', $fileToDelete), [], 'errors');
}

// Make a redirect to avoid to keep the remove_file into the url that create side effects.
$urltoredirect = $_SERVER['REQUEST_URI'];
$urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect);
$urltoredirect = preg_replace('/action=remove_file&?/', '', $urltoredirect);

header('Location: ' . $urltoredirect);
exit;
} else {
setEventMessages('BugFoundVarUploaddirnotDefined', [], 'errors');
}
}
// Action to generate pdf from odt file.
require_once __DIR__ . '/../../../saturne/core/tpl/documents/saturne_manual_pdf_generation_action.tpl.php';

// Action confirm_lock, confirm_archive.
require_once __DIR__ . '/../../../saturne/core/tpl/signature/signature_action_workflow.tpl.php';

// Actions to send emails.
Expand Down Expand Up @@ -259,18 +176,13 @@

$object->fields['fk_project']['default'] = $conf->global->DOLISIRH_HR_PROJECT;

$elementList = [];
if (!empty($conf->user->enabled)) {
if (isModEnabled('user')) {
$object->fields['element_type']['arrayofkeyval']['user'] = $langs->trans('User');
}
if (!empty($conf->societe->enabled)) {
if (isModEnabled('product')) {
$object->fields['element_type']['arrayofkeyval']['product'] = $langs->trans('Product');
} ?>

print '<tr><td class="titlefieldcreate"><label for="element_type">' . $langs->trans('ElementType') . '</label></td>';
print '<td class="valuefieldcreate">' . $form::selectarray('element_type', $elementList, GETPOSTISSET('element_type') ? GETPOST('element_type') : 'user', 1, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx') . '</td>';
print '</tr>';

<script>
$(document).ready(function(){
$('#element_type').on('change', function(){
Expand Down Expand Up @@ -333,10 +245,10 @@

print '<table class="border centpercent tableforfieldedit">';

if (!empty($conf->user->enabled)) {
if (isModEnabled('user')) {
$object->fields['element_type']['arrayofkeyval']['user'] = $langs->trans('User');
}
if (!empty($conf->societe->enabled)) {
if (isModEnabled('product')) {
$object->fields['element_type']['arrayofkeyval']['product'] = $langs->trans('Product');
} ?>

Expand Down Expand Up @@ -392,11 +304,12 @@

$formconfirm = '';

// setDraft confirmation
// setDraft confirmation.
if (($action == 'draft' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) {
$formconfirm .= $form->formconfirm($_SERVER['PHP_SELF'] . '?id=' . $object->id . '&object_type=' . $object->element, $langs->trans('ReOpenObject', $langs->transnoentities('The' . ucfirst($object->element))), $langs->trans('ConfirmReOpenObject', $langs->transnoentities('The' . ucfirst($object->element)), $langs->transnoentities('The' . ucfirst($object->element))), 'confirm_setdraft', '', 'yes', 'actionButtonInProgress', 350, 600);
}
// setPendingSignature confirmation

// setPendingSignature confirmation.
if (($action == 'pending_signature' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) {
$formconfirm .= $form->formconfirm($_SERVER['PHP_SELF'] . '?id=' . $object->id . '&object_type=' . $object->element, $langs->trans('ValidateObject', $langs->transnoentities('The' . ucfirst($object->element))), $langs->trans('ConfirmValidateObject', $langs->transnoentities('The' . ucfirst($object->element)), $langs->transnoentities('The' . ucfirst($object->element))), 'confirm_validate', '', 'yes', 'actionButtonPendingSignature', 350, 600);
}
Expand All @@ -406,16 +319,16 @@
$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?id=' . $object->id, $langs->trans('DeleteObject', $langs->transnoentities('The' . ucfirst($object->element))), $langs->trans('ConfirmDeleteObject', $langs->transnoentities('The' . ucfirst($object->element))), 'confirm_delete', '', 'yes', 1);
}

// Call Hook formConfirm
// Call Hook formConfirm.
$parameters = ['formConfirm' => $formconfirm];
$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$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 form confirm.
print $formconfirm;

print '<div class="fichecenter">';
Expand Down

0 comments on commit 9d51543

Please sign in to comment.