private function alterPollTable(\PDO $pdo) { $pdo->exec(' ALTER TABLE `' . Utils::table('poll') . '` ADD `receiveNewComments` TINYINT(1) DEFAULT \'0\' AFTER `receiveNewVotes`'); }
function bandeau_titre($titre) { global $ALLOWED_LANGUAGES; $img = IMAGE_TITRE ? '<img src="' . Utils::get_server_name() . IMAGE_TITRE . '" alt="' . NOMAPPLICATION . '" class="img-responsive">' : ''; echo ' <header role="banner">'; if (count($ALLOWED_LANGUAGES) > 1) { echo '<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="' . __('Language selector', 'Select the language') . '" >' . liste_lang() . '</select> <span class="input-group-btn"> <button type="submit" class="btn btn-default btn-sm" title="' . __('Language selector', 'Change the language') . '">OK</button> </span> </div> </form>'; } echo ' <h1><a href="' . Utils::get_server_name() . '" title="' . __('Generic', 'Home') . ' - ' . NOMAPPLICATION . '">' . $img . '</a></h1> <h2 class="lead"><i>' . $titre . '</i></h2> <hr class="trait" role="presentation" /> </header> <main role="main">'; global $connect; $tables = $connect->allTables(); $diff = array_diff([Utils::table('comment'), Utils::table('poll'), Utils::table('slot'), Utils::table('vote')], $tables); if (0 != count($diff)) { echo '<div class="alert alert-danger">' . __('Error', 'Framadate is not properly installed, please check the "INSTALL" to setup the database before continuing.') . '</div>'; bandeau_pied(); die; } }
/** * Send a notification to the poll admin to notify him about an update. * * @param $poll stdClass The poll * @param $mailService MailService The mail service * @param $name string The name user who triggered the notification * @param $type int cf: Constants on the top of this page */ function sendUpdateNotification($poll, $mailService, $name, $type) { if (!isset($_SESSION['mail_sent'])) { $_SESSION['mail_sent'] = []; } if ($poll->receiveNewVotes) { $subject = '[' . NOMAPPLICATION . '] ' . __f('Mail', 'Poll\'s participation: %s', $poll->title); $message = $name . ' '; switch ($type) { case UPDATE_VOTE: $message .= __('Mail', "updated a vote.\nYou can find your poll at the link") . " :\n\n"; break; case ADD_VOTE: $message .= __('Mail', "filled a vote.\nYou can find your poll at the link") . " :\n\n"; break; case ADD_COMMENT: $message .= __('Mail', "wrote a comment.\nYou can find your poll at the link") . " :\n\n"; break; } $urlSondage = Utils::getUrlSondage($poll->admin_id, true); $message .= '<a href="' . $urlSondage . '">' . $urlSondage . '</a>' . "\n\n"; $messageTypeKey = $type . '-' . $poll->id; $mailService->send($poll->admin_mail, $subject, $message, $messageTypeKey); } }
/** * This method could check if the execute method should be called. * It is called before the execute method. * * @param \PDO $pdo The connection to database * @return bool true is the Migration should be executed. */ function preCondition(\PDO $pdo) { $stmt = $pdo->query('SHOW TABLES'); $tables = $stmt->fetchAll(\PDO::FETCH_COLUMN); // Check if there is no tables but the MIGRATION_TABLE one $diff = array_diff($tables, [Utils::table(MIGRATION_TABLE)]); return count($diff) === 0; }
function preCondition(\PDO $pdo) { $stmt = $pdo->query('SHOW TABLES'); $tables = $stmt->fetchAll(\PDO::FETCH_COLUMN); // Check if tables of v0.9 are presents $diff = array_diff([Utils::table('poll'), Utils::table('slot'), Utils::table('vote'), Utils::table('comment')], $tables); return count($diff) === 0; }
private function alterPollTable(\PDO $pdo) { $pdo->exec(' ALTER TABLE `' . Utils::table('vote') . '` ADD `uniqId` CHAR(16) NOT NULL AFTER `id`, ADD INDEX (`uniqId`) ;'); }
private function generateUniqIdsForEmptyOnes($pdo) { $select = $pdo->query(' SELECT `id` FROM `' . Utils::table('vote') . '` WHERE `uniqid` = \'\''); $update = $pdo->prepare(' UPDATE `' . Utils::table('vote') . '` SET `uniqid` = :uniqid WHERE `id` = :id'); while ($row = $select->fetch(\PDO::FETCH_OBJ)) { $token = Token::getToken(16); $update->execute(['uniqid' => $token, 'id' => $row->id]); } }
private function rpadVotes($pdo) { $pdo->exec('UPDATE ' . Utils::table('vote') . ' fv INNER JOIN ( SELECT v.id, RPAD(v.choices, inn.slots_count, \'0\') new_choices FROM ' . Utils::table('vote') . ' v INNER JOIN (SELECT s.poll_id, SUM(IFNULL(LENGTH(s.moments) - LENGTH(REPLACE(s.moments, \',\', \'\')) + 1, 1)) slots_count FROM ' . Utils::table('slot') . ' s GROUP BY s.poll_id ORDER BY s.poll_id) inn ON inn.poll_id = v.poll_id WHERE LENGTH(v.choices) != inn.slots_count ) computed ON fv.id = computed.id SET fv.choices = computed.new_choices'); }
/** * Send a notification to the poll admin to notify him about an update. * * @param stdClass $poll The poll * @param MailService $mailService The mail service * @param int $type cf: Constants on the top of this page */ function sendUpdateNotification($poll, $mailService, $type) { if (!isset($_SESSION['mail_sent'])) { $_SESSION['mail_sent'] = []; } if ($poll->receiveNewVotes) { $subject = '[' . NOMAPPLICATION . '] ' . __f('Mail', 'Notification of poll: %s', $poll->title); $message = ''; switch ($type) { case UPDATE_POLL: $message = __f('Mail', 'Someone just change your poll available at the following link %s.', Utils::getUrlSondage($poll->admin_id, true)) . "\n\n"; break; case DELETED_POLL: $message = __f('Mail', 'Someone just delete your poll %s.', Utils::htmlEscape($poll->title)) . "\n\n"; break; } $messageTypeKey = $type . '-' . $poll->id; $mailService->send($poll->admin_mail, $subject, $message, $messageTypeKey); } }
$choices = str_split($vote->choices); foreach ($choices as $choice) { switch ($choice) { case 0: $text = __('Generic', 'No'); break; case 1: $text = __('Generic', 'Ifneedbe'); break; case 2: $text = __('Generic', 'Yes'); break; default: $text = 'unkown'; } echo Utils::csvEscape($text); echo ','; } echo "\r\n"; } // END - Vote lines // HTTP headers $content = ob_get_clean(); $filesize = strlen($content); $filename = Utils::cleanFilename($poll->title) . '.csv'; 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 echo $content;
function smarty_modifier_html($html) { return Utils::htmlEscape($html); }
function deleteByPollId($poll_id) { $prepared = $this->prepare('DELETE FROM `' . Utils::table('slot') . '` WHERE poll_id = ?'); return $prepared->execute([$poll_id]); }
if ($config['user_can_add_img_or_link']) { echo '<span class="input-group-addon btn-link md-a-img" title="' . __('Step 2 classic', 'Add a link or an image') . ' - ' . __('Generic', 'Choice') . ' ' . ($i + 1) . '" ><span class="glyphicon glyphicon-picture"></span> <span class="glyphicon glyphicon-link"></span></span>'; } echo ' </div> </div>' . "\n"; } echo ' <div class="col-md-4"> <div class="btn-group btn-group"> <button type="button" id="remove-a-choice" class="btn btn-default" title="' . __('Step 2 classic', 'Remove a choice') . '"><span class="glyphicon glyphicon-minus text-info"></span><span class="sr-only">' . __('Generic', 'Remove') . '</span></button> <button type="button" id="add-a-choice" class="btn btn-default" title="' . __('Step 2 classic', 'Add a choice') . '"><span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">' . __('Generic', 'Add') . '</span></button> </div> </div> <div class="col-md-8 text-right"> <a class="btn btn-default" href="' . Utils::get_server_name() . 'create_poll.php?type=classic" title="' . __('Step 2', 'Back to step 1') . '">' . __('Generic', 'Back') . '</a> <button name="fin_sondage_autre" value="' . __('Generic', 'Next') . '" type="submit" class="btn btn-success disabled" title="' . __('Step 2', 'Go to step 3') . '">' . __('Generic', 'Next') . '</button> </div> </div> </div> <div class="modal fade" id="md-a-imgModal" tabindex="-1" role="dialog" aria-labelledby="md-a-imgModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">' . __('Generic', 'Close') . '</span></button> <p class="modal-title" id="md-a-imgModalLabel">' . __('Step 2 classic', 'Add a link or an image') . '</p> </div> <div class="modal-body"> <p class="alert alert-info">' . __('Step 2 classic', 'These fields are optional. You can add a link, an image or both.') . '</p> <div class="form-group"> <label for="md-img"><span class="glyphicon glyphicon-picture"></span> ' . __('Step 2 classic', 'URL of the image') . '</label>
use Framadate\Migration\AddColumn_receiveNewComments_For_0_9; use Framadate\Migration\AddColumn_uniqId_In_vote_For_0_9; use Framadate\Migration\AddColumn_hidden_In_poll_For_0_9; use Framadate\Migration\Generate_uniqId_for_old_votes; use Framadate\Migration\Migration; use Framadate\Migration\RPadVotes_from_0_8; use Framadate\Utils; include_once __DIR__ . '/../app/inc/init.php'; set_time_limit(300); // List a Migration sub classes to execute $migrations = [new From_0_0_to_0_8_Migration(), new From_0_8_to_0_9_Migration(), new AddColumn_receiveNewComments_For_0_9(), new AddColumn_uniqId_In_vote_For_0_9(), new AddColumn_hidden_In_poll_For_0_9(), new Generate_uniqId_for_old_votes(), new RPadVotes_from_0_8()]; // --------------------------------------- // Check if MIGRATION_TABLE already exists $tables = $connect->allTables(); $pdo = $connect->getPDO(); $prefixedMigrationTable = Utils::table(MIGRATION_TABLE); if (!in_array($prefixedMigrationTable, $tables)) { $pdo->exec(' CREATE TABLE IF NOT EXISTS `' . $prefixedMigrationTable . '` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` TEXT NOT NULL, `execute_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE = MyISAM DEFAULT CHARSET = utf8;'); } $selectStmt = $pdo->prepare('SELECT id FROM `' . $prefixedMigrationTable . '` WHERE name=?'); $insertStmt = $pdo->prepare('INSERT INTO `' . $prefixedMigrationTable . '` (name) VALUES (?)'); $countSucceeded = 0; $countFailed = 0;
/** * @return array */ function ok() { return array('status' => 'OK', 'msg' => __f('Installation', 'Ended', Utils::get_server_name())); }
// Summary $summary = '<ul>'; $choices = $_SESSION['form']->getChoices(); foreach ($choices as $choice) { $summary .= '<li>' . strftime($date_format['txt_full'], $choice->getName()); $first = true; foreach ($choice->getSlots() as $slots) { $summary .= $first ? ': ' : ', '; $summary .= $slots; $first = false; } $summary .= '</li>'; } $summary .= '</ul>'; echo ' <form name="formulaire" action="' . Utils::get_server_name() . 'create_date_poll.php" method="POST" class="form-horizontal" role="form"> <div class="row" id="selected-days"> <div class="col-md-8 col-md-offset-2"> <h3>' . __('Step 3', 'Confirm the creation of your poll') . '</h3> <div class="well summary"> <h4>' . __('Step 3', 'List of your choices') . '</h4> ' . $summary . ' </div> <div class="alert alert-info clearfix"> <p>' . __f('Step 3', 'Your poll will be automatically archived in %d days.', $config['default_poll_duration']) . ' <br />' . __('Step 3', 'You can set a closer archiving date for it.') . '</p> <div class="form-group"> <label for="enddate" class="col-sm-5 control-label">' . __('Step 3', 'Archiving date:') . '</label> <div class="col-sm-6"> <div class="input-group date"> <span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
* 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\PollService; use Framadate\Utils; include_once __DIR__ . '/app/inc/init.php'; if (!is_file(CONF_FILENAME)) { header('Location: ' . Utils::get_server_name() . 'admin/install.php'); exit; } /* SERVICES */ /* -------- */ $logService = '\\Framadate\\Services\\LogService'; $pollService = new PollService($connect, new $logService()); /* PAGE */ /* ---- */ $demoPoll = $pollService->findById('aqg259dth55iuhwm'); $nbcol = $config['show_what_is_that'] + $config['show_the_software'] + $config['show_cultivate_your_garden']; $smarty->assign('show_what_is_that', $config['show_what_is_that']); $smarty->assign('show_the_software', $config['show_the_software']); $smarty->assign('show_cultivate_your_garden', $config['show_cultivate_your_garden']); $smarty->assign('col_size', 12 / $nbcol); $smarty->assign('demo_poll', $demoPoll);
private function alterPollTable(\PDO $pdo) { $pdo->exec(' ALTER TABLE `' . Utils::table('poll') . '` ADD `hidden` TINYINT( 1 ) NOT NULL DEFAULT "0"'); }
$errors['name']['aria'] = 'aria-describeby="poll_name_error" '; $errors['name']['class'] = ' has-error'; $errors['name']['msg'] = __('Error', 'Something is wrong with the format'); } if (empty($_POST['mail'])) { $errors['email']['aria'] = 'aria-describeby="poll_name_error" '; $errors['email']['class'] = ' has-error'; $errors['email']['msg'] = __('Error', 'Enter an email address'); } elseif ($error_on_mail) { $errors['email']['aria'] = 'aria-describeby="poll_email_error" '; $errors['email']['class'] = ' has-error'; $errors['email']['msg'] = __('Error', 'The address is not correct! You should enter a valid email address (like r.stallman@outlock.com) in order to receive the link to your poll.'); } } $useRemoteUser = USE_REMOTE_USER && isset($_SERVER['REMOTE_USER']); $smarty->assign('title', $title); $smarty->assign('useRemoteUser', $useRemoteUser); $smarty->assign('errors', $errors); $smarty->assign('use_smtp', $config['use_smtp']); $smarty->assign('goToStep2', GO_TO_STEP_2); $smarty->assign('poll_type', $poll_type); $smarty->assign('poll_title', Utils::fromPostOrDefault('title', $_SESSION['form']->title)); $smarty->assign('poll_description', Utils::fromPostOrDefault('description', $_SESSION['form']->description)); $smarty->assign('poll_name', Utils::fromPostOrDefault('name', $_SESSION['form']->admin_name)); $smarty->assign('poll_mail', Utils::fromPostOrDefault('mail', $_SESSION['form']->admin_mail)); $smarty->assign('poll_editable', Utils::fromPostOrDefault('editable', $_SESSION['form']->editable)); $smarty->assign('poll_receiveNewVotes', Utils::fromPostOrDefault('receiveNewVotes', $_SESSION['form']->receiveNewVotes)); $smarty->assign('poll_receiveNewComments', Utils::fromPostOrDefault('receiveNewComments', $_SESSION['form']->receiveNewComments)); $smarty->assign('poll_hidden', Utils::fromPostOrDefault('hidden', $_SESSION['form']->hidden)); $smarty->assign('form', $_SESSION['form']); $smarty->display('create_poll.tpl');
* * 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\InstallService; use Framadate\Utils; require_once '../app/inc/init.php'; if (is_file(CONF_FILENAME)) { header('Location: ' . Utils::get_server_name()); exit; } $error = null; $installService = new InstallService(); if (!empty($_POST)) { $installService->updateFields($_POST); $result = $installService->install($smarty); if ($result['status'] === 'OK') { header('Location: ' . Utils::get_server_name() . 'admin/migration.php'); exit; } else { $error = __('Error', $result['code']); } } $smarty->assign('error', $error); $smarty->assign('title', __('Admin', 'Installation')); $smarty->assign('fields', $installService->getFields()); $smarty->display('admin/install.tpl');
/** * Check if name is already used for the given poll. * * @param int $poll_id ID of the poll * @param string $name Name of the vote * @return bool true if vote already exists */ public function existsByPollIdAndName($poll_id, $name) { $prepared = $this->prepare('SELECT 1 FROM `' . Utils::table('vote') . '` WHERE poll_id = ? AND name = ?'); $prepared->execute(array($poll_id, $name)); return $prepared->rowCount() > 0; }
public function exists($poll_id, $name, $comment) { $prepared = $this->prepare('SELECT 1 FROM `' . Utils::table('comment') . '` WHERE poll_id = ? AND name = ? AND comment = ?'); $prepared->execute(array($poll_id, $name, $comment)); return $prepared->rowCount() > 0; }
/** * Get the total number of polls in databse. * * @param array $search Array of search : ['id'=>..., 'title'=>..., 'name'=>...] * @return int The number of polls */ public function count($search = null) { // Total count $prepared = $this->prepare(' SELECT count(1) nb FROM `' . Utils::table('poll') . '` p WHERE (:id = "" OR p.id LIKE :id) AND (:title = "" OR p.title LIKE :title) AND (:name = "" OR p.admin_name LIKE :name) ORDER BY p.title ASC'); $poll = $search == null ? '' : $search['poll'] . '%'; $title = $search == null ? '' : '%' . $search['title'] . '%'; $name = $search == null ? '' : '%' . $search['name'] . '%'; $prepared->bindParam(':id', $poll, PDO::PARAM_STR); $prepared->bindParam(':title', $title, PDO::PARAM_STR); $prepared->bindParam(':name', $name, PDO::PARAM_STR); $prepared->execute(); $count = $prepared->fetch(); /*echo '---'; print_r($count); echo '---'; exit;*/ return $count->nb; }
private function migrateFromUserStudsToVote(\PDO $pdo) { $select = $pdo->query(' SELECT `id_sondage`, `nom`, REPLACE(REPLACE(REPLACE(`reponses`, 1, \'X\'), 2, 1), \'X\', 2) reponses FROM `user_studs`'); $insert = $pdo->prepare(' INSERT INTO `' . Utils::table('vote') . '` (`poll_id`, `name`, `choices`) VALUE (?,?,?)'); while ($row = $select->fetch(\PDO::FETCH_OBJ)) { $insert->execute([$row->id_sondage, $this->unescape($row->nom), $row->reponses]); } }