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

Source for file examples.guifi_api.simple_user.step2.php

Documentation is available at examples.guifi_api.simple_user.step2.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['node_id') ) {
  20.     $node_id $_GET['node_id'];
  21. }
  22.  
  23. ifempty$node_id ) ) {
  24.     header"Location: examples.guifi_api.simple_user.php?m=1" );
  25. }
  26.  
  27. if$_POST {
  28.     $username $_POST['username'];
  29.     $password $_POST['password'];
  30.     $to_radio explode':'$_POST['radio_to');
  31.     $to_device_id $to_radio[0];
  32.     $to_radiodev_counter $to_radio[1];
  33.     
  34.     $gapi new guifiAPI$username$password );
  35.     
  36.     /**
  37.      * CREATE THE DEVICE
  38.      */
  39.     $type 'radio';
  40.     $mac $_POST['mac'];
  41.  
  42.     $device array();
  43.     $device['model_id'25// NanoStation2
  44.     $device['firmware'"AirOsv30";
  45.     
  46.     $added $gapi->addDevice($node_id$type$mac$device);
  47.     
  48.     if$added {
  49.         $device_id $added->device_id;
  50.  
  51.         $added $gapi->addRadio'client'$device_id );
  52.         if$added {
  53.             $from_radiodev_counter $added->radiodev_counter;
  54.             
  55.             $added $gapi->addLink$device_id$from_radiodev_counter$to_device_id$to_radiodev_counter );
  56.             if$added {
  57.                 header"Location: examples.guifi_api.simple_user.step3.php?node_id=$node_id&device_id=$device_id);
  58.                 die;
  59.             else {
  60.                 $message "No s'ha pogut afegir l'enllaç, error de l'API: ";
  61.                 $message .= $gapi->getErrorsStr();
  62.             }
  63.         else {
  64.             $message "No s'ha pogut afegir la ràdio, error de l'API: ";
  65.             $message .= $gapi->getErrorsStr();
  66.         }
  67.         
  68.     else {
  69.         $message "No s'ha pogut afegir el dispositiu, error de l'API: ";
  70.         $message .= $gapi->getErrorsStr();
  71.     }
  72. }
  73.  
  74. $nearest $gapi->nearestRadio$node_id );
  75. if$nearest {
  76.     if$nearest->radios {
  77.         $radios $nearest->radios;
  78.         
  79.         $radio_select '<select name="radio_to">'"\n";
  80.         
  81.         foreach$radios as $radio {
  82.             $radio_select .= '<option value="'.$radio->device_id ':' $radio->radiodev_counter '">';
  83.             $radio_select .= "$radio->ssid ($radio->distance km)";
  84.             $radio_select .= "</option>\n";
  85.         }
  86.         
  87.         $radio_select .= "</select>\n";
  88.         
  89.     else {
  90.         $radio_select "No s'han pogut trobar ràdios aprop, segurament no tinguis cap node guifi.net aprop on et puguis connectar :(";
  91.     }
  92. else {
  93.     $radio_select "No s'han pogut trobar ràdios, error de l'API: ";
  94.     $radio_select .= $gapi->getErrorsStr();
  95. }
  96.  
  97. ?>
  98. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  99. <html>
  100. <head>
  101. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  102. <title>Client PHP per l'API de guifi.net</title>
  103. <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
  104. <link rel="stylesheet" type="text/css" href="style.css" />
  105. </head>
  106. <body>
  107.  
  108. <div id="container">
  109. <div id="content">
  110. <h1>Molt bé!</h1>
  111.  
  112. <?php 
  113. if!empty($message)) {
  114.     echo '<div class="alert">';
  115.     echo '<h6>Error</h6>';
  116.     echo $message;
  117.     echo '</div>';
  118. }
  119. ?>
  120.  
  121. <p>Has aconseguit crear el teu node. El podràs veure a la pàgina
  122. següent:</p>
  123. <p><a href="http://guifi.net/node/<?php
  124. echo $node_id?>">http://guifi.net/node/<?php
  125. echo $node_id?></a></p>
  126.  
  127. <p>Ara només et queda un petit pas per acabar de configurar la teva
  128. antena: escollir allà on et connectes!</p>
  129.  
  130. <form action="examples.guifi_api.simple_user.step2.php?node_id=<?php echo $node_id ?>" method="post">
  131.  
  132. <fieldset><legend>Autenticació</legend>
  133. <p>Primer de tot, hem de saber quin nom d'usuari i contrasenya tens
  134. registrat a guifi.net</p>
  135.  
  136. <dl>
  137.     <dt><label for="ipt-username">Nom d'usuari:</label></dt>
  138.     <dd><input type="text" name="username" id="ipt-username" /></dd>
  139. </dl>
  140.  
  141. <dl>
  142.     <dt><label for="ipt-password">Contrasenya:</label></dt>
  143.     <dd><input type="password" name="password" id="ipt-password" /></dd>
  144. </dl>
  145. </fieldset>
  146.  
  147. <fieldset><legend>La teva antena</legend>
  148. <p>Necessitem saber només una cosa de la teva antena: la seva adreça MAC.</p>
  149.  
  150. <dl>
  151.     <dt><label for="ipt-mac">Adreça MAC:</label></dt>
  152.     <dd><input type="text" name="mac" id="ipt-mac" /></dd>
  153. </dl>
  154.  
  155. </fieldset>
  156.  
  157. <fieldset><legend>El node on et connectes</legend>
  158. <p>Hem escollit per tu un seguit de nodes on és possible que et puguis
  159. connectar, fins a 50.</p>
  160.  
  161. <p>Si no trobes el teu en aquesta llista, és difícil que et puguis
  162. connectar a cap altre node.</p>
  163.  
  164. <p>Selecciona el nom del node on et connectes:</p>
  165.  
  166. <dl>
  167.     <dt><label for="ipt-node">Node on et connectes:</label></dt>
  168.     <dd><?php
  169.     echo $radio_select?></dd>
  170. </dl>
  171.  
  172. </fieldset>
  173.  
  174. <h5>Aquí s'acaba el segon pas!</h5>
  175.  
  176. <p>Ara només has d'enviar les dades, i es crearà un enllaç cap el node
  177. que has seleccionat.</p>
  178.  
  179. <p>A continuació, només et caldrà <strong>configurar la teva antena</strong>,
  180. i ja estaràs connectat a guifi.net!</p>
  181.  
  182. <p class="submit"><input type="submit" name="create_link"
  183.     value="Crea l'enllaç" /></p>
  184.  
  185. </form>
  186.  
  187. </div>
  188. </div>
  189. </body>
  190. </html>

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