dolibarr  16.0.5
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 
24 if (!defined('NOLOGIN')) {
25  define("NOLOGIN", 1); // This means this output page does not require to be logged.
26 }
27 if (!defined('NOCSRFCHECK')) {
28  define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
29 }
30 if (!defined('NOIPCHECK')) {
31  define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
32 }
33 if (!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 $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))));
40 if (is_numeric($entity)) {
41  define("DOLENTITY", $entity);
42 }
43 
44 require '../../main.inc.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
46 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
47 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
48 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
49 require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
50 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
51 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
52 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
53 // Hook to be used by external payment modules (ie Payzen, ...)
54 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
55 $hookmanager = new HookManager($db);
56 $hookmanager->initHooks(array('newpayment'));
57 
58 // For encryption
59 global $dolibarr_main_url_root;
60 
61 // Load translation files
62 $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "paybox", "paypal", "stripe")); // File with generic data
63 
64 // Security check
65 // No check on module enabled. Done later according to $validpaymentmethod
66 
67 $action = GETPOST('action', 'aZ09');
68 $id = GETPOST('id');
69 $securekeyreceived = GETPOST("securekey");
70 $securekeytocompare = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'conferenceorbooth'.$id, 'md5');
71 
72 if ($securekeytocompare != $securekeyreceived) {
73  print $langs->trans('MissingOrBadSecureKey');
74  exit;
75 }
76 
77 $listofvotes = explode(',', $_SESSION["savevotes"]);
78 
79 
80 // Define $urlwithroot
81 //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
82 //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
83 $urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
84 
85 $project = new Project($db);
86 $resultproject = $project->fetch($id);
87 if ($resultproject < 0) {
88  $error++;
89  $errmsg .= $project->error;
90 }
91 
92 // Security check
93 if (empty($conf->eventorganization->enabled)) {
94  accessforbidden('', 0, 0, 1);
95 }
96 
97 
98 /*
99  * Actions
100  */
101 
102 $tmpthirdparty = new Societe($db);
103 
104 $listOfConferences = '<tr><td>'.$langs->trans('Label').'</td>';
105 $listOfConferences .= '<td>'.$langs->trans('Type').'</td>';
106 $listOfConferences .= '<td>'.$langs->trans('ThirdParty').'</td>';
107 $listOfConferences .= '<td>'.$langs->trans('Note').'</td></tr>';
108 
109 $sql = "SELECT a.id, a.fk_action, a.datep, a.datep2, a.label, a.fk_soc, a.note, ca.libelle as label
110  FROM ".MAIN_DB_PREFIX."actioncomm as a
111  INNER JOIN ".MAIN_DB_PREFIX."c_actioncomm as ca ON (a.fk_action=ca.id)
112  WHERE a.status<2";
113 
114 $sqlforconf = $sql." AND ca.module='conference@eventorganization'";
115 //$sqlforbooth = $sql." AND ca.module='booth@eventorganization'";
116 
117 // For conferences
118 $result = $db->query($sqlforconf);
119 $i = 0;
120 while ($i < $db->num_rows($result)) {
121  $obj = $db->fetch_object($result);
122  if (!empty($obj->fk_soc)) {
123  $resultthirdparty = $tmpthirdparty->fetch($obj->fk_soc);
124  if ($resultthirdparty) {
125  $thirdpartyname = $tmpthirdparty->name;
126  } else {
127  $thirdpartyname = '';
128  }
129  } else {
130  $thirdpartyname = '';
131  }
132 
133  $listOfConferences .= '<tr><td>'.$obj->label.'</td><td>'.$obj->label.'</td><td>'.$thirdpartyname.'</td><td>'.$obj->note.'</td>';
134  $listOfConferences .= '<td><button type="submit" name="vote" value="'.$obj->id.'" class="button">'.$langs->trans("Vote").'</button></td></tr>';
135  $i++;
136 }
137 
138 // For booths
139 /*
140 $result = $db->query($sqlforbooth);
141 $i = 0;
142 while ($i < $db->num_rows($result)) {
143  $obj = $db->fetch_object($result);
144  if (!empty($obj->fk_soc)) {
145  $resultthirdparty = $tmpthirdparty->fetch($obj->fk_soc);
146  if ($resultthirdparty) {
147  $thirdpartyname = $tmpthirdparty->name;
148  } else {
149  $thirdpartyname = '';
150  }
151  } else {
152  $thirdpartyname = '';
153  }
154 
155  $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>';
156  $listOfBooths .= '<td><button type="submit" name="vote" value="'.$obj->id.'" class="button">'.$langs->trans("Vote").'</button></td></tr>';
157  $i++;
158 }
159 */
160 
161 // Get vote result
162 $idvote = GETPOST("vote");
163 $hashedvote = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'vote'.$idvote);
164 
165 if (strlen($idvote)) {
166  if (in_array($hashedvote, $listofvotes)) {
167  // Has already voted
168  $votestatus = 'ko';
169  } else {
170  // Has not already voted
171  $conforbooth = new ActionComm($db);
172  $resultconforbooth = $conforbooth->fetch($idvote);
173  if ($resultconforbooth<=0) {
174  $error++;
175  $errmsg .= $conforbooth->error;
176  } else {
177  // Process to vote
178  $conforbooth->num_vote++;
179  $resupdate = $conforbooth->update($user);
180  if ($resupdate) {
181  $votestatus = 'ok';
182  $_SESSION["savevotes"] = $hashedvote.','.(empty($_SESSION["savevotes"]) ? '' : $_SESSION["savevotes"]); // Save voter
183  } else {
184  //Error during update
185  $votestatus = 'err';
186  }
187  }
188  }
189  if ($votestatus=="ok") {
190  setEventMessage($langs->trans("VoteOk"), 'mesgs');
191  } elseif ($votestatus=="ko") {
192  setEventMessage($langs->trans("AlreadyVoted"), 'warnings');
193  } elseif ($votestatus=="err") {
194  setEventMessage($langs->trans("VoteError"), 'warnings');
195  }
196  header("Refresh:0;url=".dol_buildpath('/public/project/viewandvote.php?id='.$id.'&securekey=', 1).$securekeyreceived);
197  exit;
198 }
199 
200 
201 /*
202  * View
203  */
204 
205 $head = '';
206 if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
207  $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
208 }
209 
210 $conf->dol_hide_topmenu = 1;
211 $conf->dol_hide_leftmenu = 1;
212 
213 $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
214 llxHeader($head, $langs->trans("SuggestForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
215 
216 print '<span id="dolpaymentspan"></span>'."\n";
217 print '<div class="center">'."\n";
218 print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
219 print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
220 print '<input type="hidden" name="action" value="dopayment">'."\n";
221 print '<input type="hidden" name="tag" value="'.GETPOST("tag", 'alpha').'">'."\n";
222 //print '<input type="hidden" name="suffix" value="'.dol_escape_htmltag($suffix).'">'."\n";
223 print '<input type="hidden" name="id" value="'.dol_escape_htmltag($id).'">'."\n";
224 print '<input type="hidden" name="securekey" value="'.dol_escape_htmltag($securekeyreceived).'">'."\n";
225 print '<input type="hidden" name="e" value="'.$entity.'" />';
226 print '<input type="hidden" name="forcesandbox" value="'.GETPOST('forcesandbox', 'int').'" />';
227 print "\n";
228 
229 
230 // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
231 // Define logo and logosmall
232 $logosmall = $mysoc->logo_small;
233 $logo = $mysoc->logo;
234 $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
235 if (!empty($conf->global->$paramlogo)) {
236  $logosmall = $conf->global->$paramlogo;
237 } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
238  $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
239 }
240 //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
241 // Define urllogo
242 $urllogo = '';
243 $urllogofull = '';
244 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
245  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
246  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
247 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
248  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
249  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
250 }
251 
252 // Output html code for logo
253 if ($urllogo) {
254  print '<div class="backgreypublicpayment">';
255  print '<div class="logopublicpayment">';
256  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
257  print '>';
258  print '</div>';
259  if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
260  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>';
261  }
262  print '</div>';
263 }
264 
265 if (!empty($conf->global->PROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH)) {
266  print '<div class="backimagepublicsuggestbooth">';
267  print '<img id="idPROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH" src="'.$conf->global->PROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH.'">';
268  print '</div>';
269 }
270 
271 print '<table id="welcome" class="center">'."\n";
272 $text = '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("EvntOrgRegistrationWelcomeMessage").'</strong></td></tr>'."\n";
273 $text .= '<tr><td class="textpublicpayment">'.$langs->trans("EvntOrgVoteHelpMessage").' : "'.$project->title.'".<br><br></td></tr>'."\n";
274 $text .= '<tr><td class="textpublicpayment">'.$project->note_public.'</td></tr>'."\n";
275 print $text;
276 print '</table>'."\n";
277 
278 
279 print '<table cellpadding="10" id="conferences" border="1" class="center">'."\n";
280 print '<th colspan="7">'.$langs->trans("ListOfSuggestedConferences").'</th>';
281 print $listOfConferences.'<br>';
282 print '</table>'."\n";
283 
284 /*
285 print '<br>';
286 
287 print '<table border=1 cellpadding="10" id="conferences" class="center">'."\n";
288 print '<th colspan="7">'.$langs->trans("ListOfSuggestedBooths").'</th>';
289 print $listOfBooths.'<br>';
290 print '</table>'."\n";
291 */
292 
293 $object = null;
294 
295 htmlPrintOnlinePaymentFooter($mysoc, $langs, 1, $suffix, $object);
296 
297 llxFooter('', 'public');
298 
299 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Project
Class to manage projects.
Definition: project.class.php:35
ActionComm
Class to manage agenda events (actions)
Definition: actioncomm.class.php:38
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
dol_hash
dol_hash($chain, $type='0')
Returns a hash of a string.
Definition: security.lib.php:104
setEventMessage
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
Definition: functions.lib.php:8108
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30