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