vote page ok

This commit is contained in:
Dorian Vabre 2021-05-07 12:21:15 +02:00
parent 166e15633b
commit 27cffbddf3
3 changed files with 67 additions and 7 deletions

View File

@ -98,10 +98,8 @@ EvntOrgCancelled = Cancelled
#
SuggestForm = Suggestion page
RegisterPage = Page for conferences or booth
EvntOrgRegistrationWelcomeMessage = Welcome on the conference or booth suggestion page.
EvntOrgRegistrationConfHelpMessage = Here, you can suggest a new conference for the project
EvntOrgRegistrationBoothHelpMessage = Here, you can suggest a new booth for the project
EvntOrgVoteHelpMessage = Here, you can view and vote for the suggested events for the project
ListOfSuggestedConferences = List of suggested conferences
ListOfSuggestedBooths = List of suggested booths
SuggestConference = Suggest a new conference
@ -114,6 +112,16 @@ EvntOrgDuration = This conference starts on %s and ends on %s.
ConferenceAttendeeFee = Conference attendee fee for the event : '%s' occurring from %s to %s.
BoothLocationFee = Booth location for the event : '%s' occurring from %s to %s
EventType = Event type
#
# Vote page
#
EvntOrgRegistrationWelcomeMessage = Welcome on the conference or booth suggestion page.
EvntOrgVoteHelpMessage = Here, you can view and vote for the suggested events for the project
VoteOk = Your vote has been accepted.
AlreadyVoted = You have already voted for this event.
VoteError = An error has occurred during the vote, please try again.
#
# SubscriptionOk page
#

View File

@ -1068,7 +1068,6 @@ if ($ispaymentok) {
$ispostactionok = -1;
}
} elseif (array_key_exists('BOO', $tmptag) && $tmptag['BOO'] > 0) {
// @todo BOOTH CASE (to copy and adapt from above)
// Record payment
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$object = new Facture($db);

View File

@ -70,7 +70,7 @@ $hookmanager = new HookManager($db);
$hookmanager->initHooks(array('newpayment'));
// For encryption
global $dolibarr_main_instance_unique_id;
global $dolibarr_main_instance_unique_id, $dolibarr_main_url_root;
// Load translation files
$langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "paybox", "paypal", "stripe")); // File with generic data
@ -88,6 +88,14 @@ if ($securekeytocompare != $securekeyreceived) {
exit;
}
if (GETPOST("votestatus")=="ok") {
setEventMessage($langs->trans("VoteOk"), 'mesgs');
} else if (GETPOST("votestatus")=="ko") {
setEventMessage($langs->trans("AlreadyVoted"), 'warnings');
} else if (GETPOST("votestatus")=="err") {
setEventMessage($langs->trans("VoteError"), 'warnings');
}
// Define $urlwithroot
//$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
//$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
@ -120,7 +128,6 @@ $sql = "SELECT a.id, a.fk_action, a.datep, a.datep2, a.label, a.fk_soc, a.note,
$sqlforconf = $sql." AND ca.module='conference@eventorganization'";
$sqlforbooth = $sql." AND ca.module='booth@eventorganization'";
// For conferences
$result = $db->query($sqlforconf);
$i = 0;
@ -133,7 +140,7 @@ while ($i < $db->num_rows($result)) {
$thirdpartyname = '';
}
$listOfConferences .= '<tr><td>'.$obj->label.'</td><td>'.$obj->libelle.'</td><td>'.$obj->datep.'</td><td>'.$obj->datep2.'</td><td>'.$thirdpartyname.'</td><td>'.$obj->note.'</td>';
$listOfConferences .= '<td><input type="submit" value="'.$langs->trans("Vote").'" name="'.$obj->id.'" class="button"></td></tr>';
$listOfConferences .= '<td><button type="submit" name="vote" value="'.$obj->id.'" class="button">'.$langs->trans("Vote").'</button></td></tr>';
$i++;
}
@ -149,10 +156,56 @@ while ($i < $db->num_rows($result)) {
$thirdpartyname = '';
}
$listOfBooths .= '<tr><td>'.$obj->label.'</td><td>'.$obj->libelle.'</td><td>'.$obj->datep.'</td><td>'.$obj->datep2.'</td><td>'.$thirdpartyname.'</td><td>'.$obj->note.'</td>';
$listOfBooths .= '<td><input type="submit" value="'.$langs->trans("Vote").'" name="'.$obj->id.'" class="button"></td></tr>';
$listOfBooths .= '<td><button type="submit" name="vote" value="'.$obj->id.'" class="button">'.$langs->trans("Vote").'</button></td></tr>';
$i++;
}
// Get vote result
$idvote = GETPOST("vote");
$hashedvote = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'vote'.$idvote);
if (strlen($idvote)) {
if ($_COOKIE['VOTE_SUGGESTED_EVENTS_'.$hashedvote]==1) {
// Has already voted
$votestatus = 'ko';
} else {
// Has not already voted
$conforbooth = new ActionComm($db);
$resultconforbooth = $conforbooth->fetch($idvote);
if ($resultconforbooth<=0) {
$error++;
$errmsg .= $conforbooth->error;
} else {
// Cookie expiration date : start of event, or 30 days if not specified
$startdate = $conforbooth->datep;
if (strlen($startdate)) {
$timeleftbeforestartofevent = $startdate;
} else {
// Cookie duration by default
$timeleftbeforestartofevent = time()+86400*30;
}
// Process to vote
$res = setcookie('VOTE_SUGGESTED_EVENTS_'.$hashedvote, 1, 0);
if ($res) {
$conforbooth->num_vote++;
$resupdate = $conforbooth->update($user);
if ($resupdate) {
$votestatus = 'ok';
} else {
//Error during update
$votestatus = 'err';
$res = setcookie('VOTE_SUGGESTED_EVENTS_'.$hashedvote, 0, 0);
}
} else {
$votestatus = 'err';
}
}
}
header("Refresh:0;url=".dol_buildpath('/public/project/viewandvote.php?votestatus='.$votestatus.'&id='.$id.'&securekey=', 1).$securekeyreceived);
}
/*
* View
*/