fonctions.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. {
  86. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
  87. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
  88. } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo))
  89. {
  90. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
  91. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
  92. }
  93. // Output html code for logo
  94. if ($urllogo)
  95. {
  96. print '<div class="backgreypublicpayment">';
  97. print '<div class="logopublicpayment">';
  98. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  99. print '>';
  100. print '</div>';
  101. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  102. print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref?utm_medium=website&utm_source=poweredby" href="https://www.dolibarr.org" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
  103. }
  104. print '</div>';
  105. }
  106. print '<div style="margin-left: 50px; margin-right: 50px; text-align: start;"><br>';
  107. }
  108. /**
  109. * Show footer for new member
  110. *
  111. * @return void
  112. */
  113. function llxFooterSurvey()
  114. {
  115. print '</div>';
  116. print '</form>';
  117. print '</div>';
  118. printCommonFooter('public');
  119. dol_htmloutput_events();
  120. print "</body>\n";
  121. print "</html>\n";
  122. }
  123. /**
  124. * get_server_name
  125. *
  126. * @return string URL to use
  127. */
  128. function get_server_name()
  129. {
  130. global $dolibarr_main_url_root;
  131. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  132. //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  133. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  134. $url = $urlwithouturlroot.dol_buildpath('/opensurvey/', 1);
  135. if (!preg_match("|/$|", $url)) {
  136. $url = $url."/";
  137. }
  138. return $url;
  139. }
  140. /**
  141. * Fonction vérifiant l'existance et la valeur non vide d'une clé d'un tableau
  142. *
  143. * @param string $name La clé à tester
  144. * @param array $tableau Le tableau où rechercher la clé ($_POST par défaut)
  145. * @return bool Vrai si la clé existe et renvoie une valeur non vide
  146. */
  147. function issetAndNoEmpty($name, $tableau = null)
  148. {
  149. if ($tableau === null) {
  150. $tableau = $_POST;
  151. }
  152. return (isset($tableau[$name]) === true && empty($tableau[$name]) === false);
  153. }
  154. /**
  155. * Fonction permettant de générer les URL pour les sondage
  156. *
  157. * @param string $id L'identifiant du sondage
  158. * @param bool $admin True pour générer une URL pour l'administration d'un sondage, False pour un URL publique
  159. * @return string L'url pour le sondage
  160. */
  161. function getUrlSondage($id, $admin = false)
  162. {
  163. if ($admin === true) {
  164. $url = get_server_name().'results.php?id='.$id;
  165. } else {
  166. $url = get_server_name().'/public/studs.php?sondage='.$id;
  167. }
  168. return $url;
  169. }
  170. /**
  171. * Generate a random id
  172. *
  173. * @param string $car Char to generate key
  174. * @return string
  175. */
  176. function dol_survey_random($car)
  177. {
  178. $string = "";
  179. $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
  180. mt_srand((double) microtime() * 1000000);
  181. for ($i = 0; $i < $car; $i++) {
  182. $string .= $chaine[mt_rand() % strlen($chaine)];
  183. }
  184. return $string;
  185. }
  186. /**
  187. * Add a poll
  188. *
  189. * @return void
  190. */
  191. function ajouter_sondage()
  192. {
  193. global $db, $user;
  194. require_once DOL_DOCUMENT_ROOT.'/opensurvey/class/opensurveysondage.class.php';
  195. $sondage = dol_survey_random(16);
  196. $allow_comments = empty($_SESSION['allow_comments']) ? 0 : 1;
  197. $allow_spy = empty($_SESSION['allow_spy']) ? 0 : 1;
  198. // Insert survey
  199. $opensurveysondage = new Opensurveysondage($db);
  200. $opensurveysondage->id_sondage = $sondage;
  201. $opensurveysondage->description = $_SESSION['description'];
  202. $opensurveysondage->mail_admin = $_SESSION['adresse'];
  203. $opensurveysondage->nom_admin = $_SESSION['nom'];
  204. $opensurveysondage->title = $_SESSION['title'];
  205. $opensurveysondage->date_fin = $_SESSION['champdatefin'];
  206. $opensurveysondage->format = $_SESSION['formatsondage'];
  207. $opensurveysondage->mailsonde = $_SESSION['mailsonde'];
  208. $opensurveysondage->allow_comments = $allow_comments;
  209. $opensurveysondage->allow_spy = $allow_spy;
  210. $opensurveysondage->sujet = $_SESSION['toutchoix'];
  211. $res = $opensurveysondage->create($user);
  212. if ($res < 0) {
  213. dol_print_error($db);
  214. }
  215. unset($_SESSION["title"]);
  216. unset($_SESSION["nom"]);
  217. unset($_SESSION["adresse"]);
  218. unset($_SESSION["description"]);
  219. unset($_SESSION["mailsonde"]);
  220. unset($_SESSION['allow_comments']);
  221. unset($_SESSION['allow_spy']);
  222. unset($_SESSION['toutchoix']);
  223. unset($_SESSION['totalchoixjour']);
  224. unset($_SESSION['champdatefin']);
  225. $urlback = dol_buildpath('/opensurvey/card.php', 1).'?id='.$sondage;
  226. header("Location: ".$urlback);
  227. exit();
  228. }