PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/_plugins_/gis/branches/v1/inc/parte_privada.php

https://bitbucket.org/pombredanne/spip-zone-treemap
PHP | 225 lines | 193 code | 17 blank | 15 comment | 31 complexity | 15ed34ae0c8b06f74fe8c97a78226fc9 MD5 | raw file
  1. <?php
  2. /*
  3. * Spip Gis plugin
  4. * Insetar google maps en SPIP
  5. *
  6. * Autores :
  7. * Horacio Gonzalez, Berio Molina
  8. * (c) 2007 - Distribudo baixo licencia GNU/GPL
  9. *
  10. */
  11. if (!defined("_ECRIRE_INC_VERSION")) return;
  12. include_spip('base/abstract_sql');
  13. include_spip('inc/vieilles_defs');
  14. include_spip('inc/autoriser');
  15. function gis_cambiar_coord($id,$table,$exec) {
  16. global $spip_lang_left, $spip_lang_right;
  17. $pkey = id_table_objet($table);
  18. // on recupere l'id de l'auteur en cours
  19. if ($GLOBALS["auteur_session"])
  20. $id_auteur_session = $GLOBALS['auteur_session']['id_auteur'];
  21. // et on verifie qu'il est autorisé à modifier l'élément en cours
  22. $autoriser = autoriser("modifier",$table,$id);
  23. $glat = NULL;
  24. $glonx = NULL;
  25. $gzoom = NULL;
  26. $gicon = NULL;
  27. $mapa = "";
  28. $defaut = _DIR_PLUGIN_GEOMAP ? 'geomap' : '';
  29. $api_carte = lire_config('gis/api_carte',$defaut);
  30. if (lire_config('gis/geocoding'))
  31. $geocoding = true;
  32. $result= spip_query("SELECT * FROM spip_gis WHERE $pkey = " . intval($id));
  33. if ($row = spip_fetch_array($result)){
  34. $glat = $row['lat'];
  35. $glonx = $row['lonx'];
  36. $gzoom = $row['zoom'];
  37. }
  38. if(_request('actualizar')){
  39. $glat = _request('lat');
  40. $glonx = _request('lonx');
  41. $gzoom = _request('zoom');
  42. if ($geocoding){
  43. $pays = _request('pays');
  44. $code_pays = _request('code_pays');
  45. $region = _request('region');
  46. $ville = _request('ville');
  47. $code_postal = _request('code_postal');
  48. }
  49. if (!$row){
  50. if ($geocoding) {
  51. spip_abstract_insert("spip_gis",
  52. "($pkey, lat, lonx, zoom, pays, code_pays, region, ville, code_postal)",
  53. "("._q($id) .", "._q($glat).", "._q($glonx).", "._q($gzoom).", "._q($pays).", "._q($code_pays).", "._q($region).", "._q($ville).", "._q($code_postal).")"
  54. );
  55. } else {
  56. spip_abstract_insert("spip_gis",
  57. "($pkey, lat, lonx, zoom)",
  58. "("._q($id) .", "._q($glat).", "._q($glonx).", "._q($gzoom).")"
  59. );
  60. }
  61. } else {
  62. if ($geocoding) {
  63. spip_query("UPDATE spip_gis SET lat="._q($glat).", lonx="._q($glonx).", zoom="._q($gzoom).", pays="._q($pays).", code_pays="._q($code_pays).", region="._q($region).", ville="._q($ville).", code_postal="._q($code_postal)." WHERE $pkey = " . _q($id));
  64. } else {
  65. spip_query("UPDATE spip_gis SET lat="._q($glat).", lonx="._q($glonx).", zoom="._q($gzoom)." WHERE $pkey = " . _q($id));
  66. }
  67. }
  68. }
  69. if(_request('supprimer')){
  70. sql_delete("spip_gis", array("$pkey = " . sql_quote($id)));
  71. }
  72. if ($glat!==NULL){
  73. $resultMots = spip_query("SELECT * FROM spip_mots_{$table}s WHERE $pkey = ".intval($id));
  74. $marker_icon_name = 'marker_icon';
  75. if (isset($_GET['marker_icon_name'])) {
  76. $marker_icon_name = $_GET['marker_icon_name'];
  77. }
  78. while ($rowMot = spip_fetch_array($resultMots)) {
  79. $resultMotIcon = spip_query("SELECT * FROM spip_mots WHERE type ='"._q($marker_icon_name)."' AND id_mot=".$rowMot['id_mot']);
  80. if ($rowMotIcon = spip_fetch_array($resultMotIcon)){
  81. if (file_exists("../IMG/"."moton".$rowMot['id_mot'].".png")) {
  82. $gicon = "moton".$rowMot['id_mot'].".png";
  83. } else if (file_exists("../IMG/"."moton".$rowMot['id_mot'].".gif")) {
  84. $gicon = "moton".$rowMot['id_mot'].".gif";
  85. }
  86. }
  87. }
  88. if ($api_carte) {
  89. $gis_append_view_map = charger_fonction($api_carte.'_append_view_map','inc');
  90. $mapa = '<div id="viewMap" style="width:477px;height:100px;border:1px solid #000;overflow:hidden;"></div>';
  91. $mapa .= $gis_append_view_map('viewMap',$glat,$glonx,$zoom,array(array('lonx'=>$glonx,'lat'=>$glat)),$gicon);
  92. } else {
  93. $mapa = '<div>' . _T('gis:falta_plugin') . '</div>';
  94. }
  95. }
  96. $s .= '';
  97. // Ajouter un formulaire de modification si l'auteur est autorisé
  98. if ($autoriser){
  99. // On teste la version de SPIP utilisee 2 ou 1.9
  100. if(function_exists('bouton_block_depliable')){
  101. $s .= debut_cadre('e', _DIR_PLUGIN_GIS."img_pack/correxir.png",'',bouton_block_depliable('&nbsp;&nbsp;&nbsp;<span style="text-transform: uppercase;">'._T('gis:cambiar').'</span>', false, "cadroFormulario"));
  102. }else{
  103. $s .= debut_cadre('r', _DIR_PLUGIN_GIS."img_pack/correxir.png");
  104. $s .= bouton_block_invisible("ajouter_form");
  105. $s .= '&nbsp;&nbsp;&nbsp;<strong class="verdana3" style="text-transform: uppercase;">' . _T('gis:cambiar') . ' <a onclick="$(\'#cadroFormulario\').slideToggle(\'slow\')">(' . _T('gis:clic_desplegar') . ')</a></strong>';
  106. }
  107. $s .= debut_block_visible("ajouter_form");
  108. $s .= '<div id="cadroFormulario" class="formulaire_spip formulaire_editer formulaire_cfg" style="margin-bottom:5px;">
  109. <span class="verdana2">' . _T("gis:clic_mapa") . '</span>';
  110. if ($api_carte) {
  111. $gis_append_clicable_map = charger_fonction($api_carte.'_append_clicable_map','inc');
  112. $s .= '<div id="formMap" style="width: 467px; height: 350px; margin:5px auto; overflow:hidden;"></div>';
  113. $s .= $gis_append_clicable_map('formMap','form_lat','form_long',$glat,$glonx,'form_zoom',$gzoom,$row?true:false);
  114. } else {
  115. $s .= '<div>' . _T('gis:falta_plugin') . '</div>';
  116. }
  117. // Formulario para actualizar as coordenadas do mapa______________________.
  118. $s .= '
  119. <form id="formulaire_address" action="#">
  120. <ul style="text-align:center;">
  121. <li style="padding-left:0; display:inline;">
  122. <input type="text" class="text" size="50" name="map_address" id="map_address" value="'._T('gis:address').'" onfocus="this.value=\'\';" style="width:360px; margin-right:10px;" />
  123. <input type="submit" value="'._T('gis:label_address').'" />
  124. </li>
  125. </ul>
  126. </form>
  127. <form id="formulaire_coordenadas" action="'.generer_url_ecrire($exec,"$pkey=".$id).'" method="post">
  128. '.($geocoding?'<input type="hidden" name="code_pays" id="code_pays" value="" />
  129. <input type="hidden" name="region" id="region" value="" />
  130. <input type="hidden" name="code_postal" id="code_postal" value="" />':'').'
  131. <ul style="text-align:center;">
  132. <li style="padding-left:0; display:inline;"><label for="form_lat" style="margin-left:0; float:none; display:inline;">'._T('gis:lat').': </label><input type="text" class="text" name="lat" id="form_lat" value="'.$glat.'" size="12" style="width:80px;" /></li>
  133. <li style="padding-left:0; display:inline;"><label for="form_long" style="margin-left:0; float:none; display:inline;">'._T('gis:long').': </label><input type="text" class="text" name="lonx" id="form_long" value="'.$glonx.'" size="12" style="width:80px;" /></li>
  134. <li style="padding-left:0; display:inline;"><label for="form_zoom" style="margin-left:0; float:none; display:inline;">'._T('gis:zoom').': </label><input type="text" class="text" name="zoom" id="form_zoom" value="'.$gzoom.'" size="6" style="width:30px;" /></li>
  135. </ul>
  136. '.($geocoding?'<ul style="text-align:center;">
  137. <li style="padding-left:0; display:inline;">
  138. <label for="pays" style="margin-left:0; float:none; display:inline;">'._T('gis:label_pays').': </label>
  139. <input type="text" class="text" name="pays" id="pays" value="'.$row['pays'].'" style="width:95px;" />
  140. </li>
  141. <li style="padding-left:0; display:inline;">
  142. <label for="ville" style="margin-left:0; float:none; display:inline;">'._T('gis:label_ville').': </label>
  143. <input type="text" class="text" name="ville" id="ville" value="'.$row['ville'].'" style="width:95px;" />
  144. </li>
  145. </ul>':'').'
  146. <p class="boutons">
  147. <input type="submit" name="actualizar" value="'._T("gis:boton_actualizar").'" /><input type="submit" name="supprimer" value="'._T("gis:bouton_supprimer").'" />
  148. </p>
  149. </form>
  150. </div>';
  151. $s .= $mapa;
  152. $s .= fin_block();
  153. $s .= fin_cadre(true);
  154. }else{
  155. $s .= debut_cadre('e', _DIR_PLUGIN_GIS."img_pack/correxir.png",'',_T("gis:coord"),'','', true);
  156. $s .= $mapa;
  157. $s .= fin_cadre(true);
  158. }
  159. return $s;
  160. }
  161. function gis_mots($id_mot) {
  162. global $spip_lang_left, $spip_lang_right;
  163. $glat = NULL;
  164. $glonx = NULL;
  165. $gzoom = NULL;
  166. $result = spip_query("SELECT * FROM spip_gis_mots WHERE id_mot = ".intval($id_mot));
  167. if ($row = spip_fetch_array($result)){
  168. $glat = $row['lat'];
  169. $glonx = $row['lonx'];
  170. $gzoom = $row['zoom'];
  171. }
  172. if(_request('actualizar')){
  173. $glat = _request('lat');
  174. $glonx = _request('lonx');
  175. $gzoom = _request('zoom');
  176. if (!$row)
  177. spip_abstract_insert("spip_gis_mots", "(id_mot, lat, lonx, zoom)", "("._q($id_mot).", "._q($glat).", "._q($glonx).", "._q($gzoom).")");
  178. else
  179. spip_query("UPDATE spip_gis_mots SET lat="._q($glat).", lonx="._q($glonx).", zoom="._q($gzoom)." WHERE id_mot = "._q($id_mot));
  180. }
  181. $s .= debut_cadre('r', _DIR_PLUGIN_GIS."img_pack/correxir.png");
  182. $s .= bouton_block_invisible("ajouter_form");
  183. $s .= '&nbsp;&nbsp;&nbsp;<strong class="verdana3" style="text-transform: uppercase;">'. _T("gis:cambiar") .' '. $id_mot .' <a onclick="$(\'#cadroFormulario\').slideToggle(\'slow\')">('. _T('gis:clic_desplegar') .')</a></strong>';
  184. $s .= debut_block_visible("ajouter_form");
  185. $s .= '<div class="verdana2">'. _T("gis:clic_mapa") .'</div>';
  186. $s .= debut_block_visible("ajouter_form");
  187. $s .= '<div id="cadroFormulario" style="border:1px solid #000">';
  188. if ($api_carte = lire_config('gis/api_carte')) {
  189. $gis_append_mini_map = charger_fonction($api_carte.'_append_mini_map','inc');
  190. $s .= '<div id="formMap" name="formMap" style="width: 180px; height: 180px;overflow:hidden;"></div>';
  191. $s .= $gis_append_mini_map('formMap','form_lat','form_long',$glat,$glonx,'form_zoom',$gzoom,$row?true:false);
  192. } else {
  193. $s .= '<div>'. _T('gis:falta_plugin') .'</div>';
  194. }
  195. // Formulario para actualizar as coordenadas do mapa
  196. $s .= '<form id="formulaire_coordenadas" name="formulaire_coordenadas" action="'.generer_url_ecrire("mots_edit","&id_mot=".$id_mot).'" method="post">
  197. <div style="height:20px; padding:4px;"><input type="text" name="lat" id="form_lat" value="'.$glat.'" size="12" style="float:right"/><label>'._T('gis:lat').': </label></div>
  198. <div style="height:20px; padding:4px;"><input type="text" name="lonx" id="form_long" value="'.$glonx.'" size="12" style="float:right"/><label>'._T('gis:long').': </label></div>
  199. <div style="height:20px; padding:4px;"><input type="text" name="zoom" id="form_zoom" value="'.$gzoom.'" size="12" style="float:right"/><label>'._T('gis:zoom').': </label></div>
  200. <div style="height:20px; padding:4px;"><input type="submit" name="actualizar" value="'._T("gis:boton_actualizar").'" /></div>
  201. </form>
  202. </div>';
  203. $s .= fin_block();
  204. $s .= fin_block();
  205. $s .= fin_cadre(true);
  206. return $s;
  207. }
  208. ?>