dolibarr 23.0.4
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$suffix = GETPOST("suffix", 'aZ09');
86$securekeyreceived = GETPOST("securekey");
87$securekeytocompare = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY') . 'conferenceorbooth'.((int) $id), 'md5');
88
89if ($securekeytocompare != $securekeyreceived) {
90 print $langs->trans('MissingOrBadSecureKey');
91 exit;
92}
93
94$listofvotes = explode(',', $_SESSION["savevotes"]);
95
96
97// Define $urlwithroot
98//$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
99//$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
100$urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
101
102$project = new Project($db);
103$resultproject = $project->fetch((int) $id);
104if ($resultproject < 0) {
105 $error++;
106 $errmsg .= $project->error;
107}
108
109// Security check
110if (!isModEnabled('eventorganization')) {
111 httponly_accessforbidden('Module Event organization not enabled');
112}
113
114
115/*
116 * Actions
117 */
118
119$tmpthirdparty = new Societe($db);
120
121$listOfConferences = '<tr><td>'.$langs->trans('Label').'</td>';
122$listOfConferences .= '<td>'.$langs->trans('Type').'</td>';
123$listOfConferences .= '<td>'.$langs->trans('ThirdParty').'</td>';
124$listOfConferences .= '<td>'.$langs->trans('Note').'</td></tr>';
125
126$sql = "SELECT a.id, a.fk_action, a.datep, a.datep2, a.label, a.fk_soc, a.note, ca.libelle as label
127 FROM ".MAIN_DB_PREFIX."actioncomm as a
128 INNER JOIN ".MAIN_DB_PREFIX."c_actioncomm as ca ON (a.fk_action = ca.id)
129 WHERE a.status < 2";
130
131$sqlforconf = $sql." AND ca.module='conference@eventorganization'";
132//$sqlforbooth = $sql." AND ca.module='booth@eventorganization'";
133
134// For conferences
135$result = $db->query($sqlforconf);
136$i = 0;
137while ($i < $db->num_rows($result)) {
138 $obj = $db->fetch_object($result);
139 if (!empty($obj->fk_soc)) {
140 $resultthirdparty = $tmpthirdparty->fetch($obj->fk_soc);
141 if ($resultthirdparty) {
142 $thirdpartyname = $tmpthirdparty->name;
143 } else {
144 $thirdpartyname = '';
145 }
146 } else {
147 $thirdpartyname = '';
148 }
149
150 $listOfConferences .= '<tr><td>'.$obj->label.'</td><td>'.$obj->label.'</td><td>'.$thirdpartyname.'</td><td>'.$obj->note.'</td>';
151 $listOfConferences .= '<td><button type="submit" name="vote" value="'.$obj->id.'" class="button">'.$langs->trans("Vote").'</button></td></tr>';
152 $i++;
153}
154
155// For booths
156/*
157$result = $db->query($sqlforbooth);
158$i = 0;
159while ($i < $db->num_rows($result)) {
160 $obj = $db->fetch_object($result);
161 if (!empty($obj->fk_soc)) {
162 $resultthirdparty = $tmpthirdparty->fetch($obj->fk_soc);
163 if ($resultthirdparty) {
164 $thirdpartyname = $tmpthirdparty->name;
165 } else {
166 $thirdpartyname = '';
167 }
168 } else {
169 $thirdpartyname = '';
170 }
171
172 $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>';
173 $listOfBooths .= '<td><button type="submit" name="vote" value="'.$obj->id.'" class="button">'.$langs->trans("Vote").'</button></td></tr>';
174 $i++;
175}
176*/
177
178// Get vote result
179$idvote = GETPOSTINT("vote");
180$hashedvote = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY').'vote'.$idvote);
181
182if ($idvote > 0) {
183 $votestatus = 'err';
184 if (in_array($hashedvote, $listofvotes)) {
185 // Has already voted
186 $votestatus = 'ko';
187 } else {
188 // Has not already voted
189 $conforbooth = new ActionComm($db);
190 $resultconforbooth = $conforbooth->fetch($idvote);
191 if ($resultconforbooth <= 0) {
192 $error++;
193 $errmsg .= $conforbooth->error;
194 } else {
195 // Process to vote
196 $conforbooth->num_vote++;
197 $resupdate = $conforbooth->update($user);
198 if ($resupdate) {
199 $votestatus = 'ok';
200 $_SESSION["savevotes"] = $hashedvote.','.(empty($_SESSION["savevotes"]) ? '' : $_SESSION["savevotes"]); // Save voter
201 } else {
202 //Error during update
203 $votestatus = 'err';
204 }
205 }
206 }
207 if ($votestatus == "ok") {
208 setEventMessage($langs->trans("VoteOk"), 'mesgs');
209 } elseif ($votestatus == "ko") {
210 setEventMessage($langs->trans("AlreadyVoted"), 'warnings');
211 } elseif ($votestatus == "err") {
212 setEventMessage($langs->trans("VoteError"), 'warnings');
213 }
214 header("Refresh:0;url=".dol_buildpath('/public/project/viewandvote.php?id='.$id.'&securekey=', 1).$securekeyreceived);
215 exit;
216}
217
218
219/*
220 * View
221 */
222
223$head = '';
224if (getDolGlobalString('ONLINE_PAYMENT_CSS_URL')) {
225 $head = '<link rel="stylesheet" type="text/css" href="' . getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'?lang='.$langs->defaultlang.'">'."\n";
226}
227
228$conf->dol_hide_topmenu = 1;
229$conf->dol_hide_leftmenu = 1;
230
231$replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
232llxHeader($head, $langs->trans("SuggestForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
233
234print '<span id="dolpaymentspan"></span>'."\n";
235print '<div class="center">'."\n";
236print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
237print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
238print '<input type="hidden" name="action" value="dopayment">'."\n";
239print '<input type="hidden" name="tag" value="'.GETPOST("tag", 'alpha').'">'."\n";
240//print '<input type="hidden" name="suffix" value="'.dol_escape_htmltag($suffix).'">'."\n";
241print '<input type="hidden" name="id" value="'.dol_escape_htmltag($id).'">'."\n";
242print '<input type="hidden" name="securekey" value="'.dol_escape_htmltag($securekeyreceived).'">'."\n";
243print '<input type="hidden" name="e" value="'.$entity.'" />';
244//print '<input type="hidden" name="forcesandbox" value="'.GETPOSTINT('forcesandbox').'" />';
245print "\n";
246
247
248// Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
249// Define logo and logosmall
250$logosmall = $mysoc->logo_small;
251$logo = $mysoc->logo;
252$paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
253if (getDolGlobalString($paramlogo)) {
254 $logosmall = getDolGlobalString($paramlogo);
255} elseif (getDolGlobalString('ONLINE_PAYMENT_LOGO')) {
256 $logosmall = getDolGlobalString('ONLINE_PAYMENT_LOGO');
257}
258//print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
259// Define urllogo
260$urllogo = '';
261$urllogofull = '';
262if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
263 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
264 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
265} elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
266 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
267 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
268}
269
270// Output html code for logo
271if ($urllogo) {
272 print '<div class="backgreypublicpayment">';
273 print '<div class="logopublicpayment">';
274 print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
275 print '>';
276 print '</div>';
277 if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
278 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>';
279 }
280 print '</div>';
281}
282
283if (getDolGlobalString('PROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH')) {
284 print '<div class="backimagepublicsuggestbooth">';
285 print '<img id="idPROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH" src="' . getDolGlobalString('PROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH').'">';
286 print '</div>';
287}
288
289print '<table id="welcome" class="center">'."\n";
290$text = '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("EvntOrgRegistrationWelcomeMessage").'</strong></td></tr>'."\n";
291$text .= '<tr><td class="textpublicpayment">'.$langs->trans("EvntOrgVoteHelpMessage").' : "'.dol_escape_htmltag($project->title).'".<br><br></td></tr>'."\n";
292$text .= '<tr><td class="textpublicpayment">'.dol_htmlentitiesbr($project->note_public).'</td></tr>'."\n";
293print $text;
294print '</table>'."\n";
295
296
297print '<table cellpadding="10" id="conferences" border="1" class="center">'."\n";
298print '<th colspan="7">'.$langs->trans("ListOfSuggestedConferences").'</th>';
299print $listOfConferences.'<br>';
300print '</table>'."\n";
301
302/*
303print '<br>';
304
305print '<table border=1 cellpadding="10" id="conferences" class="center">'."\n";
306print '<th colspan="7">'.$langs->trans("ListOfSuggestedBooths").'</th>';
307print $listOfBooths.'<br>';
308print '</table>'."\n";
309*/
310
311$object = null;
312
313htmlPrintOnlineFooter($mysoc, $langs, 1, $suffix, $object);
314
315llxFooter('', 'public');
316
317$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.