diff --git a/admin/index.php b/admin/index.php index a320e25..f1cc487 100644 --- a/admin/index.php +++ b/admin/index.php @@ -16,104 +16,103 @@ * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) */ -namespace Framadate; + +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') ); +Utils::print_header(_('Polls administrator')); bandeau_titre(_('Polls administrator')); -$sondage=$connect->Execute('SELECT * FROM sondage'); +$polls = $superAdminService->findAllPolls(); + +echo '
' . "\n"; -echo' - '."\n"; // Test et affichage du bouton de confirmation en cas de suppression de sondage -while($dsondage = $sondage->FetchNextObject(false)) { - if (Utils::issetAndNoEmpty('supprimersondage'.$dsondage->id_sondage) === true) { +foreach ($polls as $poll) { + if (!empty($_POST['supprimersondage' . $poll->id])) { echo '
-

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

-

-

+

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

+

+

'; } // Traitement de la confirmation de suppression - if (Utils::issetAndNoEmpty('confirmesuppression'.$dsondage->id_sondage) === true) { + if (!empty($_POST['confirmesuppression' . $poll->id])) { // On inclut la routine de suppression $date = date('H:i:s d/m/Y'); - if (Utils::remove_sondage($connect, $dsondage->id_sondage)) { - // ecriture des traces dans le fichier de logs - error_log($date . " SUPPRESSION: $dsondage->id_sondage\t$dsondage->format\t$dsondage->nom_admin\t$dsondage->mail_admin\n", 3, 'logs_studs.txt'); - } + $adminPollService->deleteEntirePoll($poll->id); } } -$sondage=$connect->Execute('SELECT * FROM sondage WHERE date_fin > DATE_SUB(now(), INTERVAL 3 MONTH) ORDER BY date_fin ASC'); -$nbsondages=$sondage->RecordCount(); +$btn_logs = (is_readable('../' . LOG_FILE)) ? '' . _("Logs") . '' : ''; -$btn_logs = (is_readable('logs_studs.txt')) ? ''. _("Logs") .'' : ''; - -echo '

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

'."\n"; +echo '

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

' . "\n"; // tableau qui affiche tous les sondages de la base echo ' - - - - - - - - - '."\n"; + + + + + + + + + ' . "\n"; $i = 0; -while($dsondage = $sondage->FetchNextObject(false)) { - /* possible en 1 bonne requête dans $sondage */ - $subjects = $connect->Execute("SELECT * FROM sujet_studs WHERE id_sondage='$dsondage->id_sondage'"); - $dsujets = $subjects->FetchObject(false); +foreach ($polls as $poll) { + $nb_users = $pollService->countVotesByPollId($poll->id); - $user_studs = $connect->Execute("SELECT * from user_studs WHERE id_sondage='$dsondage->id_sondage'"); - $nb_users = $user_studs->RecordCount(); - - echo ' - - - - - - '; - - if (strtotime($dsondage->date_fin) > time()) { - echo ''; + if ($poll->format === 'D') { + $format_html = ''. _('Date').''; } else { - echo ''; + $format_html = ''. _('Classic').''; } echo ' - - - - - '."\n"; + + + + + + '; + + 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') . '' . _('Title') . '' . _('Author') . '' . _('Email') . '' . _('Expiration\'s date') . '' . _('Users') . '' . _('Actions') . '
'.$dsondage->id_sondage.''.$dsondage->format.''. stripslashes($dsondage->titre).''.stripslashes($dsondage->nom_admin).''.stripslashes($dsondage->mail_admin).''.date('d/m/y', strtotime($dsondage->date_fin)).'' - . date('d/m/y', strtotime($dsondage->date_fin)) - . ''.$nb_users.'' . _('See the poll') . '' . _("Change the poll") . '
' . $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"; +echo '' . "\n"; bandeau_pied(true); - -// si on annule la suppression, rafraichissement de la page -/*if (Utils::issetAndNoEmpty('annulesuppression') === true) { - // TODO -}*/ diff --git a/adminstuds.php b/adminstuds.php index 9883e42..0ab3563 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -36,7 +36,7 @@ $editingVoteId = 0; /* Services */ /*----------*/ -$logService = new LogService(LOG_FILE); +$logService = new LogService(); $pollService = new PollService($connect, $logService); $adminPollService = new AdminPollService($connect, $pollService, $logService); $inputService = new InputService(); diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php index 35797d1..15ae3ce 100644 --- a/app/classes/Framadate/FramaDB.php +++ b/app/classes/Framadate/FramaDB.php @@ -274,4 +274,21 @@ class FramaDB { return $prepared->fetchAll(); } + public function findAllPolls() { + $prepared = $this->prepare('SELECT * FROM ' . Utils::table('poll') . ' ORDER BY end_date ASC'); + $prepared->execute([]); + + return $prepared->fetchAll(); + } + + public function countVotesByPollId($poll_id) { + $prepared = $this->prepare('SELECT count(1) nb FROM ' . Utils::table('vote') . ' WHERE poll_id = ?'); + + $prepared->execute([$poll_id]); + $result = $prepared->fetch(); + $prepared->closeCursor(); + + return $result->nb; + } + } diff --git a/app/classes/Framadate/Services/LogService.php b/app/classes/Framadate/Services/LogService.php index 61c5e79..8ccb48f 100644 --- a/app/classes/Framadate/Services/LogService.php +++ b/app/classes/Framadate/Services/LogService.php @@ -8,10 +8,7 @@ namespace Framadate\Services; */ class LogService { - private $output; - - function __construct($output) { - $this->output = $output; + function __construct() { } /** @@ -21,7 +18,7 @@ class LogService { * @param $message string some message */ function log($tag, $message) { - error_log(date('Ymd His') . ' [' . $tag . '] ' . $message . "\n", 3, $this->output); + error_log(date('Ymd His') . ' [' . $tag . '] ' . $message . "\n", 3, LOG_FILE); } } diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index 828be5a..949afcb 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -75,6 +75,10 @@ class PollService { return $this->connect->insertComment($poll_id, $name, $comment); } + public function countVotesByPollId($poll_id) { + return $this->connect->countVotesByPollId($poll_id); + } + function computeBestChoices($votes) { $result = []; foreach ($votes as $vote) { diff --git a/app/classes/Framadate/Services/SuperAdminService.php b/app/classes/Framadate/Services/SuperAdminService.php new file mode 100644 index 0000000..bea7b14 --- /dev/null +++ b/app/classes/Framadate/Services/SuperAdminService.php @@ -0,0 +1,29 @@ +connect = $connect; + } + + /** + * Return the list of all polls. + * + * @return array All the polls + */ + public function findAllPolls() { + return $this->connect->findAllPolls(); + } + +} + \ No newline at end of file diff --git a/choix_autre.php b/choix_autre.php index 95ba3cd..e9bd1d1 100644 --- a/choix_autre.php +++ b/choix_autre.php @@ -27,7 +27,7 @@ include_once __DIR__ . '/app/inc/init.php'; /* Service */ /*---------*/ -$logService = new LogService(LOG_FILE); +$logService = new LogService(); $pollService = new PollService($connect, $logService); $mailService = new MailService($config['use_smtp']); $purgeService = new PurgeService($connect, $logService); diff --git a/choix_date.php b/choix_date.php index 5170306..bfe0790 100644 --- a/choix_date.php +++ b/choix_date.php @@ -28,7 +28,7 @@ include_once __DIR__ . '/app/inc/init.php'; /* Service */ /*---------*/ -$logService = new LogService(LOG_FILE); +$logService = new LogService(); $pollService = new PollService($connect, $logService); $mailService = new MailService($config['use_smtp']); $purgeService = new PurgeService($connect, $logService); diff --git a/exportcsv.php b/exportcsv.php index 34b4155..f5efcd7 100644 --- a/exportcsv.php +++ b/exportcsv.php @@ -36,7 +36,7 @@ $poll = null; /* Services */ /*----------*/ -$logService = new LogService(LOG_FILE); +$logService = new LogService(); $pollService = new PollService($connect, $logService); /* PAGE */ diff --git a/studs.php b/studs.php index b7c91c8..b04ce05 100644 --- a/studs.php +++ b/studs.php @@ -36,7 +36,7 @@ $editingVoteId = 0; /* Services */ /*----------*/ -$logService = new LogService(LOG_FILE); +$logService = new LogService(); $pollService = new PollService($connect, $logService); $inputService = new InputService(); $mailService = new MailService($config['use_smtp']);