PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/opensurvey/fonctions.php

http://github.com/Dolibarr/dolibarr
PHP | 274 lines | 142 code | 44 blank | 88 comment | 13 complexity | f87f901e6f47aefcb29db1b48ca79fa1 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  1. <?php
  2. /* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  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. /**
  19. * \file htdocs/opensurvey/fonctions.php
  20. * \ingroup opensurvey
  21. * \brief Functions for module
  22. */
  23. /**
  24. * Returns an array with the tabs for the "Opensurvey poll" section
  25. * It loads tabs from modules looking for the entity Opensurveyso
  26. *
  27. * @param Opensurveysondage $object Current viewing poll
  28. * @return array Tabs for the opensurvey section
  29. */
  30. function opensurvey_prepare_head(Opensurveysondage $object)
  31. {
  32. global $langs, $conf;
  33. $h = 0;
  34. $head = array();
  35. $head[0][0] = 'card.php?id='.$object->id_sondage;
  36. $head[0][1] = $langs->trans("Survey");
  37. $head[0][2] = 'general';
  38. $h++;
  39. $head[1][0] = 'results.php?id='.$object->id_sondage;
  40. $head[1][1] = $langs->trans("SurveyResults");
  41. $head[1][2] = 'preview';
  42. $h++;
  43. // Show more tabs from modules
  44. // Entries must be declared in modules descriptor with line
  45. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  46. // $this->tabs = array('entity:-tabname); to remove a tab
  47. complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll');
  48. complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll', 'remove');
  49. return $head;
  50. }
  51. /**
  52. * Show header for new member
  53. *
  54. * @param string $title Title
  55. * @param string $head Head array
  56. * @param int $disablejs More content into html header
  57. * @param int $disablehead More content into html header
  58. * @param array $arrayofjs Array of complementary js files
  59. * @param array $arrayofcss Array of complementary css files
  60. * @param string $numsondage Num survey
  61. * @return void
  62. */
  63. function llxHeaderSurvey($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $numsondage = '')
  64. {
  65. global $conf, $langs, $mysoc;
  66. global $dolibarr_main_url_root;
  67. //$replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
  68. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers
  69. print '<body id="mainbody" class="publicnewmemberform">';
  70. print '<span id="dolpaymentspan"></span>'."\n";
  71. print '<div class="center">'."\n";
  72. print '<form name="formulaire" action="studs.php?sondage='.urlencode($numsondage).'#bas" method="POST">'."\n";
  73. print '<input type="hidden" name="sondage" value="'.$numsondage.'"/>';
  74. print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
  75. print "\n";
  76. // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
  77. // Define logo and logosmall
  78. $logosmall = $mysoc->logo_small;
  79. $logo = $mysoc->logo;
  80. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  81. // Define urllogo
  82. $urllogo = '';
  83. $urllogofull = '';
  84. if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
  85. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
  86. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
  87. } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
  88. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
  89. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
  90. }
  91. // Output html code for logo
  92. if ($urllogo) {
  93. print '<div class="backgreypublicpayment">';
  94. print '<div class="logopublicpayment">';
  95. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  96. print '>';
  97. print '</div>';
  98. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  99. 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 src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
  100. }
  101. print '</div>';
  102. }
  103. if (!empty($conf->global->OPENSURVEY_IMAGE_PUBLIC_INTERFACE)) {
  104. print '<div class="backimagepublicopensurvey">';
  105. print '<img id="idOPENSURVEY_IMAGE_PUBLIC_INTERFACE" src="'.$conf->global->OPENSURVEY_IMAGE_PUBLIC_INTERFACE.'">';
  106. print '</div>';
  107. }
  108. print '<div style="margin-left: 50px; margin-right: 50px; text-align: start;"><br>';
  109. }
  110. /**
  111. * Show footer for new member
  112. *
  113. * @return void
  114. */
  115. function llxFooterSurvey()
  116. {
  117. print '</div>';
  118. print '</form>';
  119. print '</div>';
  120. printCommonFooter('public');
  121. dol_htmloutput_events();
  122. print "</body>\n";
  123. print "</html>\n";
  124. }
  125. /**
  126. * get_server_name
  127. *
  128. * @return string URL to use
  129. */
  130. function get_server_name()
  131. {
  132. global $dolibarr_main_url_root;
  133. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  134. //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  135. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  136. $url = $urlwithouturlroot.dol_buildpath('/opensurvey/', 1);
  137. if (!preg_match("|/$|", $url)) {
  138. $url = $url."/";
  139. }
  140. return $url;
  141. }
  142. /**
  143. * Fonction vérifiant l'existance et la valeur non vide d'une clé d'un tableau
  144. *
  145. * @param string $name La clé à tester
  146. * @param array $tableau Le tableau où rechercher la clé ($_POST par défaut)
  147. * @return bool Vrai si la clé existe et renvoie une valeur non vide
  148. */
  149. function issetAndNoEmpty($name, $tableau = null)
  150. {
  151. if ($tableau === null) {
  152. $tableau = $_POST;
  153. }
  154. return (isset($tableau[$name]) === true && empty($tableau[$name]) === false);
  155. }
  156. /**
  157. * Fonction permettant de générer les URL pour les sondage
  158. *
  159. * @param string $id L'identifiant du sondage
  160. * @param bool $admin True pour générer une URL pour l'administration d'un sondage, False pour un URL publique
  161. * @return string L'url pour le sondage
  162. */
  163. function getUrlSondage($id, $admin = false)
  164. {
  165. if ($admin === true) {
  166. $url = get_server_name().'results.php?id='.$id;
  167. } else {
  168. $url = get_server_name().'/public/studs.php?sondage='.$id;
  169. }
  170. return $url;
  171. }
  172. /**
  173. * Generate a random id
  174. *
  175. * @param string $car Char to generate key
  176. * @return string
  177. */
  178. function dol_survey_random($car)
  179. {
  180. $string = "";
  181. $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
  182. mt_srand((double) microtime() * 1000000);
  183. for ($i = 0; $i < $car; $i++) {
  184. $string .= $chaine[mt_rand() % strlen($chaine)];
  185. }
  186. return $string;
  187. }
  188. /**
  189. * Add a poll
  190. *
  191. * @return void
  192. */
  193. function ajouter_sondage()
  194. {
  195. global $db, $user;
  196. require_once DOL_DOCUMENT_ROOT.'/opensurvey/class/opensurveysondage.class.php';
  197. $sondage = dol_survey_random(16);
  198. $allow_comments = empty($_SESSION['allow_comments']) ? 0 : 1;
  199. $allow_spy = empty($_SESSION['allow_spy']) ? 0 : 1;
  200. // Insert survey
  201. $opensurveysondage = new Opensurveysondage($db);
  202. $opensurveysondage->id_sondage = $sondage;
  203. $opensurveysondage->description = $_SESSION['description'];
  204. $opensurveysondage->mail_admin = $_SESSION['adresse'];
  205. $opensurveysondage->nom_admin = $_SESSION['nom'];
  206. $opensurveysondage->title = $_SESSION['title'];
  207. $opensurveysondage->date_fin = $_SESSION['champdatefin'];
  208. $opensurveysondage->format = $_SESSION['formatsondage'];
  209. $opensurveysondage->mailsonde = $_SESSION['mailsonde'];
  210. $opensurveysondage->allow_comments = $allow_comments;
  211. $opensurveysondage->allow_spy = $allow_spy;
  212. $opensurveysondage->sujet = $_SESSION['toutchoix'];
  213. $res = $opensurveysondage->create($user);
  214. if ($res < 0) {
  215. dol_print_error($db);
  216. }
  217. unset($_SESSION["title"]);
  218. unset($_SESSION["nom"]);
  219. unset($_SESSION["adresse"]);
  220. unset($_SESSION["description"]);
  221. unset($_SESSION["mailsonde"]);
  222. unset($_SESSION['allow_comments']);
  223. unset($_SESSION['allow_spy']);
  224. unset($_SESSION['toutchoix']);
  225. unset($_SESSION['totalchoixjour']);
  226. unset($_SESSION['champdatefin']);
  227. $urlback = dol_buildpath('/opensurvey/card.php', 1).'?id='.$sondage;
  228. header("Location: ".$urlback);
  229. exit();
  230. }