|
|
@@ -479,6 +479,26 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ var checkDoublon = function(formValues, callback) {
|
|
|
+
|
|
|
+ var query = 'SELECT * FROM `eligibilite`.`demandes` WHERE 1' +
|
|
|
+ ' AND `email` = "' + mysql_real_escape_string(formValues.email) + '"' +
|
|
|
+ ' AND `numero_voie` = "' + (formValues.numero_voie ? formValues.numero_voie : '') + '"' +
|
|
|
+ ' AND `type_voie` = "' + mysql_real_escape_string(formValues.type_voie) + '"' +
|
|
|
+ ' AND `nom_voie` = "' + mysql_real_escape_string(formValues.nom_voie) + '"' +
|
|
|
+ ' AND `code_postal` = "' + formValues.code_postal + '"';
|
|
|
+
|
|
|
+ $.ajax({
|
|
|
+ method : "POST",
|
|
|
+ url : "ajax/datastores.php",
|
|
|
+ data : {query: query}
|
|
|
+ })
|
|
|
+ .done(function( result ) {
|
|
|
+ var doublon = result && result !== 'null' ? result: null;
|
|
|
+ callback(doublon);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
var computeDateFTTH = function() {
|
|
|
if(!$scope.results.ftth) {return;}
|
|
|
|
|
|
@@ -830,6 +850,34 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
|
|
|
return inside;
|
|
|
};
|
|
|
|
|
|
+ var mysql_real_escape_string = function(str) {
|
|
|
+ if(typeof str !== 'string') {return str;}
|
|
|
+
|
|
|
+ return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
|
|
|
+
|
|
|
+ switch (char) {
|
|
|
+ case "\0":
|
|
|
+ return "\\0";
|
|
|
+ case "\x08":
|
|
|
+ return "\\b";
|
|
|
+ case "\x09":
|
|
|
+ return "\\t";
|
|
|
+ case "\x1a":
|
|
|
+ return "\\z";
|
|
|
+ case "\n":
|
|
|
+ return "\\n";
|
|
|
+ case "\r":
|
|
|
+ return "\\r";
|
|
|
+ case "\"":
|
|
|
+ case "'":
|
|
|
+ case "\\":
|
|
|
+ case "%":
|
|
|
+ return "\\"+char; // prepends a backslash to backslash, percent,
|
|
|
+ // and double/single quotes
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
var parseData = function(identifier, data, style, properties) {
|
|
|
var getPolygonsCoord = function(type, coord) {
|
|
|
var result = [];
|
|
|
@@ -1155,33 +1203,6 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
|
|
|
|
|
|
$scope.$evalAsync();
|
|
|
|
|
|
- function mysql_real_escape_string (str) {
|
|
|
- if(typeof str !== 'string') {return str;}
|
|
|
-
|
|
|
- return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
|
|
|
- switch (char) {
|
|
|
- case "\0":
|
|
|
- return "\\0";
|
|
|
- case "\x08":
|
|
|
- return "\\b";
|
|
|
- case "\x09":
|
|
|
- return "\\t";
|
|
|
- case "\x1a":
|
|
|
- return "\\z";
|
|
|
- case "\n":
|
|
|
- return "\\n";
|
|
|
- case "\r":
|
|
|
- return "\\r";
|
|
|
- case "\"":
|
|
|
- case "'":
|
|
|
- case "\\":
|
|
|
- case "%":
|
|
|
- return "\\"+char; // prepends a backslash to backslash, percent,
|
|
|
- // and double/single quotes
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
var keys = '';
|
|
|
var values = '';
|
|
|
_.each($scope.result.eligibilite, function(value, key) {
|
|
|
@@ -1199,127 +1220,133 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
|
|
|
|
|
|
var dateTime = (new Date ((new Date((new Date(new Date())).toISOString() )).getTime() - ((new Date()).getTimezoneOffset()*60000))).toISOString().slice(0, 19).replace('T', ' ');
|
|
|
|
|
|
- var query = "INSERT INTO `eligibilite`.`demandes` (`date`," + keys.substring(0, keys.length -2) + ") VALUES ('" + dateTime + "', " + values.substring(0, values.length -2) + ");";
|
|
|
+ checkDoublon($scope.result.eligibilite, function(doublon) {
|
|
|
|
|
|
- console.log('query', query);
|
|
|
+ if(doublon) {
|
|
|
+ $scope.postForm = {error: 'Une demande de pré-raccordement a déjà été effectuée à cette adresse. Pour tout renseignement merci de contacter les services de Manche Numérique au 02.33.77.83.60'};
|
|
|
|
|
|
- $.ajax({
|
|
|
- method : "POST",
|
|
|
- url : "ajax/datastores.php",
|
|
|
- data : {query: query}
|
|
|
- })
|
|
|
- .done(function( msg ) {
|
|
|
+ return $scope.$apply();
|
|
|
+ }
|
|
|
|
|
|
- if(!isNaN(msg)) {
|
|
|
- $scope.postForm = {ok: true};
|
|
|
-
|
|
|
- //var template = $templateCache.get('nameOfTemplate.html');
|
|
|
-
|
|
|
- var numDemande = moment().format('YYYYMMDD') + msg;
|
|
|
-
|
|
|
- var body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
|
|
|
-
|
|
|
- body += '<html><body style="font-size: 14px; font-family: calibri;">' +
|
|
|
- 'Bonjour ' + $scope.result.eligibilite.prenom + ' ' + $scope.result.eligibilite.nom + ', <br>' +
|
|
|
- 'Nous vous confirmons votre demande de pré-raccordement FTTH. <br><br>' +
|
|
|
- 'Cette demande porte le numéro: ' +
|
|
|
- '<span style="color: #31708f;font-size:17px; font-weight:bold;">' + numDemande + '</span><br><br>' +
|
|
|
- 'Voici le détail de votre demande:' +
|
|
|
- '<table WIDTH="100%" style="line-height: 40px;" bgColor="#d9edf7" bordercolor="#bce8f1">';
|
|
|
-
|
|
|
- // Numero demande
|
|
|
- body += '<tr>';
|
|
|
- body += '<th style="width:180px;text-align: left;white-space: nowrap;height: 40px;color: #666;">Numéro demande</th>';
|
|
|
- body += '<td>' + numDemande + '</td>';
|
|
|
- body += '</tr>';
|
|
|
-
|
|
|
- // Date demande
|
|
|
- body += '<tr>';
|
|
|
- body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Date</th>';
|
|
|
- body += '<td>' + moment().lang('fr').format('LLLL') + '</td>';
|
|
|
- body += '</tr>';
|
|
|
-
|
|
|
- // Demandeur
|
|
|
- body += '<tr>';
|
|
|
- body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Demandeur</th>';
|
|
|
- body += '<td>' + $scope.result.eligibilite.prenom + ' ' + $scope.result.eligibilite.nom + '</td>';
|
|
|
- body += '</tr>';
|
|
|
-
|
|
|
- // Email
|
|
|
- body += '<tr>';
|
|
|
- body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Email</th>';
|
|
|
- body += '<td>' + $scope.result.eligibilite.email + '</td>';
|
|
|
- body += '</tr>';
|
|
|
-
|
|
|
- // Adresse
|
|
|
- body += '<tr>';
|
|
|
- body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Adresse</th>';
|
|
|
- body += '<td>' + computeFullAddress() + '</td>';
|
|
|
- body += '</tr>';
|
|
|
-
|
|
|
- // Vous etes
|
|
|
- var cat = _.find(catVousEtes, {id: $scope.result.eligibilite.vous_etes});
|
|
|
- var res = cat && cat.name ? cat.name : $scope.result.eligibilite.vous_etes;
|
|
|
- body += '<tr>';
|
|
|
- body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Vous êtes</th>';
|
|
|
- body += '<td>' + res + '</td>';
|
|
|
- body += '</tr>';
|
|
|
-
|
|
|
- // Ce logement est
|
|
|
- var cat2 = _.find(catCeLogementEst, {id: $scope.result.eligibilite.ce_logement_est});
|
|
|
- var res2 = cat2 && cat2.name ? cat2.name : $scope.result.eligibilite.ce_logement_est;
|
|
|
- body += '<tr>';
|
|
|
- body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Ce logement est</th>';
|
|
|
- body += '<td>' + res2 + '</td>';
|
|
|
- body += '</tr>';
|
|
|
-
|
|
|
- //console.log('$scope.result', $scope.result);
|
|
|
-
|
|
|
- body += '</table><br><br>';
|
|
|
-
|
|
|
- body += 'Conformément à la loi "informatique et libertés" du 6 janvier 1978 modifiée, vous bénéficiez d’un droit d’accès, de rectification aux informations qui vous concernent, d’opposition au traitement de vos données personnelles. Si vous souhaitez exercer ce droit et obtenir la communication des informations vous concernant, merci de nous contacter :' + '<br>' +
|
|
|
- '<table bgcolor="#ddd" bordercolor="#666">' +
|
|
|
- ' <tr>' +
|
|
|
- ' <th style="width:180px;text-align: left;white-space: nowrap;height: 30px;color: #666;">Email</th><td>' + siteEmail + '</td>' +
|
|
|
- ' </tr><tr>' +
|
|
|
- ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Adresse</th><td>' + siteAddresse + '</td>' +
|
|
|
- ' </tr><tr>' +
|
|
|
- ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Tel</th><td>' + siteTel + '</td>' +
|
|
|
- ' </tr>' +
|
|
|
- '</table><br><br>';
|
|
|
-
|
|
|
- body += 'A bientôt sur: <a href="' + siteUrl + '">' + siteName + '</a></body></html>';
|
|
|
-
|
|
|
- console.log('body', body);
|
|
|
- var mail = {
|
|
|
- to : $scope.result.eligibilite.email,
|
|
|
- sujet : 'Votre demande de pré-raccordement FTTH n° ' + numDemande,
|
|
|
- message: body
|
|
|
- };
|
|
|
+ var query = "INSERT INTO `eligibilite`.`demandes` (`date`," + keys.substring(0, keys.length -2) + ") VALUES ('" + dateTime + "', " + values.substring(0, values.length -2) + ");";
|
|
|
|
|
|
$.ajax({
|
|
|
method : "POST",
|
|
|
url : "ajax/datastores.php",
|
|
|
- data : {
|
|
|
- siteEmail: siteEmail,
|
|
|
- mail : mail}
|
|
|
+ data : {query: query}
|
|
|
})
|
|
|
.done(function( msg ) {
|
|
|
- console.log('Mail result', msg);
|
|
|
- });
|
|
|
|
|
|
- $scope.result.eligibilite = {};
|
|
|
- $scope.autres = {};
|
|
|
- $scope.address = null;
|
|
|
- $scope.magicKey = null;
|
|
|
+ if(!isNaN(msg)) {
|
|
|
+ $scope.postForm = {ok: true};
|
|
|
+
|
|
|
+ //var template = $templateCache.get('nameOfTemplate.html');
|
|
|
+
|
|
|
+ var numDemande = moment().format('YYYYMMDD') + msg;
|
|
|
+
|
|
|
+ var body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
|
|
|
+
|
|
|
+ body += '<html><body style="font-size: 14px; font-family: calibri;">' +
|
|
|
+ 'Bonjour ' + $scope.result.eligibilite.prenom + ' ' + $scope.result.eligibilite.nom + ', <br>' +
|
|
|
+ 'Nous vous confirmons votre demande de pré-raccordement FTTH. <br><br>' +
|
|
|
+ 'Cette demande porte le numéro: ' +
|
|
|
+ '<span style="color: #31708f;font-size:17px; font-weight:bold;">' + numDemande + '</span><br><br>' +
|
|
|
+ 'Voici le détail de votre demande:' +
|
|
|
+ '<table WIDTH="100%" style="line-height: 40px;" bgColor="#d9edf7" bordercolor="#bce8f1">';
|
|
|
+
|
|
|
+ // Numero demande
|
|
|
+ body += '<tr>';
|
|
|
+ body += '<th style="width:180px;text-align: left;white-space: nowrap;height: 40px;color: #666;">Numéro demande</th>';
|
|
|
+ body += '<td>' + numDemande + '</td>';
|
|
|
+ body += '</tr>';
|
|
|
+
|
|
|
+ // Date demande
|
|
|
+ body += '<tr>';
|
|
|
+ body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Date</th>';
|
|
|
+ body += '<td>' + moment().lang('fr').format('LLLL') + '</td>';
|
|
|
+ body += '</tr>';
|
|
|
+
|
|
|
+ // Demandeur
|
|
|
+ body += '<tr>';
|
|
|
+ body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Demandeur</th>';
|
|
|
+ body += '<td>' + $scope.result.eligibilite.prenom + ' ' + $scope.result.eligibilite.nom + '</td>';
|
|
|
+ body += '</tr>';
|
|
|
+
|
|
|
+ // Email
|
|
|
+ body += '<tr>';
|
|
|
+ body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Email</th>';
|
|
|
+ body += '<td>' + $scope.result.eligibilite.email + '</td>';
|
|
|
+ body += '</tr>';
|
|
|
+
|
|
|
+ // Adresse
|
|
|
+ body += '<tr>';
|
|
|
+ body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Adresse</th>';
|
|
|
+ body += '<td>' + computeFullAddress() + '</td>';
|
|
|
+ body += '</tr>';
|
|
|
+
|
|
|
+ // Vous etes
|
|
|
+ var cat = _.find(catVousEtes, {id: $scope.result.eligibilite.vous_etes});
|
|
|
+ var res = cat && cat.name ? cat.name : $scope.result.eligibilite.vous_etes;
|
|
|
+ body += '<tr>';
|
|
|
+ body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Vous êtes</th>';
|
|
|
+ body += '<td>' + res + '</td>';
|
|
|
+ body += '</tr>';
|
|
|
+
|
|
|
+ // Ce logement est
|
|
|
+ var cat2 = _.find(catCeLogementEst, {id: $scope.result.eligibilite.ce_logement_est});
|
|
|
+ var res2 = cat2 && cat2.name ? cat2.name : $scope.result.eligibilite.ce_logement_est;
|
|
|
+ body += '<tr>';
|
|
|
+ body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Ce logement est</th>';
|
|
|
+ body += '<td>' + res2 + '</td>';
|
|
|
+ body += '</tr>';
|
|
|
+
|
|
|
+ //console.log('$scope.result', $scope.result);
|
|
|
+
|
|
|
+ body += '</table><br><br>';
|
|
|
+
|
|
|
+ body += 'Conformément à la loi "informatique et libertés" du 6 janvier 1978 modifiée, vous bénéficiez d’un droit d’accès, de rectification aux informations qui vous concernent, d’opposition au traitement de vos données personnelles. Si vous souhaitez exercer ce droit et obtenir la communication des informations vous concernant, merci de nous contacter :' + '<br>' +
|
|
|
+ '<table bgcolor="#ddd" bordercolor="#666">' +
|
|
|
+ ' <tr>' +
|
|
|
+ ' <th style="width:180px;text-align: left;white-space: nowrap;height: 30px;color: #666;">Email</th><td>' + siteEmail + '</td>' +
|
|
|
+ ' </tr><tr>' +
|
|
|
+ ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Adresse</th><td>' + siteAddresse + '</td>' +
|
|
|
+ ' </tr><tr>' +
|
|
|
+ ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Tel</th><td>' + siteTel + '</td>' +
|
|
|
+ ' </tr>' +
|
|
|
+ '</table><br><br>';
|
|
|
+
|
|
|
+ body += 'A bientôt sur: <a href="' + siteUrl + '">' + siteName + '</a></body></html>';
|
|
|
+
|
|
|
+ var mail = {
|
|
|
+ to : $scope.result.eligibilite.email,
|
|
|
+ sujet : 'Votre demande de pré-raccordement FTTH n° ' + numDemande,
|
|
|
+ message: body
|
|
|
+ };
|
|
|
+
|
|
|
+ $.ajax({
|
|
|
+ method : "POST",
|
|
|
+ url : "ajax/datastores.php",
|
|
|
+ data : {
|
|
|
+ siteEmail: siteEmail,
|
|
|
+ mail : mail}
|
|
|
+ })
|
|
|
+ .done(function( msg ) {
|
|
|
+ console.log('Email sent', msg);
|
|
|
+ });
|
|
|
+
|
|
|
+ $scope.result.eligibilite = {};
|
|
|
+ $scope.autres = {};
|
|
|
+ $scope.address = null;
|
|
|
+ $scope.magicKey = null;
|
|
|
|
|
|
- }
|
|
|
- else {
|
|
|
- $scope.postForm = {error: msg};
|
|
|
- }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $scope.postForm = {error: msg};
|
|
|
+ }
|
|
|
|
|
|
- $scope.hideResultPane();
|
|
|
- $scope.$apply();
|
|
|
+ $scope.hideResultPane();
|
|
|
+ $scope.$apply();
|
|
|
+ });
|
|
|
});
|
|
|
};
|
|
|
|
|
|
@@ -1396,34 +1423,4 @@ app.controller('mainController', function($scope, $detection, $http, $mdSidenav,
|
|
|
});
|
|
|
|
|
|
init();
|
|
|
-
|
|
|
- /*
|
|
|
- $scope.toto = 'FB SA RAXCE';
|
|
|
- var templateUrl = $sce.getTrustedResourceUrl('html/emailTemplate.html');
|
|
|
-
|
|
|
- $templateRequest(templateUrl).then(function(template) {
|
|
|
- // template is the HTML template as a string
|
|
|
-
|
|
|
- // Let's put it into an HTML element and parse any directives and expressions
|
|
|
- // in the code. (Note: This is just an example, modifying the DOM from within
|
|
|
- // a controller is considered bad style.)
|
|
|
-
|
|
|
- var factory = angular.element(template);
|
|
|
-
|
|
|
- //factory.html();
|
|
|
- $compile(factory)($scope);
|
|
|
-
|
|
|
- // get the interpolated HTML asynchronously after the interpolation happens
|
|
|
- $timeout(function () {
|
|
|
- factory.append('<div></div>');
|
|
|
-
|
|
|
- html = factory.html();
|
|
|
- console.log('template', html);
|
|
|
- // ... do whatever you need with the interpolated HTML
|
|
|
- });
|
|
|
-
|
|
|
- }, function() {
|
|
|
- // An error has occurred
|
|
|
- });
|
|
|
- */
|
|
|
});
|