card.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <?php
  2. /* Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  4. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/opensurvey/card.php
  21. * \ingroup opensurvey
  22. * \brief Page to edit survey
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  26. require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
  27. require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php";
  28. require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
  29. require_once DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php";
  30. // Security check
  31. if (!$user->rights->opensurvey->read) accessforbidden();
  32. // Initialisation des variables
  33. $action=GETPOST('action','aZ09');
  34. $cancel=GETPOST('cancel','alpha');
  35. $numsondage = '';
  36. if (GETPOST('id')) {
  37. $numsondage = GETPOST('id', 'alpha');
  38. }
  39. $object=new Opensurveysondage($db);
  40. $result=$object->fetch(0, $numsondage);
  41. if ($result <= 0)
  42. {
  43. dol_print_error($db,$object->error);
  44. exit;
  45. }
  46. $expiredate=dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GETPOST('expireyear'));
  47. /*
  48. * Actions
  49. */
  50. $parameters = array('id' => $numsondage);
  51. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  52. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  53. if (empty($reshook))
  54. {
  55. if ($cancel) $action='';
  56. // Delete
  57. if ($action == 'delete_confirm')
  58. {
  59. // Security check
  60. if (!$user->rights->opensurvey->write) accessforbidden();
  61. $result=$object->delete($user,'',$numsondage);
  62. header('Location: '.dol_buildpath('/opensurvey/list.php',1));
  63. exit();
  64. }
  65. // Close
  66. if ($action == 'close')
  67. {
  68. $object->status = Opensurveysondage::STATUS_CLOSED;
  69. $object->update($user);
  70. }
  71. // Reopend
  72. if ($action == 'reopen')
  73. {
  74. $object->status = Opensurveysondage::STATUS_VALIDATED;
  75. $object->update($user);
  76. }
  77. // Update
  78. if ($action == 'update')
  79. {
  80. // Security check
  81. if (!$user->rights->opensurvey->write) accessforbidden();
  82. $error=0;
  83. if (! GETPOST('nouveautitre'))
  84. {
  85. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors');
  86. $error++;
  87. $action = 'edit';
  88. }
  89. if (! $error)
  90. {
  91. $object->titre = GETPOST('nouveautitre');
  92. $object->commentaires = GETPOST('nouveauxcommentaires');
  93. $object->mail_admin = GETPOST('nouvelleadresse');
  94. $object->date_fin = $expiredate;
  95. $object->allow_comments = GETPOST('cancomment') == 'on' ? true : false;
  96. $object->allow_spy = GETPOST('canseeothersvote') == 'on' ? true : false;
  97. $object->mailsonde = GETPOST('mailsonde') == 'on' ? true : false;
  98. $res=$object->update($user);
  99. if ($res < 0)
  100. {
  101. setEventMessages($object->error, $object->errors, 'errors');
  102. $action='edit';
  103. }
  104. }
  105. }
  106. // Add comment
  107. if (GETPOST('ajoutcomment'))
  108. {
  109. $error=0;
  110. if (! GETPOST('comment'))
  111. {
  112. $error++;
  113. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
  114. }
  115. if (! GETPOST('commentuser'))
  116. {
  117. $error++;
  118. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors');
  119. }
  120. if (! $error)
  121. {
  122. $comment = GETPOST("comment");
  123. $comment_user = GETPOST('commentuser');
  124. $resql = $object->addComment($comment, $comment_user);
  125. if (! $resql)
  126. {
  127. setEventMessages($langs->trans('ErrorInsertingComment'), null, 'errors');
  128. }
  129. }
  130. }
  131. // Delete comment
  132. $idcomment=GETPOST('deletecomment','int');
  133. if ($idcomment)
  134. {
  135. // Security check
  136. if (!$user->rights->opensurvey->write) accessforbidden();
  137. $resql = $object->deleteComment($idcomment);
  138. }
  139. if ($action == 'edit') {
  140. // Security check
  141. if (!$user->rights->opensurvey->write) accessforbidden();
  142. }
  143. }
  144. /*
  145. * View
  146. */
  147. $form=new Form($db);
  148. if ($object->fk_user_creat)
  149. {
  150. $userstatic = new User($db);
  151. $userstatic->fetch($object->fk_user_creat);
  152. }
  153. $title = $object->titre." - ".$langs->trans('Card');
  154. $helpurl = '';
  155. $arrayofjs=array();
  156. $arrayofcss=array('/opensurvey/css/style.css');
  157. llxHeader('',$title, $helpurl, 0, 0, 0, $arrayofjs, $arrayofcss);
  158. // Define format of choices
  159. $toutsujet=explode(",",$object->sujet);
  160. $listofanswers=array();
  161. foreach ($toutsujet as $value)
  162. {
  163. $tmp=explode('@',$value);
  164. $listofanswers[]=array('label'=>$tmp[0],'format'=>($tmp[1]?$tmp[1]:'checkbox'));
  165. }
  166. $toutsujet=str_replace("@","<br>",$toutsujet);
  167. $toutsujet=str_replace("°","'",$toutsujet);
  168. print '<form name="updatesurvey" action="'.$_SERVER["PHP_SELF"].'?id='.$numsondage.'" method="POST">'."\n";
  169. print '<input type="hidden" name="action" value="update">';
  170. $head = opensurvey_prepare_head($object);
  171. dol_fiche_head($head,'general',$langs->trans("Survey"), -1, DOL_URL_ROOT.'/opensurvey/img/object_opensurvey.png', 1);
  172. $morehtmlref = '';
  173. $linkback = '<a href="'.DOL_URL_ROOT.'/opensurvey/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  174. dol_banner_tab($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage', $morehtmlref);
  175. print '<div class="fichecenter">';
  176. print '<div class="underbanner clearboth"></div>';
  177. print '<table class="border" width="100%">';
  178. // Type
  179. $type=($object->format=="A")?'classic':'date';
  180. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td colspan="2">';
  181. print img_picto('',dol_buildpath('/opensurvey/img/'.($type == 'classic'?'chart-32.png':'calendar-32.png'),1),'width="16"',1);
  182. print ' '.$langs->trans($type=='classic'?"TypeClassic":"TypeDate").'</td></tr>';
  183. // Title
  184. print '<tr><td>';
  185. $adresseadmin=$object->mail_admin;
  186. print $langs->trans("Title") .'</td><td colspan="2">';
  187. if ($action == 'edit')
  188. {
  189. print '<input type="text" name="nouveautitre" style="width: 95%" value="'.dol_escape_htmltag(dol_htmlentities($object->titre)).'">';
  190. }
  191. else print dol_htmlentities($object->titre);
  192. print '</td></tr>';
  193. // Description
  194. print '<tr><td class="tdtop">'.$langs->trans("Description") .'</td><td colspan="2">';
  195. if ($action == 'edit')
  196. {
  197. $doleditor=new DolEditor('nouveauxcommentaires', dol_htmlentities($object->commentaires),'',120,'dolibarr_notes','In',1,1,1,ROWS_7,'90%');
  198. $doleditor->Create(0,'');
  199. }
  200. else
  201. {
  202. print (dol_textishtml($object->commentaires)?$object->commentaires:dol_nl2br($object->commentaires,1,true));
  203. }
  204. print '</td></tr>';
  205. // EMail
  206. //If linked user, then emails are going to be sent to users' email
  207. if (!$object->fk_user_creat) {
  208. print '<tr><td>'.$langs->trans("EMail") .'</td><td colspan="2">';
  209. if ($action == 'edit')
  210. {
  211. print '<input type="text" name="nouvelleadresse" size="40" value="'.$object->mail_admin.'">';
  212. }
  213. else print dol_print_email($object->mail_admin, 0, 0, 1);
  214. print '</td></tr>';
  215. }
  216. // Receive an email with each vote
  217. print '<tr><td>'.$langs->trans('ToReceiveEMailForEachVote').'</td><td colspan="2">';
  218. if ($action == 'edit')
  219. {
  220. print '<input type="checkbox" name="mailsonde" '.($object->mailsonde?'checked="checked"':'').'">';
  221. }
  222. else {
  223. print yn($object->mailsonde);
  224. //If option is active and linked user does not have an email, we show a warning
  225. if ($object->fk_user_creat && $object->mailsonde) {
  226. if (!$userstatic->email) {
  227. print ' '.img_warning($langs->trans('NoEMail'));
  228. }
  229. }
  230. }
  231. print '</td></tr>';
  232. // Users can comment
  233. print '<tr><td>'.$langs->trans('CanComment').'</td><td colspan="2">';
  234. if ($action == 'edit')
  235. {
  236. print '<input type="checkbox" name="cancomment" '.($object->allow_comments?'checked="checked"':'').'">';
  237. }
  238. else print yn($object->allow_comments);
  239. print '</td></tr>';
  240. // Users can see others vote
  241. print '<tr><td>'.$langs->trans('CanSeeOthersVote').'</td><td colspan="2">';
  242. if ($action == 'edit')
  243. {
  244. print '<input type="checkbox" name="canseeothersvote" '.($object->allow_spy?'checked="checked"':'').'">';
  245. }
  246. else print yn($object->allow_spy);
  247. print '</td></tr>';
  248. // Expire date
  249. print '<tr><td>'.$langs->trans('ExpireDate').'</td><td colspan="2">';
  250. if ($action == 'edit') print $form->selectDate($expiredate?$expiredate:$object->date_fin, 'expire', 0, 0, 0, '', 1, 0);
  251. else
  252. {
  253. print dol_print_date($object->date_fin,'day');
  254. if ($object->date_fin && $object->date_fin < dol_now() && $object->status == Opensurveysondage::STATUS_VALIDATED) print img_warning($langs->trans("Expired"));
  255. }
  256. print '</td></tr>';
  257. // Author
  258. print '<tr><td>';
  259. print $langs->trans("Author") .'</td><td colspan="2">';
  260. if ($object->fk_user_creat) {
  261. print $userstatic->getLoginUrl(1);
  262. } else {
  263. print dol_htmlentities($object->nom_admin);
  264. }
  265. print '</td></tr>';
  266. // Link
  267. print '<tr><td>'.img_picto('','object_globe.png').' '.$langs->trans("UrlForSurvey",'').'</td><td colspan="2">';
  268. // Define $urlwithroot
  269. $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  270. $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  271. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  272. $url=$urlwithroot.'/public/opensurvey/studs.php?sondage='.$object->id_sondage;
  273. print '<input type="text" style="width: 60%" '.($action == 'edit' ? 'disabled' : '').' id="opensurveyurl" name="opensurveyurl" value="'.$url.'">';
  274. if ($action != 'edit') print ajax_autoselect("opensurveyurl", $url);
  275. print '</td></tr>';
  276. print '</table>';
  277. print '</div>';
  278. dol_fiche_end();
  279. if ($action == 'edit')
  280. {
  281. print '<div class="center">';
  282. print '<input type="submit" class="button" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  283. print ' &nbsp; ';
  284. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  285. print '</div>';
  286. }
  287. print '</form>'."\n";
  288. /*
  289. * Barre d'actions
  290. */
  291. print '<div class="tabsAction">';
  292. if ($action != 'edit' && $user->rights->opensurvey->write) {
  293. //Modify button
  294. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id=' . $numsondage . '">'.$langs->trans("Modify") . '</a>';
  295. if ($object->status == Opensurveysondage::STATUS_VALIDATED)
  296. {
  297. //Close button
  298. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=close&id=' . $numsondage . '">'.$langs->trans("Close") . '</a>';
  299. }
  300. if ($object->status == Opensurveysondage::STATUS_CLOSED)
  301. {
  302. //Opened button
  303. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=reopen&id=' . $numsondage . '">'.$langs->trans("ReOpen") . '</a>';
  304. }
  305. //Delete button
  306. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?suppressionsondage=1&id='.$numsondage.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
  307. }
  308. print '</div>';
  309. if ($action == 'delete')
  310. {
  311. print $form->formconfirm($_SERVER["PHP_SELF"].'?&id='.$numsondage, $langs->trans("RemovePoll"), $langs->trans("ConfirmRemovalOfPoll",$id), 'delete_confirm', '', '', 1);
  312. }
  313. print '<br>';
  314. print '<form name="formulaire5" action="#" method="POST">'."\n";
  315. print load_fiche_titre($langs->trans("CommentsOfVoters"),'','');
  316. // Comment list
  317. $comments = $object->getComments();
  318. if ($comments) {
  319. foreach ($comments as $comment) {
  320. if ($user->rights->opensurvey->write) {
  321. print '<a href="'.dol_buildpath('/opensurvey/card.php',1).'?deletecomment='.$comment->id_comment.'&id='.$numsondage.'"> '.img_picto('', 'delete.png').'</a> ';
  322. }
  323. print dol_htmlentities($comment->usercomment).': '.dol_nl2br(dol_htmlentities($comment->comment))." <br>";
  324. }
  325. }
  326. else
  327. {
  328. print $langs->trans("NoCommentYet").'<br>';
  329. }
  330. print '<br>';
  331. // Add comment
  332. if ($object->allow_comments) {
  333. print $langs->trans("AddACommentForPoll") . '<br>';
  334. print '<textarea name="comment" rows="2" class="quatrevingtpercent"></textarea><br>'."\n";
  335. print $langs->trans("Name") .': <input type="text" size="50" name="commentuser" value="'.$user->getFullName($langs).'"><br>'."\n";
  336. print '<input type="submit" class="button" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
  337. if (isset($erreur_commentaire_vide) && $erreur_commentaire_vide=="yes") {
  338. print "<font color=#FF0000>" . $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Name")) . "</font>";
  339. }
  340. }
  341. print '</form>';
  342. // End of page
  343. llxFooter();
  344. $db->close();