2015-10-22 22:48:30 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This software is governed by the CeCILL-B license. If a copy of this license
|
|
|
|
* is not distributed with this file, you can obtain one at
|
|
|
|
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
|
|
|
|
*
|
|
|
|
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
|
2016-08-04 22:26:37 +02:00
|
|
|
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
|
2015-10-22 22:48:30 +02:00
|
|
|
*
|
|
|
|
* =============================
|
|
|
|
*
|
|
|
|
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
|
|
|
|
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
|
|
|
|
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
|
|
|
|
*
|
|
|
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
|
|
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
|
|
|
*/
|
2018-02-19 00:18:43 +01:00
|
|
|
use Framadate\Message;
|
2015-10-22 22:48:30 +02:00
|
|
|
use Framadate\Services\InputService;
|
2018-02-19 00:18:43 +01:00
|
|
|
use Framadate\Services\LogService;
|
2015-10-22 22:48:30 +02:00
|
|
|
use Framadate\Services\MailService;
|
|
|
|
use Framadate\Services\NotificationService;
|
2018-02-19 00:18:43 +01:00
|
|
|
use Framadate\Services\PollService;
|
2015-10-28 17:30:42 +01:00
|
|
|
use Framadate\Services\SecurityService;
|
2015-10-22 22:48:30 +02:00
|
|
|
|
|
|
|
include_once __DIR__ . '/../app/inc/init.php';
|
|
|
|
|
|
|
|
/* Variables */
|
|
|
|
/* --------- */
|
|
|
|
|
|
|
|
$poll_id = null;
|
|
|
|
$poll = null;
|
|
|
|
$message = null;
|
|
|
|
$result = false;
|
2018-02-19 00:18:43 +01:00
|
|
|
$comments = [];
|
2016-10-14 09:02:47 +02:00
|
|
|
$is_admin = false;
|
2015-10-22 22:48:30 +02:00
|
|
|
|
|
|
|
/* Services */
|
|
|
|
/*----------*/
|
|
|
|
|
|
|
|
$logService = new LogService();
|
2021-12-20 17:46:50 +01:00
|
|
|
$pollService = new PollService($logService);
|
2015-10-22 22:48:30 +02:00
|
|
|
$inputService = new InputService();
|
2018-02-21 11:07:11 +01:00
|
|
|
$mailService = new MailService($config['use_smtp'], $config['smtp_options']);
|
2015-10-22 22:48:30 +02:00
|
|
|
$notificationService = new NotificationService($mailService);
|
2015-10-28 17:30:42 +01:00
|
|
|
$securityService = new SecurityService();
|
2015-10-22 22:48:30 +02:00
|
|
|
|
|
|
|
/* PAGE */
|
|
|
|
/* ---- */
|
|
|
|
|
|
|
|
if (!empty($_POST['poll'])) {
|
|
|
|
$poll_id = filter_input(INPUT_POST, 'poll', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
|
2016-03-05 16:33:42 +01:00
|
|
|
$poll = $pollService->findById($poll_id);
|
2015-10-22 22:48:30 +02:00
|
|
|
}
|
|
|
|
|
2016-10-14 09:02:47 +02:00
|
|
|
if (!empty($_POST['poll_admin'])) {
|
|
|
|
$admin_poll_id = filter_input(INPUT_POST, 'poll_admin', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
|
|
|
|
if (strlen($admin_poll_id) === 24) {
|
2018-02-19 00:18:43 +01:00
|
|
|
$is_admin = ($pollService->findByAdminId($admin_poll_id) !== null);
|
2016-10-14 09:02:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 22:48:30 +02:00
|
|
|
if (!$poll) {
|
|
|
|
$message = new Message('error', __('Error', 'This poll doesn\'t exist !'));
|
2021-12-20 17:46:50 +01:00
|
|
|
} else if (!$is_admin && !$securityService->canAccessPoll($poll)) {
|
2015-10-28 17:30:42 +01:00
|
|
|
$message = new Message('error', __('Password', 'Wrong password'));
|
2015-10-30 21:45:52 +01:00
|
|
|
} else {
|
2015-10-22 22:48:30 +02:00
|
|
|
$name = $inputService->filterName($_POST['name']);
|
|
|
|
$comment = $inputService->filterComment($_POST['comment']);
|
|
|
|
|
2018-02-19 00:18:43 +01:00
|
|
|
if ($name === null) {
|
2015-10-22 22:48:30 +02:00
|
|
|
$message = new Message('danger', __('Error', 'The name is invalid.'));
|
|
|
|
}
|
|
|
|
|
2018-02-19 00:18:43 +01:00
|
|
|
if ($message === null) {
|
2015-10-22 22:48:30 +02:00
|
|
|
// Add comment
|
|
|
|
$result = $pollService->addComment($poll_id, $name, $comment);
|
|
|
|
if ($result) {
|
|
|
|
$message = new Message('success', __('Comments', 'Comment added'));
|
2016-09-05 16:41:05 +02:00
|
|
|
$notificationService->sendUpdateNotification($poll, NotificationService::ADD_COMMENT, $name);
|
2015-10-22 22:48:30 +02:00
|
|
|
} else {
|
|
|
|
$message = new Message('danger', __('Error', 'Comment failed'));
|
|
|
|
}
|
|
|
|
}
|
2015-10-28 17:30:42 +01:00
|
|
|
$comments = $pollService->allCommentsByPollId($poll_id);
|
2015-10-22 22:48:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$smarty->error_reporting = E_ALL & ~E_NOTICE;
|
|
|
|
$smarty->assign('comments', $comments);
|
2021-12-20 17:46:50 +01:00
|
|
|
$smarty->assign('poll_id', $poll_id);
|
|
|
|
$smarty->assign('admin_poll_id', $admin_poll_id);
|
2015-10-22 22:48:30 +02:00
|
|
|
$comments_html = $smarty->fetch('part/comments_list.tpl');
|
|
|
|
|
2018-02-19 00:18:43 +01:00
|
|
|
$response = ['result' => $result, 'message' => $message, 'comments' => $comments_html];
|
2015-10-22 22:48:30 +02:00
|
|
|
|
2021-12-20 17:46:50 +01:00
|
|
|
echo json_encode($response, JSON_THROW_ON_ERROR);
|