default
[ class tree: default ] [ index: default ] [ all elements ]

Source for file examples.guifi_api.simple_user.php

Documentation is available at examples.guifi_api.simple_user.php

  1. <?php
  2. // The source code packaged with this file is Free Software, Copyright (C) 2005 by
  3. // Eduard Duran <eduard.duran at iglu.cat>.
  4. // It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
  5. // You can get copies of the licenses here:
  6. //         http://www.affero.org/oagpl.html
  7. // AFFERO GENERAL PUBLIC LICENSE is also included in the file called "LICENSE.txt".
  8.  
  9. require 'guifi_api.php' );
  10.  
  11. /**
  12.  * Configuration of authentication against guifi.net
  13.  */
  14. $username "";
  15. $password "";
  16.  
  17. $gapi new guifiAPI$username$password );
  18.  
  19. if!empty$_GET['a') ) {
  20.     if$_GET['a'== 'getZone' && !empty$_GET['lat'&& !empty$_GET['lon') ) {
  21.         $lat $_GET['lat'];
  22.         $lon $_GET['lon'];
  23.         
  24.         $zones $gapi->nearestZone$lat$lon );
  25.         if$zones {
  26.             if$zones->nearest {
  27.                 $nearest $zones->nearest;
  28.                 $candidates $zones->candidates;
  29.                 
  30.                 echo '<select id="ipt-zone" name="zone_id">' "\n";
  31.                 
  32.                 foreach$candidates as $candidate {
  33.                     echo '<option value="' $candidate->zone_id '"' $candidate->zone_id == $nearest->zone_id ' selected="selected"' '' '>' htmlspecialchars$candidate->title '</option>';
  34.                 }
  35.                 
  36.                 echo '</select>';
  37.             else {
  38.                 echo "No s'ha pogut trobar cap zona. És possible que no existeixi.<br />" "\n";
  39.                 echo "Si saps quina zona és, introdueix manualment l'identificador de la zona:<br />\n";
  40.                 echo '<input type="text" name="zone" id="ipt-zone" />' "\n";
  41.             }
  42.         else {
  43.             echo "No s'ha pogut trobar cap zona. Introdueix manualment l'identificador de la zona:";
  44.             echo '<input type="text" name="zone" id="ipt-zone" />' "\n";
  45.         }
  46.         die();
  47.     }
  48. }
  49.  
  50. if!empty$_GET['m') ) {
  51.     $messages[1"Hi ha hagut un error al crear el teu node. Revisa bé les dades introduïdes!";
  52.     
  53.     ifisset($messages[$_GET['m']])) {
  54.         $message $messages[$_GET['m']];
  55.     }
  56. }
  57.  
  58. if!empty$_POST ) ) {
  59.     $username $_POST['username'];
  60.     $password $_POST['password'];
  61.     $title $_POST['title'];
  62.     $zone_id $_POST['zone_id'];
  63.     $lat $_POST['lat'];
  64.     $lon $_POST['lon'];
  65.     
  66.     $gapi new guifiAPI$username$password );
  67.     
  68.     $node $gapi->addNode$title$zone_id$lat$lon );
  69.     if!empty$node->node_id ) ) {
  70.         header"Location: examples.guifi_api.simple_user.step2.php?node_id=$node->node_id");
  71.         die;
  72.     else {
  73.         $message "No s'ha pogut crear el teu node. Revisa bé les dades introduïdes!";
  74.     }
  75. }
  76.  
  77. ?>
  78. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  79. <html>
  80. <head>
  81. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  82. <title>Client PHP per l'API de guifi.net</title>
  83. <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
  84. <link rel="stylesheet" type="text/css" href="style.css" />
  85. </head>
  86. <body>
  87.  
  88. <div id="container">
  89. <div id="content">
  90.  
  91. <h1>Benvingut usuari!</h1>
  92.  
  93. <?php 
  94. if!empty($message)) {
  95.     echo '<div class="alert">';
  96.     echo '<h6>Error</h6>';
  97.     echo $message;
  98.     echo '</div>';
  99. }
  100. ?>
  101.  
  102. <p>A través d'aquest formulari podràs crear el teu node molt fàcilment!</p>
  103.  
  104. <p>Senzillament, vés omplint els senzills camps que se't demanen a
  105. continuació!</p>
  106.  
  107. <form action="examples.guifi_api.simple_user.php" method="post">
  108.  
  109. <fieldset><legend>Autenticació</legend>
  110. <p>Primer de tot, hem de saber quin nom d'usuari i contrasenya tens
  111. registrat a guifi.net</p>
  112.  
  113. <dl>
  114.     <dt><label for="ipt-username">Nom d'usuari:</label></dt>
  115.     <dd><input type="text" name="username" id="ipt-username" /></dd>
  116. </dl>
  117.  
  118. <dl>
  119.     <dt><label for="ipt-password">Contrasenya:</label></dt>
  120.     <dd><input type="password" name="password" id="ipt-password" /></dd>
  121. </dl>
  122. </fieldset>
  123.  
  124. <fieldset><legend>El teu node</legend>
  125. <p>Ara explica'ns un parell de coses sobre el teu node.</p>
  126.  
  127. <dl>
  128.     <dt><label>A quin punt del mapa està situat?</label></dt>
  129.     <dd>
  130.     <div id="map" style="width: 70%; height: 400px; margin: 0 auto"></div>
  131.     <input type="hidden" id="ipt-lat" name="lat" /> <input type="hidden"
  132.         id="ipt-lon" name="lon" /></dd>
  133. </dl>
  134.  
  135. <dl>
  136.     <dt><label>A quina zona de guifi.net et trobes?</label></dt>
  137.     <dd id="zone"><em>Primer clica sobre el mapa per saber on està situat
  138.     el node.</em></dd>
  139. </dl>
  140.  
  141. <dl>
  142.     <dt><label for="ipt-title">Quin nom vols donar-li al teu node?</label><br />
  143.     (<small>Per exemple, si vius al carrer Sant Miquel 34, un bon nom seria
  144.     <em><span id="zone-nickname">NomPoblacio</span>StMiquel34</em></small>)</dt>
  145.     <dd><input type="text" name="title" id="ipt-title" /></dd>
  146. </dl>
  147. </fieldset>
  148.  
  149. <h5>Aquí s'acaba el primer pas!</h5>
  150.  
  151. <p>Ara només has d'enviar les dades, i el teu node ja s'haurà creat.</p>
  152.  
  153. <p>A continuació, només et caldrà saber <strong>a quin node et connectes</strong>,
  154. i ja podràs configurar la teva antena!</p>
  155.  
  156. <p class="submit">
  157.     <input type="submit" name="create_node" value="Crea el node" />
  158. </p>
  159.  
  160. </form>
  161.  
  162. </div>
  163. </div>
  164.  
  165. <script
  166.     src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAr3qx5ND13lr9SgNvfMaXFRQfurk9f5l92xDxpL8LRqlGozpssRQ37VNTwe_pc8OOYwLhYa-lhKZg4w"
  167.     type="text/javascript"></script>
  168. <script type="text/javascript">
  169. //<![CDATA[
  170. var supernodes = null;
  171. var map = null;
  172. var baseIcon = null;
  173. var zones = null;
  174. var gmarker = null;
  175. var clickEvent;
  176.  
  177. function load() {
  178.     if (GBrowserIsCompatible()) {
  179.         initMap();
  180.     }
  181. }
  182.  
  183. function initMap() {
  184.     map = new GMap2(document.getElementById("map"));
  185.     map.addControl(new GSmallMapControl());
  186.     map.addControl(new GMapTypeControl());
  187.     map.addMapType(G_PHYSICAL_MAP);
  188.     map.enableScrollWheelZoom();
  189.  
  190.     map.setCenter(new GLatLng(41.583930, 1.619050), 7);
  191.  
  192.     clickEvent = GEvent.addListener(map, "click", function(marker, point) {
  193.         if (gmarker) {
  194.             map.removeOverlay(gmarker);
  195.         }
  196.         gmarker = new GMarker(point);
  197.  
  198.         if (map.getZoom() > 12) {
  199.             map.addOverlay(gmarker);
  200.             $("#ipt-lat").val(point.lat());
  201.             $("#ipt-lon").val(point.lng());
  202.             
  203.             map.setCenter(point);
  204.             loadZone();
  205.         } else {
  206.             map.setCenter(point, map.getZoom() + 3);    
  207.         }
  208.     });
  209. }
  210.  
  211. function loadZone() {
  212.     $('#zone').html('<img src="loader.gif" alt="Carregant..." />');
  213.     var params = {'a':'getZone', 'lat':$("#ipt-lat").val(), 'lon': $("#ipt-lon").val() };
  214.     $.get('examples.guifi_api.simple_user.php', params, function(data) {
  215.             $('#zone').html(data).show();
  216.         } );
  217. }
  218.  
  219. $(document).ready( function() {
  220.     load();
  221. });
  222. $(window).unload( function () {
  223.     GUnload();
  224. });
  225.  
  226. </script>
  227. </body>
  228. </html>

Documentation generated on Sun, 10 Jan 2010 21:02:49 +0100 by phpDocumentor 1.4.3