Translate database names (table+columns) to English + Reorganize some columns

This commit is contained in:
Olivier PEREZ 2014-12-30 01:41:25 +01:00
parent dcb711dccc
commit 1ca7502216
12 changed files with 206 additions and 228 deletions

View File

@ -301,15 +301,24 @@ if (!empty($_POST['delete_column'])) {
if (isset($_POST['add_slot'])) { if (isset($_POST['add_slot'])) {
$smarty->assign('poll_id', $poll_id); $smarty->assign('poll_id', $poll_id);
$smarty->assign('admin_poll_id', $admin_poll_id); $smarty->assign('admin_poll_id', $admin_poll_id);
$smarty->assign('format', $poll->format);
$smarty->assign('title', _('Poll') . ' - ' . $poll->title); $smarty->assign('title', _('Poll') . ' - ' . $poll->title);
$smarty->display('add_slot.tpl'); $smarty->display('add_slot.tpl');
exit; exit;
} }
if (isset($_POST['confirm_add_slot'])) { if (isset($_POST['confirm_add_slot'])) {
if ($poll->format === 'D') {
$newdate = filter_input(INPUT_POST, 'newdate', FILTER_DEFAULT); $newdate = filter_input(INPUT_POST, 'newdate', FILTER_DEFAULT);
$newmoment = filter_input(INPUT_POST, 'newmoment', FILTER_DEFAULT); $newmoment = filter_input(INPUT_POST, 'newmoment', FILTER_DEFAULT);
if ($adminPollService->addSlot($poll_id, $newdate, $newmoment)) { $ex = explode('/', $newdate);
$result = $adminPollService->addSlot($poll_id, mktime(0, 0, 0, $ex[1], $ex[0], $ex[2]), $newmoment);
} else {
$newslot = filter_input(INPUT_POST, 'choice', FILTER_DEFAULT);
$result = $adminPollService->addSlot($poll_id,$newslot, null);
}
if ($result) {
$message = new Message('success', _('Column added.')); $message = new Message('success', _('Column added.'));
} else { } else {
$message = new Message('danger', _('Failed to add the column.')); $message = new Message('danger', _('Failed to add the column.'));

View File

@ -34,7 +34,7 @@ class FramaDB {
$result = $this->pdo->query('SHOW TABLES'); $result = $this->pdo->query('SHOW TABLES');
$schemas = $result->fetchAll(\PDO::FETCH_COLUMN); $schemas = $result->fetchAll(\PDO::FETCH_COLUMN);
return 0 != count(array_diff($schemas, ['comments', 'sondage', 'sujet_studs', 'user_studs'])); return 0 != count(array_diff($schemas, ['comment', 'poll', 'slot', 'vote']));
} }
function prepare($sql) { function prepare($sql) {
@ -66,7 +66,7 @@ class FramaDB {
} }
function findPollById($poll_id) { function findPollById($poll_id) {
$prepared = $this->prepare('SELECT * FROM sondage WHERE sondage.poll_id = ?'); $prepared = $this->prepare('SELECT * FROM poll WHERE id = ?');
$prepared->execute([$poll_id]); $prepared->execute([$poll_id]);
$poll = $prepared->fetch(); $poll = $prepared->fetch();
@ -76,53 +76,53 @@ class FramaDB {
} }
function updatePoll($poll) { function updatePoll($poll) {
$prepared = $this->prepare('UPDATE sondage SET title=?, admin_mail=?, comment=?, active=?, editable=? WHERE poll_id = ?'); $prepared = $this->prepare('UPDATE poll SET title=?, admin_mail=?, comment=?, active=?, editable=? WHERE id = ?');
return $prepared->execute([$poll->title, $poll->admin_mail, $poll->comment, $poll->active, $poll->editable, $poll->poll_id]); return $prepared->execute([$poll->title, $poll->admin_mail, $poll->comment, $poll->active, $poll->editable, $poll->id]);
} }
function allCommentsByPollId($poll_id) { function allCommentsByPollId($poll_id) {
$prepared = $this->prepare('SELECT * FROM comments WHERE id_sondage = ? ORDER BY id_comment'); $prepared = $this->prepare('SELECT * FROM comment WHERE poll_id = ? ORDER BY id');
$prepared->execute(array($poll_id)); $prepared->execute(array($poll_id));
return $prepared->fetchAll(); return $prepared->fetchAll();
} }
function allUserVotesByPollId($poll_id) { function allUserVotesByPollId($poll_id) {
$prepared = $this->prepare('SELECT * FROM user_studs WHERE id_sondage = ? ORDER BY id_users'); $prepared = $this->prepare('SELECT * FROM vote WHERE poll_id = ? ORDER BY id');
$prepared->execute(array($poll_id)); $prepared->execute(array($poll_id));
return $prepared->fetchAll(); return $prepared->fetchAll();
} }
function allSlotsByPollId($poll_id) { function allSlotsByPollId($poll_id) {
$prepared = $this->prepare('SELECT * FROM sujet_studs WHERE id_sondage = ? ORDER BY sujet'); $prepared = $this->prepare('SELECT * FROM slot WHERE poll_id = ? ORDER BY title');
$prepared->execute(array($poll_id)); $prepared->execute(array($poll_id));
return $prepared->fetchAll(); return $prepared->fetchAll();
} }
function insertDefaultVote($poll_id, $insert_position) { function insertDefaultVote($poll_id, $insert_position) {
$prepared = $this->prepare('UPDATE user_studs SET reponses = CONCAT(SUBSTRING(reponses, 1, ?), "0", SUBSTRING(reponses, ?)) WHERE id_sondage = ?'); $prepared = $this->prepare('UPDATE vote SET choices = CONCAT(SUBSTRING(choices, 1, ?), "0", SUBSTRING(choices, ?)) WHERE poll_id = ?');
return $prepared->execute([$insert_position, $insert_position + 1, $poll_id]); return $prepared->execute([$insert_position, $insert_position + 1, $poll_id]);
} }
function insertVote($poll_id, $name, $choices) { function insertVote($poll_id, $name, $choices) {
$prepared = $this->prepare('INSERT INTO user_studs (id_sondage,nom,reponses) VALUES (?,?,?)'); $prepared = $this->prepare('INSERT INTO vote (poll_id, name, choices) VALUES (?,?,?)');
$prepared->execute([$poll_id, $name, $choices]); $prepared->execute([$poll_id, $name, $choices]);
$newVote = new \stdClass(); $newVote = new \stdClass();
$newVote->id_sondage = $poll_id; $newVote->poll_id = $poll_id;
$newVote->id_users = $this->pdo->lastInsertId(); $newVote->id = $this->pdo->lastInsertId();
$newVote->nom = $name; $newVote->name = $name;
$newVote->reponse = $choices; $newVote->choices = $choices;
return $newVote; return $newVote;
} }
function deleteVote($poll_id, $vote_id) { function deleteVote($poll_id, $vote_id) {
$prepared = $this->prepare('DELETE FROM user_studs WHERE id_sondage = ? AND id_users = ?'); $prepared = $this->prepare('DELETE FROM vote WHERE poll_id = ? AND id = ?');
return $prepared->execute([$poll_id, $vote_id]); return $prepared->execute([$poll_id, $vote_id]);
} }
@ -134,7 +134,7 @@ class FramaDB {
* @return bool|null true if action succeeded. * @return bool|null true if action succeeded.
*/ */
function deleteVotesByPollId($poll_id) { function deleteVotesByPollId($poll_id) {
$prepared = $this->prepare('DELETE FROM user_studs WHERE id_sondage = ?'); $prepared = $this->prepare('DELETE FROM vote WHERE poll_id = ?');
return $prepared->execute([$poll_id]); return $prepared->execute([$poll_id]);
} }
@ -147,7 +147,7 @@ class FramaDB {
* @return bool|null true if action succeeded. * @return bool|null true if action succeeded.
*/ */
function deleteVotesByIndex($poll_id, $index) { function deleteVotesByIndex($poll_id, $index) {
$prepared = $this->prepare('UPDATE user_studs SET reponses = CONCAT(SUBSTR(reponses, 1, ?), SUBSTR(reponses, ?)) WHERE id_sondage = ?'); $prepared = $this->prepare('UPDATE vote SET choices = CONCAT(SUBSTR(choices, 1, ?), SUBSTR(choices, ?)) WHERE poll_id = ?');
return $prepared->execute([$index, $index + 2, $poll_id]); return $prepared->execute([$index, $index + 2, $poll_id]);
} }
@ -160,7 +160,7 @@ class FramaDB {
* @return mixed Object The slot found, or null * @return mixed Object The slot found, or null
*/ */
function findSlotByPollIdAndDatetime($poll_id, $datetime) { function findSlotByPollIdAndDatetime($poll_id, $datetime) {
$prepared = $this->prepare('SELECT * FROM sujet_studs WHERE id_sondage = ? AND SUBSTRING_INDEX(sujet, \'@\', 1) = ?'); $prepared = $this->prepare('SELECT * FROM slot WHERE poll_id = ? AND SUBSTRING_INDEX(title, \'@\', 1) = ?');
$prepared->execute([$poll_id, $datetime]); $prepared->execute([$poll_id, $datetime]);
$slot = $prepared->fetch(); $slot = $prepared->fetch();
@ -173,13 +173,14 @@ class FramaDB {
* Insert a new slot into a given poll. * Insert a new slot into a given poll.
* *
* @param $poll_id int The ID of the poll * @param $poll_id int The ID of the poll
* @param $slot mixed The value of the slot * @param $title mixed The title of the slot
* @param $moments mixed|null The moments joined with ","
* @return bool true if action succeeded * @return bool true if action succeeded
*/ */
function insertSlot($poll_id, $slot) { function insertSlot($poll_id, $title, $moments) {
$prepared = $this->prepare('INSERT INTO sujet_studs (id_sondage, sujet) VALUES (?,?)'); $prepared = $this->prepare('INSERT INTO slot (poll_id, title, moments) VALUES (?,?,?)');
return $prepared->execute([$poll_id, $slot]); return $prepared->execute([$poll_id, $title, $moments]);
} }
/** /**
@ -187,13 +188,13 @@ class FramaDB {
* *
* @param $poll_id int The ID of the poll * @param $poll_id int The ID of the poll
* @param $datetime int The datetime of the slot to update * @param $datetime int The datetime of the slot to update
* @param $newValue mixed The new value of the entire slot * @param $newMoments mixed The new moments
* @return bool|null true if action succeeded. * @return bool|null true if action succeeded.
*/ */
function updateSlot($poll_id, $datetime, $newValue) { function updateSlot($poll_id, $datetime, $newMoments) {
$prepared = $this->prepare('UPDATE sujet_studs SET sujet = ? WHERE id_sondage = ? AND SUBSTRING_INDEX(sujet, \'@\', 1) = ?'); $prepared = $this->prepare('UPDATE slot SET moments = ? WHERE poll_id = ? AND title = ?');
return $prepared->execute([$newValue, $poll_id, $datetime]); return $prepared->execute([$newMoments, $poll_id, $datetime]);
} }
/** /**
@ -203,12 +204,13 @@ class FramaDB {
* @param $datetime mixed The datetime of the slot * @param $datetime mixed The datetime of the slot
*/ */
function deleteSlot($poll_id, $datetime) { function deleteSlot($poll_id, $datetime) {
$prepared = $this->prepare('DELETE FROM sujet_studs WHERE id_sondage = ? AND SUBSTRING_INDEX(sujet, \'@\', 1) = ?'); $prepared = $this->prepare('DELETE FROM slot WHERE poll_id = ? AND title = ?');
$prepared->execute([$poll_id, $datetime]); $prepared->execute([$poll_id, $datetime]);
} }
function deleteSlotsByPollId($poll_id) { function deleteSlotsByPollId($poll_id) {
$prepared = $this->prepare('DELETE FROM sujet_studs WHERE id_sondage = ?'); $prepared = $this->prepare('DELETE FROM slot WHERE poll_id = ?');
return $prepared->execute([$poll_id]); return $prepared->execute([$poll_id]);
} }
@ -219,31 +221,32 @@ class FramaDB {
* @return bool|null true if action succeeded. * @return bool|null true if action succeeded.
*/ */
function deleteCommentsByPollId($poll_id) { function deleteCommentsByPollId($poll_id) {
$prepared = $this->prepare('DELETE FROM comments WHERE id_sondage = ?'); $prepared = $this->prepare('DELETE FROM comment WHERE poll_id = ?');
return $prepared->execute([$poll_id]); return $prepared->execute([$poll_id]);
} }
function updateVote($poll_id, $vote_id, $choices) { function updateVote($poll_id, $vote_id, $choices) {
$prepared = $this->prepare('UPDATE user_studs SET reponses = ? WHERE id_sondage = ? AND id_users = ?'); $prepared = $this->prepare('UPDATE vote SET choices = ? WHERE poll_id = ? AND id = ?');
return $prepared->execute([$choices, $poll_id, $vote_id]); return $prepared->execute([$choices, $poll_id, $vote_id]);
} }
function insertComment($poll_id, $name, $comment) { function insertComment($poll_id, $name, $comment) {
$prepared = $this->prepare('INSERT INTO comments (id_sondage, usercomment, comment) VALUES (?,?,?)'); $prepared = $this->prepare('INSERT INTO comment (poll_id, name, comment) VALUES (?,?,?)');
return $prepared->execute([$poll_id, $name, $comment]); return $prepared->execute([$poll_id, $name, $comment]);
} }
function deleteComment($poll_id, $comment_id) { function deleteComment($poll_id, $comment_id) {
$prepared = $this->prepare('DELETE FROM comments WHERE id_sondage = ? AND id_comment = ?'); $prepared = $this->prepare('DELETE FROM comment WHERE poll_id = ? AND id = ?');
return $prepared->execute([$poll_id, $comment_id]); return $prepared->execute([$poll_id, $comment_id]);
} }
function deletePollById($poll_id) { function deletePollById($poll_id) {
$prepared = $this->prepare('DELETE FROM sondage WHERE poll_id = ?'); $prepared = $this->prepare('DELETE FROM poll WHERE id = ?');
return $prepared->execute([$poll_id]); return $prepared->execute([$poll_id]);
} }
@ -253,7 +256,7 @@ class FramaDB {
* @return array Array of old polls * @return array Array of old polls
*/ */
public function findOldPolls() { public function findOldPolls() {
$prepared = $this->prepare('SELECT * FROM sondage WHERE end_date < NOW() LIMIT 20'); $prepared = $this->prepare('SELECT * FROM poll WHERE end_date < NOW() LIMIT 20');
$prepared->execute([]); $prepared->execute([]);
return $prepared->fetchAll(); return $prepared->fetchAll();

View File

@ -77,7 +77,7 @@ class AdminPollService {
*/ */
function deleteEntirePoll($poll_id) { function deleteEntirePoll($poll_id) {
$poll = $this->connect->findPollById($poll_id); $poll = $this->connect->findPollById($poll_id);
$this->logService->log('DELETE_POLL', "id:$poll->poll_id, format:$poll->format, admin:$poll->admin_name, mail:$poll->admin_mail"); $this->logService->log('DELETE_POLL', "id:$poll->id, format:$poll->format, admin:$poll->admin_name, mail:$poll->admin_mail");
// Delete the entire poll // Delete the entire poll
$this->connect->deleteVotesByPollId($poll_id); $this->connect->deleteVotesByPollId($poll_id);
@ -109,11 +109,10 @@ class AdminPollService {
// Search the index of the slot to delete // Search the index of the slot to delete
foreach ($slots as $aSlot) { foreach ($slots as $aSlot) {
$ex = explode('@', $aSlot->sujet); $moments = explode(',', $aSlot->moments);
$moments = explode(',', $ex[1]);
foreach ($moments as $rowMoment) { foreach ($moments as $rowMoment) {
if ($datetime == $ex[0]) { if ($datetime == $aSlot->title) {
if ($moment == $rowMoment) { if ($moment == $rowMoment) {
$indexToDelete = $index; $indexToDelete = $index;
} else { } else {
@ -128,7 +127,7 @@ class AdminPollService {
$this->connect->beginTransaction(); $this->connect->beginTransaction();
$this->connect->deleteVotesByIndex($poll_id, $indexToDelete); $this->connect->deleteVotesByIndex($poll_id, $indexToDelete);
if (count($newMoments) > 0) { if (count($newMoments) > 0) {
$this->connect->updateSlot($poll_id, $datetime, $datetime . '@' . implode(',', $newMoments)); $this->connect->updateSlot($poll_id, $datetime, implode(',', $newMoments));
} else { } else {
$this->connect->deleteSlot($poll_id, $datetime); $this->connect->deleteSlot($poll_id, $datetime);
} }
@ -145,14 +144,11 @@ class AdminPollService {
* </ul> * </ul>
* *
* @param $poll_id int The ID of the poll * @param $poll_id int The ID of the poll
* @param $new_date string The date (format: d/m/Y) * @param $datetime int The datetime
* @param $new_moment string The moment's name * @param $new_moment string The moment's name
* @return bool true if added * @return bool true if added
*/ */
public function addSlot($poll_id, $new_date, $new_moment) { public function addSlot($poll_id, $datetime, $new_moment) {
$ex = explode('/', $new_date);
$datetime = mktime(0, 0, 0, $ex[1], $ex[0], $ex[2]);
$slots = $this->connect->allSlotsByPollId($poll_id); $slots = $this->connect->allSlotsByPollId($poll_id);
$result = $this->findInsertPosition($slots, $datetime, $new_moment); $result = $this->findInsertPosition($slots, $datetime, $new_moment);
@ -164,9 +160,7 @@ class AdminPollService {
return false; return false;
} elseif ($result->slot != null) { } elseif ($result->slot != null) {
$slot = $result->slot; $slot = $result->slot;
$moments = explode(',', $slot->moments);
$joined_moments = explode('@', $slot->sujet)[1];
$moments = explode(',', $joined_moments);
// Check if moment already exists (maybe not necessary) // Check if moment already exists (maybe not necessary)
if (in_array($new_moment, $moments)) { if (in_array($new_moment, $moments)) {
@ -176,10 +170,10 @@ class AdminPollService {
// Update found slot // Update found slot
$moments[] = $new_moment; $moments[] = $new_moment;
sort($moments); sort($moments);
$this->connect->updateSlot($poll_id, $datetime, $datetime . '@' . implode(',', $moments)); $this->connect->updateSlot($poll_id, $datetime, implode(',', $moments));
} else { } else {
$this->connect->insertSlot($poll_id, $datetime . '@' . $new_moment); $this->connect->insertSlot($poll_id, $datetime, $new_moment);
} }
$this->connect->insertDefaultVote($poll_id, $result->insert); $this->connect->insertDefaultVote($poll_id, $result->insert);
@ -209,9 +203,8 @@ class AdminPollService {
$i = 0; $i = 0;
foreach ($slots as $slot) { foreach ($slots as $slot) {
$ex = explode('@', $slot->sujet); $rowDatetime = $slot->title;
$rowDatetime = $ex[0]; $moments = explode(',', $slot->moments);
$moments = explode(',', $ex[1]);
if ($datetime == $rowDatetime) { if ($datetime == $rowDatetime) {
$result->slot = $slot; $result->slot = $slot;

View File

@ -78,7 +78,7 @@ class PollService {
function computeBestChoices($votes) { function computeBestChoices($votes) {
$result = []; $result = [];
foreach ($votes as $vote) { foreach ($votes as $vote) {
$choices = str_split($vote->reponses); $choices = str_split($vote->choices);
foreach ($choices as $i => $choice) { foreach ($choices as $i => $choice) {
if (empty($result[$i])) { if (empty($result[$i])) {
$result[$i] = 0; $result[$i] = 0;
@ -95,10 +95,9 @@ class PollService {
function splitSlots($slots) { function splitSlots($slots) {
$splitted = array(); $splitted = array();
foreach ($slots as $slot) { foreach ($slots as $slot) {
$ex = explode('@', $slot->sujet);
$obj = new \stdClass(); $obj = new \stdClass();
$obj->day = $ex[0]; $obj->day = $slot->title;
$obj->moments = explode(',', $ex[1]); $obj->moments = explode(',', $slot->moments);
$splitted[] = $obj; $splitted[] = $obj;
} }
@ -110,9 +109,9 @@ class PollService {
$splitted = array(); $splitted = array();
foreach ($votes as $vote) { foreach ($votes as $vote) {
$obj = new \stdClass(); $obj = new \stdClass();
$obj->id = $vote->id_users; $obj->id = $vote->id;
$obj->name = $vote->nom; $obj->name = $vote->name;
$obj->choices = str_split($vote->reponses); $obj->choices = str_split($vote->choices);
$splitted[] = $obj; $splitted[] = $obj;
} }
@ -134,13 +133,13 @@ class PollService {
$this->connect->beginTransaction(); $this->connect->beginTransaction();
// TODO Extract this to FramaDB (or repository layer) // TODO Extract this to FramaDB (or repository layer)
$sql = 'INSERT INTO sondage $sql = 'INSERT INTO poll
(poll_id, admin_poll_id, title, comment, admin_name, admin_mail, end_date, format, editable, receiveNewVotes) (id, admin_id, title, description, admin_name, admin_mail, end_date, format, editable, receiveNewVotes)
VALUES (?,?,?,?,?,?,FROM_UNIXTIME(?),?,?,?)'; VALUES (?,?,?,?,?,?,FROM_UNIXTIME(?),?,?,?)';
$prepared = $this->connect->prepare($sql); $prepared = $this->connect->prepare($sql);
$prepared->execute(array($poll_id, $admin_poll_id, $form->title, $form->description, $form->admin_name, $form->admin_mail, $form->end_date, $form->format, $form->editable, $form->receiveNewVotes)); $prepared->execute(array($poll_id, $admin_poll_id, $form->title, $form->description, $form->admin_name, $form->admin_mail, $form->end_date, $form->format, $form->editable, $form->receiveNewVotes));
$prepared = $this->connect->prepare('INSERT INTO sujet_studs (id_sondage, sujet) VALUES (?, ?)'); $prepared = $this->connect->prepare('INSERT INTO slot (poll_id, title, moments) VALUES (?, ?, ?)');
foreach ($form->getChoices() as $choice) { foreach ($form->getChoices() as $choice) {
@ -158,16 +157,16 @@ class PollService {
// We execute the insertion // We execute the insertion
if (empty($joinedSlots)) { if (empty($joinedSlots)) {
$prepared->execute(array($poll_id, $choice->getName())); $prepared->execute(array($poll_id, $choice->getName(), null));
} else { } else {
$prepared->execute(array($poll_id, $choice->getName() . '@' . $joinedSlots)); $prepared->execute(array($poll_id, $choice->getName(), $joinedSlots));
} }
} }
$this->connect->commit(); $this->connect->commit();
$this->logService->log('CREATE_POLL', 'id:' . $poll_id . 'title: ' . $form->title . ', format:' . $form->format . ', admin:' . $form->admin_name . ', mail:' . $form->admin_mail); $this->logService->log('CREATE_POLL', 'id:' . $poll_id . ', title: ' . $form->title . ', format:' . $form->format . ', admin:' . $form->admin_name . ', mail:' . $form->admin_mail);
return [$poll_id, $admin_poll_id]; return [$poll_id, $admin_poll_id];

View File

@ -30,10 +30,10 @@ class PurgeService {
$this->logService->log('EXPIRATION', 'Going to purge ' . $count . ' poll(s)...'); $this->logService->log('EXPIRATION', 'Going to purge ' . $count . ' poll(s)...');
foreach ($oldPolls as $poll) { foreach ($oldPolls as $poll) {
if ($this->purgePollById($poll->poll_id)) { if ($this->purgePollById($poll->id)) {
$this->logService->log('EXPIRATION_SUCCESS', 'id: ' . $poll->poll_id . ', title:' . $poll->title . ', format: '.$poll->format . ', admin: ' . $poll->admin_name); $this->logService->log('EXPIRATION_SUCCESS', 'id: ' . $poll->id . ', title:' . $poll->title . ', format: '.$poll->format . ', admin: ' . $poll->admin_name);
} else { } else {
$this->logService->log('EXPIRATION_FAILED', 'id: ' . $poll->poll_id . ', title:' . $poll->title . ', format: '.$poll->format . ', admin: ' . $poll->admin_name); $this->logService->log('EXPIRATION_FAILED', 'id: ' . $poll->id . ', title:' . $poll->title . ', format: '.$poll->format . ', admin: ' . $poll->admin_name);
} }
} }
} }
@ -48,11 +48,19 @@ class PurgeService {
* @return bool true is action succeeded * @return bool true is action succeeded
*/ */
function purgePollById($poll_id) { function purgePollById($poll_id) {
$done = false; $done = true;
$done |= $this->connect->deleteCommentsByPollId($poll_id);
$done |= $this->connect->deleteVotesByPollId($poll_id); $this->connect->beginTransaction();
$done |= $this->connect->deleteSlotsByPollId($poll_id); $done &= $this->connect->deleteCommentsByPollId($poll_id);
$done |= $this->connect->deletePollById($poll_id); $done &= $this->connect->deleteVotesByPollId($poll_id);
$done &= $this->connect->deleteSlotsByPollId($poll_id);
$done &= $this->connect->deletePollById($poll_id);
if ($done) {
$this->connect->commit();
} else {
$this->connect->rollback();
}
return $done; return $done;
} }

View File

@ -98,59 +98,6 @@ class Utils
return filter_var($email, FILTER_VALIDATE_EMAIL); return filter_var($email, FILTER_VALIDATE_EMAIL);
} }
/**
* Envoi un courrier avec un codage correct de To et Subject
* Les en-têtes complémentaires ne sont pas gérés
* @deprecated
*/
public static function sendEmail( $to, $subject, $body, $headers='', $param='')
{
mb_internal_encoding('UTF-8');
$subject = mb_encode_mimeheader(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'), 'UTF-8', 'B', "\n", 9);
$encoded_app = mb_encode_mimeheader(NOMAPPLICATION, 'UTF-8', 'B', "\n", 6);
$size_encoded_app = (6 + strlen($encoded_app)) % 75;
$size_admin_email = strlen(ADRESSEMAILADMIN);
if (($size_encoded_app + $size_admin_email + 9) > 74 ) {
$folding = "\n";
} else {
$folding = '';
};
/*
Si $headers ne contient qu'une adresse email, on la considère comme
adresse de reply-to, sinon on met l'adresse de no-reply definie
dans constants.php
*/
if (self::isValidEmail($headers)) {
$replyTo = $headers;
$headers = ''; // on reinitialise $headers
} else {
$replyTo = ADRESSEMAILREPONSEAUTO;
}
$from = sprintf( "From: %s%s <%s>\n", $encoded_app, $folding, ADRESSEMAILADMIN);
if ($headers) {
$headers .= "\n" ;
}
$headers .= $from;
$headers .= "Reply-To: $replyTo\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "Auto-Submitted:auto-generated\n";
$headers .= "Return-Path: <>";
$body = html_entity_decode($body, ENT_QUOTES, 'UTF-8')._("\n--\n\n« La route est longue, mais la voie est libre… »\nFramasoft ne vit que par vos dons (déductibles des impôts).\nMerci d'avance pour votre soutien http://soutenir.framasoft.org.");
mail($to, $subject, $body, $headers, $param);
}
/** /**
* Fonction permettant de générer les URL pour les sondage * Fonction permettant de générer les URL pour les sondage
* @param string $id L'identifiant du sondage * @param string $id L'identifiant du sondage

View File

@ -1,103 +1,113 @@
-- Base de données: `opensondage` -- --------------------------------------------------------
-- --
-- Table structure `poll`
--
CREATE TABLE IF NOT EXISTS `poll` (
`id` CHAR(16) NOT NULL,
`admin_id` CHAR(24) NOT NULL,
`title` TEXT NOT NULL,
`description` TEXT,
`admin_name` VARCHAR(64) DEFAULT NULL,
`admin_mail` VARCHAR(128) DEFAULT NULL,
`creation_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`end_date` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
`format` VARCHAR(1) DEFAULT NULL,
`editable` TINYINT(1) DEFAULT '0',
`receiveNewVotes` TINYINT(1) DEFAULT '0',
`active` TINYINT(1) DEFAULT '1',
PRIMARY KEY (`id`)
)
ENGINE =InnoDB
DEFAULT CHARSET =utf8;
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
-- Structure de la table `comments` -- Table structure `slot`
-- --
CREATE TABLE IF NOT EXISTS `comments` ( CREATE TABLE IF NOT EXISTS `slot` (
`id_comment` int(11) unsigned NOT NULL AUTO_INCREMENT, `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_sondage` char(16) NOT NULL, `poll_id` CHAR(16) NOT NULL,
`comment` text NOT NULL, `title` TEXT,
`usercomment` text, `moments` TEXT,
PRIMARY KEY (`id_comment`), PRIMARY KEY (`id`),
KEY `id_sondage` (`id_sondage`) KEY `poll_id` (`poll_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; )
ENGINE =InnoDB
DEFAULT CHARSET =utf8;
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
-- Structure de la table `sondage` -- Table structure `comment`
-- --
CREATE TABLE IF NOT EXISTS `sondage` ( CREATE TABLE IF NOT EXISTS `comment` (
`poll_id` char(16) NOT NULL, `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`admin_poll_id` char(24) DEFAULT NULL, `poll_id` CHAR(16) NOT NULL,
`title` text NOT NULL, `name` TEXT,
`comment` text, `comment` TEXT NOT NULL,
`admin_name` varchar(64) DEFAULT NULL, PRIMARY KEY (`id`),
`admin_mail` varchar(128) DEFAULT NULL, KEY `poll_id` (`poll_id`)
`creation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, )
`end_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', ENGINE =InnoDB
`format` varchar(1) DEFAULT NULL, DEFAULT CHARSET =utf8;
`editable` tinyint(1) DEFAULT '0',
`receiveNewVotes` tinyint(1) DEFAULT '0',
`active` tinyint(1) DEFAULT '1',
`statut` int(11) NOT NULL DEFAULT '1' COMMENT '1 = actif ; 0 = inactif ; ',
UNIQUE KEY `poll_id` (`poll_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
-- Structure de la table `sujet_studs` -- Table structure `vote`
-- --
CREATE TABLE IF NOT EXISTS `sujet_studs` ( CREATE TABLE IF NOT EXISTS `vote` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_sondage` char(16) NOT NULL, `poll_id` CHAR(16) NOT NULL,
`sujet` text, `name` VARCHAR(64) NOT NULL,
KEY `id_sondage` (`id_sondage`) `choices` TEXT NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8; PRIMARY KEY (`id`),
KEY `poll_id` (`poll_id`)
)
ENGINE =InnoDB
DEFAULT CHARSET =utf8
AUTO_INCREMENT =160284;
-- --------------------------------------------------------
-- --
-- Structure de la table `user_studs` -- Data for Name: poll; Type: TABLE DATA;
-- --
CREATE TABLE IF NOT EXISTS `user_studs` ( INSERT INTO `poll`
`id_users` int(11) unsigned NOT NULL AUTO_INCREMENT, (`id`, `description`, `admin_mail`, `admin_name`, `title`, `admin_id`, `end_date`, `format`)
`nom` varchar(64) NOT NULL,
`id_sondage` char(16) NOT NULL,
`reponses` text NOT NULL,
PRIMARY KEY (`id_users`),
KEY `id_sondage` (`id_sondage`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=160284 ;
INSERT INTO `sondage`
(`id_sondage`, `commentaires`, `mail_admin`, `nom_admin`,
`titre`, `id_sondage_admin`,
`date_fin`, `format`)
VALUES VALUES
('aqg259dth55iuhwm','Repas de Noel du service','Stephanie@retaillard.com','Stephanie', ('aqg259dth55iuhwm', 'Repas de Noel du service', 'Stephanie@retaillard.com', 'Stephanie', 'Repas de Noel',
'Repas de Noel','aqg259dth55iuhwmy9d8jlwk', 'aqg259dth55iuhwmy9d8jlwk', FROM_UNIXTIME('1627100361'), 'D');
FROM_UNIXTIME('1627100361'),'D+');
-- --
-- Data for Name: sujet_studs; Type: TABLE DATA; -- Data for Name: slot; Type: TABLE DATA;
-- --
INSERT INTO `sujet_studs` (`id_sondage`, `sujet`) VALUES INSERT INTO `slot` (`poll_id`, `title`, `moments`) VALUES
('aqg259dth55iuhwm','1225839600@12h,1225839600@19h,1226012400@12h,1226012400@19h,1226876400@12h,1226876400@19h,1227049200@12h,1227049200@19h,1227826800@12h,1227826800@19h'); ('aqg259dth55iuhwm', '1225839600', '12h,19h'),
('aqg259dth55iuhwm', '1226012400', '12h,19h'),
('aqg259dth55iuhwm', '1226876400', '12h,19h'),
('aqg259dth55iuhwm', '1227826800', '12h,19h');
-- --
-- Data for Name: user_studs; Type: TABLE DATA; -- Data for Name: vote; Type: TABLE DATA;
-- --
INSERT INTO `user_studs` (`nom`, `id_sondage`, `reponses`, `id_users`) VALUES INSERT INTO `vote` (`name`, `poll_id`, `choices`) VALUES
('marcel','aqg259dth55iuhwm','0110111101','933'), ('marcel', 'aqg259dth55iuhwm', '02202222'),
('paul','aqg259dth55iuhwm','1011010111','935'), ('paul', 'aqg259dth55iuhwm', '20220202'),
('sophie','aqg259dth55iuhwm','1110110000','945'), ('sophie', 'aqg259dth55iuhwm', '22202200'),
('barack','aqg259dth55iuhwm','0110000','948'), ('barack', 'aqg259dth55iuhwm', '02200000'),
('takashi','aqg259dth55iuhwm','0000110100','951'), ('takashi','aqg259dth55iuhwm', '00002202'),
('albert','aqg259dth55iuhwm','1010110','975'), ('albert', 'aqg259dth55iuhwm', '20202200'),
('alfred','aqg259dth55iuhwm','0110010','1135'), ('alfred', 'aqg259dth55iuhwm', '02200200'),
('marcs','aqg259dth55iuhwm','0100001010','1143'), ('marcs', 'aqg259dth55iuhwm', '02000020'),
('laure','aqg259dth55iuhwm','0011000','1347'), ('laure', 'aqg259dth55iuhwm', '00220000'),
('benda','aqg259dth55iuhwm','1101101100','1667'), ('benda', 'aqg259dth55iuhwm', '22022022'),
('Albert','aqg259dth55iuhwm','1111110011','1668'); ('albert', 'aqg259dth55iuhwm', '22222200');

View File

@ -50,7 +50,7 @@ $mailService = new MailService($config['use_smtp']);
* @param $mailService MailService The mail service * @param $mailService MailService The mail service
*/ */
function sendUpdateNotification($poll, $mailService) { function sendUpdateNotification($poll, $mailService) {
if ($poll->receiveNewVotes && !isset($_SESSION['mail_sent'][$poll->poll_id])) { if ($poll->receiveNewVotes && !isset($_SESSION['mail_sent'][$poll->id])) {
$subject = '[' . NOMAPPLICATION . '] ' . _('Poll\'s participation') . ' : ' . html_entity_decode($poll->title, ENT_QUOTES, 'UTF-8'); $subject = '[' . NOMAPPLICATION . '] ' . _('Poll\'s participation') . ' : ' . html_entity_decode($poll->title, ENT_QUOTES, 'UTF-8');
$message = html_entity_decode('"$nom" ', ENT_QUOTES, 'UTF-8') . $message = html_entity_decode('"$nom" ', ENT_QUOTES, 'UTF-8') .
@ -60,7 +60,7 @@ function sendUpdateNotification($poll, $mailService) {
$mailService->send($poll->admin_mail, $subject, $message); $mailService->send($poll->admin_mail, $subject, $message);
$_SESSION["mail_sent"][$poll->poll_id] = true; $_SESSION["mail_sent"][$poll->id] = true;
} }
} }

View File

@ -3,24 +3,33 @@
{block name=main} {block name=main}
<form action="{$admin_poll_id|poll_url:true}" method="POST"> <form action="{$admin_poll_id|poll_url:true}" method="POST">
<div class="alert alert-info text-center"> <div class="alert alert-info text-center">
<h2>{_("Column's adding")}</h2> <h2>{_('Column\'s adding')}</h2>
{if $format === 'D'}
<div class="form-group"> <div class="form-group">
<label for="newdate" class="col-md-4">{_("Day")}</label> <label for="newdate" class="col-md-4">{_('Day')}</label>
<div class="col-md-8"> <div class="col-md-8">
<div class="input-group date"> <div class="input-group date">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span> <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
<input type="text" id="newdate" data-date-format="{_("dd/mm/yyyy")}" aria-describedby="dateformat" name="newdate" class="form-control" placeholder="{_("dd/mm/yyyy")}" /> <input type="text" id="newdate" data-date-format="{_('dd/mm/yyyy')}" aria-describedby="dateformat" name="newdate" class="form-control" placeholder="{_('dd/mm/yyyy')}" />
</div> </div>
<span id="dateformat" class="sr-only">{_("(dd/mm/yyyy)")}</span> <span id="dateformat" class="sr-only">{_('(dd/mm/yyyy)')}</span>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="newmoment" class="col-md-4">{_("Time")}</label> <label for="newmoment" class="col-md-4">{_('Time')}</label>
<div class="col-md-8"> <div class="col-md-8">
<input type="text" id="newmoment" name="newmoment" class="form-control" /> <input type="text" id="newmoment" name="newmoment" class="form-control" />
</div> </div>
</div> </div>
{else}
<div class="form-group">
<label for="choice" class="col-md-4">{_('Choice')}</label>
<div class="col-md-8">
<input type="text" id="choice" name="choice" class="form-control" />
</div>
</div>
{/if}
<div class="form-group"> <div class="form-group">
<button class="btn btn-default" type="submit" name="back">{_('Back to the poll')}</button> <button class="btn btn-default" type="submit" name="back">{_('Back to the poll')}</button>
<button type="submit" name="confirm_add_slot" class="btn btn-success">{_('Add a column')}</button> <button type="submit" name="confirm_add_slot" class="btn btn-success">{_('Add a column')}</button>

View File

@ -8,9 +8,9 @@
{foreach $comments as $comment} {foreach $comments as $comment}
<div class="comment"> <div class="comment">
{if $admin} {if $admin}
<button type="submit" name="delete_comment" value="{$comment->id_comment}" class="btn btn-link" title="{_('Remove the comment')}"><span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">{_('Remove')}</span></button> <button type="submit" name="delete_comment" value="{$comment->id}" class="btn btn-link" title="{_('Remove the comment')}"><span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">{_('Remove')}</span></button>
{/if} {/if}
<b>{$comment->usercomment}</b>&nbsp; <b>{$comment->name}</b>&nbsp;
<span class="comment">{nl2br($comment->comment)}</span> <span class="comment">{nl2br($comment->comment)}</span>
</div> </div>
{/foreach} {/foreach}

View File

@ -14,7 +14,7 @@
<th role="presentation"></th> <th role="presentation"></th>
{foreach $slots as $id=>$slot} {foreach $slots as $id=>$slot}
<td headers="C{$id}"> <td headers="C{$id}">
<button type="submit" name="delete_column" value="{$slot->sujet}" class="btn btn-link btn-sm" title="{_('Remove the column')} {$slot->sujet}"><span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">{_('Remove')}</span></button> <button type="submit" name="delete_column" value="{$slot->id}" class="btn btn-link btn-sm" title="{_('Remove the column')} {$slot->title}"><span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">{_('Remove')}</span></button>
</td> </td>
{/foreach} {/foreach}
<td> <td>
@ -25,7 +25,7 @@
<tr> <tr>
<th role="presentation"></th> <th role="presentation"></th>
{foreach $slots as $id=>$slot} {foreach $slots as $id=>$slot}
<th class="bg-info" id="H{$id}">{$slot->sujet}</th> <th class="bg-info" id="H{$id}">{$slot->title}</th>
{/foreach} {/foreach}
<th></th> <th></th>
</tr> </tr>
@ -113,19 +113,19 @@
<ul class="list-unstyled choice"> <ul class="list-unstyled choice">
<li class="yes"> <li class="yes">
<input type="radio" id="y-choice-{$id}" name="choices[{$id}]" value="2" /> <input type="radio" id="y-choice-{$id}" name="choices[{$id}]" value="2" />
<label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{_('Vote yes for')} {$slot->sujet}"> <label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{_('Vote yes for')} {$slot->title}">
<span class="glyphicon glyphicon-ok"></span><span class="sr-only">{_('Yes')}</span> <span class="glyphicon glyphicon-ok"></span><span class="sr-only">{_('Yes')}</span>
</label> </label>
</li> </li>
<li class="ifneedbe"> <li class="ifneedbe">
<input type="radio" id="i-choice-{$id}" name="choices[{$id}]" value="1" /> <input type="radio" id="i-choice-{$id}" name="choices[{$id}]" value="1" />
<label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{_('Vote ifneedbe for')} {$slot->sujet}"> <label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{_('Vote ifneedbe for')} {$slot->title}">
(<span class="glyphicon glyphicon-ok"></span>)<span class="sr-only">{_('Ifneedbe')}</span> (<span class="glyphicon glyphicon-ok"></span>)<span class="sr-only">{_('Ifneedbe')}</span>
</label> </label>
</li> </li>
<li class="no"> <li class="no">
<input type="radio" id="n-choice-{$id}" name="choices[{$id}]" value="0" checked/> <input type="radio" id="n-choice-{$id}" name="choices[{$id}]" value="0" checked/>
<label class="btn btn-default btn-xs" for="n-choice-{$id}" title="{_('Vote no for')} {$slot->sujet}"> <label class="btn btn-default btn-xs" for="n-choice-{$id}" title="{_('Vote no for')} {$slot->title}">
<span class="glyphicon glyphicon-ban-circle"></span><span class="sr-only">{_('No')}</span> <span class="glyphicon glyphicon-ban-circle"></span><span class="sr-only">{_('No')}</span>
</label> </label>
</li> </li>
@ -177,7 +177,7 @@
<ul style="list-style:none"> <ul style="list-style:none">
{foreach $slots as $slot} {foreach $slots as $slot}
{if $best_choices[$i] == $max} {if $best_choices[$i] == $max}
<li><strong>{$slot->sujet}</strong></li> <li><strong>{$slot->title}</strong></li>
{/if} {/if}
{$i = $i+1} {$i = $i+1}
{/foreach} {/foreach}

View File

@ -1,5 +1,5 @@
{if !is_array($best_moments) || empty($best_moments)} {if !is_array($best_choices) || empty($best_choices)}
{$best_moments = [0]} {$best_choices = [0]}
{/if} {/if}
<h3>{_('Votes of the poll')}</h3> <h3>{_('Votes of the poll')}</h3>
@ -168,11 +168,11 @@
{* Line displaying best moments *} {* Line displaying best moments *}
{$count_bests = 0} {$count_bests = 0}
{$max = max($best_moments)} {$max = max($best_choices)}
{if $max > 0} {if $max > 0}
<tr id="addition"> <tr id="addition">
<td>{_("Addition")}</td> <td>{_("Addition")}</td>
{foreach $best_moments as $best_moment} {foreach $best_choices as $best_moment}
{if $max == $best_moment} {if $max == $best_moment}
{$count_bests = $count_bests +1} {$count_bests = $count_bests +1}
<td><span class="glyphicon glyphicon-star text-warning"></span><span>{$max}</span></td> <td><span class="glyphicon glyphicon-star text-warning"></span><span>{$max}</span></td>
@ -189,7 +189,7 @@
{* Best votes listing *} {* Best votes listing *}
{$max = max($best_moments)} {$max = max($best_choices)}
{if $max > 0} {if $max > 0}
<div class="row"> <div class="row">
{if $count_bests == 1} {if $count_bests == 1}
@ -207,7 +207,7 @@
<ul style="list-style:none"> <ul style="list-style:none">
{foreach $slots as $slot} {foreach $slots as $slot}
{foreach $slot->moments as $moment} {foreach $slot->moments as $moment}
{if $best_moments[$i] == $max} {if $best_choices[$i] == $max}
<li><strong>{$slot->day|date_format:$date_format.txt_full} - {$moment}</strong></li> <li><strong>{$slot->day|date_format:$date_format.txt_full} - {$moment}</strong></li>
{/if} {/if}
{$i = $i+1} {$i = $i+1}