public function showMessages($echo = TRUE)
 {
     $msg = '';
     try {
         $errors = $this->sessionHelper->read('sr_errors');
     } catch (SessionDataIOException $e) {
         $errors = array();
     }
     try {
         $messages = $this->sessionHelper->read('sr_messages');
     } catch (SessionDataIOException $e) {
         $messages = array();
     }
     while ($e = array_shift($errors)) {
         $msg .= '<div class="' . Configuration::read('error_div_class') . '">' . $e . '</div>';
     }
     while ($e = array_shift($messages)) {
         $msg .= '<div class="' . Configuration::read('message_div_class') . '">' . $e . '</div>';
     }
     $this->sessionHelper->destroy('sr_errors');
     $this->sessionHelper->destroy('sr_messages');
     if (!$echo) {
         return $msg;
     }
     echo $msg;
 }
Example #2
0
 /**
  * Check auth level of an user
  *
  * @param integer $auth Auth level asked to show content
  *
  * @return boolean
  * @static
  */
 public static function protection($auth = 1)
 {
     if (isset($_COOKIE['leqg'], $_COOKIE['time']) && !empty($_COOKIE['time']) && !empty($_COOKIE['leqg'])) {
         $query = Core::query('user-data-cookie', 'core');
         $query->bindValue(':cookie', $_COOKIE['leqg'], PDO::PARAM_INT);
         $query->execute();
         if ($query->rowCount() == 1) {
             $data = $query->fetch(PDO::FETCH_ASSOC);
             if ($data['client'] == Configuration::read('client')) {
                 if ($data['auth_level'] >= $auth) {
                     return true;
                 } else {
                     header('Location: http://' . $data['client'] . '.leqg.info');
                 }
             } else {
                 header('Location: http://' . $data['client'] . '.leqg.info' . $_SERVER['PHP_SELF']);
             }
         } else {
             setcookie('leqg', null, time(), '/', 'leqg.info');
             setcookie('time', null, time(), '/', 'leqg.info');
             header('Location: http://auth.leqg.info');
         }
     } else {
         setcookie('leqg', null, time(), '/', 'leqg.info');
         setcookie('time', null, time(), '/', 'leqg.info');
         header('Location: http://auth.leqg.info');
     }
 }
Example #3
0
 protected function __construct()
 {
     $this->mysqli = mysqli_init();
     if (!$this->mysqli->real_connect(Configuration::read('db_host'), Configuration::read('db_username'), Configuration::read('db_password'), Configuration::read('db_name'))) {
         throw new MysqliConnectionException('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
     }
 }
 public static function loadView($v, $viewData = NULL)
 {
     $file = Configuration::read('view_path') . $v . '.view.php';
     if (file_exists($file)) {
         extract($viewData);
         include $file;
     }
 }
 public function postcontroller()
 {
     $postController = scandir(Configuration::read('task_path'));
     foreach ($postController as $post) {
         if (preg_match('/postcontroller.php$/', $post) > 0) {
             $post = preg_replace('/\\..*$/', '', $post);
             $task = new $post();
             $task->execute();
         }
     }
 }
Example #6
0
 /**
  * Prepare an SQL query existing in a file (sql/ directory)
  *
  * @param string $query file to load
  * @param string $bdd   which database?
  *
  * @return object
  * @static
  */
 public static function query(string $query, $bdd = 'link')
 {
     // On récupère le lien vers la BDD
     $link = Configuration::read('db.' . $bdd);
     // On vérifie que la requête existe
     if (file_exists("sql/{$query}.sql")) {
         // On récupère la requête et on retourne la requête préparée
         $query = file_get_contents("sql/{$query}.sql");
         return $link->prepare($query);
     } else {
         exit;
     }
 }
 /**
  * Add a script to the header.
  * 
  * @param string $script The name of the script to add or the path if using a script outside of the default script location.
  * @param int $priority [Optional] The priority of the script. 0 is higest meaning it will be loaded first. Default is -1 
  *                      meaning add the script onto the end of the list.
  * @param boolean $absolute [Optional] Whether or not the script name is absolute. Default is false.
  */
 public function addScript($script, $priority = -1, $absolute = FALSE)
 {
     if (!$absolute) {
         if ($priority >= 0) {
             $priority = min(array($priority, count($this->script)));
             array_splice($this->script, $priority, 0, Configuration::read('basepath') . '/Webroot/js/' . $script . '.js');
         } else {
             $this->script[] = Configuration::read('basepath') . '/Webroot/js/' . $script . '.js';
         }
     } else {
         if ($priority >= 0) {
             $priority = min(array($priority, count($this->script)));
             array_splice($this->script, $priority, 0, $script);
         } else {
             $this->script[] = $script;
         }
     }
 }
Example #8
0
 /**
  * Create a new template
  *
  * @return integer
  * @static
  */
 public static function create()
 {
     $user = User::ID();
     $query = Core::query('template-create');
     $query->bindParam(':user', $user);
     $query->execute();
     return Configuration::read('db.link')->lastInsertId();
 }
Example #9
0
 /**
  * Tracking informations
  *
  * @param string $track_id Tracking ID
  *
  * @return array
  * @static
  **/
 public static function trackingInfos(string $track_id)
 {
     $mandrill = Configuration::read('mail');
     $result = $mandrill->messages->info($track_id);
     return $result;
 }
Example #10
0
 /**
  * Créé un nouvel envoi
  *
  * @param string $objet   Objet de l'envoi
  * @param string $message Message de l'envoi
  * @param string $type    Type de l'envoi
  *
  * @return integer
  * @static
  */
 public static function envoi(string $objet, string $message, string $type)
 {
     // On récupère les données
     $user = User::ID();
     // On lance la création de l'envoi
     $link = Configuration::read('db.link');
     $query = 'INSERT INTO `envois` (`compte_id`,
                                     `envoi_type`,
                                     `envoi_time`,
                                     `envoi_titre`,
                                     `envoi_texte`)
               VALUES (:compte,
                       :type,
                       NOW(),
                       :titre,
                       :texte)';
     $query = $link->prepare($query);
     $query->bindValue(':compte', $user, PDO::PARAM_INT);
     $query->bindValue(':type', $type);
     $query->bindValue(':titre', $objet);
     $query->bindValue(':texte', $message);
     $query->execute();
     return $link->lastInsertId();
 }
Example #11
0
 * @category Ajax
 * @package  LeQG
 * @author   Damien Senger <*****@*****.**>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License 3.0
 * @link     http://leqg.info
 */
if (is_string($_POST['message']) && is_numeric($_POST['numero']) && is_numeric($_POST['contact'])) {
    // On créé le lien vers la BDD Client
    $dsn = 'mysql:host=' . Configuration::read('db.host') . ';dbname=' . Configuration::read('db.basename');
    $user = Configuration::read('db.user');
    $pass = Configuration::read('db.pass');
    $link = new PDO($dsn, $user, $pass);
    // On créé le lien vers la BDD Centrale
    $dsn = 'mysql:host=' . Configuration::read('db.host') . ';dbname=leqg';
    $user = Configuration::read('db.user');
    $pass = Configuration::read('db.pass');
    $zentrum = new PDO($dsn, $user, $pass);
    // On règle l'expéditeur
    $expediteur = 'LeQG';
    // On récupère le numéro de téléphone
    $query = 'SELECT `coordonnee_numero`
               FROM `coordonnees`
               WHERE `coordonnee_id` = :id';
    $query = $link->prepare($query);
    $query->bindParam(':id', $_POST['numero']);
    $query->execute();
    $numero = $query->fetch(PDO::FETCH_ASSOC);
    $numero = $numero['coordonnee_numero'];
    // On prépare l'envoi
    $message = new \Esendex\Model\DispatchMessage($expediteur, $numero, $_POST['message'], \Esendex\Model\Message::SmsType);
    // On assure le démarrage du service
Example #12
0
 /**
  * Last created persons
  *
  * @param  int $number Asked number of created persons
  * @return array
  * */
 public static function last($number = 5)
 {
     $link = Configuration::read('db.link');
     $query = $link->query('SELECT `id` FROM `people` ORDER BY `id` DESC LIMIT 0, ' . $number);
     return $query->fetchAll(PDO::FETCH_ASSOC);
 }
Example #13
0
 /**
  * Number of phonecall to do in a mission
  *
  * @param array $args sorting methods
  *
  * @return integer
  * @static
  */
 public static function estimation(array $args)
 {
     // On commence par paramétrer les données PDO
     $link = Configuration::read('db.link');
     // On prépare la requête de récupération de tous les numéros
     // connus par le système
     $sql = 'SELECT *
             FROM `coordonnees`
             WHERE `coordonnee_type` != "email"';
     $query = $link->prepare($sql);
     $query->execute();
     $numeros = $query->fetchAll(PDO::FETCH_ASSOC);
     // On prépare le tableau des résultats du tri $num
     $num = array();
     // On retraite les arguments entrés
     if (isset($args['age']) && !empty($args['age'])) {
         $age = array();
         $age['usr'] = explode(':', $args['age']);
         $age['min'] = $age['usr'][0];
         $age['max'] = $age['usr'][1];
     } else {
         $age = false;
     }
     if (isset($args['bureaux']) && !empty($args['bureaux'])) {
         $bureaux = explode(',', $args['bureaux']);
     } else {
         $bureaux = false;
     }
     if (isset($args['thema']) && !empty($args['thema'])) {
         $thema = $args['thema'];
     } else {
         $thema = false;
     }
     // On fait la boucle de tous les numéros,
     // et on charge les informations pour chacun
     foreach ($numeros as $numero) {
         // On réinitialise le test
         $test = true;
         // On ouvre la fiche correspondante
         $contact = new People($numero['contact_id']);
         // On récupère son bureau de vote, son âge et ses tags
         $ageContact = $contact->age();
         $bureau = $contact->get('bureau');
         $tags = $contact->get('tags');
         // On vérifie si la fiche correspond aux arguments entrés
         if ($age && $test) {
             if ($ageContact <= $age['max'] && $ageContact >= $age['min']) {
                 // On le rajoute au test
                 $test = true;
                 $testAge = true;
             } else {
                 $test = false;
                 $testAge = false;
             }
         }
         // On fait les vérifications concernant le bureau de vote
         if ($bureaux && $test) {
             if (in_array($bureau, $bureaux)) {
                 $test = true;
                 $testBureau = true;
             } else {
                 $test = false;
                 $testBureau = false;
             }
         }
         // On fait les vérifications concernant les thématiques
         if ($thema && $test) {
             if (in_array($thema, $tags)) {
                 $test = true;
             } else {
                 $test = false;
             }
         }
         // Si le test est concluant, on l'ajoute à la liste des numéros
         // en utilisant comme key l'ID du contact pour éviter les doublons
         if ($test) {
             $id = $contact->get('id');
             $num[$id] = $numero['coordonnee_id'];
         }
     }
     // On calcule maintenant le nombre de numéros concluant
     $nombre = count($num);
     // On retourne cette estimation
     return $nombre;
 }
Example #14
0
 /**
  * Create a new event
  *
  * @param integer $person Person ID for this event
  *
  * @return integer
  */
 public static function create(int $person)
 {
     $user = User::ID();
     $query = Core::query('event-new');
     $query->bindValue(':person', $person, PDO::PARAM_INT);
     $query->bindValue(':user', $user, PDO::PARAM_INT);
     $query->execute();
     return Configuration::read('db.link')->lastInsertId();
 }
 /**
  *
  * @param string $key The name of the key to use for this instance 
  */
 public function __construct($key = 'random_salt')
 {
     $this->secretKey = Configuration::read($key);
 }
Example #16
0
 /**
  * Create a new folder
  *
  * @param string $name Folder's name
  * @param string $desc Folder's description
  *
  * @return integer New folder ID
  * @static
  **/
 public static function create(string $name, string $desc)
 {
     $query = Core::query('folder-new');
     $query->bindValue(':name', $name);
     $query->bindValue(':desc', $desc);
     $query->execute();
     return Configuration::read('db.link')->lastInsertId();
 }
Example #17
0
 /**
  * Describe a new links for top-level links informations
  * 
  * @version 1.0
  * @param   string  $toplevel   Name of the top level element
  * @param   string  $link       Name of the linked element
  * @param   string  $type       Type of the linked element
  * @param   string  $href       URL of the linked element
  * @result  void
  */
 public static function link($toplevel, $link, $type, $href = null)
 {
     if (is_null($href)) {
         self::$links[$toplevel . '.' . $link] = array('href' => Configuration::read('url') . $type . '/{' . $toplevel . '.' . $link . '}', 'type' => $type);
     } else {
         self::$links[$toplevel . '.' . $link] = array('href' => Configuration::read('url') . $href . '{' . $toplevel . '.' . $link . '}', 'type' => $type);
     }
 }
 /**
  * This helper function will correctly decode a session package (whether it is
  * a flat package or a timed package and return the value.
  *  
  * @param string $name The name of the session data.
  */
 private function readSessionPackage($name)
 {
     if (is_array($_SESSION[$name])) {
         return $_SESSION[$name];
     }
     $package = explode('~', $_SESSION[$name]);
     if (count($package) == 4) {
         list($data, $duration, $initialized, $checksum) = $package;
         $actualChecksum = hash_hmac('md5', $data . '~' . $duration . '~' . $initialized, Configuration::read('random_salt'));
         if ($actualChecksum != $checksum) {
             //Normal session value
             return $_SESSION[$name];
         } else {
             if ($initialized + $duration < time()) {
                 throw new SessionDataExpiredException('The session data ' . $name . ' has expired!');
             } else {
                 return unserialize(base64_decode($data));
             }
         }
     } else {
         return $_SESSION[$name];
     }
 }
Example #19
0
 /**
  * Open missions for an user
  *
  * @param string  $type mission type
  * @param integer $user user id
  *
  * @return array
  * @static
  */
 public static function openMissions(string $type, int $user)
 {
     // On récupère la connexion à la base de données
     $link = Configuration::read('db.link');
     // On récupère les invitations liées à l'utilisateur
     $sql = 'SELECT *
             FROM `inscriptions`
             WHERE `user_id` = :user
             AND `inscription_statut` = 1';
     $query = $link->prepare($sql);
     $query->bindParam(':user', $user);
     $query->execute();
     // On regarde s'il existe des invitations
     if ($query->rowCount()) {
         $missions = $query->fetchAll(PDO::FETCH_ASSOC);
         // On vérifie que les missions sont bien du bon type et ouvertes
         $missions_ouvertes = array();
         foreach ($missions as $mission) {
             $sql = 'SELECT *
                     FROM `mission`
                     WHERE `mission_type` = :type
                     AND `mission_statut` = 1
                     AND `mission_id` = :mission';
             $query = $link->prepare($sql);
             $query->bindParam(':type', $type);
             $query->bindParam(':mission', $mission['mission_id']);
             $query->execute();
             if ($query->rowCount()) {
                 $infos = $query->fetch(PDO::FETCH_ASSOC);
                 $missions_ouvertes[] = $infos['mission_id'];
             }
         }
         return $missions_ouvertes;
     } else {
         return false;
     }
 }
Example #20
0
 /**
  * Return civil status of an asked contact
  *
  * @version 1.0
  * @param   int     $id         Contact ID
  * @return  array               Contact civil status
  */
 public static function civilstatus($id)
 {
     // we load informations from database
     $query = API::query('contact_civilstatus');
     $query->bindParam(':id', $id, PDO::PARAM_INT);
     $query->execute();
     // if we found a contact
     if ($query->rowCount() == 1) {
         // Yay! we have a contact!
         API::response(200);
         // we load contact informations
         $data = $query->fetch(PDO::FETCH_ASSOC);
         $data['url'] = Configuration::read('url') . 'contact/' . $id;
         API::add('contacts', $data);
     } else {
         // we display an error
         API::error(404, 'ContactUnknown', 'Le contact demandé n\'existe pas.');
     }
 }
Example #21
0
 /**
  * Effectue le reporting d'un boîtage
  *
  * @param string  $mission  ID de la mission concernée par le reporting (MD5)
  * @param string  $immeuble ID de l'immeuble concerné par le reporting (MD5)
  * @param integer $statut   Statut du reporting :
  *                          2 pour fait,
  *                          1 pour inaccessible
  *
  * @return void
  * @static
  */
 public static function reporting(string $mission, string $immeuble, int $statut)
 {
     // On met en place le lien vers la base de données
     $link = Configuration::read('db.link');
     // On récupère les informations sur la mission
     $informations = self::informations($mission);
     // On prépare et exécute la requête
     $query = 'UPDATE `boitage`
               SET `boitage_statut` = :statut,
                   `boitage_date` = NOW(),
                   `boitage_militant` = :cookie
               WHERE MD5(`mission_id`) = :mission
               AND MD5(`immeuble_id`) = :immeuble';
     $query = $link->prepare($query);
     $query->bindParam(':statut', $statut);
     $query->bindParam(':cookie', User::ID(), PDO::PARAM_INT);
     $query->bindParam(':mission', $mission);
     $query->bindParam(':immeuble', $immeuble);
     $query->execute();
     // Si l'immeuble a été fait,
     // on reporte le boitage pour tous les les contacts
     if ($statut == 2) {
         // On cherche tous les contacts qui habitent ou sont déclarés
         // électoralement dans l'immeuble en question pour
         // créer un élément d'historique
         $query = 'SELECT `contact_id`
                   FROM `contacts`
                   WHERE MD5(`immeuble_id`) = :immeuble
                   OR MD5(`adresse_id`) = :immeuble';
         $query = $link->prepare($query);
         $query->bindParam(':immeuble', $immeuble);
         $query->execute();
         $contacts = $query->fetchAll(PDO::FETCH_NUM);
         // On fait la boucle de tous ces contacts
         // pour leur ajouter l'élément d'historique
         foreach ($contacts as $contact) {
             $query = 'INSERT INTO `historique` (`contact_id`,
                                                 `compte_id`,
                                                 `historique_type`,
                                                 `historique_date`,
                                                 `historique_objet`)
                       VALUES (:contact,
                               :compte,
                               "boite",
                               NOW(),
                               :mission)';
             $query = $link->prepare($query);
             $query->bindParam(':contact', $contact[0], PDO::PARAM_INT);
             $query->bindParam(':compte', User::ID(), PDO::PARAM_INT);
             $query->bindParam(':mission', $informations['mission_nom']);
             $query->execute();
         }
     }
 }
Example #22
0
 /**
  * List all last created contact
  *
  * @param integer $nombre number of contacts
  *
  * @return array
  * @static
  */
 public static function last($nombre = 5)
 {
     // On commence par paramétrer les données PDO
     $link = Configuration::read('db.link');
     // On prépare le tableau de résultat de la requête
     $fiches = array();
     // On prépare la requête
     $sql = 'SELECT `contact_id`
             FROM `contacts`
             ORDER BY `contact_id` DESC
             LIMIT 0, ' . $nombre;
     $query = $link->prepare($sql);
     // On exécute la requête
     if ($query->execute()) {
         // On affecte les résultats au tableau des fiches
         $ids = $query->fetchAll(PDO::FETCH_ASSOC);
         // On retraite les informations pour les ajouter au tableau $fiches
         foreach ($ids as $id) {
             $fiches[] = $id['contact_id'];
         }
         // On retourne le tableau correspondant
         return $fiches;
     } else {
         // On retourne une erreur
         return false;
     }
 }
Example #23
0
 $query->bindParam(':first', $form['prenom']);
 $query->bindParam(':last', $form['nom']);
 $query->bindParam(':auth', $form['selectAuth']);
 $query->execute();
 // On lance l'envoi du mail avec les informations de connexion
 $email = file_get_contents('tpl/mail/user-creation.tpl.html');
 $objet = 'LeQG – Votre compte a été créé par ' . User::getLoginByID(User::ID()) . '.';
 // On insère dans le mail l'URL du fichier pour qu'il puisse être téléchargé
 $email = strtr($email, array('{COMPTE}' => $form['prenom'] . ' ' . $form['nom']));
 $email = strtr($email, array('{USER}' => User::getLoginByID(User::ID())));
 $email = strtr($email, array('{EMAIL}' => $form['email']));
 $email = strtr($email, array('{PASS}' => $form['pass']));
 // On démarre l'instance
 $mail = new PHPMailer();
 // On récupère les informations sur l'API
 $api = Configuration::read('api');
 // On contacte le serveur d'envoi SMTP
 $mail->IsSMTP();
 $mail->SMTPAuth = true;
 $mail->Host = $api['mail']['smtp']['host'];
 $mail->Port = $api['mail']['smtp']['port'];
 $mail->Username = $api['mail']['smtp']['user'];
 $mail->Password = $api['mail']['smtp']['pass'];
 // On configure le mail à envoyer
 $mail->CharSet = $api['mail']['charset'];
 $mail->SetFrom('*****@*****.**', 'LeQG');
 $mail->AddReplyTo('*****@*****.**', 'LeQG équipe technique');
 $mail->AddAddress($form['email'], $form['prenom'] . ' ' . $form['nom']);
 $mail->Subject = $objet;
 $mail->MsgHTML($email);
 $mail->Send();
Example #24
0
 /**
  * Get all datas for an address
  *
  * @param array $adresse target address
  *
  * @return array
  * @static
  */
 public static function geocoder(array $adresse)
 {
     // On prépare la liaison à la base de données
     $link = Configuration::read('db.link');
     // On prépare l'encodage de l'adresse
     // et de la ville pour la passer dans l'URL
     $ville = urlencode($adresse['ville']);
     $street = urlencode($adresse['numero'] . ' ' . $adresse['adresse']);
     // On prépare l'URL de récupération des données JSON
     $url = "https://nominatim.openstreetmap.org/" . "?format=json&city={$ville}&street={$street}";
     // On récupère les informations sur l'adresse au format JSON
     $json = file_get_contents($url);
     // On décode les informations reçues
     $infos = json_decode($json);
     // On récupère uniquement l'entrée qui nous intéresse
     $infos = $infos[0];
     // Au sein de ces informations, on retraite les données d'adresse complète
     $adresse = explode(',', $infos->display_name);
     // On va attribuer les données de "adresse" à "place" au fur à mesure
     // en leur donnant un nom
     $place = ['numero' => $adresse[0], 'rue' => $adresse[1], 'ville' => $adresse[4], 'arrondissement' => $adresse[5], 'departement' => $adresse[6], 'region' => $adresse[7], 'cp' => $adresse[9], 'pays' => $adresse[10]];
     // On applique un trim() à toutes les valeurs du tableau $place
     $place = array_map('trim', $place);
     // on récupère les informations qui nous intéresse
     $data = ['place_id' => $infos->place_id, 'lat' => $infos->lat, 'lng' => $infos->lon, 'adresse' => $place, 'type' => $infos->type, 'licence' => $infos->licence];
     // On regarde si l'immeuble existe déjà dans la base de données
     $sql = 'SELECT `street_id`
             FROM `place`
             WHERE `place_id` = :id';
     $query = $link->prepare($sql);
     $query->bindParam(':id', $data['place_id']);
     $query->execute();
     // S'il existe déjà, on récupère l'ID de la rue
     if ($query->rowCount() == 1) {
         $street = $query->fetch(PDO::FETCH_NUM);
         // On ajoute l'ID de la rue aux données
         $data['street_id'] = $street[0];
     } else {
         // On regarde d'abord sur une rue existe correspondant aux données
         $sql = 'SELECT `street_id`
                 FROM `street`
                 WHERE `street_name` = :street';
         $query = $link->prepare($sql);
         $query->bindParam(':street', $data['adresse']['rue']);
         $query->execute();
         // S'il existe une rue, on récupère son identifiant
         if ($query->rowCount() == 1) {
             $street = $query->fetch(PDO::FETCH_NUM);
             $data['street_id'] = $street[0];
         } else {
             // On récupère l'identifiant de la ville
             $sql = 'SELECT `city_id`
                     FROM `city`
                     WHERE `city_name` = :city';
             $query = $link->prepare($sql);
             $query->bindParam(':city', $data['adresse']['ville']);
             $query->execute();
             // Si une ville existe, on récupère son identifiant
             if ($query->rowCount() == 1) {
                 $city = $query->fetch(PDO::FETCH_NUM);
                 $data['city_id'] = $city[0];
             } else {
                 $sql = 'INSERT INTO `city` (`city_name`)
                         VALUES (:city)';
                 $query = $link->prepare($sql);
                 $query->bindParam(':city', $data['adresse']['ville']);
                 $query->execute();
                 // On enregistre l'identifiant de cette ville
                 $data['city_id'] = $link->lastInsertId();
             }
             // Une fois l'identifiant de la ville récupéré,
             // on enregistre cette nouvelle rue
             $sql = 'INSERT INTO `street` (`city_id`, `street_name`)
                     VALUES (:city, :street)';
             $query = $link->prepare($sql);
             $query->bindParam(':city', $data['city_id'], PDO::PARAM_INT);
             $query->bindParam(':street', $data['adresse']['rue']);
             $query->execute();
             // On enregistre l'identifiant de cette rue
             $data['street_id'] = $link->lastInsertId();
         }
         // On va transformer le numéro de l'immeuble pour en avoir
         // une version uniquement numérique
         $numeric = preg_replace('#[^0-9]#', '', $data['adresse']['numero']);
         // Une fois l'identifiant de la rue récupéré,
         // on enregistre ce nouvel immeuble
         $sql = 'INSERT INTO `place` (`place_id`,
                                      `street_id`,
                                      `place_number`,
                                      `place_number_numeric`,
                                      `place_lat`,
                                      `place_lng`,
                                      `place_type`,
                                      `place_licence`)
                 VALUES (:place,
                         :street,
                         :number,
                         :numeric,
                         :lat,
                         :lng,
                         :type,
                         :licence)';
         $query = $link->prepare($sql);
         $query->bindParam(':place', $data['place_id'], PDO::PARAM_INT);
         $query->bindParam(':street', $data['street_id'], PDO::PARAM_INT);
         $query->bindParam(':number', $data['adresse']['numero']);
         $query->bindParam(':numeric', $numeric, PDO::PARAM_INT);
         $query->bindParam(':lat', $data['lat'], PDO::PARAM_INT);
         $query->bindParam(':lng', $data['lng'], PDO::PARAM_INT);
         $query->bindParam(':type', $data['type']);
         $query->bindParam(':licence', $data['licence']);
         $query->execute();
     }
     // On retourne ces données
     return $data;
 }
Example #25
0
 /**
  * List all existing folders
  *
  * @param boolean $tous true for all folders, false for all open folders only
  *
  * @return array
  * @static
  */
 public static function listeComplete($tous = false)
 {
     // On prépare le lien vers la BDD
     $link = Configuration::read('db.link');
     // On lance la recherche des dossiers selon le critère choisi
     if ($tous) {
         $sql = 'SELECT *
                 FROM `dossiers`
                 ORDER BY `dossier_nom` ASC';
     } else {
         $sql = 'SELECT *
                 FROM `dossiers`
                 WHERE `dossier_date_fermeture` IS NULL
                 ORDER BY `dossier_nom` ASC';
     }
     $query = $link->query($sql);
     // On retourne les informations
     return $query->fetchAll(PDO::FETCH_ASSOC);
 }
Example #26
0
Configuration::write('db.basename', 'leqg');
Configuration::write('db.user', $config['BDD']['user']);
Configuration::write('db.pass', $config['BDD']['pass']);
Configuration::write('ini', $config);
// On fabrique la classe $noyau de connexion au noyau central
$host = '217.70.189.234';
$port = 3306;
$dbname = 'leqg-core';
$user = '******';
$pass = '******';
$charset = 'utf8';
$dsn = "mysql:host={$host};port={$port};dbname={$dbname};charset={$charset}";
$core = new PDO($dsn, $user, $pass);
// On fabrique la classe $link de liaison PDO
$dsn = 'mysql:host=' . Configuration::read('db.host') . ';dbname=' . Configuration::read('db.basename') . ';charset=utf8';
$link = new PDO($dsn, Configuration::read('db.user'), Configuration::read('db.pass'));
// On enregistre les liaisons SQL
Configuration::write('db.core', $core);
Configuration::write('db.link', $link);
// On charge les API extérieures
require_once '../api/esendex/autoload.php';
require_once '../api/phpmailer/class.phpmailer.php';
// On configure les données des API extérieures
$api['sms']['auth'] = new \Esendex\Authentication\LoginAuthentication($config['SMS']['compte'], $config['SMS']['login'], $config['SMS']['pass']);
$api['mail']['charset'] = 'UTF-8';
$api['mail']['smtp']['host'] = $config['MAIL']['host'];
$api['mail']['smtp']['user'] = $config['MAIL']['user'];
$api['mail']['smtp']['pass'] = $config['MAIL']['pass'];
$api['mail']['smtp']['port'] = $config['MAIL']['port'];
$api['mail']['from']['email'] = '*****@*****.**';
$api['mail']['from']['nom'] = 'Ne Pas Répondre';
 private function executePreLaunchTasks()
 {
     /*
      * Look for any pre-launch tasks
      */
     $preLaunch = scandir(Configuration::read('task_path'));
     foreach ($preLaunch as $pre) {
         if (preg_match('/prelaunch\\.php$/', $pre) > 0) {
             $pre = preg_replace('/\\..*$/', '', $pre);
             $task = new $pre();
             $task->execute();
         }
     }
 }
Example #28
0
/**
 * Display all of the registered paths.
 */
$app->command('paths', function () {
    $paths = Configuration::read()['paths'];
    if (count($paths) > 0) {
        output(json_encode($paths, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
    } else {
        info('No paths have been registered.');
    }
})->descriptions('Get all of the paths registered with Valet');
/**
 * Open the current directory in the browser.
 */
$app->command('open', function () {
    $url = "http://" . Site::host(getcwd()) . '.' . Configuration::read()['domain'] . '/';
    passthru("xdg-open " . escapeshellarg($url));
})->descriptions('Open the site for the current directory in your browser');
/**
 * Echo the currently tunneled URL.
 */
$app->command('fetch-share-url', function () {
    output(Ngrok::currentTunnelUrl());
})->descriptions('Get the URL to the current Ngrok tunnel');
/**
 * Start the daemon services.
 */
$app->command('start', function () {
    PhpFpm::restart();
    Caddy::restart();
    info('Valet services have been started.');
Example #29
0
<?php

/**
 * Inscription à une mission de porte à porte
 *
 * PHP version 5
 *
 * @category Ajax
 * @package  LeQG
 * @author   Damien Senger <*****@*****.**>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License 3.0
 * @link     http://leqg.info
 */
// On lance la connexion
$link = Configuration::read('db.link');
// On réalise l'inscription
if (isset($_POST['mission'])) {
    $userId = User::ID();
    $query = 'INSERT INTO `inscriptions` (`mission_id`, `user_id`)
              VALUES (:mission, :user)';
    $query = $link->prepare($query);
    $query->bindParam(':mission', $_POST['mission'], PDO::PARAM_INT);
    $query->bindParam('user', $userId, PDO::PARAM_INT);
    $query->execute();
}
Example #30
0
$nomFichier = 'export-' . User::ID() . '-' . uniqid() . '.csv';
$file = fopen('exports/' . $nomFichier, 'w+');
$entete = ['nom', 'nom_usage', 'prenoms', 'sexe', 'date_naissance', 'age', 'adresse declaree', 'adresse electorale', 'bureau', 'ville', 'electeur', 'electeur_europeen', 'electeur_municipales', 'organisme', 'fonction', 'tags'];
fputcsv($file, $entete, ';', '"');
foreach ($contacts as $_contact) {
    $contact = new People($_contact);
    $address = $contact->postal_address();
    $poll = Maps::pollData($contact->get('bureau'));
    $birthdate = new DateTime($contact->get('date_naissance'));
    $_fichier = array($contact->get('nom'), $contact->get('nom_usage'), $contact->get('prenoms'), $contact->get('sexe'), $birthdate->format('d/m/Y'), $contact->age(), $address['reel'], $address['officiel'], $poll['number'], $poll['city'], $contact->get('electeur'), $contact->get('electeur_europeen'), $contact->get('electeur_municipales'), $contact->get('organisme'), $contact->get('fonction'), implode(',', $contact->get('tags')));
    fputcsv($file, $_fichier, ';', '"');
}
// On retraite le nom du fichier
$f = 'exports/' . $nomFichier;
if ($f) {
    $email = file_get_contents('tpl/mail/export-reussi.tpl.html');
    $objet = '[LeQG] Votre export est prêt à être téléchargé';
    $email = strtr($email, array('{URL}' => 'http://' . Configuration::read('url') . $f));
} else {
    $email = file_get_contents('tpl/mail/export-echec.tpl.html');
    $objet = '[LeQG] Votre export a provoqué un erreur';
}
$query = Core::query('user-data', 'core');
$query->bindValue(':user', User::ID());
$query->execute();
$data = $query->fetch(PDO::FETCH_ASSOC);
$service = Configuration::read('mail');
$to = array(array('email' => $data['email'], 'name' => $data['firstname'] . ' ' . $data['lastname'], 'type' => 'to'));
$mail = array('html' => $email, 'subject' => $objet, 'from_email' => '*****@*****.**', 'from_name' => 'LeQG.info', 'to' => $to, 'headers' => array('Reply-To' => '*****@*****.**'), 'track_opens' => true, 'auto_text' => true);
$async = true;
$service->messages->send($mail, $async);