| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505 |
- var app = angular.module('application', ['ngMaterial', 'adaptive.detection', 'ui.bootstrap.typeahead']).config([
- '$locationProvider',
- function($locationProvider) {
- $locationProvider.html5Mode({
- enabled: true,
- requireBase: false
- });
- }
- ]);
- app.directive('skrollr', function() {
- var directiveDefinitionObject = {
- link: function() {
- skrollr.init();
- }
- };
- return directiveDefinitionObject;
- });
- app.controller('mainController', function($scope, $detection, $http, $mdSidenav, $timeout, $sce, $mdToast, $location) {
- // Debugging mode
- $scope.debug = window.location.hostname === 'localhost' || typeof $location.search().debug !== 'undefined';
- if ($scope.debug) {
- console.log('***** Debugging mode ****');
- }
- $scope.title = 'Manche Numerique';
- $scope.$sce = $sce;
- var getGeoCodeInProgress = false,
- nbJoursFTTH = 730, // 2 ans
- siteName = 'Eligibilité Manche Numérique',
- siteUrl = 'http://eligibilite.manchenumerique.fr',
- siteEmail = 'ftth@manchenumerique.fr',
- siteAddresse = '235, rue Joseph Cugnot Zone Delta, 50000 SAINT LÔ',
- siteTel = '02.33.77.83.60',
- layer = {},
- currentMarker,
- cLayer;
- // Coordinates around Manche to limit the extent of the queries
- var mancheCoordinates = [[49.732307856286, -1.97117692088061], [48.4, -1.75], [48.4, -0.5], [49.732307856286, -1.2]];
- // This limit the search area
- var searchExtent = {
- xmin: _.max(
- _.map(mancheCoordinates, function(c) {
- return c[1];
- })
- ),
- ymin: _.max(
- _.map(mancheCoordinates, function(c) {
- return c[0];
- })
- ),
- xmax: _.min(
- _.map(mancheCoordinates, function(c) {
- return c[1];
- })
- ),
- ymax: _.min(
- _.map(mancheCoordinates, function(c) {
- return c[0];
- })
- ),
- spatialReference: { wkid: 84 }
- };
- var suggestURL =
- 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest?f=pjson&searchExtent=' +
- JSON.stringify(searchExtent);
- var maps = {
- carte: 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
- satellite: 'http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'
- };
- var catTypeVoie = [
- {
- name: 'Allée',
- id: 'allee'
- },
- {
- name: 'Avenue',
- id: 'avenue'
- },
- {
- name: 'Boulevard',
- id: 'boulevard'
- },
- {
- name: 'Carrefour',
- id: 'carrefour'
- },
- {
- name: 'Chemin',
- id: 'chemin'
- },
- {
- name: 'Cité',
- id: 'cite'
- },
- {
- name: 'Hammeau',
- id: 'hammeau'
- },
- {
- name: 'Impasse',
- id: 'impasse'
- },
- {
- name: 'Lieu-dit',
- id: 'lieu_dit'
- },
- {
- name: 'Lotissement',
- id: 'lotissement'
- },
- {
- name: 'Place',
- id: 'place'
- },
- {
- name: 'Résidence',
- id: 'residence'
- },
- {
- name: 'Route',
- id: 'route'
- },
- {
- name: 'Rue',
- id: 'rue'
- },
- {
- name: 'Villa',
- id: 'villa'
- },
- {
- name: 'Village',
- id: 'village'
- }
- ];
- var catVousEtes = [
- {
- name: 'Locataire de ce logement',
- id: 'locataire'
- },
- {
- name: 'Occupant à titre gratuit de ce logement',
- id: 'occupant_gratuit'
- },
- {
- name: 'Propriétaire de ce logement',
- id: 'proprietaire'
- }
- ];
- var catCeLogementEst = [
- {
- name: 'Votre résidence principale',
- id: 'residence_principale'
- },
- {
- name: 'Votre résidence secondaire',
- id: 'residence_secondaire'
- }
- ];
- var catAccord = [
- {
- name:
- 'J’ai l’intention de souscrire à une offre Très Haut Débit et bénéficier du raccordement de mon logement au tarif préférentiel de 50€',
- id: 'avec_souscription'
- },
- {
- name: 'Je n’ai pas l’intention de souscrire à une offre Très Haut Débit',
- id: 'sans_souscription'
- }
- ];
- $scope.formulaires = {
- eligibilite: {
- sections: [
- {
- name: 'Générale',
- visible: false,
- lines: [
- {
- ctrls: [
- {
- name: 'Prénom',
- id: 'prenom',
- type: 'text',
- width: '50%',
- require: true,
- isValid: function(value) {
- return !!value && value.length > 2;
- },
- msg: 'Prénom invalide'
- },
- {
- name: 'Nom',
- id: 'nom',
- type: 'text',
- width: '50%',
- require: true,
- isValid: function(value) {
- return !!value && value.length > 2;
- },
- msg: 'Nom invalide'
- }
- ]
- },
- {
- ctrls: [
- {
- name: 'Email',
- id: 'email',
- type: 'text',
- width: null,
- require: true,
- isValid: function(value) {
- function validateEmail(email) {
- var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
- return re.test(email);
- }
- return validateEmail(value);
- },
- msg: 'Email invalide.'
- }
- ]
- },
- {
- ctrls: [
- {
- name: 'Téléphone fixe',
- id: 'telephone_fixe',
- type: 'text',
- width: '50%',
- require: false
- },
- {
- name: 'Téléphone portable',
- id: 'telephone_portable',
- type: 'text',
- width: '50%',
- require: false
- }
- ]
- }
- ]
- },
- {
- name: 'Adresse',
- visible: true,
- lines: [
- {
- ctrls: [
- {
- name: 'Numero',
- id: 'numero_voie',
- type: 'text',
- width: '80px',
- require: false
- },
- {
- name: 'Type voie',
- id: 'type_voie',
- type: 'select',
- width: '106px',
- require: false,
- options: {
- categories: catTypeVoie
- }
- },
- {
- name: 'Nom voie',
- id: 'nom_voie',
- type: 'text',
- width: '378px',
- require: true,
- isValid: function(value) {
- return !!value;
- },
- msg: 'Nom de voie invalide.'
- }
- ]
- },
- {
- ctrls: [
- {
- name: 'Complément Adresse',
- id: 'complement_addresse',
- type: 'textarea',
- width: null,
- require: false
- }
- ]
- },
- {
- ctrls: [
- {
- name: 'Bâtiment',
- id: 'batiment',
- type: 'text',
- width: '50%',
- require: false
- },
- {
- name: 'Cage escalier',
- id: 'cage_escalier',
- type: 'text',
- width: '50%',
- require: false
- }
- ]
- },
- {
- ctrls: [
- {
- name: 'Etage / Niveau',
- id: 'etage',
- type: 'text',
- width: '50%',
- require: false
- },
- {
- name: 'Numero appartement / porte',
- id: 'numero_appartement',
- type: 'text',
- width: '50%',
- require: false
- }
- ]
- },
- {
- ctrls: [
- {
- name: 'Code postal',
- id: 'code_postal',
- type: 'text',
- width: '50%',
- require: true,
- isValid: function(value) {
- if (!value || value.length !== 5 || isNaN(parseInt(value, 10))) {
- return false;
- }
- return true;
- },
- msg: 'Non valide'
- },
- {
- name: 'Ville',
- id: 'ville',
- type: 'text',
- width: '50%',
- require: true,
- isValid: function(value) {
- return !!value && value.length > 2;
- },
- msg: 'Ville invalide.'
- }
- ]
- }
- ]
- },
- {
- name: 'Logement',
- visible: true,
- lines: [
- {
- ctrls: [
- {
- name: 'Vous êtes',
- id: 'vous_etes',
- type: 'radio',
- width: null,
- require: true,
- other: true,
- options: {
- categories: catVousEtes,
- alertes: {
- locataire:
- 'Si vous êtes locataire, vous devez impérativement avertir votre propriétaire que vous souhaitez bénéficier du pré-raccordement à la fibre optique.'
- }
- },
- isValid: function(value, other) {
- return (!!value && value !== 'autre') || !!other;
- },
- msg: 'Choix incomplet.'
- }
- ]
- },
- {
- ctrls: [
- {
- name: 'Ce logement est',
- id: 'ce_logement_est',
- type: 'radio',
- width: null,
- require: true,
- other: true,
- options: {
- categories: catCeLogementEst
- },
- isValid: function(value, other) {
- return (!!value && value !== 'autre') || !!other;
- },
- msg: 'Choix incomplet.'
- }
- ]
- }
- ]
- },
- {
- name: 'Conditions pour le raccordement final d’abonné dans un immeuble individuel',
- visible: true,
- lines: [
- {
- text:
- 'Manche Numérique propose aux personnes qui le souhaitent, de manifester d’ores et déjà leur intérêt pour bénéficier d’une offre Très Haut Débit et ainsi raccorder leur logement ou local à usage professionnel, au futur réseau de communications électroniques à Très Haut Débit FTTH. Le montant de ce raccordement s’élèvera à <b>50€</b><sup>1</sup> pour les personnes qui souscriront à une offre Très Haut Débit auprès d’un opérateur dans l’année qui suit l’ouverture officielle du réseau à la commercialisation. <br><br>Les personnes qui ne se seront pas inscrites via ce formulaire en ligne ne pourront pas bénéficier du raccordement de leur habitation au tarif préférentiel de 50 €. Le raccordement sera directement pris en charge par le Fournisseur d’Accès Internet, auprès duquel elles souscriront un abonnement, et c’est lui qui fixera le montant appliqué au raccordement. <b><br><sup>1</sup> Remarque : Ce raccordement s’appuiera sur vos infrastructures existantes, le coût lié à leur remise en état sera à votre charge en supplément des 50€.',
- ctrls: [
- {
- name: 'Accord',
- id: 'accord',
- options: {
- categories: catAccord
- },
- type: 'radio',
- width: null,
- require: true,
- other: false,
- isValid: function(value) {
- return !!value;
- },
- msg: 'Choix incorrect.',
- note:
- 'IMPORTANT : le règlement vous sera demandé par le Fournisseur d’Accès Internet auprès duquel vous aurez souscrit un abonnement à la fibre optique.'
- }
- ]
- }
- ]
- },
- {
- name: 'Informatique et libertés',
- visible: false,
- lines: [
- {
- ctrls: [
- {
- name: 'Informatique et libertés',
- id: 'info_et_libertes',
- libelle:
- 'La personne responsable du traitement de la présente demande de pré-inscription est le représentant du Syndicat Mixte Manche Numérique, le Président, Monsieur Serge DESLANDES. Les informations portées sur ce formulaire sont obligatoires. Elles font l’objet d’un traitement informatisé destiné au raccordement final de l’usager à la fibre optique (FTTH) ainsi qu’à l’exploitation du réseau optique. Les destinataires des données sont : le Syndicat Mixte Manche Numérique ainsi que l’exploitant du réseau optique. Les données sont conservées pendant une durée de 3 ans à partir de la date de transmission à l’entreprise en charge des travaux de raccordement. 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 communication des informations vous concernant, veuillez-vous adresser au Syndicat Mixte Manche Numérique ftth@manchenumerique.fr. Dans l’hypothèse où le présent formulaire est incomplet et/ou illisible, la présente demande de raccordement ne sera pas traitée.',
- type: 'checkbox',
- width: null,
- require: true,
- isValid: function(value) {
- return !!value;
- },
- msg: 'Vous devez accepter.'
- }
- ]
- }
- ]
- }
- ]
- }
- };
- var addCurrentMarker = function(withReverse) {
- if (currentMarker) {
- map.removeLayer(currentMarker);
- }
- currentMarker = L.marker([$scope.geoCode.y, $scope.geoCode.x], { draggable: true, title: 'Votre addresse' }).addTo(
- map
- );
- // currentMarker.on('add', function(event) {
- // map.setZoom(18);
- // });
- currentMarker
- .bindPopup(
- "L'adresse que vous nous avez fournie est localisée sur la carte. Il se peut que la position réelle de votre logement soit un peu différente. Dans ce cas, merci de déplacer le pointeur sur la carte pour le positionner à l'emplacement de votre logement."
- )
- .openPopup();
- if (withReverse) {
- $scope.magicKey = null;
- reverseLocation($scope.geoCode, null, function(address) {
- $scope.address = address;
- });
- }
- currentMarker.on('dragend', function(event) {
- var p = currentMarker.getLatLng();
- $scope.magicKey = null;
- $scope.geoCode = {
- x: p.lng,
- y: p.lat
- };
- reverseLocation($scope.geoCode, null, function(address) {
- $scope.address = address;
- getResults();
- });
- });
- };
- 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;
- }
- $scope.results.ftth.eligible = false;
- var momentDate;
- // Already deployed
- if (
- $scope.results.ftth.phase_trav === 'Perimetre deploye FTTH MT' ||
- $scope.results.ftth.phase_trav === 'Perimetre Manche Telecom'
- ) {
- $scope.results.ftth.eligible = true;
- }
- // Si date de début de travaux réelle est renseignée
- if ($scope.results.ftth.date_deb_trav_reel) {
- // Compute Date
- momentDate = moment($scope.results.ftth.date_deb_trav_reel, 'YYYY-MM-DD');
- momentDate.add(nbJoursFTTH, 'days');
- var semester = '1er';
- if (parseInt(momentDate.format('M'), 10) > 5) {
- semester = '2nd';
- }
- $scope.results.ftth.date = semester + ' semestre ' + momentDate.format('YYYY');
- } else if (
- ($scope.results.ftth.phase_trav === 'Tranche 1 Travaux' ||
- $scope.results.ftth.phase_trav === 'Tranche 1 Travaux completude') &&
- $scope.results.ftth.date_deb_trav_prev
- ) {
- // Si date de début de travaux prévisionnelle est renseignée
- // Compute Date
- momentDate = moment($scope.results.ftth.date_abonnement_prev, 'YYYY-MM-DD');
- momentDate.add(nbJoursFTTH, 'days');
- var semester = '1er';
- if (parseInt(momentDate.format('M'), 10) > 5) {
- semester = '2nd';
- }
- $scope.results.ftth.date = semester + ' semestre ' + momentDate.format('YYYY');
- }
- };
- var computeFullAddress = function() {
- return $scope.result.eligibilite.complement_addresse;
- };
- var formatDate = function(value) {
- return moment(value, 'YYYY-MM-DD');
- };
- var getFullAddress = function(callback) {
- if ($scope.magicKey) {
- var findURL = 'http://api-adresse.data.gouv.fr/search/?';
- var url = findURL + 'q=' + $scope.address;
- $.get(url, function(data, status) {
- var next = function(record) {
- reverseLocation($scope.geoCode, null, function(string, address) {
- if (record) {
- address.StreetNumber = record.housenumber;
- address.Match_addr = $scope.address;
- }
- callback(null, address);
- });
- };
- if (data && data.features && data.features[0] && data.features[0].properties) {
- next(data.features[0].properties);
- } else {
- next();
- }
- });
- } else {
- reverseLocation($scope.geoCode, null, function(string, address) {
- callback(null, address);
- });
- }
- };
- var getRecordsFor = function(identifier, coordinates) {
- var records = [];
- _.each($scope.data[identifier], function(record) {
- _.some(record._polygons, function(polygon) {
- if (isInside(polygon, coordinates)) {
- records.push(record);
- return true;
- }
- });
- });
- return records;
- };
- var getResults = function() {
- $scope.results = {};
- $.ajax({
- method: 'POST',
- url: 'ajax/db.php',
- data: $scope.geoCode
- })
- .error(function(err) {
- console.error('Database issue', err);
- })
- .done(function(msg) {
- onResults(msg);
- });
- var onResults = function(results) {
- try {
- $scope.results = JSON.parse(results);
- $scope.results.address = $scope.address;
- $scope.results.ftth = parseResults($scope.results.ftth);
- $scope.results.adsl = parseResults($scope.results.adsl);
- $scope.results.mimo = parseResults($scope.results.mimo);
- computeDateFTTH();
- console.log('results', $scope.results);
- } catch (e) {
- // Debugging purpose
- if (window.location.hostname === 'localhost') {
- onResults(
- '{"x":-1.763289,"y":49.3660125,"ftth":[{"id_zapm_partielle":"049AP0","phase_trav":"Tranche 1 Travaux","date_deb_trav_prev":"19/02/16","date_deb_trav_reel":"26/10/17","date_ouv_bul_preracco":"01/01/16","date_ferm_bul_preracco":null,"date_abonnement_prev":"26/10/19","date_ouv_commercialisation":null,"eligible":false,"date":"2nd semestre 2019"}],"adsl":{"id_num":"2842","classedebi":"2","classe_legende":"ADSL 3 a 8 Mbit/s"},"mimo":{"id_site_mimo":"10","date_ouv_service_reel":"19/02/16","date_ouv_service_prev":"T1 2016"},"address":"Rue des Fauvettes, 50270, Barneville-Plage, Barneville-Carteret, Manche, Normandie, FRA"}'
- );
- } else {
- console.error(e);
- alert('Probleme de connexion à la base de donnée.');
- $scope.hideResultPane();
- }
- }
- $scope.refreshInscriptionInfo();
- $scope.$apply();
- };
- $scope.$evalAsync();
- };
- var init = function() {
- var stlo = [49.1154686, -1.0828136000000086];
- var map = L.map('map', { zoomControl: false }).setView(stlo, 9);
- map.on('dblclick', function(e) {
- var p = e.latlng;
- $scope.geoCode = {
- x: p.lng,
- y: p.lat
- };
- addCurrentMarker(true);
- $scope.showResultPane();
- getResults();
- });
- cLayer = L.tileLayer(maps.satellite, {
- attribution: 'Carte fournie par <a href="http://openstreetmap.org">OpenStreetMap</a>',
- maxZoom: 18
- }).addTo(map);
- var styleOpts = {
- color: 'red',
- fillColor: 'red',
- weight: 8
- };
- $scope.data = {};
- $scope.colors = {
- ftth: '#8cc474', // green
- mimo: '#f9b256', // orange
- adsl: '#76a7fa' // blue
- };
- $http({ method: 'POST', url: 'data/dictionary.json' }).success(function(data) {
- $scope.dictionary = data;
- });
- // Debug: show manche limits on the map
- if ($scope.debug) {
- L.polygon(mancheCoordinates, { color: 'blue', fillColor: 'blue', weight: 8 }).addTo(map);
- }
- window.map = map;
- $scope.mapType = 'Satellite';
- $scope.view = {};
- $scope.isShown = {};
- if ($location.search().q) {
- $scope.address = $location.search().q;
- $scope.suggestLocation($location.search().q);
- }
- };
- var isDate = function(value) {
- return (
- /^\d{4}-\d{2}-\d{2}$/.test(value.toString())
- );
- };
- var isInside = function(polygon, point) {
- var y = point.x ? point.x : point[0],
- x = point.y ? point.y : point[1];
- var inside = false;
- for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
- var xi = polygon[i][0],
- yi = polygon[i][1];
- var xj = polygon[j][0],
- yj = polygon[j][1];
- var intersect = yi > y != yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
- if (intersect) {
- inside = !inside;
- }
- }
- 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;
- }
- });
- };
- var parseData = function(identifier, data, style, properties) {
- var getPolygonsCoord = function(type, coord) {
- var result = [];
- if (type === 'Polygon') {
- result.push(
- _.map(coord[0], function(r) {
- return [r[1], r[0]];
- })
- );
- }
- if (type === 'MultiPolygon') {
- var p = [];
- _.each(coord, function(c) {
- result.push(
- _.map(c[0], function(r) {
- return [r[1], r[0]];
- })
- );
- });
- }
- return result;
- };
- var records = [];
- _.each(data.features, function(r) {
- var record = r.properties;
- var polygons = getPolygonsCoord(r.geometry.type, r.geometry.coordinates);
- record._coordinates = r.geometry.coordinates;
- record._type = r.geometry.type;
- record._polygons = polygons;
- record._style = style;
- record._properties = properties;
- records.push(record);
- });
- $scope.data[identifier] = records;
- };
- var parseResults = function(records) {
- if (!records || !records.length) {
- return null;
- }
- if (records.length === 1) {
- return records[0];
- }
- var result = records[0];
- return result;
- };
- var reverseLocation = function(geoCode, address, callback) {
- var reverseGeo =
- 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?f=pjson&distance=300';
- var url = reverseGeo + '&location=' + (geoCode ? $scope.geoCode.x + ',' + $scope.geoCode.y : address);
- $.get(url, function(data, status) {
- data = JSON.parse(data);
- var adresse = data && data.address && data.address.Match_addr;
- if (data && data.address && data.address.Address) {
- var i = 0;
- var num = '';
- while (!isNaN(parseInt(data.address.Address[i], 10))) {
- num += data.address.Address[i];
- i++;
- }
- data.address.StreetNumber = num;
- data.address.Address = data.address.Address.substr(num.length).trim();
- var typeVoie = data.address.Address.substring(0, data.address.Address.indexOf(' ')).toLowerCase();
- type = _.find(catTypeVoie, function(c) {
- if (c.id === typeVoie || c.name.toLowerCase() === typeVoie) {
- return true;
- }
- });
- if (type) {
- data.address.StreetType = type.id;
- data.address.Address = data.address.Address.substr(typeVoie.length).trim();
- }
- }
- callback(adresse, data.address);
- $scope.$evalAsync();
- });
- };
- $scope.changeMap = function(value) {
- map.removeLayer(cLayer);
- cLayer = L.tileLayer(maps[value], {
- attribution:
- 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
- maxZoom: 18
- }).addTo(map);
- };
- $scope.closeRight = function() {
- $mdSidenav('right')
- .close()
- .then(function() {});
- };
- $scope.computeLayer = function(identifier) {
- var Lpolygons = [];
- _.each($scope.data[identifier], function(record) {
- _.each(record._polygons, function(polygon) {
- Lpolygons.push(L.polygon(polygon, record._style).bindPopup($scope.getHtmlContent(identifier, record)));
- });
- });
- layer[identifier] = L.layerGroup(Lpolygons);
- };
- $scope.formatDateFTTH = function(date) {
- if (!date || date === 'Invalid date') {
- return;
- }
- var result =
- '<div class="popup-line"><div class="box-eligibilite-title">Date prévisionnelle abonnement FTTH</div><div style="font-weight: bold;" class="popup-value">' +
- date +
- '</div></div>';
- return $sce.trustAsHtml(result);
- };
- $scope.formatResults = function(identifier, results) {
- return $sce.trustAsHtml($scope.getHtmlContent(identifier, results));
- };
- $scope.getGeoCode = function(address, magicKey, callback) {
- var findURL =
- 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?f=pjson&searchExtent=' +
- JSON.stringify(searchExtent);
- getGeoCodeInProgress = true;
- var url = findURL + '&text=' + address + (magicKey ? '&magicKey=' + magicKey : ', Basse-Normandie, France');
- $.get(url, function(data, status) {
- data = JSON.parse(data);
- if (status === 'success' && data.locations[0]) {
- if (
- data.locations[0].extent.xmax < searchExtent.xmin &&
- data.locations[0].extent.xmax > searchExtent.xmax &&
- data.locations[0].extent.xmin > searchExtent.xmax &&
- data.locations[0].extent.xmin > searchExtent.xmax
- ) {
- getGeoCodeInProgress = false;
- return callback(null, data);
- }
- getGeoCodeInProgress = false;
- callback('No result for ' + address);
- } else {
- getGeoCodeInProgress = false;
- callback(status !== 'success' ? status : 'No result for ' + address);
- }
- });
- };
- $scope.getHtmlContent = function(identifier, record) {
- // Tooltip content
- var tooltip = '';
- _.each(record, function(value, property) {
- if (
- property.charAt(0) === '_' ||
- (property === 'date' && identifier === 'ftth') ||
- value === null ||
- typeof value === 'undefined'
- ) {
- return;
- }
- var label = $scope.dictionary[property] || property;
- value = $scope.dictionary[value] || value;
- var date;
- if (property.substring(0, 5) === 'date_' && !$scope.dictionary[value] && isDate(value)) {
- date = formatDate(value);
- }
- if (!date || $scope.debug) {
- // Do not show dates to user otherwise
- tooltip +=
- '<div class="popup-line"><div class="popup-label">' +
- label +
- '</div><div class="popup-value">' +
- (date ? date.locale('fr').format('MMMM YYYY') : value) +
- '</div><div class="popup-small-date">' +
- (date ? date.locale('fr').fromNow() : '') +
- '</div></div>';
- }
- });
- if (identifier === 'adsl') {
- tooltip =
- '<a style="float: right;" href="http://www.ariase.com/fr/eligibilite/test.html" target="_blank">Tester mon éligibilité ADSL avec Ariase.com</a>';
- }
- return tooltip;
- };
- $scope.hideLayer = function(identifier) {
- map.removeLayer(layer[identifier]);
- };
- $scope.hideResultPane = function() {
- if (!$('#result').height()) {
- return;
- }
- $('#result').animate({ height: 0 }, 1000);
- $('#map').animate(
- {
- height: $('body').height()
- },
- 1000,
- function() {
- // Animation complete.
- map.invalidateSize();
- var centerPoint = $scope.geoCode ? new L.LatLng($scope.geoCode.y, $scope.geoCode.x) : stlo;
- map.setView(centerPoint, 14);
- }
- );
- };
- $scope.initPopup = function() {
- $scope.postForm = null;
- getFullAddress(function(err, address) {
- if (err) {
- console.error(err);
- }
- $scope.result = { eligibilite: {}, autres: {} };
- $scope.result.eligibilite.geo_code = JSON.stringify($scope.geoCode);
- $scope.result.eligibilite.code_postal = address.Postal;
- $scope.result.eligibilite.complement_addresse = address.Match_addr;
- $scope.result.eligibilite.nom_voie = address.Address;
- $scope.result.eligibilite.numero_voie = address.StreetNumber;
- $scope.result.eligibilite.type_voie = address.StreetType;
- $scope.result.eligibilite.ville = address.City;
- });
- };
- $scope.isFormValid = function() {
- if (!$scope.result || !$scope.result.eligibilite) {
- return;
- }
- var isValid = true;
- _.each($scope.formulaires.eligibilite.sections, function(section) {
- _.each(section.lines, function(line) {
- _.each(line.ctrls, function(ctrl) {
- ctrl.invalid = false;
- if (ctrl.require && !ctrl.isValid($scope.result.eligibilite[ctrl.id], $scope.result.autres[ctrl.id])) {
- isValid = false;
- ctrl.invalid = true;
- }
- });
- });
- });
- return isValid;
- };
- $scope.refreshInscriptionInfo = function() {
- if (!$scope.results.ftth) {
- return false;
- }
- var dateDeb = moment($scope.results.ftth.date_ouv_bul_preracco, 'YYYY-MM-DD');
- var dateFin = moment($scope.results.ftth.date_ferm_bul_preracco, 'YYYY-MM-DD');
- var dateCom = moment($scope.results.ftth.date_ouv_commercialisation, 'YYYY-MM-DD');
- var dateEndButton = dateFin.add(31, 'days');
- var now = moment();
- var diffDaysDeb = now.diff(dateDeb) / 1000 / 3600 / 24;
- var diffDaysFin = now.diff(dateFin) / 1000 / 3600 / 24;
- var diffDaysCom = now.diff(dateCom) / 1000 / 3600 / 24;
- var diffDaysEndButton = now.diff(dateEndButton) / 1000 / 3600 / 24;
- var isOpen = diffDaysDeb > 0 && (!$scope.results.ftth.date_ferm_bul_preracco || diffDaysEndButton < 0);
- var isMarketable = !!diffDaysCom;
- var cas = 0;
- var message = 'Déploiement prévu ultérieurement.';
- if ($scope.results.ftth.eligible) {
- // Perimetre MT Saint Love et Cherbourg
- cas = 7;
- message = null;
- } else if ($scope.results.ftth.date_ouv_commercialisation && isMarketable) {
- var jct = diffDaysCom < 0 ? 'va débuter' : 'a débuté';
- message =
- 'La commercialisation des offres FttH sur votre secteur ' +
- jct +
- ' le ' +
- dateCom.lang('fr').format('ll') +
- '. Pour souscrire à une offre internet Très Haut Débit, contactez les fournisseurs d’accès présents sur le réseau :';
- cas = 6;
- } else if ($scope.results.ftth.date_ferm_bul_preracco && diffDaysFin > 31) {
- cas = 5;
- isOpen = false;
- message =
- "Les travaux dans votre secteur sont terminés et ont été livrés à Manche Fibre, délégataire de service public. Vous n'avez plus la possibilité de vous inscrire.";
- } else if (isOpen) {
- message =
- dateFin && diffDaysFin > 0 && diffDaysEndButton < 0
- ? 'L’inscription se termine le ' + dateEndButton.lang('fr').format('ll')
- : '';
- cas = 3;
- if (!message && $scope.results.ftth.date_ferm_bul_preracco) {
- if (diffDaysFin < 31) {
- message =
- 'Les travaux dans votre secteur sont terminés. Il vous reste ' +
- Math.abs(parseInt(diffDaysEndButton, 10)) +
- ' jours pour vous pré-inscrire sur notre site.';
- cas = 4;
- }
- }
- } else if ($scope.results.ftth.date_ouv_bul_preracco && diffDaysDeb < 0) {
- message = 'L’inscription sera possible à partir du ' + dateDeb.lang('fr').format('ll');
- cas = 2;
- } else if ($scope.results.ftth.date_deb_trav_prev) {
- var date = moment($scope.results.ftth.date_deb_trav_prev, 'YYYY-MM-DD').add(24, 'M');
- message = null;
- cas = 1;
- }
- console.log('Cas ' + cas);
- $scope.inscription = {
- open: isOpen,
- message: message,
- cas: cas
- };
- };
- $scope.onSubmitAddress = function($item, $model, $label) {
- // Get magic key
- var item = _.find($scope.suggestions, { text: $item });
- if (!item) {
- item = $scope.suggestions[0];
- $scope.address = item.text;
- }
- $scope.magicKey = item.magicKey;
- $scope.getGeoCode($scope.address, $scope.magicKey, function(err, data) {
- $scope.geoCode = data && data.locations && data.locations[0] && data.locations[0].feature.geometry;
- if (err) {
- console.error('Geocode error', err);
- }
- var toast = toast || {
- template:
- '<md-toast><i class = " md-error"></i> Oups! Aucun résultat trouvé dans la Manche pour: ' +
- $scope.address +
- '</md-toast>',
- hideDelay: 3000,
- position: 'bottom right'
- };
- if (err || !$scope.geoCode) {
- $scope.hideResultPane();
- $mdToast.show(toast);
- }
- if ($scope.geoCode) {
- addCurrentMarker();
- $scope.showResultPane();
- getResults();
- }
- });
- };
- $scope.postFormEl = function() {
- $scope.postForm = { inProgress: true };
- // Add ID_ZAPM_PARTIELLE
- $scope.result.eligibilite.id_zapm_partielle = $scope.results.ftth.id_zapm_partielle;
- _.each($scope.result.autres, function(value, key) {
- $scope.result.eligibilite[key] = value;
- });
- $scope.$evalAsync();
- var keys = '';
- var values = '';
- _.each($scope.result.eligibilite, function(value, key) {
- keys += '`' + key + '`, ';
- if (value === 'undefined' || value === undefined) {
- value = '';
- }
- if (key === 'telephone_fixe' || key === 'telephone_portable') {
- value = value
- .replace(/ /g, '')
- .replace(/\./g, '')
- .replace(/-/g, '');
- }
- if (typeof value === 'boolean') {
- values += value + ', ';
- } else {
- values += "'" + mysql_real_escape_string(value) + "', ";
- }
- });
- var dateTime = new Date(
- new Date(new Date(new Date()).toISOString()).getTime() - new Date().getTimezoneOffset() * 60000
- )
- .toISOString()
- .slice(0, 19)
- .replace('T', ' ');
- checkDoublon($scope.result.eligibilite, function(doublon) {
- 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'
- };
- return $scope.$apply();
- }
- 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: { query: query }
- }).done(function(msg) {
- if (!isNaN(msg)) {
- $scope.postForm = { ok: true };
- 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>';
- 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 };
- }
- $scope.hideResultPane();
- $scope.$apply();
- });
- });
- };
- $scope.showLayer = function(identifier) {
- map.addLayer(layer[identifier]);
- };
- $scope.showResultPane = function() {
- var bodyHeight = $('body').height();
- var height = Math.max(300, bodyHeight / 3);
- var heightMap = bodyHeight - height;
- $('#result').animate({ height: height + 'px' }, 1000);
- $('#map').animate(
- {
- height: heightMap + 'px'
- },
- 1000,
- function() {
- // Animation complete.
- map.invalidateSize();
- map.setView(new L.LatLng($scope.geoCode.y, $scope.geoCode.x), 18);
- }
- );
- };
- var i = 0,
- j = 0;
- $scope.suggestLocation = function(val) {
- try {
- var coordinates = JSON.parse(val);
- if (coordinates && coordinates.x) {
- $scope.geoCode = coordinates;
- addCurrentMarker();
- }
- return;
- } catch (e) {
- $scope.suggestionsReady = false;
- i++;
- return $http
- .get(suggestURL, {
- params: {
- text: val
- }
- })
- .then(function(response) {
- if (val === $scope.address) {
- // Very important to debounce queries
- $scope.suggestionsReady = response.data.suggestions.length !== 0;
- $scope.suggestions = _.cloneDeep(response.data.suggestions);
- }
- return response.data.suggestions.map(function(item) {
- return item.text;
- });
- });
- }
- };
- $scope.toggleResultPane = function() {
- if ($('#result').height()) {
- return $scope.hideResultPane();
- }
- if ($scope.results && $scope.results.ftth) {
- return $scope.showResultPane();
- }
- };
- $scope.toggleRight = function() {
- $mdSidenav('right')
- .toggle()
- .then(function() {});
- };
- $scope.$watch(
- 'view',
- function(view) {
- if (_.isEmpty(view)) {
- return;
- }
- $('#layer-loading')
- .removeClass('force-hidden')
- .find('.md-inner')
- .show();
- setTimeout(function() {
- _.each(view, function(value, key) {
- if ($scope.isShown[key] !== value) {
- if (value) {
- if (typeof $scope.isShown[key] !== 'undefined') {
- $scope.showLayer(key);
- $('#layer-loading')
- .find('.md-inner')
- .hide();
- } else {
- $timeout(function() {
- $scope.computeLayer(key);
- $scope.showLayer(key);
- $('#layer-loading')
- .find('.md-inner')
- .hide();
- }, 500);
- }
- } else {
- $scope.hideLayer(key);
- setTimeout(function() {
- $('#layer-loading')
- .find('.md-inner')
- .hide();
- }, 1000);
- }
- $scope.isShown[key] = value;
- }
- });
- });
- },
- true
- );
- $(window).resize(function() {
- if (!$('#result').height()) {
- return;
- }
- $scope.showResultPane();
- });
- init();
- });
|