viewandvote.php 11 KB

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