private function alterPollTable(\PDO $pdo)
    {
        $pdo->exec('
ALTER TABLE `' . Utils::table('poll') . '`
        ADD `receiveNewComments` TINYINT(1) DEFAULT \'0\'
        AFTER `receiveNewVotes`');
    }
Esempio n. 2
0
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;
    }
}
 private function alterPollTable(\PDO $pdo)
 {
     $pdo->exec('
     ALTER TABLE `' . Utils::table('vote') . '`
     ADD `uniqId` CHAR(16) NOT NULL
     AFTER `id`,
     ADD INDEX (`uniqId`) ;');
 }
 /**
  * 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;
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
    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');
    }
    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]);
        }
    }
Esempio n. 8
0
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;
Esempio n. 9
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;
    }
Esempio n. 10
0
 /**
  * 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;
 }
Esempio n. 11
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;
 }
Esempio n. 12
0
 function deleteByPollId($poll_id)
 {
     $prepared = $this->prepare('DELETE FROM `' . Utils::table('slot') . '` WHERE poll_id = ?');
     return $prepared->execute([$poll_id]);
 }
 private function alterPollTable(\PDO $pdo)
 {
     $pdo->exec('
     ALTER TABLE `' . Utils::table('poll') . '`
     ADD `hidden` TINYINT( 1 ) NOT NULL DEFAULT "0"');
 }
    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]);
        }
    }