2011-05-15 01:32:47 +02:00
|
|
|
<?php
|
2014-09-04 17:52:18 +02:00
|
|
|
/**
|
|
|
|
* 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)
|
2014-09-04 17:52:18 +02:00
|
|
|
*
|
2014-07-04 11:21:31 +02:00
|
|
|
* =============================
|
2014-09-04 17:52:18 +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
|
|
|
|
*
|
2014-07-04 11:21:31 +02:00
|
|
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
2014-09-04 17:52:18 +02:00
|
|
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
2014-07-04 11:21:31 +02:00
|
|
|
*/
|
2015-01-03 17:24:39 +01:00
|
|
|
use Framadate\Services\LogService;
|
|
|
|
use Framadate\Services\PollService;
|
2016-10-06 22:42:57 +02:00
|
|
|
use Framadate\Services\SecurityService;
|
2015-01-03 17:24:39 +01:00
|
|
|
use Framadate\Utils;
|
2011-05-15 01:32:47 +02:00
|
|
|
|
2014-09-04 17:52:18 +02:00
|
|
|
include_once __DIR__ . '/app/inc/init.php';
|
2011-05-15 01:32:47 +02:00
|
|
|
|
2015-01-03 17:24:39 +01:00
|
|
|
ob_start();
|
2011-05-15 01:32:47 +02:00
|
|
|
|
2015-01-03 17:24:39 +01:00
|
|
|
/* Variables */
|
|
|
|
/* --------- */
|
2011-05-15 01:32:47 +02:00
|
|
|
|
2015-01-03 17:24:39 +01:00
|
|
|
$poll_id = null;
|
|
|
|
$poll = null;
|
2011-05-15 01:32:47 +02:00
|
|
|
|
2015-01-03 17:24:39 +01:00
|
|
|
/* Services */
|
|
|
|
/*----------*/
|
2011-05-15 01:32:47 +02:00
|
|
|
|
2015-01-06 23:52:52 +01:00
|
|
|
$logService = new LogService();
|
2015-01-03 17:24:39 +01:00
|
|
|
$pollService = new PollService($connect, $logService);
|
2016-10-06 22:42:57 +02:00
|
|
|
$securityService = new SecurityService();
|
2014-09-04 17:52:18 +02:00
|
|
|
|
2015-01-03 17:24:39 +01:00
|
|
|
/* PAGE */
|
|
|
|
/* ---- */
|
2011-05-15 01:32:47 +02:00
|
|
|
|
2015-01-03 17:24:39 +01:00
|
|
|
if (!empty($_GET['poll'])) {
|
2015-04-07 23:17:26 +02:00
|
|
|
$poll_id = filter_input(INPUT_GET, 'poll', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
|
2015-01-03 17:24:39 +01:00
|
|
|
$poll = $pollService->findById($poll_id);
|
2016-10-06 21:13:01 +02:00
|
|
|
} else if (!empty($_GET['admin'])) {
|
|
|
|
$admin_id = filter_input(INPUT_GET, 'admin', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => ADMIN_POLL_REGEX]]);
|
|
|
|
$poll = $pollService->findByAdminId($admin_id);
|
|
|
|
if ($poll) {
|
|
|
|
$poll_id = $poll->id;
|
|
|
|
}
|
2015-01-03 17:24:39 +01:00
|
|
|
}
|
2014-09-04 17:52:18 +02:00
|
|
|
|
2015-01-03 17:24:39 +01:00
|
|
|
if (!$poll) {
|
2018-07-06 18:06:35 +02:00
|
|
|
$smarty->assign('error', __('Error', "This poll doesn't exist!"));
|
2015-01-03 17:24:39 +01:00
|
|
|
$smarty->display('error.tpl');
|
|
|
|
exit;
|
2011-05-15 01:32:47 +02:00
|
|
|
}
|
|
|
|
|
2016-10-06 22:42:57 +02:00
|
|
|
if (empty($admin_id)) {
|
|
|
|
$forbiddenBecauseOfPassword = !$poll->results_publicly_visible && !$securityService->canAccessPoll($poll);
|
|
|
|
$resultsAreHidden = $poll->hidden;
|
|
|
|
|
|
|
|
if ($resultsAreHidden || $forbiddenBecauseOfPassword) {
|
|
|
|
$smarty->assign('error', __('Error', 'Forbidden!'));
|
|
|
|
$smarty->display('error.tpl');
|
|
|
|
exit;
|
|
|
|
}
|
2016-10-06 21:13:01 +02:00
|
|
|
}
|
2015-01-03 17:24:39 +01:00
|
|
|
|
2015-05-30 23:36:04 +02:00
|
|
|
$slots = $pollService->allSlotsByPoll($poll);
|
2015-01-03 17:24:39 +01:00
|
|
|
$votes = $pollService->allVotesByPollId($poll_id);
|
|
|
|
|
|
|
|
// CSV header
|
|
|
|
if ($poll->format === 'D') {
|
|
|
|
$titles_line = ',';
|
|
|
|
$moments_line = ',';
|
|
|
|
foreach ($slots as $slot) {
|
|
|
|
$title = Utils::csvEscape(strftime($date_format['txt_date'], $slot->title));
|
|
|
|
$moments = explode(',', $slot->moments);
|
|
|
|
|
|
|
|
$titles_line .= str_repeat($title . ',', count($moments));
|
|
|
|
$moments_line .= implode(',', array_map('\Framadate\Utils::csvEscape', $moments)) . ',';
|
|
|
|
}
|
|
|
|
echo $titles_line . "\r\n";
|
|
|
|
echo $moments_line . "\r\n";
|
|
|
|
} else {
|
|
|
|
echo ',';
|
|
|
|
foreach ($slots as $slot) {
|
|
|
|
echo Utils::markdown($slot->title, true) . ',';
|
|
|
|
}
|
|
|
|
echo "\r\n";
|
|
|
|
}
|
|
|
|
// END - CSV header
|
|
|
|
|
|
|
|
// Vote lines
|
|
|
|
foreach ($votes as $vote) {
|
|
|
|
echo Utils::csvEscape($vote->name) . ',';
|
|
|
|
$choices = str_split($vote->choices);
|
|
|
|
foreach ($choices as $choice) {
|
|
|
|
switch ($choice) {
|
|
|
|
case 0:
|
2015-04-07 20:06:24 +02:00
|
|
|
$text = __('Generic', 'No');
|
2015-01-03 17:24:39 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2018-07-06 18:06:35 +02:00
|
|
|
$text = __('Generic', 'Under reserve');
|
2015-01-03 17:24:39 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2015-04-07 20:06:24 +02:00
|
|
|
$text = __('Generic', 'Yes');
|
2015-01-03 17:24:39 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$text = 'unkown';
|
2014-09-04 17:52:18 +02:00
|
|
|
}
|
2015-01-03 17:24:39 +01:00
|
|
|
echo Utils::csvEscape($text);
|
|
|
|
echo ',';
|
2011-05-15 03:56:54 +02:00
|
|
|
}
|
2015-01-03 17:24:39 +01:00
|
|
|
echo "\r\n";
|
2011-05-15 01:32:47 +02:00
|
|
|
}
|
2015-01-03 17:24:39 +01:00
|
|
|
// END - Vote lines
|
2011-05-15 01:32:47 +02:00
|
|
|
|
2015-01-03 17:24:39 +01:00
|
|
|
// HTTP headers
|
|
|
|
$content = ob_get_clean();
|
|
|
|
$filesize = strlen($content);
|
|
|
|
$filename = Utils::cleanFilename($poll->title) . '.csv';
|
2014-09-04 17:52:18 +02:00
|
|
|
|
2015-01-03 17:24:39 +01:00
|
|
|
header('Content-Type: text/csv; charset=utf-8');
|
|
|
|
header('Content-Length: ' . $filesize);
|
|
|
|
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
|
|
|
header('Cache-Control: max-age=10');
|
|
|
|
// END - HTTP headers
|
2014-09-04 17:52:18 +02:00
|
|
|
|
2015-01-03 17:24:39 +01:00
|
|
|
echo $content;
|