Debug event organization module

This commit is contained in:
Laurent Destailleur 2021-09-16 17:46:47 +02:00
parent 424ddcb218
commit bfe305dc47
2 changed files with 74 additions and 33 deletions

View File

@ -55,6 +55,7 @@ $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always ''
$id = GETPOST('id', 'int');
$projectid = GETPOST('projectid', 'int');
$projectref = GETPOST('ref');
// Load variable for pagination
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
@ -152,12 +153,12 @@ if (!$permissiontoread) accessforbidden();
* Actions
*/
if (preg_match('/^set/', $action) && $projectid > 0 && !empty($user->rights->eventorganization->write)) {
if (preg_match('/^set/', $action) && ($projectid > 0 || $projectref) && !empty($user->rights->eventorganization->write)) {
$project = new Project($db);
//If "set" fields keys is in projects fields
$project_attr=preg_replace('/^set/', '', $action);
if (array_key_exists($project_attr, $project->fields)) {
$result = $project->fetch($projectid);
$result = $project->fetch($projectid, $projectref);
if ($result < 0) {
setEventMessages(null, $project->errors, 'errors');
} else {
@ -234,11 +235,13 @@ $now = dol_now();
$help_url = '';
$title = $langs->trans('ListOfConferencesOrBooths');
if ($projectid > 0) {
if ($projectid > 0 || $projectref) {
$project = new Project($db);
$result = $project->fetch($projectid);
$result = $project->fetch($projectid, $projectref);
if ($result < 0) {
setEventMessages(null, $project->errors, 'errors');
} else {
$projectid = $project->id;
}
$result = $project->fetch_thirdparty();
if ($result < 0) {
@ -430,8 +433,8 @@ if ($projectid > 0) {
print $form->textwithpicto($langs->trans("SuggestOrVoteForConfOrBooth"), $langs->trans("EvntOrgRegistrationHelpMessage"));
//print '</span>';
print '</td><td>';
$linksuggest = $dolibarr_main_url_root.'/public/project/index.php?id='.$project->id;
$encodedsecurekey = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'conferenceorbooth'.$project->id, 'md5');
$linksuggest = $dolibarr_main_url_root.'/public/project/index.php?id='.((int) $project->id);
$encodedsecurekey = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'conferenceorbooth'.((int) $project->id), 'md5');
$linksuggest .= '&securekey='.urlencode($encodedsecurekey);
//print '<div class="urllink">';
//print '<input type="text" value="'.$linksuggest.'" id="linkregister" class="quatrevingtpercent paddingrightonly">';
@ -447,8 +450,8 @@ if ($projectid > 0) {
print $langs->trans("PublicAttendeeSubscriptionGlobalPage");
//print '</span>';
print '</td><td>';
$link_subscription = $dolibarr_main_url_root.'/public/eventorganization/attendee_register.php?id='.$project->id.'&type=global';
$encodedsecurekey = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'conferenceorbooth'.$project->id, 'md5');
$link_subscription = $dolibarr_main_url_root.'/public/eventorganization/attendee_register.php?id='.((int) $project->id).'&type=global';
$encodedsecurekey = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'conferenceorbooth'.((int) $project->id), 'md5');
$link_subscription .= '&securekey='.urlencode($encodedsecurekey);
//print '<div class="urllink">';
//print '<input type="text" value="'.$linkregister.'" id="linkregister" class="quatrevingtpercent paddingrightonly">';
@ -582,7 +585,7 @@ if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit
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('/eventorganization/conferenceorbooth_card.php', 1).'?id='.$id);
header("Location: ".DOL_URL_ROOT.'/eventorganization/conferenceorbooth_card.php?id='.((int) $id));
exit;
}

View File

@ -64,6 +64,7 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
global $dolibarr_main_instance_unique_id;
global $dolibarr_main_url_root;
@ -293,7 +294,9 @@ if (empty($reshook) && $action == 'add' && (!empty($conference->id) && $conferen
exit;
}
$resultfetchthirdparty = -1;
$resultfetchthirdparty = 0;
$genericcompanyname = $langs->trans('EventParticipant').' '.$email; // Keep this label simple so we can retreive same thirdparty for another event
// Getting the thirdparty or creating it
$thirdparty = new Societe($db);
@ -303,36 +306,66 @@ if (empty($reshook) && $action == 'add' && (!empty($conference->id) && $conferen
$resultfetchthirdparty = $thirdparty->fetch($confattendee->fk_soc);
} else {
if (empty($conf->global->EVENTORGANIZATION_DISABLE_RETREIVE_THIRDPARTY_FROM_NAME)) {
// Fetch using the input field by user if we just created the attendee
if (!empty($societe)) {
// Fetch using the field input by end user if we have just created the attendee
if ($resultfetchthirdparty <= 0 && !empty($societe)) {
$resultfetchthirdparty = $thirdparty->fetch('', $societe, '', '', '', '', '', '', '', '', $email);
if ($resultfetchthirdparty <= 0) {
// Try to find the thirdparty from the contact
$resultfetchcontact = $contact->fetch('', null, '', $email);
if ($resultfetchcontact <= 0 || $contact->fk_soc <= 0) {
// Need to create a new one (not found or multiple with the same name/email)
$resultfetchthirdparty = 0;
} else {
$thirdparty->fetch($contact->fk_soc);
$confattendee->fk_soc = $thirdparty->id;
$confattendee->update($user);
$resultfetchthirdparty = 1;
}
} else {
// We found a unique result with that name/email, so we set the fk_soc of attendee
if ($resultfetchthirdparty > 0) {
// We found a unique result with the name + email, so we set the fk_soc of attendee
$confattendee->fk_soc = $thirdparty->id;
$confattendee->update($user);
}
} else {
// Need to create a thirdparty (put number>0 if we do not want to create a thirdparty for free-conferences)
$resultfetchthirdparty = 0;
}
} else {
// Need to create a thirdparty (put number>0 if we do not want to create a thirdparty for free-conferences)
$resultfetchthirdparty = 0;
if ($resultfetchthirdparty <= 0 && !empty($genericcompanyname)) {
// Try to find thirdparty from the generic mail only
$resultfetchthirdparty = $thirdparty->fetch('', $genericcompanyname, '', '', '', '', '', '', '', '', '');
if ($resultfetchthirdparty > 0) {
// We found a unique result with that name + email, so we set the fk_soc of attendee
$confattendee->fk_soc = $thirdparty->id;
$confattendee->update($user);
}
}
if ($resultfetchthirdparty <= 0 && !empty($email)) {
// Try to find thirdparty from the email only
$resultfetchthirdparty = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $email);
if ($resultfetchthirdparty > 0) {
// We found a unique result with that email only, so we set the fk_soc of attendee
$confattendee->fk_soc = $thirdparty->id;
$confattendee->update($user);
}
}
// TODO Add more tests on a VAT number, profid or a name ?
if ($resultfetchthirdparty <= 0 && !empty($email)) {
// Try to find the thirdparty from the contact
$resultfetchcontact = $contact->fetch('', null, '', $email);
if ($resultfetchcontact > 0 && $contact->fk_soc > 0) {
$thirdparty->fetch($contact->fk_soc);
$confattendee->fk_soc = $thirdparty->id;
$confattendee->update($user);
$resultfetchthirdparty = 1;
}
}
if ($resultfetchthirdparty <= 0 && !empty($societe)) {
// Try to find thirdparty from the company name only
$resultfetchthirdparty = $thirdparty->fetch('', $societe, '', '', '', '', '', '', '', '', '');
if ($resultfetchthirdparty > 0) {
// We found a unique result with that name only, so we set the fk_soc of attendee
$confattendee->fk_soc = $thirdparty->id;
$confattendee->update($user);
} elseif ($resultfetchthirdparty == -2) {
$thirdparty->error = "ErrorSeveralCompaniesWithNameContactUs";
}
}
}
}
// If price is empty, no need to create a thirdparty, so we force $resultfetchthirdparty as if we have already found thirdp party.
if (empty(floatval($project->price_registration))) {
$resultfetchthirdparty = 1;
}
if ($resultfetchthirdparty < 0) {
$error++;
$errmsg .= $thirdparty->error;
@ -341,7 +374,7 @@ if (empty($reshook) && $action == 'add' && (!empty($conference->id) && $conferen
if (!empty($societe)) {
$thirdparty->name = $societe;
} else {
$thirdparty->name = $email;
$thirdparty->name = $genericcompanyname;
}
$thirdparty->address = GETPOST("address");
$thirdparty->zip = GETPOST("zipcode");
@ -387,6 +420,11 @@ if (empty($reshook) && $action == 'add' && (!empty($conference->id) && $conferen
if (!$error) {
if (!empty(floatval($project->price_registration))) {
$outputlangs = $langs;
// TODO Use default language of $thirdparty->default_lang to build $outputlang