viewandvote.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. /**
  18. * \file htdocs/public/payment/newpayment.php
  19. * \ingroup core
  20. * \brief File to offer a way to make a payment for a particular Dolibarr object
  21. */
  22. if (!defined('NOLOGIN')) {
  23. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  24. }
  25. if (!defined('NOCSRFCHECK')) {
  26. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  27. }
  28. if (!defined('NOIPCHECK')) {
  29. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  30. }
  31. if (!defined('NOBROWSERNOTIF')) {
  32. define('NOBROWSERNOTIF', '1');
  33. }
  34. // For MultiCompany module.
  35. // Do not use GETPOST here, function is not defined and get of entity must be done before including main.inc.php
  36. $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))));
  37. if (is_numeric($entity)) {
  38. define("DOLENTITY", $entity);
  39. }
  40. // Load Dolibarr environment
  41. require '../../main.inc.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  45. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  48. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  49. require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
  50. // Hook to be used by external payment modules (ie Payzen, ...)
  51. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  52. $hookmanager = new HookManager($db);
  53. $hookmanager->initHooks(array('newpayment'));
  54. // For encryption
  55. global $dolibarr_main_url_root;
  56. // Load translation files
  57. $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "paybox", "paypal", "stripe")); // File with generic data
  58. // Security check
  59. // No check on module enabled. Done later according to $validpaymentmethod
  60. $action = GETPOST('action', 'aZ09');
  61. $id = GETPOST('id');
  62. $securekeyreceived = GETPOST("securekey");
  63. $securekeytocompare = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'conferenceorbooth'.$id, 'md5');
  64. if ($securekeytocompare != $securekeyreceived) {
  65. print $langs->trans('MissingOrBadSecureKey');
  66. exit;
  67. }
  68. $listofvotes = explode(',', $_SESSION["savevotes"]);
  69. // Define $urlwithroot
  70. //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  71. //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  72. $urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
  73. $project = new Project($db);
  74. $resultproject = $project->fetch($id);
  75. if ($resultproject < 0) {
  76. $error++;
  77. $errmsg .= $project->error;
  78. }
  79. // Security check
  80. if (empty($conf->eventorganization->enabled)) {
  81. httponly_accessforbidden('Module Event organization not enabled');
  82. }
  83. /*
  84. * Actions
  85. */
  86. $tmpthirdparty = new Societe($db);
  87. $listOfConferences = '<tr><td>'.$langs->trans('Label').'</td>';
  88. $listOfConferences .= '<td>'.$langs->trans('Type').'</td>';
  89. $listOfConferences .= '<td>'.$langs->trans('ThirdParty').'</td>';
  90. $listOfConferences .= '<td>'.$langs->trans('Note').'</td></tr>';
  91. $sql = "SELECT a.id, a.fk_action, a.datep, a.datep2, a.label, a.fk_soc, a.note, ca.libelle as label
  92. FROM ".MAIN_DB_PREFIX."actioncomm as a
  93. INNER JOIN ".MAIN_DB_PREFIX."c_actioncomm as ca ON (a.fk_action=ca.id)
  94. WHERE a.status<2";
  95. $sqlforconf = $sql." AND ca.module='conference@eventorganization'";
  96. //$sqlforbooth = $sql." AND ca.module='booth@eventorganization'";
  97. // For conferences
  98. $result = $db->query($sqlforconf);
  99. $i = 0;
  100. while ($i < $db->num_rows($result)) {
  101. $obj = $db->fetch_object($result);
  102. if (!empty($obj->fk_soc)) {
  103. $resultthirdparty = $tmpthirdparty->fetch($obj->fk_soc);
  104. if ($resultthirdparty) {
  105. $thirdpartyname = $tmpthirdparty->name;
  106. } else {
  107. $thirdpartyname = '';
  108. }
  109. } else {
  110. $thirdpartyname = '';
  111. }
  112. $listOfConferences .= '<tr><td>'.$obj->label.'</td><td>'.$obj->label.'</td><td>'.$thirdpartyname.'</td><td>'.$obj->note.'</td>';
  113. $listOfConferences .= '<td><button type="submit" name="vote" value="'.$obj->id.'" class="button">'.$langs->trans("Vote").'</button></td></tr>';
  114. $i++;
  115. }
  116. // For booths
  117. /*
  118. $result = $db->query($sqlforbooth);
  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. $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>';
  133. $listOfBooths .= '<td><button type="submit" name="vote" value="'.$obj->id.'" class="button">'.$langs->trans("Vote").'</button></td></tr>';
  134. $i++;
  135. }
  136. */
  137. // Get vote result
  138. $idvote = GETPOST("vote");
  139. $hashedvote = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'vote'.$idvote);
  140. if (strlen($idvote)) {
  141. if (in_array($hashedvote, $listofvotes)) {
  142. // Has already voted
  143. $votestatus = 'ko';
  144. } else {
  145. // Has not already voted
  146. $conforbooth = new ActionComm($db);
  147. $resultconforbooth = $conforbooth->fetch($idvote);
  148. if ($resultconforbooth<=0) {
  149. $error++;
  150. $errmsg .= $conforbooth->error;
  151. } else {
  152. // Process to vote
  153. $conforbooth->num_vote++;
  154. $resupdate = $conforbooth->update($user);
  155. if ($resupdate) {
  156. $votestatus = 'ok';
  157. $_SESSION["savevotes"] = $hashedvote.','.(empty($_SESSION["savevotes"]) ? '' : $_SESSION["savevotes"]); // Save voter
  158. } else {
  159. //Error during update
  160. $votestatus = 'err';
  161. }
  162. }
  163. }
  164. if ($votestatus=="ok") {
  165. setEventMessage($langs->trans("VoteOk"), 'mesgs');
  166. } elseif ($votestatus=="ko") {
  167. setEventMessage($langs->trans("AlreadyVoted"), 'warnings');
  168. } elseif ($votestatus=="err") {
  169. setEventMessage($langs->trans("VoteError"), 'warnings');
  170. }
  171. header("Refresh:0;url=".dol_buildpath('/public/project/viewandvote.php?id='.$id.'&securekey=', 1).$securekeyreceived);
  172. exit;
  173. }
  174. /*
  175. * View
  176. */
  177. $head = '';
  178. if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
  179. $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
  180. }
  181. $conf->dol_hide_topmenu = 1;
  182. $conf->dol_hide_leftmenu = 1;
  183. $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
  184. llxHeader($head, $langs->trans("SuggestForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
  185. print '<span id="dolpaymentspan"></span>'."\n";
  186. print '<div class="center">'."\n";
  187. print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  188. print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
  189. print '<input type="hidden" name="action" value="dopayment">'."\n";
  190. print '<input type="hidden" name="tag" value="'.GETPOST("tag", 'alpha').'">'."\n";
  191. //print '<input type="hidden" name="suffix" value="'.dol_escape_htmltag($suffix).'">'."\n";
  192. print '<input type="hidden" name="id" value="'.dol_escape_htmltag($id).'">'."\n";
  193. print '<input type="hidden" name="securekey" value="'.dol_escape_htmltag($securekeyreceived).'">'."\n";
  194. print '<input type="hidden" name="e" value="'.$entity.'" />';
  195. print '<input type="hidden" name="forcesandbox" value="'.GETPOST('forcesandbox', 'int').'" />';
  196. print "\n";
  197. // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
  198. // Define logo and logosmall
  199. $logosmall = $mysoc->logo_small;
  200. $logo = $mysoc->logo;
  201. $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
  202. if (!empty($conf->global->$paramlogo)) {
  203. $logosmall = $conf->global->$paramlogo;
  204. } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
  205. $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
  206. }
  207. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  208. // Define urllogo
  209. $urllogo = '';
  210. $urllogofull = '';
  211. if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
  212. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
  213. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
  214. } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
  215. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
  216. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
  217. }
  218. // Output html code for logo
  219. if ($urllogo) {
  220. print '<div class="backgreypublicpayment">';
  221. print '<div class="logopublicpayment">';
  222. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  223. print '>';
  224. print '</div>';
  225. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  226. 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>';
  227. }
  228. print '</div>';
  229. }
  230. if (!empty($conf->global->PROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH)) {
  231. print '<div class="backimagepublicsuggestbooth">';
  232. print '<img id="idPROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH" src="'.$conf->global->PROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH.'">';
  233. print '</div>';
  234. }
  235. print '<table id="welcome" class="center">'."\n";
  236. $text = '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("EvntOrgRegistrationWelcomeMessage").'</strong></td></tr>'."\n";
  237. $text .= '<tr><td class="textpublicpayment">'.$langs->trans("EvntOrgVoteHelpMessage").' : "'.$project->title.'".<br><br></td></tr>'."\n";
  238. $text .= '<tr><td class="textpublicpayment">'.$project->note_public.'</td></tr>'."\n";
  239. print $text;
  240. print '</table>'."\n";
  241. print '<table cellpadding="10" id="conferences" border="1" class="center">'."\n";
  242. print '<th colspan="7">'.$langs->trans("ListOfSuggestedConferences").'</th>';
  243. print $listOfConferences.'<br>';
  244. print '</table>'."\n";
  245. /*
  246. print '<br>';
  247. print '<table border=1 cellpadding="10" id="conferences" class="center">'."\n";
  248. print '<th colspan="7">'.$langs->trans("ListOfSuggestedBooths").'</th>';
  249. print $listOfBooths.'<br>';
  250. print '</table>'."\n";
  251. */
  252. $object = null;
  253. htmlPrintOnlinePaymentFooter($mysoc, $langs, 1, $suffix, $object);
  254. llxFooter('', 'public');
  255. $db->close();