<?
/*
CL CMS
Version: 1.0
Author: David Boardman
URL: http://www.netzfunk.org/?usr=d
Licenced under Creative Commons Attribution-NonCommercial-ShareAlike 2.5
If redistributed in any form, please include credits and a link to http://www.netzfunk.org/?usr=d
*/
include("inc/config.php");
require_once("cls/cls.clCms.php");
$cl=new clCms($config);
$cl->connectDB();
// ELENCO CONTESTI
$q="SELECT * FROM context ORDER BY titolo ASC;";
$r=mysql_query($q,$cl->lid);
$contlist="";
while($l=mysql_fetch_array($r)){
$contlist.="<li><strong>".$l['titolo']."</strong><br /><a href=\"?task=showcont&d=".$l['id']."\">Mostra</a> :: <a href=\"?task=modcont&c=".$l['id']."\">Modifica</a> :: <a href=\"?task=deletecont&d=".$l['id']."\">Cancella</a></li>";
}
// ELENCO POI
$q="SELECT * FROM poi ORDER BY titolo ASC;";
$r=mysql_query($q,$cl->lid);
$poilist="";
while($l=mysql_fetch_array($r)){
$poilist.="<li><strong>".$l['titolo']."</strong><br/><a href=\"".$config['poifolder']."/".$l['link']."\">Mostra</a> :: <a href=\"?task=&d=".$l['id']."\">Modifica</a> :: <a href=\"?task=deletepoi&d=".$l['id']."\">Cancella</a></li>";
}
if(!empty($_GET['d'])){ // se è selezionato un poi
$qd="SELECT * FROM poi WHERE id='".$_GET['d']."';";
$rd=mysql_query($qd,$cl->lid);
$ld=mysql_fetch_array($rd);
}
if(!empty($_GET['c'])){ // Se è selezionato un contesto
$qc="SELECT * FROM context WHERE id='".$_GET['c']."';";
$rc=mysql_query($qc,$cl->lid);
$lc=mysql_fetch_array($rc);
}
?>
<html>
<head>
<title><?=$config['sitename']?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
switch($_GET['task']){
case "deletecont":
?>
<p align="center">Sei sicuro di voler cancellare questo contesto?<br/><br/>
<a href="?task=deletecontconfirm&d=<?=$_GET['d']?>">SI</a> | <a href="?task=">NO</a></p>
<?
break;
case "deletecontconfirm":
$q="DELETE FROM context WHERE id='".$_GET['d']."';";
mysql_query($q,$cl->lid);
echo $cl->goMain();
break;
case "deletepoi":
?>
<p align="center">Sei sicuro di voler cancellare questo POI?<br/><br/>
<a href="?task=deletepoiconfirm&d=<?=$_GET['d']?>">SI</a> | <a href="?task=">NO</a></p>
<?
break;
case "deletepoiconfirm":
$q="DELETE FROM poi WHERE id='".$_GET['d']."';";
mysql_query($q,$cl->lid);
echo $cl->goMain();
break;
case "showcont":
$q="SELECT * FROM context WHERE id='".$_GET['d']."';";
$r=mysql_query($q,$cl->lid);
$l=mysql_fetch_array($r);
echo "<h1>".strtoupper($l['titolo'])." [id:".$l['id']."]</h1>".$l['descr']."";
break;
case "addcontext":
if(empty($_POST['id'])){ // se è inserimento
if(($_POST['titolo']!="") && ($_POST['descr']!="")){
$checkData=$cl->checkContext($cl->cleanStr($_POST['titolo']));
echo "CHECK $checkData";
if($checkData == 0) $qc="INSERT INTO context (id,titolo,descr) VALUES ('','".$_POST['titolo']."','".$_POST['descr']."');";
else exit("<p> </p><p align='center'>Esiste già un contesto con titolo <strong>".$cl->cleanStr($_POST['titolo'])."</strong><br/><br/><a href='javascript:history.back()'>Torna indietro</a></p>");
}
}
else{ // se è modifica
$qc="UPDATE context SET titolo='".$cl->cleanStr($_POST['titolo'])."',descr='".$cl->cleanStr($_POST['descr'])."' WHERE id='".$_POST['id']."';";
}
mysql_query($qc,$cl->lid);
echo $cl->goMain();
break;
case "addpoi":
if(($_POST['lat0']!="")&&($_POST['lat1']!="")&&($_POST['lon0']!="")&&($_POST['lon1']!="")&&($_POST['ew']!="")&&($_POST['ns']!="")&&($_POST['contesto']!="")){
$lat0=$cl->pointCoord($_POST['lat0']);
$lat1=$cl->pointCoord($_POST['lat1']);
$lon0=$cl->pointCoord($_POST['lon0']);
$lon1=$cl->pointCoord($_POST['lon1']);
$calc_x=doubleval(($lon0 - $lon1) * ($lon0 - $lon1));
$calc_y=doubleval(($lat0 - $lat1) * ($lat0 - $lat1));
$tot=doubleval($calc_x + $calc_y);
$r=doubleval(sqrt($tot));
if(($r<=0)||($r>1)) exit("<p align='center'>R ".$r." non corretto<br/><br/><a href='javascript:history.back()'>Torna indietro</a></p>");
}
//echo $cl->goMain();
if(empty($_POST['id'])){
$checkData=$cl->checkPOI($cl->cleanStr($_POST['titolo']),$r);
if(($checkData['raggio']==0) && ($checkData['titolo']==0)){
$q="INSERT INTO poi (id,titolo,descr,lat0,ns,lon0,ew,lat1,lon1,raggio,link,luogo) VALUES ('','".$cl->cleanStr($_POST['titolo'])."','".$cl->cleanStr($_POST['desc'])."','".$lat0."','".$_POST['ns']."','".$lon0."','".$_POST['ew']."','".$lat1."','".$lon1."','".$r."','".$cl->checkLink($_POST['link'])."','".$_POST['contesto']."');";
$cl->createHTML($cl->checkLink($_POST['link']),$cl->config['sitename']." :: ".$cl->cleanStr($_POST['titolo']),$cl->cleanStr($_POST['desc']),"LAT0: $lat0".$_POST['ns']." - LON0: $lon0".$_POST['ew']." - LAT1: $lat1".$_POST['ns']." - LON1: $lon1".$_POST['ew']." - R: $r",$meta,$style,$script);
}
else{
if($checkData['raggio'] > 0) exit("<p> </p><p align='center'>Esiste già un POI con r <strong>$r</strong><br/><br/><a href='javascript:history.back()'>Torna indietro</a></p>");
if($checkData['titolo'] > 0) exit("<p> </p><p align='center'>Esiste già un POI con titolo <strong>".$cl->cleanStr($_POST['titolo'])."</strong><br/><br/><a href='javascript:history.back()'>Torna indietro</a></p>");
}
}
else{
if(!empty($r)) $q="UPDATE poi SET titolo='".$cl->cleanStr($_POST['titolo'])."',descr='".$cl->cleanStr($_POST['desc'])."',lat0='".$lat0."',ns='".$_POST['ns']."',lon0='".$lon0."',ew='".$_POST['ew']."',lat1='".$lat1."',lon1='".$lon1."',raggio='".$r."',link='".$cl->checkLink($_POST['link'])."',luogo='".$_POST['contesto']."' WHERE id='".$_POST['id']."';";
else $q="UPDATE poi SET titolo='".$cl->cleanStr($_POST['titolo'])."',descr='".$cl->cleanStr($_POST['desc']).",link='".$cl->checkLink($_POST['link'])."'luogo='".$_POST['contesto']."' WHERE id='".$_POST['id']."';";
}
mysql_query($q,$cl->lid);
//echo $cl->goMain();
break;
default:
break;
}
?>
<table width="100%" border="0" cellspacing="6" cellpadding="6">
<tr valign="top">
<td width="50%"><table width="90%" border="0" align="center" cellpadding="4" cellspacing="4">
<tr>
<td> <h3>ELENCO CONTESTI</h3>
<p><a href="?task=">Nuovo contesto</a></p>
<?
if($contlist!="") echo "<ol>$contlist</ol>";
else echo "<strong>Nessun contesto presente</strong>";
?>
</td>
</tr>
</table>
<form action="?task=addcontext" method="post" name="addcontext" id="addcontext">
<table width="90%" border="0" align="center" cellpadding="4" cellspacing="4">
<tr align="left">
<td colspan="2"> <h3>INSERIMENTO CONTESTO</h3></td>
</tr>
<tr valign="middle">
<td width="24%" align="right"><strong>Titolo</strong></td>
<td width="76%"> <input type="text" size="20" name="titolo" value="<?=$lc['titolo']?>"/></td>
</tr>
<tr valign="middle">
<td align="right"><strong>Descrizione</strong></td>
<td> <textarea name="descr" cols="20" rows="10" id="descr"><?=$lc['descr']?></textarea></td>
</tr>
<tr>
<td> </td>
<td align="right" valign="top"><br /> <input type="hidden" name="id" id="id" value="<?=$lc['id']?>" />
<input type="submit" value="»" />
</td>
</tr>
</table>
</form>
</td>
<td><table width="90%" border="0" align="center" cellpadding="4" cellspacing="4">
<tr>
<td> <h3>ELENCO POI</h3>
<p><a href="?task=">Nuovo poi</a></p>
<?
if($poilist!="") echo "<ol>$poilist</ol>";
else echo "<strong>Nessun POI presente</strong>";
?>
</td>
</tr>
</table>
<form action="?task=addpoi" method="post" name="addpoi" id="addpoi">
<table width="90%" border="0" align="center" cellpadding="4" cellspacing="4">
<tr align="left">
<td colspan="2"> <h3>INSERIMENTO POI</h3></td>
</tr>
<tr valign="middle">
<td width="24%" align="right"><strong>Titolo</strong></td>
<td width="76%"> <input type="text" size="20" name="titolo" value="<?=$ld['titolo']?>"
<?
if(empty($_POST['id'])){
echo " onBlur=\"document.addpoi.link.value=this.value;\";";
}
?>
/>
</td>
</tr>
<tr valign="middle">
<td align="right"><strong>Descrizione</strong></td>
<td> <textarea name="desc" cols="20" rows="10" id="desc"><?=$ld['descr']?></textarea></td>
</tr>
<tr valign="middle">
<td align="right"><strong>Lat0</strong><br /> </td>
<td> <input name="lat0" type="text" id="lat0" value="<?=$ld['lat0']?>" size="20"/>
<select name="ns" id="ns">
<optgroup label="---Latitudine---">
<option value="N" <?=$cl->checkOrient($ld['ns'],'n');?>>Nord</option>
<option value="S" <?=$cl->checkOrient($ld['ns'],'s');?>>Sud</option>
</optgroup>
</select></td>
</tr>
<tr valign="middle">
<td align="right"><strong>Lon0</strong><span></span></td>
<td> <input name="lon0" type="text" id="lon0" value="<?=$ld['lon0']?>" size="20"/>
<select name="ew" id="ew">
<optgroup label="---Longitudine---">
<option value="W" <?=$cl->checkOrient($ld['ew'],'w');?>>Ovest</option>
<option value="E" <?=$cl->checkOrient($ld['ew'],'e');?>>Est</option>
</optgroup>
</select></td>
</tr>
<tr valign="middle">
<td align="right"><strong>Lat1</strong><span></span></td>
<td> <input name="lat1" type="text" id="lat1" value="<?=$ld['lat1']?>" size="20" /></td>
</tr>
<tr valign="middle">
<td align="right"><strong>Lon1</strong><span></span></td>
<td> <input name="lon1" type="text" id="lon1" value="<?=$ld['lon1']?>" size="20" /></td>
</tr>
<?
if(!empty($_GET['d'])){
?>
<tr valign="middle">
<td align="right"><strong>Raggio</strong></td>
<td> <input type="text" disabled id="raggio" name="raggio" value="<?=$ld['raggio']?>" size="20"/></td>
</tr>
<?
}
?>
<tr valign="middle">
<td align="right"> <p><strong>Link</strong><br />
</p></td>
<td> <input type="text" size="20" name="link" value="<?=$ld['link']?>"/>.htm</td>
</tr>
<tr valign="middle">
<td align="right"><strong>Contesto</strong></td>
<td><select name="contesto" id="contesto">
<optgroup label="---Contesto---">
<option value=""></option>
<?=$cl->optContext($ld['luogo'])?>
</optgroup>
</select></td>
</tr>
<tr>
<td> </td>
<td align="right" valign="top"><br /> <input type="hidden" name="id" id="id" value="<?=$ld['id']?>" />
<input type="submit" value="»" />
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?
$cl->closeDB();
?>
</body>
</html>
|