Skip to content

Commit

Permalink
[Session] fix: documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo David committed Aug 25, 2022
1 parent d4e8033 commit eb71b8f
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 54 deletions.
97 changes: 62 additions & 35 deletions core/modules/dolimeet/documents/doc_attendancesheet_odt.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
$usertmp = new User($db);
$contract = new Contrat($db);
$project = new Project($db);
$signatorytmp = new DolimeetSignature($db);
$signatorytmp = $signatorytmp->fetchSignatory('TRAININGSESSION_SESSION_TRAINER', $object->id, $object->type);
if (is_array($signatorytmp) && !empty($signatorytmp)) {
$signatorytmp = array_shift($signatorytmp);
}

$contract->fetch($object->fk_contrat);
$project->fetch($object->fk_project);
Expand All @@ -280,11 +285,28 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
$tmparray['DESESSION'] = dol_print_date($object->date_end, 'dayhour');
$tmparray['DURATION'] = $object->duration;

$tmparray['intervenant_name'] = $signatorytmp->firstname . ' ' . $signatorytmp->lastname;
if (dol_strlen($signatorytmp->signature) > 0) {
$encoded_image = explode(",", $signatorytmp->signature)[1];
$decoded_image = base64_decode($encoded_image);
file_put_contents($tempdir . "signature.png", $decoded_image);
$tmparray['intervenant_signature'] = $tempdir . "signature.png";
} else {
$tmparray['intervenant_signature'] = '';
}

foreach ($tmparray as $key=>$value)
{
try {
if ($key == 'photoDefault' || preg_match('/logo$/', $key)) // Image
if (($key == 'intervenant_signature' || preg_match('/logo$/', $key)) && is_file($value)) // Image
{
$list = getimagesize($value);
$newWidth = 200;
if ($list[0]) {
$ratio = $newWidth / $list[0];
$newHeight = $ratio * $list[1];
dol_imageResizeOrCrop($value, 0, $newWidth, $newHeight);
}
if (file_exists($value)) $odfHandler->setImage($key, $value);
else $odfHandler->setVars($key, $langs->transnoentities('ErrorFileNotFound'), true, 'UTF-8');
}
Expand All @@ -302,6 +324,7 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
dol_syslog($e->getMessage(), LOG_INFO);
}
}

// Replace tags of lines
try
{
Expand All @@ -314,44 +337,47 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
if ( ! empty($signatoriesList) && is_array($signatoriesList)) {
$k = 1;
foreach ($signatoriesList as $objectSignatory) {
$tmparray['attendant_number'] = $k;
$tmparray['attendant_lastname'] = $objectSignatory->lastname;
$tmparray['attendant_firstname'] = $objectSignatory->firstname;
if (dol_strlen($objectSignatory->signature) > 0) {
$encoded_image = explode(",", $objectSignatory->signature)[1];
$decoded_image = base64_decode($encoded_image);
file_put_contents($tempdir . "signature" . $k . ".png", $decoded_image);
$tmparray['attendant_signature'] = $tempdir . "signature" . $k . ".png";
} else {
$tmparray['attendant_signature'] = '';
}
foreach ($tmparray as $key=>$value)
{
try {
if ($key == 'attendant_signature' && is_file($value)) { // Image
$list = getimagesize($value);

$newWidth = 200;
if ($list[0]) {
$ratio = $newWidth / $list[0];
$newHeight = $ratio * $list[1];
dol_imageResizeOrCrop($value, 0, $newWidth, $newHeight);
}
$listlines->setImage($key, $value);
} else if (empty($value)) {
$listlines->setVars($key, $langs->trans('NoData'), true, 'UTF-8');
} else if (!is_array($value)) {
$listlines->setVars($key, html_entity_decode($value, ENT_QUOTES | ENT_HTML5), true, 'UTF-8');
}
if ($objectSignatory->role != "TRAININGSESSION_SESSION_TRAINER") {
$tmparray['attendant_number'] = $k;
$tmparray['attendant_lastname'] = $objectSignatory->lastname;
$tmparray['attendant_firstname'] = $objectSignatory->firstname;
if (dol_strlen($objectSignatory->signature) > 0) {
$encoded_image = explode(",", $objectSignatory->signature)[1];
$decoded_image = base64_decode($encoded_image);
file_put_contents($tempdir . "signature" . $k . ".png", $decoded_image);
$tmparray['attendant_signature'] = $tempdir . "signature" . $k . ".png";
} else {
$tmparray['attendant_signature'] = '';
}
catch (OdfException $e)
foreach ($tmparray as $key=>$value)
{
dol_syslog($e->getMessage(), LOG_INFO);
try {
if ($key == 'attendant_signature' && is_file($value)) { // Image
$list = getimagesize($value);

$newWidth = 200;
if ($list[0]) {
$ratio = $newWidth / $list[0];
$newHeight = $ratio * $list[1];
dol_imageResizeOrCrop($value, 0, $newWidth, $newHeight);
}
$listlines->setImage($key, $value);
} else if (empty($value)) {
$listlines->setVars($key, $langs->trans('NoData'), true, 'UTF-8');
} else if (!is_array($value)) {
$listlines->setVars($key, html_entity_decode($value, ENT_QUOTES | ENT_HTML5), true, 'UTF-8');
}
}
catch (OdfException $e)
{
dol_syslog($e->getMessage(), LOG_INFO);
}
}
$listlines->merge();
dol_delete_file($tempdir . "signature" . $k . ".png");
$k++;
}
$listlines->merge();
dol_delete_file($tempdir . "signature" . $k . ".png");
$k++;

}
$odfHandler->mergeSegment($listlines);

Expand Down Expand Up @@ -417,6 +443,7 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
$odfHandler = null; // Destroy object

$this->result = array('fullpath'=>$file);
dol_delete_file($tempdir . "signature.png");

return 1; // Success
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
$usertmp = new User($db);
$contract = new Contrat($db);
$project = new Project($db);
$signatorytmp = new DolimeetSignature($db);
$signatorytmp = $signatorytmp->fetchSignatory('TRAININGSESSION_SESSION_TRAINER', $object->id, $object->type);
if (is_array($signatorytmp) && !empty($signatorytmp)) {
$signatorytmp = array_shift($signatorytmp);
}

$contract->fetch($object->fk_contrat);
$contract->fetch_optionals();
Expand Down Expand Up @@ -309,22 +314,38 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
$thirdparty = new Societe($db);
$contact->fetch($attendant->element_id);
$thirdparty->fetch($contact->fk_soc);
$tmparray['attendant_company_name'] = $thirdparty->nom;
$tmparray['attendant_company_name'] = $thirdparty->name;
}

$tmparray['trainingsession_name'] = $contract->array_options['options_label'];
$tmparray['trainingsession_company_name'] = $conf->global->MAIN_INFO_SOCIETE_NOM;

$tmparray['sessiontrainer_fullname'] = $object->duration;
$tmparray['sessiontrainer_signature'] = $object->duration;
$tmparray['sessiontrainer_fullname'] = $signatorytmp->firstname . ' ' . $signatorytmp->lastname;

if (dol_strlen($signatorytmp->signature) > 0) {
$encoded_image = explode(",", $signatorytmp->signature)[1];
$decoded_image = base64_decode($encoded_image);
file_put_contents($tempdir . "signature.png", $decoded_image);
$tmparray['sessiontrainer_signature'] = $tempdir . "signature.png";
} else {
$tmparray['sessiontrainer_signature'] = '';
}

$tmparray['document_date'] = dol_print_date(dol_now('tzuser'), 'dayhour');
$tmparray['location'] = $object->duration;

foreach ($tmparray as $key=>$value)
{
try {
if ($key == 'photoDefault' || preg_match('/logo$/', $key)) // Image
if (($key == 'sessiontrainer_signature' || preg_match('/logo$/', $key)) && is_file($value)) // Image
{
$list = getimagesize($value);
$newWidth = 200;
if ($list[0]) {
$ratio = $newWidth / $list[0];
$newHeight = $ratio * $list[1];
dol_imageResizeOrCrop($value, 0, $newWidth, $newHeight);
}
if (file_exists($value)) $odfHandler->setImage($key, $value);
else $odfHandler->setVars($key, $langs->transnoentities('ErrorFileNotFound'), true, 'UTF-8');
}
Expand All @@ -349,10 +370,6 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
foreach ($tmparray as $key=>$value)
{
try {
if ($key == 'attendant_lastname') {
echo '<pre>'; print_r( $value ); echo '</pre>'; exit;

}
$odfHandler->setVars($key, $value, true, 'UTF-8');
}
catch (OdfException $e)
Expand Down
19 changes: 14 additions & 5 deletions core/tpl/session/dolimeet_session_attendants.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
$attendant_id = GETPOST('user_attendant');

if ( ! $error) {
$result = $signatory->setSignatory($object->id, $object->element, 'user', array($attendant_id), strtoupper($object->element).'_SOCIETY_ATTENDANT', 1);
$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);
Expand Down Expand Up @@ -319,6 +320,9 @@

//Society attendants -- Participants de la société
$society_intervenants = $signatory->fetchSignatory(strtoupper($object->element).'_SOCIETY_ATTENDANT', $object->id, $object->element);
$society_trainer = $signatory->fetchSignatory(strtoupper($object->element).'_SESSION_TRAINER', $object->id, $object->element);

$society_intervenants = array_merge($society_intervenants, $society_trainer);

print load_fiche_titre($langs->trans("Attendants"), '', '');

Expand Down Expand Up @@ -352,7 +356,7 @@
print '<tr class="oddeven"><td class="minwidth200">';
print $usertmp->getNomUrl(1);
print '</td><td>';
print $langs->trans("SocietyAttendant") . ' ' . $j;
print $langs->trans($element->role);
print '</td><td class="center">';
if ($object->status == 2) {
$signatureUrl = dol_buildpath('/custom/dolimeet/public/signature/add_signature.php?track_id=' . $element->signature_url . '&type=' . $object->element, 3);
Expand Down Expand Up @@ -401,8 +405,13 @@
print '<tr class="oddeven"><td class="maxwidth200">';
print $form->select_dolusers('', 'user_attendant', 1, $already_added_users);
print '</td>';
print '<td>' . $langs->trans("SocietyAttendant") . '</td>';
print '<td class="center">';
print '<td>';
print '<select id="attendantRole" name="attendantRole">';
print '<option value="society_attendant">' . $langs->trans("SocietyAttendant") . '</option>';
print '<option value="session_trainer">' . $langs->trans("SessionTrainer") . '</option>';
print '</select>';
print ajax_combobox('attendantRole');
print '</td><td class="center">';
print '-';
print '</td><td class="center">';
print '-';
Expand Down Expand Up @@ -459,7 +468,7 @@
print '</td><td>';
print $contact->getNomUrl(1);
print '</td><td>';
print $langs->trans("ExtSocietyIntervenant") . ' ' . $j;
print $langs->trans("ExtSocietyIntervenant");
print '</td><td class="center">';
if ($object->status == 2) {
$signatureUrl = dol_buildpath('/custom/dolimeet/public/signature/add_signature.php?track_id=' . $element->signature_url . '&type=' . $object->element, 3);
Expand Down
12 changes: 7 additions & 5 deletions core/tpl/session/dolimeet_session_card.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,13 @@
$signatoriesList = $signatory->fetchSignatories($object->id, $object->type);
if (!empty($signatoriesList)) {
foreach($signatoriesList as $objectSignatory) {
$moreparams['attendant'] = $objectSignatory;
$result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
if ($result <= 0) {
setEventMessages($object->error, $object->errors, 'errors');
$action = '';
if ($objectSignatory->role != 'TRAININGSESSION_SESSION_TRAINER') {
$moreparams['attendant'] = $objectSignatory;
$result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
if ($result <= 0) {
setEventMessages($object->error, $object->errors, 'errors');
$action = '';
}
}
}
if (empty($donotredirect)) {
Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions langs/fr_FR/dolimeet.lang
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ DurationH = Durée (en h)
ContratOpeningHours = Horaires de la formation
ObjectType = Type
Object = Objet
SessionTrainer = Formateur
TRAININGSESSION_SESSION_TRAINER = Formateur
TRAININGSESSION_SOCIETY_ATTENDANT = Participant

#
# Meeting
Expand Down
2 changes: 1 addition & 1 deletion lib/dolimeet_function.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function dolimeetshowdocuments($modulepart, $modulesubdir, $filedir, $urlsource,
$modulepart = $tmp[0];
$submodulepart = $tmp[1];
}
if ($submodulepart == 'trainingsession') {
if ($submodulepart == 'trainingsession' || $submodulepart == 'meeting' || $submodulepart == 'audit') {
$subtype = $submodulepart;
$submodulepart = 'session';
}
Expand Down

0 comments on commit eb71b8f

Please sign in to comment.