Skip to content

Commit

Permalink
#116 [Signature] add: remove object for Saturne integration
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Jan 26, 2023
1 parent 8c1327a commit 1b25dc2
Show file tree
Hide file tree
Showing 54 changed files with 5 additions and 6,969 deletions.
2 changes: 2 additions & 0 deletions class/session.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Session extends CommonObject
const STATUS_SENT_BY_MAIL = 4;
const STATUS_RECEIVED_BY_MAIL_AND_SIGNED = 5;
const STATUS_RECEIVED_BY_LETTER_AND_SIGNED = 6;
const STATUS_DRAFT = 0;
const STATUS_VALIDATED = 1;

/**
* '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')
Expand Down
4 changes: 2 additions & 2 deletions core/modules/modDoliMeet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function __construct($db)
// Set this to 1 if module has its own theme directory (theme)
'theme' => 0,
// Set this to relative path of css file if module has its own css file
//'css' => ['/priseo/css/priseo_all.css'],
'css' => [],
// Set this to relative path of js file if module must load a js on all pages
'js' => [],
// Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context to 'all'
Expand Down Expand Up @@ -203,7 +203,7 @@ public function __construct($db)
$this->tabs[] = ['data' => 'contact:+sessionList:' . $picto . 'DoliMeetdolimeet@dolimeet:$user->rights->dolimeet->session->read:/custom/dolimeet/view/session/session_list.php?fromtype=socpeople&fromid=__ID__']; // To add a new tab identified by code tabname1
$this->tabs[] = ['data' => 'project:+sessionList:' . $picto . 'DoliMeetdolimeet@dolimeet:$user->rights->dolimeet->session->read:/custom/dolimeet/view/session/session_list.php?fromtype=project&fromid=__ID__']; // To add a new tab identified by code tabname1
$this->tabs[] = ['data' => 'contract:+sessionList:' . $picto . 'DoliMeetdolimeet@dolimeet:$user->rights->dolimeet->session->read:/custom/dolimeet/view/session/session_list.php?fromtype=contrat&fromid=__ID__']; // To add a new tab identified by code tabname1
$this->tabs[] = ['data' => 'contract:+openinghours:'. $picto . $langs->trans('OpeningHours') . ':dolimeet@dolimeet:$user->rights->contrat->lire:/custom/dolimeet/view/openinghours_card.php?element_type=contrat&id=__ID__']; // To add a new tab identified by code tabname1
$this->tabs[] = ['data' => 'contract:+openinghours:'. $picto . $langs->trans('OpeningHours') . ':dolimeet@dolimeet:$user->rights->contrat->lire:/custom/saturne/view/openinghours_card.php?module_name=DoliMeet&element_type=contrat&id=__ID__']; // To add a new tab identified by code tabname1
// 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:-tabname:NU:conditiontoremove');
Expand Down
277 changes: 0 additions & 277 deletions core/tpl/session/dolimeet_session_attendants.tpl.php
Original file line number Diff line number Diff line change
@@ -1,287 +1,10 @@
<?php
require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php';

$usertmp = new User($db);
$contact = new Contact($db);
$form = new Form($db);
$project = new Project($db);
$thirdparty = new Societe($db);
$contract = new Contrat($db);

$object->fetch($id);

$hookmanager->initHooks(array($object->element.'signature', 'globalcard')); // Note that conf->hooks_modules contains array

//Security check
$object_type = $object->element;
$permissiontoread = $user->rights->dolimeet->$object_type->read;
$permissiontoadd = $user->rights->dolimeet->$object_type->write;
$permissiontodelete = $user->rights->dolimeet->$object_type->delete;

if ( ! $permissiontoread) 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($backtopage) || ($cancel && empty($id))) {
if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
$backtopage = dol_buildpath('/dolimeet/view/'. $object->element .'/' . $object->element .'_attendants.php', 1) . '?id=' . ($object->id > 0 ? $object->id : '__ID__');
}
}

// Action to add internal attendant
if ($action == 'addSocietyAttendant') {
$error = 0;
$object->fetch($id);
$attendant_id = GETPOST('user_attendant');

if ( ! $error) {
$role = strtoupper(GETPOST('attendantRole'));
$result = $signatory->setSignatory($object->id, $object->element, 'user', array($attendant_id), strtoupper($object->element).'_' . $role, $role == 'SESSION_TRAINER' ? 0 : 1);
if ($result > 0) {
$usertmp = $user;
$usertmp->fetch($attendant_id);
setEventMessages($langs->trans('AddAttendantMessage') . ' ' . $usertmp->firstname . ' ' . $usertmp->lastname, array());
// Creation attendant OK
$urltogo = str_replace('__ID__', $result, $backtopage);
$urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation
header("Location: " . $urltogo);
exit;
} else {
// Creation attendant KO
if ( ! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
else setEventMessages($object->error, null, 'errors');
}
}
}

// Action to add external attendant
if ($action == 'addExternalAttendant') {
$error = 0;
$object->fetch($id);
$extintervenant_id = GETPOST('external_attendant');

if ( ! $error) {
$result = $signatory->setSignatory($object->id, $object->element, 'socpeople', array($extintervenant_id), strtoupper($object->element).'_EXTERNAL_ATTENDANT', 1);
if ($result > 0) {
$contact->fetch($extintervenant_id);
setEventMessages($langs->trans('AddAttendantMessage') . ' ' . $contact->firstname . ' ' . $contact->lastname, array());
// Creation attendant OK
$urltogo = str_replace('__ID__', $result, $backtopage);
$urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation
header("Location: " . $urltogo);
exit;
} else {
// Creation attendant KO
if ( ! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
else setEventMessages($object->error, null, 'errors');
}
}
}

// Action to add record
if ($action == 'addSignature') {
$signatoryID = GETPOST('signatoryID');
$data = json_decode(file_get_contents('php://input'), true);

$signatory->fetch($signatoryID);
$signatory->signature = $data['signature'];
$signatory->signature_date = dol_now('tzuser');

if ( ! $error) {
$result = $signatory->update($user, false);

if ($result > 0) {
// Creation signature OK
$signatory->setSigned($user, 0);
setEventMessages($langs->trans('SignatureEvent') . ' ' . $contact->firstname . ' ' . $contact->lastname, array());
$urltogo = str_replace('__ID__', $result, $backtopage);
$urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation
header("Location: " . $urltogo);
exit;
} else {
// Creation signature KO
if ( ! empty($signatory->errors)) setEventMessages(null, $signatory->errors, 'errors');
else setEventMessages($signatory->error, null, 'errors');
}
}
}

// Action to set status STATUS_ABSENT
if ($action == 'setAbsent') {
$signatoryID = GETPOST('signatoryID');

$signatory->fetch($signatoryID);

if ( ! $error) {
$result = $signatory->setAbsent($user, 0);
if ($result > 0) {
// set absent OK
setEventMessages($langs->trans('Attendant') . ' ' . $signatory->firstname . ' ' . $signatory->lastname . ' ' . $langs->trans('SetAbsentAttendant'), array());
$urltogo = str_replace('__ID__', $result, $backtopage);
$urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation
header("Location: " . $urltogo);
exit;
} else {
// set absent KO
if ( ! empty($signatory->errors)) setEventMessages(null, $signatory->errors, 'errors');
else setEventMessages($signatory->error, null, 'errors');
}
}
}

// Action to send Email
if ($action == 'send') {
$signatoryID = GETPOST('signatoryID');
$signatory->fetch($signatoryID);

if ( ! $error) {
$langs->load('mails');

if (!dol_strlen($signatory->email)) {
if ($signatory->element_type == 'user') {
$usertmp = $user;
$usertmp->fetch($signatory->element_id);
if (dol_strlen($usertmp->email)) {
$signatory->email = $usertmp->email;
$signatory->update($user, true);
}
} else if ($signatory->element_type == 'socpeople') {
$contact->fetch($signatory->element_id);
if (dol_strlen($contact->email)) {
$signatory->email = $contact->email;
$signatory->update($user, true);
}
}
}

$sendto = $signatory->email;

if (dol_strlen($sendto) && ( ! empty($conf->global->MAIN_MAIL_EMAIL_FROM))) {
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';

$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
$url = dol_buildpath('/custom/dolimeet/public/signature/add_signature.php?track_id=' . $signatory->signature_url . '&type=' . $object->element, 3);

$message = $langs->trans('SignatureEmailMessage') . ' ' . $url;
$subject = $langs->trans('SignatureEmailSubject') . ' ' . $object->ref;

// Create form object
// Send mail (substitutionarray must be done just before this)
$mailfile = new CMailFile($subject, $sendto, $from, $message, array(), array(), array(), "", "", 0, -1, '', '', '', '', 'mail');

if ($mailfile->error) {
setEventMessages($mailfile->error, $mailfile->errors, 'errors');
} else {
if ( ! empty($conf->global->MAIN_MAIL_SMTPS_ID)) {
$result = $mailfile->sendfile();
if ($result) {
$signatory->last_email_sent_date = dol_now('tzuser');
$signatory->update($user, true);
$signatory->setPending($user, false);
setEventMessages($langs->trans('SendEmailAt') . ' ' . $signatory->email, array());
// This avoid sending mail twice if going out and then back to page
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
exit;
} else {
$langs->load("other");
$mesg = '<div class="error">';
if ($mailfile->error) {
$mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto));
$mesg .= '<br>' . $mailfile->error;
} else {
$mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto));
}
$mesg .= '</div>';
setEventMessages($mesg, null, 'warnings');
}
} else {
setEventMessages($langs->trans('ErrorSetupEmail'), '', 'errors');
}
}
} else {
$langs->load("errors");
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("MailTo")), null, 'warnings');
dol_syslog('Try to send email with no recipient defined', LOG_WARNING);
}
} else {
// Mail sent KO
if ( ! empty($signatory->errors)) setEventMessages(null, $signatory->errors, 'errors');
else setEventMessages($signatory->error, null, 'errors');
}
}

// Action to delete attendant
if ($action == 'deleteAttendant') {
$signatoryToDeleteID = GETPOST('signatoryID');
$signatory->fetch($signatoryToDeleteID);

if ( ! $error) {
$result = $signatory->setDeleted($user, 0);
if ($result > 0) {
setEventMessages($langs->trans('DeleteAttendantMessage') . ' ' . $signatory->firstname . ' ' . $signatory->lastname, array());
// Deletion attendant OK
$urltogo = str_replace('__ID__', $result, $backtopage);
$urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation
header("Location: " . $urltogo);
exit;
} else {
// Deletion attendant KO
if ( ! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
else setEventMessages($object->error, null, 'errors');
}
} else {
$action = 'create';
}
}

/*
* View
*/

$formcompany = new FormCompany($db);
$title = $langs->trans(ucfirst($object->element)."Attendants");
$help_url = '';
$morejs = array("/dolimeet/js/signature-pad.min.js", "/dolimeet/js/dolimeet.js.php");
$morecss = array("/dolimeet/css/dolimeet.css");

llxHeader('', $title, $help_url, '', '', '', $morejs, $morecss);

if ( ! empty($object->id)) $res = $object->fetch_optionals();

// Object card
// ------------------------------------------------------------

$head = sessionPrepareHead($object);
print dol_get_fiche_head($head, 'attendants', $langs->trans(ucfirst($object->element)), -1, $object->picto);

$width = 80; $cssclass = 'photoref';
dol_strlen($object->label) ? $morehtmlref = '<span>' . ' - ' . $object->label . '</span>' : '';
$morehtmlref .= '<div class="refidno">';

// Project
$project->fetch($object->fk_project);
$morehtmlref = '- ' . $object->label;
$morehtmlref .= '<div class="refidno">';
$morehtmlref .= $langs->trans('Project') . ' : ' . $project->getNomUrl(1);
$morehtmlref .= '</tr>';
$morehtmlref .= '</td><br>';
$morehtmlref .= '</div>';

if ($object->element == 'trainingsession') {
$contract->fetch($object->fk_contrat);
$morehtmlref .= '<div class="refidno">';
$morehtmlref .= $langs->trans('Contract') . ' : ' . $contract->getNomUrl(1);
$morehtmlref .= '</tr>';
$morehtmlref .= '</td><br>';
$morehtmlref .= '</div>';
}

//$morehtmlleft = '<div class="floatleft inline-block valignmiddle divphotoref">'.digirisk_show_photos('dolimeet', $conf->dolimeet->multidir_output[$entity].'/'.$object->element_type, 'small', 5, 0, 0, 0, $width,0, 0, 0, 0, $object->element_type, $object).'</div>';

Expand Down
Loading

0 comments on commit 1b25dc2

Please sign in to comment.