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