Valider 86e039aa rédigé par Sébastien RENOU's avatar Sébastien RENOU
Parcourir les fichiers

init

parent
Chargement en cours
Chargement en cours
Chargement en cours
Chargement en cours

.gitignore

0 → 100644
+8 −0
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
/composer.phar
/utils/conf.php
/nbproject/
/Niveaux/Commandes/ImportDrealHauteurs.class.php
/Niveaux/Commandes/ImportDrealPluies.class.php
/Niveaux/Commandes/ImportRibou.class.php
/Niveaux/Commandes/ImportVerdon.class.php
/Niveaux/Commandes/ImportVigicrue.class.php
 No newline at end of file

LICENSE

0 → 100644
+661 −0

Fichier ajouté.

La taille limite d'aperçu a été dépassée, l'affichage des modifications a donc été réduit.

Niveaux/App.php

0 → 100644
+6 −0
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
<?php


require_once __DIR__ . '/../Niveaux/CommonConf.php';
require_once __DIR__ . '/../Niveaux/AppConf.php';
require_once __DIR__ . '/../Niveaux/Controllers/Controllers.php';

Niveaux/AppConf.php

0 → 100644
+82 −0
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
<?php

/*
 * partie de la conf spécifique à l'application web
 */


// TWIG
$app->register(new Silex\Provider\HttpFragmentServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => __DIR__ . '/../views'
));

// TRANSLATION
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
    'locale_fallbacks' => array('fr'),
));

// VALIDATOR
use Symfony\Component\Validator\Constraints as Assert;

$app->register(new Silex\Provider\ValidatorServiceProvider());

// FORM
use Silex\Provider\FormServiceProvider;

$app->register(new FormServiceProvider());


// SESSION & COOKIES
$app->register(new Silex\Provider\SessionServiceProvider());
// session par defaut sur xx heures
$app['session.storage.options'] = [
    'cookie_lifetime' => (3600 * 24 * 7)
];

use Symfony\Component\HttpFoundation\Cookie;

// URL MANAGER
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());

// REQUEST & RESPONSE & FLASH
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;

// SECURITY

$app['security.firewalls'] = array(
    // 'security' => $app['debug'] ? false : true,

    'secured' => array(
        'pattern' => '^/',
        'anonymous' => true,
        'form' => array('login_path' => '/login', 'check_path' => '/control', 'default_target_path' => '/control', 'always_use_default_target_path' => true, 'csrf_token_generator' => 'security.csrf.token_manager'),
        'logout' => array('logout_path' => '/logout', 'invalidate_session' => true, 'target' => '/'),
        'remember_me' => array(
            'key' => REMEMBERKEY,
            'always_remember_me' => true,
        ),
        'users' => function () use ($app) {
            return new UserProviderNiveaux($app['pdo']);
        },
    ),
);

$app->register(new Silex\Provider\SecurityServiceProvider(), array(
    'security.firewalls' => $app['security.firewalls']
));
$app['security.access_rules'] = array(
    array('^/admin', 'ROLE_ADMIN')
);


$app->register(new Silex\Provider\RememberMeServiceProvider(), array('lifetime' => 3600 * 24 * 7));
$app['security.default_encoder'] = function ($app) {
    return $app['security.encoder.bcrypt'];
};

// SMS OVH
use \Ovh\Sms\SmsApi;
+165 −0
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
<?php

/**
 * Description of Notification
 *
 * @author srenou
 */
class Notification {

    public function __construct($pdo, $id = null) {

        if ($id !== null) {

            $qry = $pdo->prepare('select * from ' . SCHEMA . '.notification_infos where id_notification = :id');
            $qry->bindParam(':id', $id, PDO::PARAM_INT);
            $qry->execute();
            $res = $qry->fetch(PDO::FETCH_ASSOC);
            foreach ($res as $key => $value) {
                $this->$key = $value;
            }
            return true;
        }
        return false;
    }

    public function insert($pdo, $request) {

        $pp = prepInsertQuery($request);

        $qry = $pdo->prepare("insert into " . SCHEMA . ".notification (" . $pp['reqFields'] . ") VALUES (" . $pp['reqParams'] . ")");

        foreach ($pp['tabD'] as $key => $val) {
            $qry->bindValue($key, $val);
        }

        return returnResultQuery($qry, $pdo, $pp['tabD']);
    }

    public function update($pdo, $request) {


        $pp = prepUpdateQuery($request, 'id_notification');
        $qry = $pdo->prepare("update " . SCHEMA . ".notification set " . $pp['req'] . " where id_notification = :id_notification");


        foreach ($pp['tabD'] as $key => $val) {
            $qry->bindValue($key, $val);
            echo $key . $val . '<br>';
        }

        return returnResultQuery($qry, $pdo, $pp['tabD']);
    }

    public function delete($pdo) {

        $qry = $pdo->prepare('delete from ' . SCHEMA . '.notification where  id_notification = :id_notification');
        $qry->bindParam(':id_notification', $this->id_notification, PDO::PARAM_INT);
        return $qry->execute();
    }

    /*
     * function envoie
     * 
     * @param integer id_releve 
     * @param string valeur 
     * @param DateTime date_valeur,
     * @param array Dern
     * @param pdo
     */

    public function envoie($id_releve, $valeur, $date_valeur, $Dern, $app) {

        $pdo = $app['pdo'];
        $R = new Releve($app, $id_releve);
        $dtdern = new DateTime($Dern['date_valeur'], new DateTimeZone($app['TIMEZONE']));

        if ($this->type_notification === 'mail') {

            $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                        <html xmlns="http://www.w3.org/1999/xhtml">
                        <head>
                        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                        <title>Notification ' . $app['BRAND'] . '</title>
                        <style>
                        body {
                            font-family:arial,sans-serif;
                            }
                        </style>
                        </head>
                        <body>';
            $message .= '<h2>Notification ' . $app['BRAND'] . ' ' . $app['BRANDSTRUCTURE'] . '</h2>';
            $message .= '<h1>Point de suivi ' . $this->point_suivi . ' / ' . $this->element_mesure . ' : ' . $valeur . ' ' . $this->unite . ' à ' . $date_valeur->format('H:i \l\e d/m/Y') . ' (' . $this->montant_descendant . ')</h1>';
            $message .= '<p>Cette notification a été déclenchée automatiquement suite au dernier relevé effetué sur la station de ' . $this->point_suivi . '</p>';
            $message .= '<p>Informations complémentaires : </p>';
            $message .= '<ul>';
            $message .= '<li>Nouvelle valeur de ' . $valeur . ' ' . $this->unite . ' issue du relevé ' . $R->type_releve . ' du ' . $R->datetime_releve->format('d/m/Y \à H:i') . ' effectué par ' . $R->prenom . ' ' . $R->nom . '</li>';
            $message .= '<li>Valeur précédente : ' . $Dern['valeur'] . ' ' . $this->unite . ' le ' . $dtdern->format('d/m/Y \à H:i') . '</li>';
            $message .= '</ul>';
            $message .= '<p>Paramétrage de votre notification : </p>';
            $message .= '<ul>';
            $message .= '<li>' . $this->element_mesure . ' de déclenchement : ' . $this->seuil . ' ' . $this->unite . ' (' . $this->montant_descendant . ')</li>';
            $message .= '</ul>';
            $message .= '</body></html>';

            $object = '' . $this->point_suivi . ' / ' . $this->type_point . ' à ' . $date_valeur->format('H:i \l\e d/m/Y') . ' : ' . $valeur;
            $senderMail = $app['MAILEXP'];
            $sender = $app['BRAND'] . ' ' . $app['BRANDSTRUCTURE'];

            if (envoieMail($this->mail, $senderMail, $sender, $message, $object)) {
                $this->traceEnvoi($id_releve, 'succes', array('dest' => $this->mail, 'sender-mail' => $senderMail, 'sender' => $sender, 'message' => $message, 'object' => $object), $valeur, $date_valeur->format('Y-m-d H:i:s'), $pdo);
                return true;
            } else {
                $this->traceEnvoi($id_releve, 'echec', array($this->mail, $senderMail, $sender, $message, $object), $valeur, $date_valeur->format('Y-m-d H:i:s'), $pdo);
                return false;
            }
        }

        if ($this->type_notification === 'sms') {

            if ($this->telephone != null) {

                $message = $this->point_suivi . ' : ' . $this->element_mesure . ' de ' . $valeur . ' ' . $this->unite . ' à ' . $date_valeur->format('H:i \l\e d/m/Y') . ' (' . $this->montant_descendant . '). Nouvelle valeur issue du relevé ' . $R->type_releve . ' du ' . $R->datetime_releve->format('d/m/Y \à H:i') . ' effectué par ' . $R->prenom . ' ' . $R->nom . '.';

                if (envoiSMS($this->username, $this->telephone, $message, $app)) {

                    $this->traceEnvoi($id_releve, 'succes', array('dest' => $this->telephone, 'message' => $message), $valeur, $date_valeur->format('Y-m-d H:i:s'), $pdo);
                    return true;
                } else {
                    $this->traceEnvoi($id_releve, 'echec', array('dest' => $this->telephone, 'message' => $message), $valeur, $date_valeur->format('Y-m-d H:i:s'), $pdo);
                    return false;
                }
            }
        }
    }

    private function traceEnvoi($id_releve, $statut, $contenu, $valeur, $date_valeur, $pdo) {

        $qry = $pdo->prepare('insert into ' . SCHEMA . '.notification_envoi (id_notification,id_releve,statut,contenu_notification,releve_valeur,releve_valeur_date) VALUES (:id_notification,:id_releve,:statut,:contenu,:releve_valeur,to_timestamp(:releve_valeur_date, \'yyyy-mm-dd hh24:mi:ss\'))');
        $qry->bindParam(':id_notification', $this->id_notification, PDO::PARAM_INT);
        $qry->bindParam(':id_releve', $id_releve, PDO::PARAM_INT);
        $qry->bindParam(':statut', $statut, PDO::PARAM_STR);
        $cont = json_encode($contenu);
        $qry->bindParam(':contenu', $cont, PDO::PARAM_STR);
        $qry->bindParam(':releve_valeur', $valeur, PDO::PARAM_STR);
        $qry->bindParam(':releve_valeur_date', $date_valeur, PDO::PARAM_STR);


        return $qry->execute();
    }

    public function chargeEnvois($pdo, $limit = 5) {

        $qry = $pdo->prepare('select * from ' . SCHEMA . '.notification_envoi_infos where id_notification = ' . $this->id_notification . ' order by date_envoi_notification desc LIMIT ' . $limit);
        $qry->execute();
        return $qry->fetchAll(PDO::FETCH_ASSOC);
    }

    public function desactive($pdo) {

        $qry = $pdo->prepare('update ' . SCHEMA . '.notification set active = 0 where id_notification = :id');
        $qry->bindParam(':id', $this->id_notification, PDO::PARAM_INT);
        return $qry->execute();
    }

}
Chargement en cours