Refactoring some code:
* Store all informations about forms into an object "Form" stored in $_SESSION['form'] * Replace connection to database by PDO object * Check if database is ready in bandeaux.php file
This commit is contained in:
parent
514369387b
commit
1437eaf47e
42
app/classes/Framadate/Choice.php
Normal file
42
app/classes/Framadate/Choice.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
namespace Framadate;
|
||||||
|
|
||||||
|
class Choice
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Name of the Choice
|
||||||
|
*/
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All availables slots for this Choice.
|
||||||
|
*/
|
||||||
|
private $slots;
|
||||||
|
|
||||||
|
public function __construct($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
$this->slots = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSlot($slot)
|
||||||
|
{
|
||||||
|
$this->slots[] = $slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSlots()
|
||||||
|
{
|
||||||
|
return $this->slots;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function compare(Choice $a, Choice $b)
|
||||||
|
{
|
||||||
|
return strcmp($a->name, $b->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
58
app/classes/Framadate/Form.php
Normal file
58
app/classes/Framadate/Form.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
namespace Framadate;
|
||||||
|
|
||||||
|
class Form
|
||||||
|
{
|
||||||
|
|
||||||
|
public $titre;
|
||||||
|
public $commentaires;
|
||||||
|
public $nom;
|
||||||
|
public $adresse;
|
||||||
|
public $formatsondage;
|
||||||
|
public $champdatefin;
|
||||||
|
public $choix_sondage;
|
||||||
|
public $studsplus;
|
||||||
|
public $mailsonde;
|
||||||
|
public $toutchoix;
|
||||||
|
public $totalchoixjour;
|
||||||
|
public $horaires;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Step of form
|
||||||
|
*/
|
||||||
|
public $step = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of available choices
|
||||||
|
*/
|
||||||
|
private $choices;
|
||||||
|
|
||||||
|
public function __construct(){
|
||||||
|
$this->clearChoices();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clearChoices() {
|
||||||
|
$this->choices = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addChoice(Choice $choice)
|
||||||
|
{
|
||||||
|
$this->choices[] = $choice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getChoices()
|
||||||
|
{
|
||||||
|
return $this->choices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sortChoices()
|
||||||
|
{
|
||||||
|
usort($this->choices, array('Framadate\Choice', 'compare'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function lastChoice()
|
||||||
|
{
|
||||||
|
return end($this->choices);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
39
app/classes/Framadate/FramaDB.php
Normal file
39
app/classes/Framadate/FramaDB.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
namespace Framadate;
|
||||||
|
|
||||||
|
class FramaDB
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* PDO Object, connection to database.
|
||||||
|
*/
|
||||||
|
private $pdo = null;
|
||||||
|
|
||||||
|
function __construct($connection_string, $user, $password)
|
||||||
|
{
|
||||||
|
$this->pdo = new \PDO($connection_string, $user, $password);
|
||||||
|
}
|
||||||
|
|
||||||
|
function areTablesCreated()
|
||||||
|
{
|
||||||
|
$result= $this->pdo->query('SHOW TABLES');
|
||||||
|
$schemas = $result->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
|
return !empty(array_diff($schemas, ['comments', 'sondage', 'sujet_studs', 'user_studs']));
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepare($sql) {
|
||||||
|
return $this->pdo->prepare($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
function beginTransaction() {
|
||||||
|
$this->pdo->beginTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
function commit() {
|
||||||
|
$this->pdo->commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
function query($sql) {
|
||||||
|
return $this->pdo->query($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -23,9 +23,10 @@ class Utils
|
|||||||
public static function get_server_name()
|
public static function get_server_name()
|
||||||
{
|
{
|
||||||
$scheme = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') ? 'https' : 'http';
|
$scheme = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') ? 'https' : 'http';
|
||||||
$port = in_array($_SERVER['SERVER_PORT'], [80, 443]) ? '/' : ':' . $_SERVER['SERVER_PORT'] . '/';
|
$port = in_array($_SERVER['SERVER_PORT'], [80, 443]) ? '' : ':' . $_SERVER['SERVER_PORT'];
|
||||||
$server_name = $_SERVER['SERVER_NAME'] . $port . dirname($_SERVER['SCRIPT_NAME']) . '/';
|
$dirname = dirname($_SERVER['SCRIPT_NAME']);
|
||||||
|
$dirname = $dirname === '\\' ? '/' : $dirname . '/';
|
||||||
|
$server_name = $_SERVER['SERVER_NAME'] . $port . $dirname;
|
||||||
return $scheme . '://' . str_replace('/admin','',str_replace('//','/',str_replace('///','/',$server_name)));
|
return $scheme . '://' . str_replace('/admin','',str_replace('//','/',str_replace('///','/',$server_name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,43 +223,41 @@ class Utils
|
|||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function remove_sondage($connect, $numsondage)
|
/**
|
||||||
|
* Completly delete data about the given poll
|
||||||
|
*/
|
||||||
|
public static function removeSondage($poll_id)
|
||||||
{
|
{
|
||||||
$connect->StartTrans();
|
global $connect;
|
||||||
|
|
||||||
$req = 'DELETE FROM sondage WHERE id_sondage = ' . $connect->Param('numsondage') ;
|
$prepared = $connect->prepare('DELETE FROM sujet_studs WHERE id_sondage = ?');
|
||||||
$sql = $connect->Prepare($req);
|
$prepared->execute(array($poll_id));
|
||||||
$connect->Execute($sql, [$numsondage]);
|
|
||||||
|
|
||||||
$req = 'DELETE FROM sujet_studs WHERE id_sondage = ' . $connect->Param('numsondage') ;
|
$prepared = $connect->prepare('DELETE FROM user_studs WHERE id_sondage = ?');
|
||||||
$sql = $connect->Prepare($req);
|
$prepared->execute(array($poll_id));
|
||||||
$connect->Execute($sql, [$numsondage]);
|
|
||||||
|
|
||||||
$req = 'DELETE FROM user_studs WHERE id_sondage = ' . $connect->Param('numsondage') ;
|
$prepared = $connect->prepare('DELETE FROM comments WHERE id_sondage = ?');
|
||||||
$sql = $connect->Prepare($req);
|
$prepared->execute(array($poll_id));
|
||||||
$connect->Execute($sql, [$numsondage]);
|
|
||||||
|
|
||||||
$req = 'DELETE FROM comments WHERE id_sondage = ' . $connect->Param('numsondage') ;
|
$prepared = $connect->prepare('DELETE FROM sondage WHERE id_sondage = ?');
|
||||||
$sql = $connect->Prepare($req);
|
$prepared->execute(array($poll_id));
|
||||||
$connect->Execute($sql, [$numsondage]);
|
|
||||||
|
|
||||||
$suppression_OK = ! $connect->HasFailedTrans();
|
|
||||||
$connect->CompleteTrans();
|
|
||||||
|
|
||||||
return $suppression_OK ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function cleaning_polls($connect, $log_txt) {
|
public static function cleaningOldPolls($log_txt) {
|
||||||
$connect->StartTrans();
|
global $connect;
|
||||||
$req = 'SELECT * FROM sondage WHERE date_fin < NOW() LIMIT 20';
|
|
||||||
$sql = $connect->Prepare($req);
|
|
||||||
$cleaning = $connect->Execute($sql);
|
|
||||||
|
|
||||||
while ($dcleaning = $cleaning->FetchNextObject(false)) {
|
$resultSet = $connect->query('SELECT id_sondage, format, nom_admin, mail_admin FROM sondage WHERE date_fin < NOW() LIMIT 20');
|
||||||
if (self::remove_sondage($connect, $dcleaning->id_sondage)) {
|
$toClean = $resultSet->fetchAll(\PDO::FETCH_CLASS);
|
||||||
error_log(date('H:i:s d/m/Y:') . ' EXPIRATION: '. $dcleaning->id_sondage."\t".$dcleaning->format."\t".$dcleaning->nom_admin."\t".$dcleaning->mail_admin."\n", 3, $log_txt);
|
|
||||||
|
echo '<pre>toClean:'.print_r($toClean, true).'</pre>';
|
||||||
|
|
||||||
|
$connect->beginTransaction();
|
||||||
|
foreach ($toClean as $row) {
|
||||||
|
if (self::removeSondage($row->id_sondage)) {
|
||||||
|
error_log(date('H:i:s d/m/Y:') . ' EXPIRATION: '. $row->id_sondage."\t".$row->format."\t".$row->nom_admin."\t".$row->mail_admin."\n", 3, $log_txt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$connect->CompleteTrans();
|
$connect->commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,14 @@ require_once __DIR__ . '/../../vendor/autoload.php';
|
|||||||
include_once __DIR__ . '/constants.php';
|
include_once __DIR__ . '/constants.php';
|
||||||
include_once __DIR__ . '/i18n.php';
|
include_once __DIR__ . '/i18n.php';
|
||||||
|
|
||||||
$connect = NewADOConnection(BASE_TYPE);
|
use Framadate\FramaDB;
|
||||||
$connect->Connect(SERVEURBASE, USERBASE, USERPASSWD, BASE);
|
use Framadate\Form;
|
||||||
|
use Framadate\Choice;
|
||||||
|
use Framadate\Utils;
|
||||||
|
|
||||||
|
if (session_id() == "") {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
$connect = new Framadate\FramaDB(DB_CONNECTION_STRING, DB_USER, DB_PASSWORD);
|
||||||
$err = 0;
|
$err = 0;
|
||||||
|
@ -43,6 +43,14 @@ function bandeau_titre($titre)
|
|||||||
<hr class="trait" role="presentation" />
|
<hr class="trait" role="presentation" />
|
||||||
</header>
|
</header>
|
||||||
<main role="main">';
|
<main role="main">';
|
||||||
|
|
||||||
|
global $connect;
|
||||||
|
if ($connect->areTablesCreated()) {
|
||||||
|
echo '<div class="alert alert-danger">'. _('Framadate is not properly installed, please check the "INSTALL" to setup the database before continuing.') .'</div>';
|
||||||
|
bandeau_pied();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function liste_lang()
|
function liste_lang()
|
||||||
|
102
choix_date.php
102
choix_date.php
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
namespace Framadate;
|
namespace Framadate;
|
||||||
|
|
||||||
session_start();
|
include_once __DIR__ . '/app/inc/init.php';
|
||||||
|
|
||||||
include_once('creation_sondage.php');
|
include_once('creation_sondage.php');
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ if (is_readable('bandeaux_local.php')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Step 1/3 : error if $_SESSION from info_sondage are not valid
|
// Step 1/3 : error if $_SESSION from info_sondage are not valid
|
||||||
if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmpty('nom', $_SESSION) === false || (($config['use_smtp']) ? Utils::issetAndNoEmpty('adresse', $_SESSION) === false : false)) {
|
if (!isset($_SESSION['form']->titre) || !isset($_SESSION['form']->nom) || (($config['use_smtp']) ? !isset($_SESSION['form']->adresse) : false)) {
|
||||||
|
|
||||||
Utils::print_header ( _("Error!") );
|
Utils::print_header ( _("Error!") );
|
||||||
bandeau_titre(_("Error!"));
|
bandeau_titre(_("Error!"));
|
||||||
@ -73,70 +73,103 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$_SESSION["toutchoix"]=substr($choixdate,1);
|
$_SESSION['form']->toutchoix=substr($choixdate,1);
|
||||||
|
|
||||||
// Expiration date → 6 months after last day if not filled or in bad format
|
// Expiration date → 6 months after last day if not filled or in bad format
|
||||||
$_SESSION["champdatefin"]=end($temp_results)+(86400 * $config['default_poll_duration']);
|
$_SESSION['form']->champdatefin=end($temp_results)+(86400 * $config['default_poll_duration']);
|
||||||
|
|
||||||
if (Utils::issetAndNoEmpty('champdatefin')) {
|
if (Utils::issetAndNoEmpty('champdatefin')) {
|
||||||
$registredate = explode("/",$_POST["champdatefin"]);
|
$registredate = explode("/",$_POST["champdatefin"]);
|
||||||
if (is_array($registredate) == true && count($registredate) == 3) {
|
if (is_array($registredate) == true && count($registredate) == 3) {
|
||||||
$time = mktime(0,0,0,$registredate[1],$registredate[0],$registredate[2]);
|
$time = mktime(0,0,0,$registredate[1],$registredate[0],$registredate[2]);
|
||||||
if ($time > time() + (24*60*60)) {
|
if ($time > time() + (24*60*60)) {
|
||||||
$_SESSION["champdatefin"]=$time;
|
$_SESSION['form']->champdatefin=$time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ajouter_sondage();
|
exit('<pre>'.print_r($_SESSION, true).'</pre>');
|
||||||
|
$admin_poll_id = ajouter_sondage(
|
||||||
|
$_SESSION['form']->titre,
|
||||||
|
$_SESSION['form']->commentaires,
|
||||||
|
$_SESSION['form']->nom,
|
||||||
|
$_SESSION['form']->adresse,
|
||||||
|
$_SESSION['form']->formatsondage,
|
||||||
|
$_SESSION['form']->champdatefin,
|
||||||
|
$_SESSION['form']->mailsonde,
|
||||||
|
$_SESSION['form']->toutchoix
|
||||||
|
);
|
||||||
|
|
||||||
|
unset($_SESSION['form']);
|
||||||
|
exit('<pre>'.print_r($_SESSION, true).'</pre>');
|
||||||
|
|
||||||
|
|
||||||
|
Utils::cleaningOldPolls($connect, 'admin/logs_studs.txt');
|
||||||
|
|
||||||
|
// TODO cleanup $_SESSION + Redirect
|
||||||
|
|
||||||
|
// Don't keep days, hours and choices in memory (in order to make new polls)
|
||||||
|
//for ($i = 0; $i < count($_SESSION['totalchoixjour']); $i++) {
|
||||||
|
// unset($_SESSION['horaires'.$i]);
|
||||||
|
//}
|
||||||
|
//unset($_SESSION['totalchoixjour']);
|
||||||
|
//unset($_SESSION['choices']);
|
||||||
|
|
||||||
|
//header('Location:' . Utils::getUrlSondage($sondage_admin, true));
|
||||||
|
|
||||||
|
exit;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (Utils::issetAndNoEmpty('days')) {
|
|
||||||
if (!isset($_SESSION["totalchoixjour"])) {
|
|
||||||
$_SESSION["totalchoixjour"]=array();
|
|
||||||
}
|
|
||||||
$k = 0;
|
|
||||||
for ($i = 0; $i < count($_POST["days"]); $i++) {
|
|
||||||
if (isset($_POST["days"][$i]) && $_POST["days"][$i] !='') {
|
|
||||||
$_SESSION['totalchoixjour'][$k] = mktime(0, 0, 0, substr($_POST["days"][$i],3,2),substr($_POST["days"][$i],0,2),substr($_POST["days"][$i],6,4));
|
|
||||||
|
|
||||||
$l = 0;
|
if (Utils::issetAndNoEmpty('days')) {
|
||||||
for($j = 0; $j < count($_POST['horaires'.$i]); $j++) {
|
|
||||||
if (isset($_POST['horaires'.$i][$j]) && $_POST['horaires'.$i][$j] != '') {
|
// Clear previous choices
|
||||||
$_SESSION['horaires'.$k][$l] = $_POST['horaires'.$i][$j];
|
$_SESSION['form']->clearChoices();
|
||||||
$l++;
|
|
||||||
|
for ($i = 0; $i < count($_POST['days']); $i++) {
|
||||||
|
$day = $_POST['days'][$i];
|
||||||
|
|
||||||
|
if (!empty($day)) {
|
||||||
|
// Add choice to Form data
|
||||||
|
$time = mktime(0, 0, 0, substr($_POST["days"][$i],3,2),substr($_POST["days"][$i],0,2),substr($_POST["days"][$i],6,4));
|
||||||
|
$choice = new Choice($time);
|
||||||
|
$_SESSION['form']->addChoice($choice);
|
||||||
|
|
||||||
|
$schedules = $_POST['horaires'.$i];
|
||||||
|
for($j = 0; $j < count($schedules); $j++) {
|
||||||
|
if (!empty($schedules[$j])) {
|
||||||
|
$choice->addSlot($schedules[$j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$k++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//le format du sondage est DATE
|
//le format du sondage est DATE
|
||||||
$_SESSION["formatsondage"] = "D".$_SESSION["studsplus"];
|
$_SESSION['form']->formatsondage = "D".$_SESSION['form']->studsplus;
|
||||||
|
|
||||||
// Step 3/3 : Confirm poll creation
|
// Step 3/3 : Confirm poll creation
|
||||||
if (Utils::issetAndNoEmpty('choixheures') && Utils::issetAndNoEmpty('totalchoixjour', $_SESSION)) {
|
if (Utils::issetAndNoEmpty('choixheures') && !isset($_SESSION['form']->totalchoixjour)) {
|
||||||
|
|
||||||
Utils::print_header ( _("Removal date and confirmation (3 on 3)") );
|
Utils::print_header ( _("Removal date and confirmation (3 on 3)") );
|
||||||
bandeau_titre(_("Removal date and confirmation (3 on 3)"));
|
bandeau_titre(_("Removal date and confirmation (3 on 3)"));
|
||||||
|
|
||||||
$temp_array = array_unique($_SESSION["totalchoixjour"]);
|
$_SESSION['form']->sortChoices();
|
||||||
sort($temp_array);
|
$last_date = $_SESSION['form']->lastChoice()->getName();
|
||||||
$removal_date=utf8_encode(strftime($date_format['txt_full'], end($temp_array)+ (86400 * $config['default_poll_duration'])));
|
$removal_date = utf8_encode(strftime($date_format['txt_full'], $last_date + (86400 * $config['default_poll_duration'])));
|
||||||
|
|
||||||
// Sumary
|
// Summary
|
||||||
$summary = '<ul>';
|
$summary = '<ul>';
|
||||||
for ($i=0;$i<count($_SESSION["totalchoixjour"]);$i++) {
|
foreach ($_SESSION['form']->getChoices() as $choice) {
|
||||||
$summary .= '<li>'.strftime($date_format['txt_full'], $_SESSION["totalchoixjour"][$i]);
|
$summary .= '<li>'.strftime($date_format['txt_full'], $choice->getName());
|
||||||
for ($j=0;$j<count($_SESSION['horaires'.$i]);$j++) {
|
$first = true;
|
||||||
if (isset($_SESSION['horaires'.$i][$j])) {
|
foreach ($choice->getSlots() as $slots) {
|
||||||
$summary .= ($j==0) ? ' : ' : ', ';
|
$summary .= $first ? ' : ' : ', ';
|
||||||
$summary .= $_SESSION['horaires'.$i][$j];
|
$summary .= $slots;
|
||||||
|
$first = false;
|
||||||
}
|
}
|
||||||
}
|
$summary .= '</li>';
|
||||||
$summary .= '</li>'."\n";
|
|
||||||
}
|
}
|
||||||
$summary .= '</ul>';
|
$summary .= '</ul>';
|
||||||
|
|
||||||
@ -177,6 +210,7 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>'."\n";
|
</form>'."\n";
|
||||||
|
//exit('<pre>POST<br/>'.print_r($_POST, true).'<hr/>SESSION<br/>'.print_r($_SESSION, true).'</pre>');
|
||||||
|
|
||||||
bandeau_pied();
|
bandeau_pied();
|
||||||
|
|
||||||
|
@ -16,20 +16,20 @@
|
|||||||
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
||||||
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
||||||
*/
|
*/
|
||||||
|
// TODO Move this file into a class into app/classes/Framadate
|
||||||
namespace Framadate;
|
namespace Framadate;
|
||||||
|
|
||||||
if (session_id() == "") {
|
|
||||||
session_start();
|
|
||||||
}
|
|
||||||
|
|
||||||
include_once __DIR__ . '/app/inc/init.php';
|
include_once __DIR__ . '/app/inc/init.php';
|
||||||
|
|
||||||
|
|
||||||
//Generer une chaine de caractere unique et aleatoire
|
/**
|
||||||
|
* Generer une chaine de caractere unique et aleatoire
|
||||||
|
*/
|
||||||
function random($car)
|
function random($car)
|
||||||
{
|
{
|
||||||
$string = "";
|
// TODO Better random ?
|
||||||
$chaine = "abcdefghijklmnopqrstuvwxyz123456789";
|
$string = '';
|
||||||
|
$chaine = 'abcdefghijklmnopqrstuvwxyz123456789';
|
||||||
srand((double)microtime()*1000000);
|
srand((double)microtime()*1000000);
|
||||||
for($i=0; $i<$car; $i++) {
|
for($i=0; $i<$car; $i++) {
|
||||||
$string .= $chaine[rand()%strlen($chaine)];
|
$string .= $chaine[rand()%strlen($chaine)];
|
||||||
@ -38,63 +38,43 @@ function random($car)
|
|||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ajouter_sondage()
|
function ajouter_sondage($title, $comment, $adminName, $adminMail, $format, $endDate, $mailsonde, $slots)
|
||||||
{
|
{
|
||||||
global $connect;
|
global $connect;
|
||||||
|
global $config;
|
||||||
|
$poll_id = random(16);
|
||||||
|
$admin_poll_id = $poll_id.random(8);
|
||||||
|
|
||||||
$sondage=random(16);
|
$date_fin = $_SESSION['champdatefin']; // provided by choix_autre.php or choix_date.php
|
||||||
$sondage_admin=$sondage.random(8);
|
$_SESSION['champdatefin'] = ''; //clean param cause 2 polls created by the same user in the same session can be affected by this param during the 2nd creation.
|
||||||
|
|
||||||
$date_fin = $_SESSION["champdatefin"]; // provided by choix_autre.php or choix_date.php
|
|
||||||
$_SESSION["champdatefin"]=""; //clean param cause 2 polls created by the same user in the same session can be affected by this param during the 2nd creation.
|
|
||||||
$sql = 'INSERT INTO sondage
|
$sql = 'INSERT INTO sondage
|
||||||
(id_sondage, commentaires, mail_admin, nom_admin, titre, id_sondage_admin, date_fin, format, mailsonde)
|
(id_sondage, commentaires, mail_admin, nom_admin, titre, id_sondage_admin, date_fin, format, mailsonde)
|
||||||
VALUES (
|
VALUES (?,?,?,?,?,?,?,?)';
|
||||||
'.$connect->Param('id_sondage').',
|
$prepared = $connect->prepare($sql);
|
||||||
'.$connect->Param('commentaires').',
|
$res = $prepared->execute(array($poll_id, $comment, $adminMail, $adminName, $title, $admin_poll_id, $format, $mailsonde));
|
||||||
'.$connect->Param('mail_admin').',
|
|
||||||
'.$connect->Param('nom_admin').',
|
|
||||||
'.$connect->Param('titre').',
|
|
||||||
'.$connect->Param('id_sondage_admin').',
|
|
||||||
FROM_UNIXTIME('.$date_fin.'),
|
|
||||||
'.$connect->Param('format').',
|
|
||||||
'.$connect->Param('mailsonde').'
|
|
||||||
)';
|
|
||||||
$sql = $connect->Prepare($sql);
|
|
||||||
$res = $connect->Execute($sql, array($sondage, $_SESSION['commentaires'], $_SESSION['adresse'], $_SESSION['nom'], $_SESSION['titre'], $sondage_admin, $_SESSION['formatsondage'], $_SESSION['mailsonde']));
|
|
||||||
|
|
||||||
$sql = 'INSERT INTO sujet_studs values ('.$connect->Param('sondage').', '.$connect->Param('choix').')';
|
$prepared = $connect->prepare('INSERT INTO sujet_studs values (?, ?)');
|
||||||
$sql = $connect->Prepare($sql);
|
$prepared->execute(array($poll_id, $slots));
|
||||||
$connect->Execute($sql, array($sondage, $_SESSION['toutchoix']));
|
|
||||||
|
|
||||||
if($config['use_smtp']==true){
|
if($config['use_smtp'] === true){
|
||||||
$message = _("This is the message you have to send to the people you want to poll. \nNow, you have to send this message to everyone you want to poll.");
|
$message = _("This is the message you have to send to the people you want to poll. \nNow, you have to send this message to everyone you want to poll.");
|
||||||
$message .= "\n\n";
|
$message .= "\n\n";
|
||||||
$message .= stripslashes(html_entity_decode($_SESSION["nom"],ENT_QUOTES,"UTF-8"))." " . _("hast just created a poll called") . " : \"".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES))."\".\n";
|
$message .= stripslashes(html_entity_decode($adminName, ENT_QUOTES, "UTF-8"))." " . _("hast just created a poll called") . " : \"".stripslashes(htmlspecialchars_decode($title,ENT_QUOTES))."\".\n";
|
||||||
$message .= _("Thanks for filling the poll at the link above") . " :\n\n%s\n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION;
|
$message .= _("Thanks for filling the poll at the link above") . " :\n\n%s\n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION;
|
||||||
|
|
||||||
$message_admin = _("This message should NOT be sent to the polled people. It is private for the poll's creator.\n\nYou can now modify it at the link above");
|
$message_admin = _("This message should NOT be sent to the polled people. It is private for the poll's creator.\n\nYou can now modify it at the link above");
|
||||||
$message_admin .= " :\n\n"."%s \n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION;
|
$message_admin .= " :\n\n"."%s \n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION;
|
||||||
|
|
||||||
$message = sprintf($message, Utils::getUrlSondage($sondage));
|
$message = sprintf($message, Utils::getUrlSondage($poll_id));
|
||||||
$message_admin = sprintf($message_admin, Utils::getUrlSondage($sondage_admin, true));
|
$message_admin = sprintf($message_admin, Utils::getUrlSondage($admin_poll_id, true));
|
||||||
|
|
||||||
if (Utils::isValidEmail($_SESSION['adresse'])) {
|
if (Utils::isValidEmail($_SESSION['adresse'])) {
|
||||||
Utils::sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("Author's message") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message_admin, $_SESSION['adresse'] );
|
Utils::sendEmail( $adminMail, "[".NOMAPPLICATION."][" . _("Author's message") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($title,ENT_QUOTES)), $message_admin, $_SESSION['adresse'] );
|
||||||
Utils::sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("For sending to the polled users") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message, $_SESSION['adresse'] );
|
Utils::sendEmail( $adminMail, "[".NOMAPPLICATION."][" . _("For sending to the polled users") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($title,ENT_QUOTES)), $message, $_SESSION['adresse'] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error_log(date('H:i:s d/m/Y:') . ' CREATION: '.$sondage."\t".$_SESSION[formatsondage]."\t".$_SESSION[nom]."\t".$_SESSION[adresse]."\t \t".$_SESSION[toutchoix]."\n", 3, 'admin/logs_studs.txt');
|
|
||||||
Utils::cleaning_polls($connect, 'admin/logs_studs.txt');
|
|
||||||
|
|
||||||
// Don't keep days, hours and choices in memory (in order to make new polls)
|
error_log(date('H:i:s d/m/Y:') . ' CREATION: '.$poll_id."\t".$format."\t".$adminName."\t".$adminMail."\t \t".$slots."\n", 3, 'admin/logs_studs.txt');
|
||||||
for ($i = 0; $i < count($_SESSION["totalchoixjour"]); $i++) {
|
|
||||||
unset($_SESSION['horaires'.$i]);
|
|
||||||
}
|
|
||||||
unset($_SESSION["totalchoixjour"]);
|
|
||||||
unset($_SESSION['choices']);
|
|
||||||
|
|
||||||
header("Location:".Utils::getUrlSondage($sondage_admin, true));
|
return $admin_poll_id;
|
||||||
|
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
namespace Framadate;
|
namespace Framadate;
|
||||||
|
|
||||||
use Framadate\Utils;
|
|
||||||
|
|
||||||
include_once __DIR__ . '/app/inc/init.php';
|
include_once __DIR__ . '/app/inc/init.php';
|
||||||
|
|
||||||
if (is_readable('bandeaux_local.php')) {
|
if (is_readable('bandeaux_local.php')) {
|
||||||
@ -28,12 +26,9 @@ if (is_readable('bandeaux_local.php')) {
|
|||||||
include_once('bandeaux.php');
|
include_once('bandeaux.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
session_start();
|
|
||||||
|
|
||||||
// affichage de la page
|
// affichage de la page
|
||||||
Utils::print_header( _("Home") );
|
Utils::print_header( _("Home") );
|
||||||
bandeau_titre(_("Make your polls"));
|
bandeau_titre(_("Make your polls"));
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 text-center">
|
<div class="col-md-6 text-center">
|
||||||
|
@ -18,8 +18,10 @@
|
|||||||
*/
|
*/
|
||||||
namespace Framadate;
|
namespace Framadate;
|
||||||
|
|
||||||
session_start();
|
|
||||||
include_once __DIR__ . '/app/inc/init.php';
|
include_once __DIR__ . '/app/inc/init.php';
|
||||||
|
if (!isset($_SESSION['form'])) {
|
||||||
|
$_SESSION['form'] = new Form();
|
||||||
|
}
|
||||||
|
|
||||||
if (file_exists('bandeaux_local.php')) {
|
if (file_exists('bandeaux_local.php')) {
|
||||||
include_once('bandeaux_local.php');
|
include_once('bandeaux_local.php');
|
||||||
@ -27,14 +29,14 @@ if (file_exists('bandeaux_local.php')) {
|
|||||||
include_once('bandeaux.php');
|
include_once('bandeaux.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type de sondage : <button value="$_SESSION["choix_sondage"]">
|
// Type de sondage : <button value="$_SESSION['form']->choix_sondage">
|
||||||
if ((isset($_GET['choix_sondage']) && $_GET['choix_sondage'] == 'date') ||
|
if ((isset($_GET['choix_sondage']) && $_GET['choix_sondage'] == 'date') ||
|
||||||
(isset($_POST["choix_sondage"]) && $_POST["choix_sondage"] == 'creation_sondage_date')) {
|
(isset($_POST["choix_sondage"]) && $_POST["choix_sondage"] == 'creation_sondage_date')) {
|
||||||
$choix_sondage = "creation_sondage_date";
|
$choix_sondage = "creation_sondage_date";
|
||||||
$_SESSION["choix_sondage"] = $choix_sondage;
|
$_SESSION['form']->choix_sondage = $choix_sondage;
|
||||||
} else {
|
} else {
|
||||||
$choix_sondage = "creation_sondage_autre";
|
$choix_sondage = "creation_sondage_autre";
|
||||||
$_SESSION["choix_sondage"] = $choix_sondage;
|
$_SESSION['form']->choix_sondage = $choix_sondage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// On teste toutes les variables pour supprimer l'ensemble des warnings PHP
|
// On teste toutes les variables pour supprimer l'ensemble des warnings PHP
|
||||||
@ -48,14 +50,6 @@ foreach ($post_var as $var) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// On initialise egalement la session car sinon bonjour les warning :-)
|
|
||||||
$session_var = array('titre', 'nom', 'adresse', 'commentaires', 'mailsonde', 'studsplus', );
|
|
||||||
foreach ($session_var as $var) {
|
|
||||||
if (Utils::issetAndNoEmpty($var, $_SESSION) === false) {
|
|
||||||
$_SESSION[$var] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// On initialise également les autres variables
|
// On initialise également les autres variables
|
||||||
$erreur_adresse = false;
|
$erreur_adresse = false;
|
||||||
$erreur_injection_titre = false;
|
$erreur_injection_titre = false;
|
||||||
@ -66,16 +60,12 @@ $cochemail = '';
|
|||||||
|
|
||||||
#tests
|
#tests
|
||||||
if (Utils::issetAndNoEmpty("poursuivre")){
|
if (Utils::issetAndNoEmpty("poursuivre")){
|
||||||
$_SESSION["titre"] = $titre;
|
$_SESSION['form']->titre = $titre;
|
||||||
$_SESSION["nom"] = $nom;
|
$_SESSION['form']->nom = $nom;
|
||||||
$_SESSION["adresse"] = $adresse;
|
$_SESSION['form']->adresse = $adresse;
|
||||||
$_SESSION["commentaires"] = $commentaires;
|
$_SESSION['form']->commentaires = $commentaires;
|
||||||
|
$_SESSION['form']->studsplus = ($studsplus !== null) ? '+' : $_SESSION['form']->studsplus = '';
|
||||||
unset($_SESSION["studsplus"]);
|
$_SESSION['form']->mailsonde = ($mailsonde !== null) ? true : false;
|
||||||
$_SESSION["studsplus"] = ($studsplus !== null) ? '+' : $_SESSION["studsplus"] = '';
|
|
||||||
|
|
||||||
unset($_SESSION["mailsonde"]);
|
|
||||||
$_SESSION["mailsonde"] = ($mailsonde !== null) ? true : false;
|
|
||||||
|
|
||||||
if ($config['use_smtp']==true){
|
if ($config['use_smtp']==true){
|
||||||
if (Utils::isValidEmail($adresse) === false) {
|
if (Utils::isValidEmail($adresse) === false) {
|
||||||
@ -125,15 +115,6 @@ if (Utils::issetAndNoEmpty("poursuivre")){
|
|||||||
|
|
||||||
bandeau_titre( _("Poll creation (1 on 3)") );
|
bandeau_titre( _("Poll creation (1 on 3)") );
|
||||||
|
|
||||||
// premier sondage ? test l'existence des schémas SQL avant d'aller plus loin
|
|
||||||
if(!Utils::check_table_sondage()) {
|
|
||||||
echo '<div class="alert alert-danger text-center">' . _("Framadate is not properly installed, please check the 'INSTALL' to setup the database before continuing.") . "</div>"."\n";
|
|
||||||
|
|
||||||
bandeau_pied();
|
|
||||||
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Préparation des messages d'erreur
|
* Préparation des messages d'erreur
|
||||||
*/
|
*/
|
||||||
@ -161,7 +142,7 @@ $errors = array(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$_SESSION["titre"] && Utils::issetAndNoEmpty("poursuivre") ) {
|
if (!$_SESSION['form']->titre && Utils::issetAndNoEmpty("poursuivre") ) {
|
||||||
$errors['title']['aria'] = 'aria-describeby="poll_title_error" '; $errors['title']['class'] = ' has-error';
|
$errors['title']['aria'] = 'aria-describeby="poll_title_error" '; $errors['title']['class'] = ' has-error';
|
||||||
$errors['title']['msg'] = '<div class="alert alert-danger" ><p id="poll_title_error">' . _("Enter a title") . '</p></div>';
|
$errors['title']['msg'] = '<div class="alert alert-danger" ><p id="poll_title_error">' . _("Enter a title") . '</p></div>';
|
||||||
} elseif ($erreur_injection_titre) {
|
} elseif ($erreur_injection_titre) {
|
||||||
@ -174,7 +155,7 @@ if ($erreur_injection_commentaires) {
|
|||||||
$errors['description']['msg'] = '<div class="alert alert-danger"><p id="poll_comment_error">' . _("Characters < > and \" are not permitted") . '</p></div>';
|
$errors['description']['msg'] = '<div class="alert alert-danger"><p id="poll_comment_error">' . _("Characters < > and \" are not permitted") . '</p></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$_SESSION["nom"] && Utils::issetAndNoEmpty("poursuivre")) {
|
if (!$_SESSION['form']->nom && Utils::issetAndNoEmpty("poursuivre")) {
|
||||||
$errors['name']['aria'] = 'aria-describeby="poll_name_error" '; $errors['name']['class'] = ' has-error';
|
$errors['name']['aria'] = 'aria-describeby="poll_name_error" '; $errors['name']['class'] = ' has-error';
|
||||||
$errors['name']['msg'] = '<div class="alert alert-danger"><p id="poll_name_error">' . _("Enter a name") . '</p></div>';
|
$errors['name']['msg'] = '<div class="alert alert-danger"><p id="poll_name_error">' . _("Enter a name") . '</p></div>';
|
||||||
} elseif ($erreur_injection_nom) {
|
} elseif ($erreur_injection_nom) {
|
||||||
@ -182,7 +163,7 @@ if (!$_SESSION["nom"] && Utils::issetAndNoEmpty("poursuivre")) {
|
|||||||
$errors['name']['msg'] = '<div class="alert alert-danger"><p id="poll_name_error">' . _("Characters < > and \" are not permitted") . '</p></div>';
|
$errors['name']['msg'] = '<div class="alert alert-danger"><p id="poll_name_error">' . _("Characters < > and \" are not permitted") . '</p></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$_SESSION["adresse"] && Utils::issetAndNoEmpty("poursuivre")) {
|
if (!$_SESSION['form']->adresse && Utils::issetAndNoEmpty("poursuivre")) {
|
||||||
$errors['email']['aria'] = 'aria-describeby="poll_name_error" '; $errors['email']['class'] = ' has-error';
|
$errors['email']['aria'] = 'aria-describeby="poll_name_error" '; $errors['email']['class'] = ' has-error';
|
||||||
$errors['email']['msg'] = '<div class="alert alert-danger"><p id="poll_email_error">' . _("Enter an email address") . '</p></div>';
|
$errors['email']['msg'] = '<div class="alert alert-danger"><p id="poll_email_error">' . _("Enter an email address") . '</p></div>';
|
||||||
} elseif ($erreur_adresse && Utils::issetAndNoEmpty("poursuivre")) {
|
} elseif ($erreur_adresse && Utils::issetAndNoEmpty("poursuivre")) {
|
||||||
@ -196,27 +177,27 @@ if (!$_SESSION["adresse"] && Utils::issetAndNoEmpty("poursuivre")) {
|
|||||||
|
|
||||||
// REMOTE_USER ?
|
// REMOTE_USER ?
|
||||||
if (USE_REMOTE_USER && isset($_SERVER['REMOTE_USER'])) {
|
if (USE_REMOTE_USER && isset($_SERVER['REMOTE_USER'])) {
|
||||||
$input_name = '<input type="hidden" name="nom" value="'.$_SESSION["nom"].'" />'.stripslashes($_SESSION["nom"]);
|
$input_name = '<input type="hidden" name="nom" value="'.$_SESSION['form']->nom.'" />'.stripslashes($_SESSION['form']->nom);
|
||||||
} else {
|
} else {
|
||||||
$input_name = '<input id="yourname" type="text" name="nom" class="form-control" '.$errors['name']['aria'].' value="'.stripslashes($_SESSION["nom"]).'" />';
|
$input_name = '<input id="yourname" type="text" name="nom" class="form-control" '.$errors['name']['aria'].' value="'.stripslashes($_SESSION['form']->nom).'" />';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (USE_REMOTE_USER && isset($_SERVER['REMOTE_USER'])) {
|
if (USE_REMOTE_USER && isset($_SERVER['REMOTE_USER'])) {
|
||||||
$input_email = '<input type="hidden" name="adresse" value="'.$_SESSION["adresse"].'">'.$_SESSION["adresse"];
|
$input_email = '<input type="hidden" name="adresse" value="'.$_SESSION['form']->adresse.'">'.$_SESSION['form']->adresse;
|
||||||
} else {
|
} else {
|
||||||
$input_email = '<input id="email" type="text" name="adresse" class="form-control" '.$errors['email']['aria'].' value="'.$_SESSION["adresse"].'" />';
|
$input_email = '<input id="email" type="text" name="adresse" class="form-control" '.$errors['email']['aria'].' value="'.$_SESSION['form']->adresse.'" />';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checkbox checked ?
|
// Checkbox checked ?
|
||||||
if (!$_SESSION["studsplus"] && !Utils::issetAndNoEmpty('creation_sondage_date') && !Utils::issetAndNoEmpty('creation_sondage_autre')) {
|
if (!$_SESSION['form']->studsplus && !Utils::issetAndNoEmpty('creation_sondage_date') && !Utils::issetAndNoEmpty('creation_sondage_autre')) {
|
||||||
$_SESSION["studsplus"]="+";
|
$_SESSION['form']->studsplus="+";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_SESSION["studsplus"]=="+") {
|
if ($_SESSION['form']->studsplus=="+") {
|
||||||
$cocheplus="checked";
|
$cocheplus="checked";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_SESSION["mailsonde"]) {
|
if ($_SESSION['form']->mailsonde) {
|
||||||
$cochemail="checked";
|
$cochemail="checked";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,14 +214,14 @@ echo '
|
|||||||
<div class="form-group'.$errors['title']['class'].'">
|
<div class="form-group'.$errors['title']['class'].'">
|
||||||
<label for="poll_title" class="col-sm-4 control-label">' . _("Poll title") . ' *</label>
|
<label for="poll_title" class="col-sm-4 control-label">' . _("Poll title") . ' *</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input id="poll_title" type="text" name="titre" class="form-control" '.$errors['title']['aria'].' value="'.stripslashes($_SESSION["titre"]).'" />
|
<input id="poll_title" type="text" name="titre" class="form-control" '.$errors['title']['aria'].' value="'.stripslashes($_SESSION['form']->titre).'" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
'.$errors['title']['msg'].'
|
'.$errors['title']['msg'].'
|
||||||
<div class="form-group'.$errors['description']['class'].'">
|
<div class="form-group'.$errors['description']['class'].'">
|
||||||
<label for="poll_comments" class="col-sm-4 control-label">'. _("Description") .'</label>
|
<label for="poll_comments" class="col-sm-4 control-label">'. _("Description") .'</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<textarea id="poll_comments" name="commentaires" class="form-control" '.$errors['description']['aria'].' rows="5">'.stripslashes($_SESSION["commentaires"]).'</textarea>
|
<textarea id="poll_comments" name="commentaires" class="form-control" '.$errors['description']['aria'].' rows="5">'.stripslashes($_SESSION['form']->commentaires).'</textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
'.$errors['description']['msg'].'
|
'.$errors['description']['msg'].'
|
||||||
|
Loading…
Reference in New Issue
Block a user