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