Ville de la météo modifiable

This commit is contained in:
Chouchen 2010-09-15 21:36:14 +00:00
parent f52b55ed1e
commit e5415117a1
5 changed files with 118 additions and 17 deletions

View File

@ -1,20 +1,22 @@
<?// Escaping the input data:
//TODO automatisation ! Je veux plus de "$config_xml[x]"
$clock = $_POST['clock'];
$meteo = $_POST['meteo'];
$weather = $_POST['weather'];
$notes = $_POST['notes'];
$search = $_POST['search'];
$links = $_POST['links'];
$blogs = $_POST['blogs'];
$todo = $_POST['todo'];
$xmla = simplexml_load_file('../db/config.xml');
$config_xml = $xmla->item;
$config_xml[0]->visibility = $clock;
$config_xml[1]->visibility = $meteo;
$config_xml[1]->visibility = $weather;
$config_xml[2]->visibility = $notes;
$config_xml[3]->visibility = $search;
$config_xml[4]->visibility = $links;
$config_xml[5]->visibility = $blogs;
$config_xml[6]->visibility = $todo;
$xmla->asXML('../db/config.xml');
echo "1";

10
ajax/update-city.php Normal file
View File

@ -0,0 +1,10 @@
<?php
// Error reporting
error_reporting(E_ALL^E_NOTICE);
// Escaping:
$city = $_GET['city'];
include '../class/AccueilModules.php';
echo AccueilModules::updateModule('weather', array('city'=>$city));
?>

View File

@ -1,11 +1,16 @@
<?php
class AccueilModules {
private $persistance = 'db/config.xml';
const CONFIG_FILE = 'db/config.xml';
private $modules = array();
/**
* Constructeur
* Initialise le XML de conf générale
* Active les modules
* Construit le menu
*/
function __construct(){
if($config = simplexml_load_file($this->persistance)){
if($config = simplexml_load_file(self::CONFIG_FILE)){
$config_xml = $config->item;
foreach($config_xml as $item){
$this->modules["$item[id]"] = $item;
@ -17,6 +22,10 @@ class AccueilModules {
}
}
/**
*
* Initialise les modules activés uniquement
*/
function getModules(){
foreach($this->modules as $module=>$moduleConf){
if(file_exists('class/'.ucfirst($module).'.php') && $moduleConf->visibility == "true"){
@ -30,6 +39,10 @@ class AccueilModules {
}
}
/**
*
* Construit et insère le menu de changement de config
*/
function buildConfigMenu(){
echo '<a href="#config" id="config-menu">Configuration</a>
<div style="display:none;">
@ -48,4 +61,16 @@ class AccueilModules {
</div>
</div>';
}
/**
*
* @property Chaque module possède la fonction updateModule en static qui permet de changer un ou plusieurs de ses attributs
* @param $module String Nom du module à modifier
* @param $things2change Array du ou des attributs à modifier avec sa ou ses nouvelles valeurs
* @return "ok" String si c'est bon, ou le message d'erreur
*/
public static function updateModule($module, $things2change){
require ucfirst($module).'.php';
return call_user_func(array($module, "updateConfig"), $things2change);
}
}

View File

@ -1,9 +1,15 @@
<?php
class weather {
private $params = array();
//TODO rajouter les params en détail
public static $params = array(
'visibility',
'city',
'x',
'y'
);
public function __construct($params){
$this->setParams($params);
//$this->setParams($params);
$city = $params['city'];
include 'GoogleMeteo.php';
echo '<script type="text/javascript" src="js/jquery.weather.js"></script>
@ -16,11 +22,44 @@ class weather {
</div>';
}
private function setParams($params){
private static function setParams($params){
$this->params = $params;
}
public static function start($params){
$weather = new weather($params);
}
public static function updateConfig($updated){
foreach ($updated as $what=>$withWhat){
if(in_array($what, self::$params)){
switch($what){
case 'city':
self::setCity($withWhat);
break;
default:
break;
}
}
}
}
/**
*
* Modifie la ville
* @param String $city la ville.
* @return String "ok" ou message d'erreur (effectue aussi l'enregistrement en XML)
*/
public function setCity($city){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='weather']");
$path[0]->city = $city;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
}

View File

@ -1,4 +1,29 @@
$(document).ready(function(){
$('body').append('<a href="#city" id="city-menu">Weather City Choice</a><div style="display:none;"><div id="city"></div></div>');
$('#city').append('<h3>Quelle ville pour la météo ?</h3><br/><input type="text" id="cityChoice" name="cityChoice"/><span id="city-submit" class="green-button">Enregistrer</span>');
$('#city-menu').fancybox({
'zoomSpeedIn' : 600,
'zoomSpeedOut' : 500,
'easingIn' : 'easeOutBack',
'easingOut' : 'easeInBack',
'hideOnContentClick': false,
'padding' : 15
});
$('#city-submit').live('click', function(){
var ville = $('#cityChoice').val();
if(ville != '' || ville != null){
$.get('ajax/update-city.php', {city: ville}, function(msg){
if(msg=='ok'){
location.reload();
}else{
$('#city').append('<span class="error">An error occured while changing city.</span>');
}
});
}else{
$('#city').append('<span class="error">City can\'t be empty.</span>');
}
});
var tmp;
/* A helper function for converting a set of elements to draggables: */