1 | <?php |
---|
2 | |
---|
3 | function diogene_geo_diogene_avant_formulaire($flux){ |
---|
4 | if(is_array(unserialize($flux['args']['champs_ajoutes'])) && in_array('geo',unserialize($flux['args']['champs_ajoutes']))){ |
---|
5 | $flux['data'] .= recuperer_fond('prive/diogene_geo_avant_formulaire', $flux['args']); |
---|
6 | } |
---|
7 | return $flux; |
---|
8 | } |
---|
9 | |
---|
10 | function diogene_geo_diogene_ajouter_media($flux){ |
---|
11 | $id_article = $flux['args']['contexte']['id_article']; |
---|
12 | if(is_array(unserialize($flux['args']['champs_ajoutes'])) && in_array('geo',unserialize($flux['args']['champs_ajoutes']))){ |
---|
13 | if($id_article){ |
---|
14 | if(intval($id_article)){ |
---|
15 | $valeurs_gis = sql_fetsel("lat,lonx,zoom","spip_gis","id_article=$id_article"); |
---|
16 | if(is_array($valeurs_gis)){ |
---|
17 | $flux['args']['contexte'] = array_merge($flux['args']['contexte'],$valeurs_gis); |
---|
18 | } |
---|
19 | } |
---|
20 | $flux['data'] .= recuperer_fond('formulaires/diogene_ajouter_medias_geo',$flux['args']['contexte']); |
---|
21 | } |
---|
22 | } |
---|
23 | return $flux; |
---|
24 | } |
---|
25 | |
---|
26 | function diogene_geo_diogene_ajout_media_post_traiter($flux){ |
---|
27 | if($flux['args']['action']=='modifier'){ |
---|
28 | |
---|
29 | $id_objet = $flux['args']['id_objet']; |
---|
30 | $type = $flux['args']['type']; |
---|
31 | $table = $flux['args']['table']; |
---|
32 | $id_table_objet = id_table_objet($type); |
---|
33 | spip_log("hop","bb"); |
---|
34 | if(($lat = _request('lat')) && ($lng = _request('lonx')) && (!$non_localisable = _request('non_localisable'))){ |
---|
35 | // On crée l'array pour l'update et pour la création des coordonnées |
---|
36 | spip_log("on devrait pas passer ici","bb"); |
---|
37 | $zoom = _request('zoom') ? _request('zoom') : lire_config('geomap/zoom'); |
---|
38 | |
---|
39 | $coords = array( |
---|
40 | $id_table_objet=> $id_objet, |
---|
41 | 'lat'=> $lat, |
---|
42 | 'lonx' => $lng, |
---|
43 | 'zoom' => $zoom |
---|
44 | ); |
---|
45 | |
---|
46 | if(lire_config('gis/geocoding') == 'oui'){ |
---|
47 | $geocoding = array( |
---|
48 | "pays" => _request('pays'), |
---|
49 | "code_pays" => _request('code_pays'), |
---|
50 | "region" => _request('region'), |
---|
51 | "ville" => _request('ville'), |
---|
52 | "code_postal" => _request('code_postal') |
---|
53 | ); |
---|
54 | $coords = array_merge($coords,$geocoding); |
---|
55 | } |
---|
56 | |
---|
57 | $coords_existantes = sql_getfetsel("id_gis","spip_gis","$id_table_objet = $id_objet"); |
---|
58 | if($coords_existantes){ |
---|
59 | // Des coordonnées sont déjà définies pour cet article |
---|
60 | // => on les update |
---|
61 | sql_updateq("spip_gis",$coords,"id_gis = $coords_existantes"); |
---|
62 | } |
---|
63 | else{ |
---|
64 | // Aucune coordonnée n'est définie pour cet article |
---|
65 | // => on les crées |
---|
66 | $id_gis = sql_insertq("spip_gis",$coords); |
---|
67 | } |
---|
68 | } |
---|
69 | spip_log($non_localisable,"bb"); |
---|
70 | set_request('non_localisable',$non_localisable); |
---|
71 | } |
---|
72 | return $flux; |
---|
73 | } |
---|
74 | |
---|
75 | function diogene_geo_diogene_ajout_media_post_verifier($flux){ |
---|
76 | spip_log("DIOGENE_GEO : Verification des champs géographiques"); |
---|
77 | |
---|
78 | $id_article = _request('id_article'); |
---|
79 | $erreurs = &$flux['args']['erreurs']; |
---|
80 | |
---|
81 | if((!$erreur['lat']) && ($lat = _request('lat'))){ |
---|
82 | if((!empty($lat)) && !is_numeric($lat)){ |
---|
83 | $erreurs['lat'] = _T('diogene:valeur_pas_float',array('champs'=> _T('diogene_geo:latitude'))); |
---|
84 | } |
---|
85 | } |
---|
86 | if((!$erreur['lonx']) && ($lonx = _request('lonx'))){ |
---|
87 | if((!empty($lonx)) && !is_numeric($lonx)){ |
---|
88 | $erreurs['lonx'] = _T('diogene:valeur_pas_float',array('champs'=> _T('diogene_geo:longitude'))); |
---|
89 | } |
---|
90 | } |
---|
91 | if((!$erreur['zoom']) && ($zoom = _request('zoom'))){ |
---|
92 | if((!empty($zoom)) && !is_numeric($zoom)){ |
---|
93 | $erreurs['zoom'] = _T('diogene:valeur_pas_int',array('champs'=>_T('diogene_geo:zoom'))); |
---|
94 | } |
---|
95 | } |
---|
96 | return $flux; |
---|
97 | } |
---|
98 | |
---|
99 | function diogene_geo_diogene_ajout_media_post_charger($flux){ |
---|
100 | $flux['data']['non_localisable'] = _request('non_localisable'); |
---|
101 | return $flux; |
---|
102 | } |
---|
103 | |
---|
104 | function diogene_geo_diogene_champs_sup($flux){ |
---|
105 | $flux['article']['geo'] = _T('diogene_geo:form_legend'); |
---|
106 | $flux['rubrique']['geo'] = _T('diogene_geo:form_legend'); |
---|
107 | return $flux; |
---|
108 | } |
---|
109 | ?> |
---|