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