fonctions.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 <http://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("Card");
  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. * @return void
  61. */
  62. function llxHeaderSurvey($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='')
  63. {
  64. global $conf, $mysoc;
  65. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
  66. print '<body id="mainbody" class="publicnewmemberform" style="margin-top: 10px;">';
  67. // Print logo
  68. if ($mysoc->logo) {
  69. if (file_exists($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
  70. $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
  71. }
  72. }
  73. if (!$urllogo && (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.png')))
  74. {
  75. $urllogo=DOL_URL_ROOT.'/theme/dolibarr_logo.png';
  76. }
  77. print '<div style="text-align:center"><img alt="Logo" id="logosubscribe" title="" src="'.$urllogo.'"/></div>';
  78. print '<br>';
  79. print '<div style="margin-left: 50px; margin-right: 50px;">';
  80. }
  81. /**
  82. * Show footer for new member
  83. *
  84. * @return void
  85. */
  86. function llxFooterSurvey()
  87. {
  88. print '</div>';
  89. printCommonFooter('public');
  90. dol_htmloutput_events();
  91. print "</body>\n";
  92. print "</html>\n";
  93. }
  94. /**
  95. * get_server_name
  96. *
  97. * @return string URL to use
  98. */
  99. function get_server_name()
  100. {
  101. global $dolibarr_main_url_root;
  102. $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  103. $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  104. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  105. $url=$urlwithouturlroot.dol_buildpath('/opensurvey/',1);
  106. if (!preg_match("|/$|", $url)) {
  107. $url = $url."/";
  108. }
  109. return $url;
  110. }
  111. /**
  112. * Fonction vérifiant l'existance et la valeur non vide d'une clé d'un tableau
  113. *
  114. * @param string $name La clé à tester
  115. * @param array $tableau Le tableau où rechercher la clé ($_POST par défaut)
  116. * @return bool Vrai si la clé existe et renvoie une valeur non vide
  117. */
  118. function issetAndNoEmpty($name, $tableau = null)
  119. {
  120. if ($tableau === null) {
  121. $tableau = $_POST;
  122. }
  123. return (isset($tableau[$name]) === true && empty($tableau[$name]) === false);
  124. }
  125. /**
  126. * Fonction permettant de générer les URL pour les sondage
  127. *
  128. * @param string $id L'identifiant du sondage
  129. * @param bool $admin True pour générer une URL pour l'administration d'un sondage, False pour un URL publique
  130. * @return string L'url pour le sondage
  131. */
  132. function getUrlSondage($id, $admin = false)
  133. {
  134. if ($admin === true) {
  135. $url = get_server_name().'results.php?id='.$id;
  136. } else {
  137. $url = get_server_name().'/public/studs.php?sondage='.$id;
  138. }
  139. return $url;
  140. }
  141. /**
  142. * Generate a random id
  143. *
  144. * @param string $car Char to generate key
  145. * @return string
  146. */
  147. function dol_survey_random($car)
  148. {
  149. $string = "";
  150. $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
  151. mt_srand((double) microtime()*1000000);
  152. for($i=0; $i<$car; $i++) {
  153. $string .= $chaine[mt_rand() % strlen($chaine)];
  154. }
  155. return $string;
  156. }
  157. /**
  158. * Add a poll
  159. *
  160. * @return void
  161. */
  162. function ajouter_sondage()
  163. {
  164. global $db, $user;
  165. require_once DOL_DOCUMENT_ROOT.'/opensurvey/class/opensurveysondage.class.php';
  166. $sondage=dol_survey_random(16);
  167. $allow_comments = empty($_SESSION['allow_comments']) ? 0 : 1;
  168. $allow_spy = empty($_SESSION['allow_spy']) ? 0 : 1;
  169. // Insert survey
  170. $opensurveysondage = new Opensurveysondage($db);
  171. $opensurveysondage->id_sondage = $sondage;
  172. $opensurveysondage->commentaires = $_SESSION['commentaires'];
  173. $opensurveysondage->mail_admin = $_SESSION['adresse'];
  174. $opensurveysondage->nom_admin = $_SESSION['nom'];
  175. $opensurveysondage->titre = $_SESSION['titre'];
  176. $opensurveysondage->date_fin = $_SESSION['champdatefin'];
  177. $opensurveysondage->format = $_SESSION['formatsondage'];
  178. $opensurveysondage->mailsonde = $_SESSION['mailsonde'];
  179. $opensurveysondage->allow_comments = $allow_comments;
  180. $opensurveysondage->allow_spy = $allow_spy;
  181. $opensurveysondage->sujet = $_SESSION['toutchoix'];
  182. $res = $opensurveysondage->create($user);
  183. if ($res < 0) {
  184. dol_print_error($db);
  185. }
  186. unset($_SESSION["titre"]);
  187. unset($_SESSION["nom"]);
  188. unset($_SESSION["adresse"]);
  189. unset($_SESSION["commentaires"]);
  190. unset($_SESSION["mailsonde"]);
  191. unset($_SESSION['allow_comments']);
  192. unset($_SESSION['allow_spy']);
  193. unset($_SESSION['toutchoix']);
  194. unset($_SESSION['totalchoixjour']);
  195. unset($_SESSION['champdatefin']);
  196. $urlback=dol_buildpath('/opensurvey/card.php',1).'?id='.$sondage;
  197. header("Location: ".$urlback);
  198. exit();
  199. }