From 2495a8002fa194e45d6fd686cbd5fdba36fc13da Mon Sep 17 00:00:00 2001 From: Olivier PEREZ Date: Wed, 7 Jan 2015 22:47:34 +0100 Subject: [PATCH] Admin: The polls page now use Smarty template --- admin/polls.php | 102 +++++------------- adminstuds.php | 1 + app/classes/Framadate/Services/LogService.php | 2 +- tpl/admin/polls.tpl | 63 +++++++++++ 4 files changed, 89 insertions(+), 79 deletions(-) create mode 100644 tpl/admin/polls.tpl diff --git a/admin/polls.php b/admin/polls.php index f1cc487..ac5780a 100644 --- a/admin/polls.php +++ b/admin/polls.php @@ -26,93 +26,39 @@ use Framadate\Utils; include_once __DIR__ . '/../app/inc/init.php'; include_once __DIR__ . '/../bandeaux.php'; +/* Variables */ +/* --------- */ + +$polls = null; +$poll_to_delete = null; + /* Services */ /*----------*/ + $logService = new LogService(); $pollService = new PollService($connect, $logService); $adminPollService = new AdminPollService($connect, $pollService, $logService); $superAdminService = new SuperAdminService($connect); -// Ce fichier index.php se trouve dans le sous-repertoire ADMIN de Studs. Il sert à afficher l'intranet de studs -// pour modifier les sondages directement sans avoir reçu les mails. C'est l'interface d'aministration -// de l'application. +/* PAGE */ +/* ---- */ -// Affichage des balises standards -Utils::print_header(_('Polls administrator')); -bandeau_titre(_('Polls administrator')); +if (!empty($_POST['delete_poll'])) { + $delete_id = filter_input(INPUT_POST, 'delete_poll', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^[a-z0-9]+$/']]); + $poll_to_delete = $pollService->findById($delete_id); +} + +// Traitement de la confirmation de suppression +if (!empty($_POST['delete_confirm'])) { + $poll_id = filter_input(INPUT_POST, 'delete_confirm', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^[a-z0-9]+$/']]); + $adminPollService->deleteEntirePoll($poll_id); +} $polls = $superAdminService->findAllPolls(); -echo '
' . "\n"; +// Assign data to template +$smarty->assign('polls', $polls); +$smarty->assign('poll_to_delete', $poll_to_delete); +$smarty->assign('log_file', is_readable('../' . LOG_FILE) ? LOG_FILE : null); -// Test et affichage du bouton de confirmation en cas de suppression de sondage -foreach ($polls as $poll) { - if (!empty($_POST['supprimersondage' . $poll->id])) { - echo ' -
-

' . _("Confirm removal of the poll ") . '"' . $poll->id . '

-

-

-
'; - } - - // Traitement de la confirmation de suppression - if (!empty($_POST['confirmesuppression' . $poll->id])) { - // On inclut la routine de suppression - $date = date('H:i:s d/m/Y'); - - $adminPollService->deleteEntirePoll($poll->id); - } -} - -$btn_logs = (is_readable('../' . LOG_FILE)) ? '' . _("Logs") . '' : ''; - -echo '

' . count($polls) . ' ' . _("polls in the database at this time") . $btn_logs . '

' . "\n"; - -// tableau qui affiche tous les sondages de la base -echo ' - - - - - - - - - - ' . "\n"; - -$i = 0; -foreach ($polls as $poll) { - $nb_users = $pollService->countVotesByPollId($poll->id); - - if ($poll->format === 'D') { - $format_html = ''. _('Date').''; - } else { - $format_html = ''. _('Classic').''; - } - echo ' - - - - - - '; - - if (strtotime($poll->end_date) > time()) { - echo ''; - } else { - echo ''; - } - echo ' - - - - - ' . "\n"; - ++$i; -} - -echo '
' . _('Poll ID') . '' . _('Format') . '' . _('Title') . '' . _('Author') . '' . _('Email') . '' . _('Expiration\'s date') . '' . _('Users') . '' . _('Actions') . '
' . $poll->id . '' . $format_html . '' . htmlentities($poll->title) . '' . htmlentities($poll->admin_name) . '' . htmlentities($poll->admin_mail) . '' . date('d/m/y', strtotime($poll->end_date)) . '' . date('d/m/y', strtotime($poll->end_date)) . '' . $nb_users . '' . _('See the poll') . '' . _("Change the poll") . '
' . "\n"; - -bandeau_pied(true); +$smarty->display('admin/polls.tpl'); diff --git a/adminstuds.php b/adminstuds.php index 0ab3563..8de758c 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -27,6 +27,7 @@ include_once __DIR__ . '/app/inc/init.php'; /* Variables */ /* --------- */ + $admin_poll_id = null; $poll_id = null; $poll = null; diff --git a/app/classes/Framadate/Services/LogService.php b/app/classes/Framadate/Services/LogService.php index 8ccb48f..4f68463 100644 --- a/app/classes/Framadate/Services/LogService.php +++ b/app/classes/Framadate/Services/LogService.php @@ -18,7 +18,7 @@ class LogService { * @param $message string some message */ function log($tag, $message) { - error_log(date('Ymd His') . ' [' . $tag . '] ' . $message . "\n", 3, LOG_FILE); + error_log(date('Ymd His') . ' [' . $tag . '] ' . $message . "\n", 3, ROOT_DIR . LOG_FILE); } } diff --git a/tpl/admin/polls.tpl b/tpl/admin/polls.tpl new file mode 100644 index 0000000..c594caa --- /dev/null +++ b/tpl/admin/polls.tpl @@ -0,0 +1,63 @@ +{extends 'admin/admin_page.tpl'} + +{block 'admin_main'} +
+ {if $poll_to_delete} +
+

{_("Confirm removal of the poll ")}"{$poll_to_delete->id}"

+ +

+ + +

+
+ {/if} + +

+ {$polls|count} {_('polls in the database at this time')} + {if $log_file} + {_('Logs')} + {/if} +

+ + + + + + + + + + + + + {foreach $polls as $poll} + + + + + + + + {if strtotime($poll->end_date) > time()} + + {else} + + {/if} + + + + + + {/foreach} +
{_('Poll ID')}{_('Format')}{_('Title')}{_('Author')}{_('Email')}{_('Expiration\'s date')}{_('Users')}{_('Actions')}
{$poll->id} + {if $poll->format === 'D'} + { _('Date')} + {else} + {_('Classic')} + {/if} + {htmlentities($poll->title)}{htmlentities($poll->admin_name)}{htmlentities($poll->admin_mail)}{date('d/m/y', strtotime($poll->end_date))}{strtotime($poll->end_date)|date_format:'d/m/Y'}TODO{_('See the poll')}{_('Change the poll')}
+
+{/block} \ No newline at end of file