From 1f8fd2e3e244d4f3ded848dd436708c4c78a301b Mon Sep 17 00:00:00 2001 From: "Olivier Perez [a570709]" <olivier.perez@worldline.com> Date: Wed, 7 Jan 2015 14:01:08 +0100 Subject: [PATCH] Admin: Move migration page + add landing page --- admin/index.php | 119 +-------------------------- migration.php => admin/migration.php | 30 ++++--- admin/polls.php | 118 ++++++++++++++++++++++++++ app/inc/init.php | 12 ++- tpl/admin/admin_page.tpl | 10 +++ tpl/admin/index.tpl | 12 +++ tpl/admin/migration.tpl | 35 ++++++++ tpl/head.tpl | 22 ++--- tpl/header.tpl | 4 +- 9 files changed, 218 insertions(+), 144 deletions(-) rename migration.php => admin/migration.php (74%) create mode 100644 admin/polls.php create mode 100644 tpl/admin/admin_page.tpl create mode 100644 tpl/admin/index.tpl create mode 100644 tpl/admin/migration.tpl diff --git a/admin/index.php b/admin/index.php index f1cc487a..2d98b7e7 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,118 +1,5 @@ <?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 - * Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft) - * - * ============================= - * - * 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) - */ +require_once '../app/inc/init.php'; -use Framadate\Services\AdminPollService; -use Framadate\Services\LogService; -use Framadate\Services\PollService; -use Framadate\Services\SuperAdminService; -use Framadate\Utils; - -include_once __DIR__ . '/../app/inc/init.php'; -include_once __DIR__ . '/../bandeaux.php'; - -/* 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. - -// Affichage des balises standards -Utils::print_header(_('Polls administrator')); -bandeau_titre(_('Polls administrator')); - -$polls = $superAdminService->findAllPolls(); - -echo '<form action="' . Utils::get_server_name() . 'admin/index.php" method="POST">' . "\n"; - -// Test et affichage du bouton de confirmation en cas de suppression de sondage -foreach ($polls as $poll) { - if (!empty($_POST['supprimersondage' . $poll->id])) { - echo ' - <div class="alert alert-warning text-center"> - <h3>' . _("Confirm removal of the poll ") . '"' . $poll->id . '</h3> - <p><button class="btn btn-default" type="submit" value="1" name="annullesuppression">' . _('Keep this poll!') . '</button> - <button type="submit" name="confirmesuppression' . $poll->id . '" value="1" class="btn btn-danger">' . _('Remove this poll!') . '</button></p> - </div>'; - } - - // 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)) ? '<a role="button" class="btn btn-default btn-xs pull-right" href="' . Utils::get_server_name() . LOG_FILE . '">' . _("Logs") . '</a>' : ''; - -echo '<p>' . count($polls) . ' ' . _("polls in the database at this time") . $btn_logs . '</p>' . "\n"; - -// tableau qui affiche tous les sondages de la base -echo '<table class="table table-bordered"> - <tr align="center"> - <th scope="col">' . _('Poll ID') . '</th> - <th scope="col">' . _('Format') . '</th> - <th scope="col">' . _('Title') . '</th> - <th scope="col">' . _('Author') . '</th> - <th scope="col">' . _('Email') . '</th> - <th scope="col">' . _('Expiration\'s date') . '</th> - <th scope="col">' . _('Users') . '</th> - <th scope="col" colspan="3">' . _('Actions') . '</th> - </tr>' . "\n"; - -$i = 0; -foreach ($polls as $poll) { - $nb_users = $pollService->countVotesByPollId($poll->id); - - if ($poll->format === 'D') { - $format_html = '<span class="glyphicon glyphicon-calendar" aria-hidden="true"></span><span class="sr-only">'. _('Date').'</span>'; - } else { - $format_html = '<span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span><span class="sr-only">'. _('Classic').'</span>'; - } - echo ' - <tr align="center"> - <td>' . $poll->id . '</td> - <td>' . $format_html . '</td> - <td>' . htmlentities($poll->title) . '</td> - <td>' . htmlentities($poll->admin_name) . '</td> - <td>' . htmlentities($poll->admin_mail) . '</td>'; - - if (strtotime($poll->end_date) > time()) { - echo '<td>' . date('d/m/y', strtotime($poll->end_date)) . '</td>'; - } else { - echo '<td><span class="text-danger">' . date('d/m/y', strtotime($poll->end_date)) . '</span></td>'; - } - echo ' - <td>' . $nb_users . '</td> - <td><a href="' . Utils::getUrlSondage($poll->id) . '" class="btn btn-link" title="' . _('See the poll') . '"><span class="glyphicon glyphicon-eye-open"></span><span class="sr-only">' . _('See the poll') . '</span></a></td> - <td><a href="' . Utils::getUrlSondage($poll->admin_id, true) . '" class="btn btn-link" title="' . _('Change the poll') . '"><span class="glyphicon glyphicon-pencil"></span><span class="sr-only">' . _("Change the poll") . '</span></a></td> - <td><button type="submit" name="supprimersondage' . $poll->id . '" value="' . _('Remove the poll') . '" class="btn btn-link" title="' . _("Remove the poll") . '"><span class="glyphicon glyphicon-trash text-danger"></span><span class="sr-only">' . _('Remove the poll') . '</span></td> - </tr>' . "\n"; - ++$i; -} - -echo '</table></form>' . "\n"; - -bandeau_pied(true); +$smarty->assign('title', _('Administration')); +$smarty->display('admin/index.tpl'); \ No newline at end of file diff --git a/migration.php b/admin/migration.php similarity index 74% rename from migration.php rename to admin/migration.php index 2617b843..07ffb2e2 100644 --- a/migration.php +++ b/admin/migration.php @@ -4,11 +4,7 @@ use Framadate\Migration\From_0_8_to_0_9_Migration; use Framadate\Migration\Migration; use Framadate\Utils; -include_once __DIR__ . '/app/inc/init.php'; - -function output($msg) { - echo $msg . '<br/>'; -} +include_once __DIR__ . '/../app/inc/init.php'; // List a Migration sub classes to execute $migrations = [ @@ -43,12 +39,15 @@ $countFailed = 0; $countSkipped = 0; // Loop on every Migration sub classes +$success = []; +$fail = []; foreach ($migrations as $migration) { $className = get_class($migration); // Check if $className is a Migration sub class if (!$migration instanceof Migration) { - output('The class ' . $className . ' is not a sub class of Framadate\\Migration\\Migration.'); + $smarty->assign('error', 'The class ' . $className . ' is not a sub class of Framadate\\Migration\\Migration.'); + $smarty->display('error.tpl'); exit; } @@ -61,10 +60,10 @@ foreach ($migrations as $migration) { $migration->execute($pdo); if ($insertStmt->execute([$className])) { $countSucceeded++; - output('Migration done: ' . $className); + $success[] = $className; } else { $countFailed++; - output('Migration failed: ' . $className); + $fail[] = $className; } } else { $countSkipped++; @@ -74,7 +73,14 @@ foreach ($migrations as $migration) { $countTotal = $countSucceeded + $countFailed + $countSkipped; -output('Summary<hr/>'); -output('Success: ' . $countSucceeded . ' / ' . $countTotal); -output('Fail: ' . $countFailed . ' / ' . $countTotal); -output('Skipped: ' . $countSkipped . ' / ' . $countTotal); +$smarty->assign('success', $success); +$smarty->assign('fail', $fail); + +$smarty->assign('countSucceeded', $countSucceeded); +$smarty->assign('countFailed', $countFailed); +$smarty->assign('countSkipped', $countSkipped); +$smarty->assign('countTotal', $countTotal); + +$smarty->assign('title', _('Migration')); + +$smarty->display('admin/migration.tpl'); diff --git a/admin/polls.php b/admin/polls.php new file mode 100644 index 00000000..f1cc487a --- /dev/null +++ b/admin/polls.php @@ -0,0 +1,118 @@ +<?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 + * Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft) + * + * ============================= + * + * 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) + */ + +use Framadate\Services\AdminPollService; +use Framadate\Services\LogService; +use Framadate\Services\PollService; +use Framadate\Services\SuperAdminService; +use Framadate\Utils; + +include_once __DIR__ . '/../app/inc/init.php'; +include_once __DIR__ . '/../bandeaux.php'; + +/* 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. + +// Affichage des balises standards +Utils::print_header(_('Polls administrator')); +bandeau_titre(_('Polls administrator')); + +$polls = $superAdminService->findAllPolls(); + +echo '<form action="' . Utils::get_server_name() . 'admin/index.php" method="POST">' . "\n"; + +// Test et affichage du bouton de confirmation en cas de suppression de sondage +foreach ($polls as $poll) { + if (!empty($_POST['supprimersondage' . $poll->id])) { + echo ' + <div class="alert alert-warning text-center"> + <h3>' . _("Confirm removal of the poll ") . '"' . $poll->id . '</h3> + <p><button class="btn btn-default" type="submit" value="1" name="annullesuppression">' . _('Keep this poll!') . '</button> + <button type="submit" name="confirmesuppression' . $poll->id . '" value="1" class="btn btn-danger">' . _('Remove this poll!') . '</button></p> + </div>'; + } + + // 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)) ? '<a role="button" class="btn btn-default btn-xs pull-right" href="' . Utils::get_server_name() . LOG_FILE . '">' . _("Logs") . '</a>' : ''; + +echo '<p>' . count($polls) . ' ' . _("polls in the database at this time") . $btn_logs . '</p>' . "\n"; + +// tableau qui affiche tous les sondages de la base +echo '<table class="table table-bordered"> + <tr align="center"> + <th scope="col">' . _('Poll ID') . '</th> + <th scope="col">' . _('Format') . '</th> + <th scope="col">' . _('Title') . '</th> + <th scope="col">' . _('Author') . '</th> + <th scope="col">' . _('Email') . '</th> + <th scope="col">' . _('Expiration\'s date') . '</th> + <th scope="col">' . _('Users') . '</th> + <th scope="col" colspan="3">' . _('Actions') . '</th> + </tr>' . "\n"; + +$i = 0; +foreach ($polls as $poll) { + $nb_users = $pollService->countVotesByPollId($poll->id); + + if ($poll->format === 'D') { + $format_html = '<span class="glyphicon glyphicon-calendar" aria-hidden="true"></span><span class="sr-only">'. _('Date').'</span>'; + } else { + $format_html = '<span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span><span class="sr-only">'. _('Classic').'</span>'; + } + echo ' + <tr align="center"> + <td>' . $poll->id . '</td> + <td>' . $format_html . '</td> + <td>' . htmlentities($poll->title) . '</td> + <td>' . htmlentities($poll->admin_name) . '</td> + <td>' . htmlentities($poll->admin_mail) . '</td>'; + + if (strtotime($poll->end_date) > time()) { + echo '<td>' . date('d/m/y', strtotime($poll->end_date)) . '</td>'; + } else { + echo '<td><span class="text-danger">' . date('d/m/y', strtotime($poll->end_date)) . '</span></td>'; + } + echo ' + <td>' . $nb_users . '</td> + <td><a href="' . Utils::getUrlSondage($poll->id) . '" class="btn btn-link" title="' . _('See the poll') . '"><span class="glyphicon glyphicon-eye-open"></span><span class="sr-only">' . _('See the poll') . '</span></a></td> + <td><a href="' . Utils::getUrlSondage($poll->admin_id, true) . '" class="btn btn-link" title="' . _('Change the poll') . '"><span class="glyphicon glyphicon-pencil"></span><span class="sr-only">' . _("Change the poll") . '</span></a></td> + <td><button type="submit" name="supprimersondage' . $poll->id . '" value="' . _('Remove the poll') . '" class="btn btn-link" title="' . _("Remove the poll") . '"><span class="glyphicon glyphicon-trash text-danger"></span><span class="sr-only">' . _('Remove the poll') . '</span></td> + </tr>' . "\n"; + ++$i; +} + +echo '</table></form>' . "\n"; + +bandeau_pied(true); diff --git a/app/inc/init.php b/app/inc/init.php index a9dc8b19..4c9eaf58 100644 --- a/app/inc/init.php +++ b/app/inc/init.php @@ -30,15 +30,17 @@ if (ini_get('date.timezone') == '') { date_default_timezone_set('Europe/Paris'); } +define('ROOT_DIR', __DIR__ . '/../../'); + require_once __DIR__ . '/constants.php'; require_once __DIR__ . '/i18n.php'; // Smarty require_once __DIR__ . '/../../vendor/smarty/smarty/libs/Smarty.class.php'; $smarty = new \Smarty(); -$smarty->setTemplateDir('tpl/'); -$smarty->setCompileDir('tpl_c/'); -$smarty->setCacheDir('cache/'); +$smarty->setTemplateDir(ROOT_DIR . '/tpl/'); +$smarty->setCompileDir(ROOT_DIR . '/tpl_c/'); +$smarty->setCacheDir(ROOT_DIR . '/cache/'); $smarty->caching = false; $smarty->assign('APPLICATION_NAME', NOMAPPLICATION); @@ -57,6 +59,10 @@ function smarty_modifier_markdown($md, $clear = false) { return Utils::markdown($md, $clear); } +function smarty_modifier_resource($link) { + return Utils::get_server_name() . $link; +} + // End- Smarty $connect = new FramaDB(DB_CONNECTION_STRING, DB_USER, DB_PASSWORD); diff --git a/tpl/admin/admin_page.tpl b/tpl/admin/admin_page.tpl new file mode 100644 index 00000000..2fb2f77b --- /dev/null +++ b/tpl/admin/admin_page.tpl @@ -0,0 +1,10 @@ +{extends 'page.tpl'} + +{block 'main'} + <div class="row"> + <div class="col-xs-12"> + <a href="{'admin'|resource}">{_('Back to administration')}</a> + </div> + </div> + {block 'admin_main'}{/block} +{/block} \ No newline at end of file diff --git a/tpl/admin/index.tpl b/tpl/admin/index.tpl new file mode 100644 index 00000000..11bf4b7b --- /dev/null +++ b/tpl/admin/index.tpl @@ -0,0 +1,12 @@ +{extends 'admin/admin_page.tpl'} + +{block 'main'} +<div class="row"> + <div class="col-md-6 col-xs-12"> + <a href="./polls.php"><h2>{_('Polls')}</h2></a> + </div> + <div class="col-md-6 col-xs-12"> + <a href="./migration.php"><h2>{_('Migration')}</h2></a> + </div> +</div> +{/block} \ No newline at end of file diff --git a/tpl/admin/migration.tpl b/tpl/admin/migration.tpl new file mode 100644 index 00000000..6cd818c9 --- /dev/null +++ b/tpl/admin/migration.tpl @@ -0,0 +1,35 @@ +{extends 'admin/admin_page.tpl'} + +{block 'admin_main'} + <div class="row"> + <div class="col-xs-12 col-md-4"> + <h2>{_('Summary')}</h2> + {_('Succeeded:')} <span class="label label-warning">{$countSucceeded} / {$countTotal}</span> + <br/> + {_('Failed:')} <span class="label label-danger">{$countFailed} / {$countTotal}</span> + <br/> + {_('Skipped:')} <span class="label label-info">{$countSkipped} / {$countTotal}</span> + </div> + <div class="col-xs-12 col-md-4"> + <h2>{_('Success')}</h2> + <ul> + {foreach $success as $s} + <li>{$s}</li> + {foreachelse} + <li>{_('Nothing')}</li> + {/foreach} + </ul> + </div> + + <div class="col-xs-12 col-md-4"> + <h2>{_('Fail')}</h2> + <ul> + {foreach $fail as $f} + <li>{$f}</li> + {foreachelse} + <li>{_('Nothing')}</li> + {/foreach} + </ul> + </div> + </div> +{/block} \ No newline at end of file diff --git a/tpl/head.tpl b/tpl/head.tpl index 6267892f..98084def 100644 --- a/tpl/head.tpl +++ b/tpl/head.tpl @@ -9,19 +9,19 @@ <title>{$APPLICATION_NAME}</title> {/if} - <link rel="stylesheet" href="{$SERVER_URL}css/bootstrap.min.css"> - <link rel="stylesheet" href="{$SERVER_URL}css/datepicker3.css"> - <link rel="stylesheet" href="{$SERVER_URL}css/style.css"> - <link rel="stylesheet" href="{$SERVER_URL}css/frama.css"> - <link rel="stylesheet" href="{$SERVER_URL}css/print.css" media="print"> - <script type="text/javascript" src="{$SERVER_URL}js/jquery-1.11.1.min.js"></script> - <script type="text/javascript" src="{$SERVER_URL}js/bootstrap.min.js"></script> - <script type="text/javascript" src="{$SERVER_URL}js/bootstrap-datepicker.js"></script> - <script type="text/javascript" src="{$SERVER_URL}js/locales/bootstrap-datepicker.{$lang}.js"></script> - <script type="text/javascript" src="{$SERVER_URL}js/core.js"></script> + <link rel="stylesheet" href="{'css/bootstrap.min.css'|resource}"> + <link rel="stylesheet" href="{'css/datepicker3.css'|resource}"> + <link rel="stylesheet" href="{'css/style.css'|resource}"> + <link rel="stylesheet" href="{'css/frama.css'|resource}"> + <link rel="stylesheet" href="{'css/print.css'|resource}" media="print"> + <script type="text/javascript" src="{'js/jquery-1.11.1.min.js'|resource}"></script> + <script type="text/javascript" src="{'js/bootstrap.min.js'|resource}"></script> + <script type="text/javascript" src="{'js/bootstrap-datepicker.js'|resource}"></script> + <script type="text/javascript" src="{"js/locales/bootstrap-datepicker.$lang.js"|resource}"></script> + <script type="text/javascript" src="{'js/core.js'|resource}"></script> {if !empty($nav_js)} - <script src="/nav/nav.js" id="nav_js" type="text/javascript" charset="utf-8"></script><!-- /Framanav --> + <script src="{'nav/nav.js'|resource}" id="nav_js" type="text/javascript" charset="utf-8"></script><!-- /Framanav --> {/if} </head> diff --git a/tpl/header.tpl b/tpl/header.tpl index 838de01b..949d3b6a 100644 --- a/tpl/header.tpl +++ b/tpl/header.tpl @@ -2,7 +2,7 @@ {if count($langs)>1} <form method="post" action="" class="hidden-print"> <div class="input-group input-group-sm pull-right col-md-2 col-xs-4"> - <select name="lang" class="form-control" title="${_("Select the language")}" > + <select name="lang" class="form-control" title="{_("Select the language")}" > {foreach $langs as $lang_key=>$lang_value} <option lang="{substr($lang_key, 0, 2)}" {if substr($lang_key, 0, 2)==$lang}selected{/if} value="{$lang_key}">{$lang_value}</option> {/foreach} @@ -14,7 +14,7 @@ </form> {/if} - <h1><a href="{$SERVER_URL}" title="{_("Home")} - {$APPLICATION_NAME}"><img src="{$TITLE_IMAGE}" alt="{$APPLICATION_NAME}"/></a></h1> + <h1><a href="{$SERVER_URL}" title="{_("Home")} - {$APPLICATION_NAME}"><img src="{$TITLE_IMAGE|resource}" alt="{$APPLICATION_NAME}"/></a></h1> {if !empty($title)}<h2 class="lead"><i>{$title}</i></h2>{/if} <hr class="trait" role="presentation" /> </header> -- GitLab