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

Source for file examples.guifi_api.zone.php

Documentation is available at examples.guifi_api.zone.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. /**
  18.  * Code from here!
  19.  */
  20. $gapi new guifiAPI$username$password );
  21.  
  22. $action $_GET['action'];
  23.  
  24. switch$action {
  25.     case 'add':
  26.         // All possible parameters to add a zone
  27.         $title "Sant Jaume de Frontanyà"// Nom de la zona
  28.         $master 4176// Zona pare
  29.         $min_lat '42.183122730364815'// Latitud de l'escaire SO de la zona
  30.         $min_lon '2.0180511474609375'// Longitud de l'escaire SO de la zona
  31.         $max_lat '42.19139028706819'// Latitud de l'escaire NE de la zona
  32.         $max_lon '2.0276641845703125'// Longitud de l'escaire NE de la zona
  33.         
  34.  
  35.         $zone array();
  36.         $zone['nick'"StJaumeFrontanyà";
  37.         $zone['zone_mode''infrastructure';
  38.         $zone['body'"Sant Jaume de Frontanyà és un municipi de la comarca del Berguedà.<br /><br />El seu terme és muntanyenc i escassament poblat, amb boscos de pins i pastures per a la ramaderia que juntament amb l'agricultura de cereals i el turisme és la base de la seva economia. Regat per afluents de la reira de Merlès.";
  39.         $zone['graph_server'14428;
  40.         $zone['proxy_server'15903;
  41.         $zone['dns_servers''10.145.2.34,10.145.2.66';
  42.         $zone['ntp_servers''10.145.8.226';
  43.         $zone['ospf_zone'5;
  44.         $zone['homepage''http://www.santjaumedefrontanya.net';
  45.         $zone['notification'"name@example.com";
  46.         
  47.         $added $gapi->addZone$title$master$min_lat$min_lon$max_lat$max_lon$zone );
  48.         if$added {
  49.             echo "Zone created correctly!!<br />\n<br />\nThe identificator of the new zone is: zone_id = <strong>$added->zone_id</strong>";
  50.         else {
  51.             echo "There was an error adding the zone.<br />\n";
  52.             echo $gapi->getErrorsStr();
  53.         }
  54.         break;
  55.     case 'update':
  56.         $zone_id 27181;
  57.         
  58.         $zone array();
  59.         $zone['title'"Sant Jaume de Frontanyà - Autèntic";
  60.         $zone['nick'"StJaumeFrontanyàAutentic";
  61.         $zone['zone_mode''ad-hoc';
  62.         $zone['body'"Sant Jaume de Frontanyà és un municipi de la comarca del Berguedà.<br /><br />El seu terme és muntanyenc i escassament poblat, amb boscos de pins i pastures per a la ramaderia que juntament amb l'agricultura de cereals i el turisme és la base de la seva economia. Regat per afluents de la reira de Merlès. Ara a més a més és ad-hoc";
  63.         $zone['graph_server'""// Get from parents
  64.         $zone['proxy_server'''// Get from parents
  65.         $zone['dns_servers'''// Get from parents
  66.         $zone['ntp_servers'''// Get from parents
  67.         $zone['ospf_zone'0;
  68.         $zone['homepage''http://www.santjaumedefrontanya.net/novaweb';
  69.         
  70.         $updated $gapi->updateZone$zone_id$zone );
  71.         if$updated {
  72.             echo "Zone <strong>$zone_id</strong> was updated correctly.<br />\n<br />\n";
  73.         else {
  74.             echo "There was an error updating the zone.<br />\n";
  75.             echo $gapi->getErrorsStr();
  76.         }
  77.         break;
  78.     case 'delete':
  79.         $zone_id 27181;
  80.         $removed $gapi->removeZone$zone_id );
  81.         if$removed {
  82.             echo "Zone <strong>$zone_id</strong> removed correctly.<br />\n<br />\n";
  83.         else {
  84.             echo "There was an error deleting the zone.<br />\n";
  85.             echo $gapi->getErrorsStr();
  86.         }
  87.         break;
  88.     case 'nearest':
  89.         $lat "41.5787648";
  90.         $lon "1.6171926";
  91.         $nearest $gapi->nearestZone$lat$lon );
  92.         if$nearest {
  93.             if$nearest->nearest {
  94.                 $zone $nearest->nearest;
  95.                 echo "Found nearest zone:<br />\n";
  96.                 echo "&nbsp;&nbsp;Title: <strong>$zone->title</strong><br />\n";
  97.                 echo "&nbsp;&nbsp;Zone ID: <strong>$zone->zone_id</strong><br />\n";
  98.             }
  99.             if$nearest->candidates {
  100.                 $candidates $nearest->candidates;
  101.                 echo "<br />\n";
  102.                 echo "Found candidate zones:\n";
  103.                 echo '<ul>' "\n";
  104.                 foreach$candidates as $zone {
  105.                     echo "<li>\n";
  106.                     echo "&nbsp;&nbsp;Title: <strong>$zone->title</strong><br />\n";
  107.                     echo "&nbsp;&nbsp;Zone ID: <strong>$zone->zone_id</strong>\n";
  108.                     echo "</li>\n";
  109.                 }
  110.                 echo "</ul>\n";
  111.             }
  112.         else {
  113.             echo "There was an error getting the nearest zone.<br />\n";
  114.             echo $gapi->getErrorsStr();
  115.         }
  116.         break;
  117. }
  118.  
  119. ?>

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