dolibarr 23.0.3
viewandvote.php
1<?php
2/* Copyright (C) 2021 Dorian Vabre <dorian.vabre@gmail.com>
3 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26if (!defined('NOLOGIN')) {
27 define("NOLOGIN", 1); // This means this output page does not require to be logged.
28}
29if (!defined('NOCSRFCHECK')) {
30 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
31}
32if (!defined('NOIPCHECK')) {
33 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
34}
35if (!defined('NOBROWSERNOTIF')) {
36 define('NOBROWSERNOTIF', '1');
37}
38
39// For MultiCompany module.
40// Do not use GETPOST here, function is not defined and get of entity must be done before including main.inc.php
41// Because 2 entities can have the same ref.
42$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : (!empty($_GET['e']) ? (int) $_GET['e'] : (!empty($_POST['e']) ? (int) $_POST['e'] : 1))));
43if (is_numeric($entity)) {
44 define("DOLENTITY", $entity);
45}
46
47// Load Dolibarr environment
48require '../../main.inc.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
50require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
51require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
52require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
53require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
54require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
55require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
56require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
57
67// Hook to be used by external payment modules (ie Payzen, ...)
68$hookmanager = new HookManager($db);
69
70$hookmanager->initHooks(array('newpayment'));
71
72// For encryption
74
75// Load translation files
76$langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "paypal", "stripe")); // File with generic data
77
78// Security check
79// No check on module enabled. Done later according to $validpaymentmethod
80
81$errmsg = '';
82$error = 0;
83$action = GETPOST('action', 'aZ09');
84$id = GETPOST('id');
85$securekeyreceived = GETPOST("securekey");
86$securekeytocompare = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY') . 'conferenceorbooth'.((int) $id), 'md5');
87
88if ($securekeytocompare != $securekeyreceived) {
89 print $langs->trans('MissingOrBadSecureKey');
90 exit;
91}
92
93$listofvotes = explode(',', $_SESSION["savevotes"]);
94
95
96// Define $urlwithroot
97//$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
98//$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
99$urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
100
101$project = new Project($db);
102$resultproject = $project->fetch((int) $id);
103if ($resultproject < 0) {
104 $error++;
105 $errmsg .= $project->error;
106}
107
108// Security check
109if (!isModEnabled('eventorganization')) {
110 httponly_accessforbidden('Module Event organization not enabled');
111}
112
113
114/*
115 * Actions
116 */
117
118$tmpthirdparty = new Societe($db);
119
120$listOfConferences = '<tr><td>'.$langs->trans('Label').'</td>';
121$listOfConferences .= '<td>'.$langs->trans('Type').'</td>';
122$listOfConferences .= '<td>'.$langs->trans('ThirdParty').'</td>';
123$listOfConferences .= '<td>'.$langs->trans('Note').'</td></tr>';
124
125$sql = "SELECT a.id, a.fk_action, a.datep, a.datep2, a.label, a.fk_soc, a.note, ca.libelle as label
126 FROM ".MAIN_DB_PREFIX."actioncomm as a
127 INNER JOIN ".MAIN_DB_PREFIX."c_actioncomm as ca ON (a.fk_action = ca.id)
128 WHERE a.status < 2";
129
130$sqlforconf = $sql." AND ca.module='conference@eventorganization'";
131//$sqlforbooth = $sql." AND ca.module='booth@eventorganization'";
132
133// For conferences
134$result = $db->query($sqlforconf);
135$i = 0;
136while ($i < $db->num_rows($result)) {
137 $obj = $db->fetch_object($result);
138 if (!empty($obj->fk_soc)) {
139 $resultthirdparty = $tmpthirdparty->fetch($obj->fk_soc);
140 if ($resultthirdparty) {
141 $thirdpartyname = $tmpthirdparty->name;
142 } else {
143 $thirdpartyname = '';
144 }
145 } else {
146 $thirdpartyname = '';
147 }
148
149 $listOfConferences .= '<tr><td>'.$obj->label.'</td><td>'.$obj->label.'</td><td>'.$thirdpartyname.'</td><td>'.$obj->note.'</td>';
150 $listOfConferences .= '<td><button type="submit" name="vote" value="'.$obj->id.'" class="button">'.$langs->trans("Vote").'</button></td></tr>';
151 $i++;
152}
153
154// For booths
155/*
156$result = $db->query($sqlforbooth);
157$i = 0;
158while ($i < $db->num_rows($result)) {
159 $obj = $db->fetch_object($result);
160 if (!empty($obj->fk_soc)) {
161 $resultthirdparty = $tmpthirdparty->fetch($obj->fk_soc);
162 if ($resultthirdparty) {
163 $thirdpartyname = $tmpthirdparty->name;
164 } else {
165 $thirdpartyname = '';
166 }
167 } else {
168 $thirdpartyname = '';
169 }
170
171 $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>';
172 $listOfBooths .= '<td><button type="submit" name="vote" value="'.$obj->id.'" class="button">'.$langs->trans("Vote").'</button></td></tr>';
173 $i++;
174}
175*/
176
177// Get vote result
178$idvote = GETPOSTINT("vote");
179$hashedvote = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY').'vote'.$idvote);
180
181if ($idvote > 0) {
182 $votestatus = 'err';
183 if (in_array($hashedvote, $listofvotes)) {
184 // Has already voted
185 $votestatus = 'ko';
186 } else {
187 // Has not already voted
188 $conforbooth = new ActionComm($db);
189 $resultconforbooth = $conforbooth->fetch($idvote);
190 if ($resultconforbooth <= 0) {
191 $error++;
192 $errmsg .= $conforbooth->error;
193 } else {
194 // Process to vote
195 $conforbooth->num_vote++;
196 $resupdate = $conforbooth->update($user);
197 if ($resupdate) {
198 $votestatus = 'ok';
199 $_SESSION["savevotes"] = $hashedvote.','.(empty($_SESSION["savevotes"]) ? '' : $_SESSION["savevotes"]); // Save voter
200 } else {
201 //Error during update
202 $votestatus = 'err';
203 }
204 }
205 }
206 if ($votestatus == "ok") {
207 setEventMessage($langs->trans("VoteOk"), 'mesgs');
208 } elseif ($votestatus == "ko") {
209 setEventMessage($langs->trans("AlreadyVoted"), 'warnings');
210 } elseif ($votestatus == "err") {
211 setEventMessage($langs->trans("VoteError"), 'warnings');
212 }
213 header("Refresh:0;url=".dol_buildpath('/public/project/viewandvote.php?id='.$id.'&securekey=', 1).$securekeyreceived);
214 exit;
215}
216
217
218/*
219 * View
220 */
221
222$head = '';
223if (getDolGlobalString('ONLINE_PAYMENT_CSS_URL')) {
224 $head = '<link rel="stylesheet" type="text/css" href="' . getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'?lang='.$langs->defaultlang.'">'."\n";
225}
226
227$conf->dol_hide_topmenu = 1;
228$conf->dol_hide_leftmenu = 1;
229
230$replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
231llxHeader($head, $langs->trans("SuggestForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
232
233print '<span id="dolpaymentspan"></span>'."\n";
234print '<div class="center">'."\n";
235print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
236print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
237print '<input type="hidden" name="action" value="dopayment">'."\n";
238print '<input type="hidden" name="tag" value="'.GETPOST("tag", 'alpha').'">'."\n";
239//print '<input type="hidden" name="suffix" value="'.dol_escape_htmltag($suffix).'">'."\n";
240print '<input type="hidden" name="id" value="'.dol_escape_htmltag($id).'">'."\n";
241print '<input type="hidden" name="securekey" value="'.dol_escape_htmltag($securekeyreceived).'">'."\n";
242print '<input type="hidden" name="e" value="'.$entity.'" />';
243//print '<input type="hidden" name="forcesandbox" value="'.GETPOSTINT('forcesandbox').'" />';
244print "\n";
245
246
247// Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
248// Define logo and logosmall
249$logosmall = $mysoc->logo_small;
250$logo = $mysoc->logo;
251$paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
252if (getDolGlobalString($paramlogo)) {
253 $logosmall = getDolGlobalString($paramlogo);
254} elseif (getDolGlobalString('ONLINE_PAYMENT_LOGO')) {
255 $logosmall = getDolGlobalString('ONLINE_PAYMENT_LOGO');
256}
257//print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
258// Define urllogo
259$urllogo = '';
260$urllogofull = '';
261if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
262 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
263 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
264} elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
265 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
266 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
267}
268
269// Output html code for logo
270if ($urllogo) {
271 print '<div class="backgreypublicpayment">';
272 print '<div class="logopublicpayment">';
273 print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
274 print '>';
275 print '</div>';
276 if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
277 print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img class="poweredbyimg" src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
278 }
279 print '</div>';
280}
281
282if (getDolGlobalString('PROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH')) {
283 print '<div class="backimagepublicsuggestbooth">';
284 print '<img id="idPROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH" src="' . getDolGlobalString('PROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH').'">';
285 print '</div>';
286}
287
288print '<table id="welcome" class="center">'."\n";
289$text = '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("EvntOrgRegistrationWelcomeMessage").'</strong></td></tr>'."\n";
290$text .= '<tr><td class="textpublicpayment">'.$langs->trans("EvntOrgVoteHelpMessage").' : "'.dol_escape_htmltag($project->title).'".<br><br></td></tr>'."\n";
291$text .= '<tr><td class="textpublicpayment">'.dol_htmlentitiesbr($project->note_public).'</td></tr>'."\n";
292print $text;
293print '</table>'."\n";
294
295
296print '<table cellpadding="10" id="conferences" border="1" class="center">'."\n";
297print '<th colspan="7">'.$langs->trans("ListOfSuggestedConferences").'</th>';
298print $listOfConferences.'<br>';
299print '</table>'."\n";
300
301/*
302print '<br>';
303
304print '<table border=1 cellpadding="10" id="conferences" class="center">'."\n";
305print '<th colspan="7">'.$langs->trans("ListOfSuggestedBooths").'</th>';
306print $listOfBooths.'<br>';
307print '</table>'."\n";
308*/
309
310$object = null;
311
312htmlPrintOnlineFooter($mysoc, $langs, 1, $suffix, $object);
313
314llxFooter('', 'public');
315
316$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
global $dolibarr_main_url_root
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage agenda events (actions)
Class to manage hooks.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML public pages.
global $mysoc
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.