weathermap |
Subversion Repositories: |
Rev 1 | Rev 13 | |
---|---|---|
Line 2... | Line 2... | |
$use_jquery = FALSE; |
$use_jquery = FALSE; | |
|
| |
require_once 'editor-config.php'; |
||
require_once 'editor.inc.php'; |
require_once 'editor.inc.php'; | |
require_once 'Weathermap.class.php'; |
require_once 'Weathermap.class.php'; | |
|
| |
chdir(dirname(__FILE__)); |
// sensible defaults | |
$mapdir='configs'; | ||
$cacti_base = '../../'; | ||
$cacti_url = '/'; | ||
$ignore_cacti=FALSE; | ||
| ||
$config_loaded = @include_once 'editor-config.php'; | ||
| ||
if( is_dir($cacti_base) && file_exists($cacti_base."/include/config.php") ) | ||
{ | ||
// include the cacti-config, so we know about the database | ||
include_once($cacti_base."/include/config.php"); | ||
| ||
// CHANGE: this to be the URL of the base of your Cacti install | ||
// it MUST end with a / character! | ||
$config['base_url']=$cacti_url; | ||
$cacti_found=TRUE; | ||
} | ||
else | ||
{ | ||
$cacti_found = FALSE; | ||
} | ||
| ||
chdir(dirname(__FILE__)); | ||
|
| |
$action = ''; |
$action = ''; | |
$mapname = ''; |
$mapname = ''; | |
$selected = ''; |
$selected = ''; | |
|
| |
Line 47... | Line 69... | |
case 'newmap': |
case 'newmap': | |
$map->WriteConfig($mapfile); |
$map->WriteConfig($mapfile); | |
break; |
break; | |
|
| |
case 'font_samples': |
case 'font_samples': | |
$map->ReadConfig($mapfile); | ||
ksort($map->fonts); | ||
header('Content-type: image/png'); |
header('Content-type: image/png'); | |
|
| |
$im = imagecreate(250,imagefontheight(5)+5); |
$keyfont = 2; | |
$keyheight = imagefontheight($keyfont)+2; | ||
| ||
$sampleheight = 32; | ||
// $im = imagecreate(250,imagefontheight(5)+5); | ||
$im = imagecreate(2000,$sampleheight); | ||
$imkey = imagecreate(2000,$keyheight); | ||
|
| |
$white = imagecolorallocate($im,255,255,255); |
$white = imagecolorallocate($im,255,255,255); | |
$black = imagecolorallocate($im,0,0,0); |
$black = imagecolorallocate($im,0,0,0); | |
$whitekey = imagecolorallocate($imkey,255,255,255); | ||
$blackkey = imagecolorallocate($imkey,0,0,0); | ||
|
| |
$x = 3; |
$x = 3; | |
for($i=1; $i< 6; $i++) |
#for($i=1; $i< 6; $i++) | |
foreach ($map->fonts as $fontnumber => $font) | ||
{ |
{ | |
imagestring($im, $i, $x, 2, "Font $i", $black); |
$string = "Abc123%"; | |
$x = $x + imagefontwidth($i)*7; |
$keystring = "Font $fontnumber"; | |
list($width,$height) = $map->myimagestringsize($fontnumber,$string); | ||
list($kwidth,$kheight) = $map->myimagestringsize($keyfont,$keystring); | ||
| ||
if($kwidth > $width) $width = $kwidth; | ||
| ||
$y = ($sampleheight/2) + $height/2; | ||
$map->myimagestring($im, $fontnumber, $x, $y, $string, $black); | ||
$map->myimagestring($imkey, $keyfont,$x,$keyheight,"Font $fontnumber",$blackkey); | ||
| ||
$x = $x + $width + 6; | ||
} |
} | |
imagepng($im); |
$im2 = imagecreate($x,$sampleheight + $keyheight); | |
imagecopy($im2,$im, 0,0, 0,0, $x, $sampleheight); | ||
imagecopy($im2,$imkey, 0,$sampleheight, 0,0, $x, $keyheight); | ||
imagedestroy($im); |
imagedestroy($im); | |
imagepng($im2); | ||
imagedestroy($im2); | ||
|
| |
exit(); |
exit(); | |
break; |
break; | |
case 'draw': |
case 'draw': | |
header('Content-type: image/png'); |
header('Content-type: image/png'); | |
Line 224... | Line 271... | |
else |
else | |
{ |
{ | |
$map->background = stripslashes($_REQUEST['map_bgfile']); |
$map->background = stripslashes($_REQUEST['map_bgfile']); | |
} |
} | |
|
| |
$oldlinkwidth = $map->defaultlink->width; |
| |
$newlinkwidth = intval($_REQUEST['map_linkdefaultwidth']); |
$inheritables = array( | |
$map->defaultlink->width = $newlinkwidth; |
array('link','width','map_linkdefaultwidth'), | |
// find all the links that have the old default width, and change them to the new default width |
); | |
// this is something that has bugged me for a while |
| |
foreach ($map->links as $link) |
handle_inheritance($map, $inheritables); | |
| ||
$bwin = $_REQUEST['map_linkdefaultbwin']; | ||
$bwout = $_REQUEST['map_linkdefaultbwout']; | ||
| ||
$bwin_old = $map->defaultlink->max_bandwidth_in_cfg; | ||
$bwout_old = $map->defaultlink->max_bandwidth_out_cfg; | ||
| ||
if( ($bwin_old != $bwin) || ($bwout_old != $bwout) ) | ||
{ |
{ | |
if($link->width == $oldlinkwidth) |
$map->defaultlink->SetBandwidth($bwin,$bwout); | |
foreach ($map->links as $link) | ||
{ |
{ | |
$map->links[$link->name]->width = $newlinkwidth; |
if( ($link->max_bandwidth_in_cfg == $bwin_old) || ($link->max_bandwidth_out_cfg == $bwout_old) ) | |
{ | ||
$link->SetBandwidth($bwin,$bwout); | ||
} | ||
} |
} | |
} |
} | |
|
| |
$bwin = $_REQUEST['map_linkdefaultbwin']; |
| |
$bwout = $_REQUEST['map_linkdefaultbwout']; |
||
|
||
$map->defaultlink->SetBandwidth($bwin,$bwout); |
||
|
| |
$map->WriteConfig($mapfile); |
$map->WriteConfig($mapfile); | |
break; |
break; | |
|
| |
case 'set_map_style': |
case 'set_map_style': | |
$map->ReadConfig($mapfile); |
$map->ReadConfig($mapfile); | |
|
| |
$map->defaultlink->labelstyle = $_REQUEST['mapstyle_linklabels']; |
||
$map->htmlstyle = $_REQUEST['mapstyle_htmlstyle']; |
$map->htmlstyle = $_REQUEST['mapstyle_htmlstyle']; | |
$map->defaultlink->arrowstyle = $_REQUEST['mapstyle_arrowstyle']; |
||
|
||
$map->defaultlink->bwfont = intval($_REQUEST['mapstyle_linkfont']); |
||
$map->defaultnode->labelfont = intval($_REQUEST['mapstyle_nodefont']); |
||
$map->keyfont = intval($_REQUEST['mapstyle_legendfont']); |
$map->keyfont = intval($_REQUEST['mapstyle_legendfont']); | |
|
| |
$inheritables = array( | ||
array('link','labelstyle','mapstyle_linklabels'), | ||
array('link','bwfont','mapstyle_linkfont'), | ||
array('link','arrowstyle','mapstyle_arrowstyle'), | ||
array('node','labelfont','mapstyle_nodefont') | ||
); | ||
| ||
handle_inheritance($map, $inheritables); | ||
| ||
$map->WriteConfig($mapfile); |
$map->WriteConfig($mapfile); | |
break; |
break; | |
|
| |
case "add_link": |
case "add_link": | |
$map->ReadConfig($mapfile); |
$map->ReadConfig($mapfile); | |
Line 327... | Line 387... | |
$x = intval($_REQUEST['x']); |
$x = intval($_REQUEST['x']); | |
$y = intval($_REQUEST['y']); |
$y = intval($_REQUEST['y']); | |
$node_name = $_REQUEST['node_name']; |
$node_name = $_REQUEST['node_name']; | |
|
| |
$map->ReadConfig($mapfile); |
$map->ReadConfig($mapfile); | |
| ||
if(1==1) | ||
{ | ||
// This is a complicated bit. Find out if this node is involved in any | ||
// links that have VIAs. If it is, we want to rotate those VIA points | ||
// about the *other* node in the link | ||
foreach ($map->links as $link) | ||
{ | ||
if( (count($link->vialist)>0) && (($link->a->name == $node_name) || ($link->b->name == $node_name)) ) | ||
{ | ||
// get the other node from us | ||
if($link->a->name == $node_name) $pivot = $link->b; | ||
if($link->b->name == $node_name) $pivot = $link->a; | ||
| ||
if( ($link->a->name == $node_name) && ($link->b->name == $node_name) ) | ||
{ | ||
// this is a wierd special case, but it is possible | ||
# $log .= "Special case for node1->node1 links\n"; | ||
$dx = $link->a->x - $x; | ||
$dy = $link->a->y - $y; | ||
| ||
for($i=0; $i<count($link->vialist); $i++) | ||
{ | ||
$link->vialist[$i][0] = $link->vialist[$i][0]-$dx; | ||
$link->vialist[$i][1] = $link->vialist[$i][1]-$dy; | ||
} | ||
} | ||
else | ||
{ | ||
$pivx = $pivot->x; | ||
$pivy = $pivot->y; | ||
| ||
$dx_old = $pivx - $map->nodes[$node_name]->x; | ||
$dy_old = $pivy - $map->nodes[$node_name]->y; | ||
$dx_new = $pivx - $x; | ||
$dy_new = $pivy - $y; | ||
$l_old = sqrt($dx_old*$dx_old + $dy_old*$dy_old); | ||
$l_new = sqrt($dx_new*$dx_new + $dy_new*$dy_new); | ||
| ||
$angle_old = rad2deg(atan2(-$dy_old,$dx_old)); | ||
$angle_new = rad2deg(atan2(-$dy_new,$dx_new)); | ||
| ||
# $log .= "$pivx,$pivy\n$dx_old $dy_old $l_old => $angle_old\n"; | ||
# $log .= "$dx_new $dy_new $l_new => $angle_new\n"; | ||
| ||
// the geometry stuff uses a different point format, helpfully | ||
$points = array(); | ||
foreach($link->vialist as $via) | ||
{ | ||
$points[] = $via[0]; | ||
$points[] = $via[1]; | ||
} | ||
| ||
$scalefactor = $l_new/$l_old; | ||
# $log .= "Scale by $scalefactor along link-line"; | ||
| ||
// rotate so that link is along the axis | ||
RotateAboutPoint($points,$pivx, $pivy, deg2rad($angle_old)); | ||
// do the scaling in here | ||
for($i=0; $i<(count($points)/2); $i++) | ||
{ | ||
$basex = ($points[$i*2] - $pivx) * $scalefactor + $pivx; | ||
$points[$i*2] = $basex; | ||
} | ||
// rotate back so that link is along the new direction | ||
RotateAboutPoint($points,$pivx, $pivy, deg2rad(-$angle_new)); | ||
| ||
// now put the modified points back into the vialist again | ||
$v = 0; $i = 0; | ||
foreach($points as $p) | ||
{ | ||
$link->vialist[$v][$i]=$p; | ||
$i++; | ||
if($i==2) { $i=0; $v++;} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
| |
$map->nodes[$node_name]->x = $x; |
$map->nodes[$node_name]->x = $x; | |
$map->nodes[$node_name]->y = $y; |
$map->nodes[$node_name]->y = $y; | |
|
| |
$map->WriteConfig($mapfile); |
$map->WriteConfig($mapfile); | |
Line 401... | Line 540... | |
$imageurl .= '&selected='.$selected; |
$imageurl .= '&selected='.$selected; | |
} |
} | |
|
| |
$imageurl .= '&unique='.time(); |
$imageurl .= '&unique='.time(); | |
|
| |
$imlist = get_imagelist("images") |
$imlist = get_imagelist("images"); | |
| ||
$fontlist = array(); | ||
| ||
|
| |
?> |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> | |
<head> |
<head> | |
Line 414... | Line 556... | |
// if the cacti config was included properly, then |
// if the cacti config was included properly, then | |
// this will be non-empty, and we can unhide the cacti links in the Link Properties box |
// this will be non-empty, and we can unhide the cacti links in the Link Properties box | |
if( ! isset($config['cacti_version']) ) |
if( ! isset($config['cacti_version']) ) | |
{ |
{ | |
echo " .cactilink { display: none; }\n"; |
echo " .cactilink { display: none; }\n"; | |
echo " .cactinode { display: none; }\n"; | ||
} |
} | |
?> |
?> | |
</style> |
</style> | |
<link rel="stylesheet" type="text/css" media="screen" href="editor.css" /> |
<link rel="stylesheet" type="text/css" media="screen" href="editor.css" /> | |
<script src="editor.js" type="text/javascript"></script> |
<script src="editor.js" type="text/javascript"></script> | |
<?php |
<?php | |
if($use_jquery) |
if($use_jquery) | |
{ |
{ | |
?> |
?> | |
<script src="lib/javascript/jquery-latest.pack.js" type="text/javascript"></script> |
<script src="lib/javascript/jquery-latest.pack.js" type="text/javascript"></script> | |
<script src="lib/javascript/jquery.shortkeys.js" type="text/javascript"></script> | ||
<script src="lib/javascript/jquery.contextmenu.packed.js" type="text/javascript"></script> |
<script src="lib/javascript/jquery.contextmenu.packed.js" type="text/javascript"></script> | |
<?php |
<?php | |
} |
} | |
?> |
?> | |
<script type="text/javascript"> |
<script type="text/javascript"> | |
Line 444... | Line 588... | |
$imlist[]=$im; |
$imlist[]=$im; | |
} |
} | |
} |
} | |
|
| |
sort($imlist); |
sort($imlist); | |
|
||
if(1==0) |
||
{ |
||
$out = ""; |
||
$out .= 'var mapimages = ['; |
||
|
||
foreach ($imlist as $im) |
||
{ |
||
$out .= js_escape($im); |
||
$out .= ","; |
||
} |
||
$out = rtrim($out,', '); |
||
$out .= "];\n"; |
||
print $out; |
||
} |
||
|
||
|
| |
if($use_jquery) |
if($use_jquery) | |
{ |
{ | |
?> |
?> | |
$(document).ready(function(){ |
$(document).ready(function(){ | |
Line 484... | Line 612... | |
|
| |
}); |
}); | |
<?php |
<?php | |
} |
} | |
?> |
?> | |
|
||
|
||
</script> |
</script> | |
<title>PHP Weathermap Editor <?php echo $WEATHERMAP_VERSION; ?></title> |
<title>PHP Weathermap Editor <?php echo $WEATHERMAP_VERSION; ?></title> | |
</head> |
</head> | |
|
| |
<body id="mainview"> |
<body id="mainview"> | |
Line 520... | Line 646... | |
<span><label for="action">action</label><input type="text" id="action" name="action" value="<?php echo $newaction ?>" /></span> |
<span><label for="action">action</label><input type="text" id="action" name="action" value="<?php echo $newaction ?>" /></span> | |
<span><label for="param">param</label><input type="text" name="param" id="param" value="" /></span> |
<span><label for="param">param</label><input type="text" name="param" id="param" value="" /></span> | |
<span><label for="param2">param2</label><input type="text" name="param2" id="param2" value="<?php echo $param2 ?>" /></span> |
<span><label for="param2">param2</label><input type="text" name="param2" id="param2" value="<?php echo $param2 ?>" /></span> | |
<span><label for="debug">debug</label><input id="debug" value="" name="debug" /></span> |
<span><label for="debug">debug</label><input id="debug" value="" name="debug" /></span> | |
<a target="configwindow" href="?action=show_config&mapname=<?php echo $mapname ?>">See config</a></p> |
<a target="configwindow" href="?action=show_config&mapname=<?php echo $mapname ?>">See config</a></p> | |
<?php echo $log ?> |
<pre><?php echo $log ?></pre> | |
</div> |
</div> | |
<map name="weathermap_imap"> |
<map name="weathermap_imap"> | |
<?php |
<?php | |
// we need to draw and throw away a map, to get the |
// we need to draw and throw away a map, to get the | |
// dimensions for the imagemap. Oh well. |
// dimensions for the imagemap. Oh well. | |
Line 564... | Line 690... | |
<th>Info URL</th> |
<th>Info URL</th> | |
<td><input id="node_infourl" name="node_infourl" type="text" /></td> |
<td><input id="node_infourl" name="node_infourl" type="text" /></td> | |
</tr> |
</tr> | |
<tr> |
<tr> | |
<th>'Hover' Graph URL</th> |
<th>'Hover' Graph URL</th> | |
<td><input id="node_hover" name="node_hover" type="text" />[Pick from |
<td><input id="node_hover" name="node_hover" type="text" /> | |
Cacti] (not yet)</td> |
<span class="cactinode"><a id="node_cactipick">[Pick from Cacti]</a></span></td> | |
</tr> |
</tr> | |
<tr> |
<tr> | |
<th>Icon Filename</th> |
<th>Icon Filename</th> | |
<td><select id="node_iconfilename" name="node_iconfilename"> |
<td><select id="node_iconfilename" name="node_iconfilename"> | |
|
| |
Line 804... | Line 930... | |
<option <?php echo ($map->defaultlink->arrowstyle=='compact' ? 'selected' : '') ?> value="compact">Compact</option> |
<option <?php echo ($map->defaultlink->arrowstyle=='compact' ? 'selected' : '') ?> value="compact">Compact</option> | |
</select></td> |
</select></td> | |
</tr> |
</tr> | |
<tr> |
<tr> | |
<th>Node Font</th> |
<th>Node Font</th> | |
<td><select name="mapstyle_nodefont"><?php |
<td><?php echo get_fontlist($map,'mapstyle_nodefont',$map->defaultnode->labelfont); ?></td> | |
for($i=1; $i<6; $i++) |
||
{ |
||
print '<option '; |
||
if($map->defaultnode->labelfont == $i) { print "selected "; } |
||
print 'value="'.$i.'">'.$i.'</option>'; |
||
} |
||
foreach ($map->fonts as $n => $font) |
||
{ |
||
print '<option '; |
||
if($map->defaultnode->labelfont == $n) { print " selected "; } |
||
print 'value="'.$n.'">'.$n.'</option>'; |
||
} |
||
?></select></td> |
||
</tr> |
</tr> | |
<tr> |
<tr> | |
<th>Link Label Font</th> |
<th>Link Label Font</th> | |
<td><select name="mapstyle_linkfont"><?php |
<td><?php echo get_fontlist($map,'mapstyle_linkfont',$map->defaultlink->bwfont); ?></td> | |
for($i=1; $i<6; $i++) |
||
{ |
||
print '<option '; |
||
if($map->defaultlink->bwfont==$i) { print "selected "; } |
||
print 'value="'.$i.'">'.$i.'</option>'; |
||
} |
||
foreach ($map->fonts as $n => $font) |
||
{ |
||
print '<option '; |
||
if($map->defaultlink->bwfont == $n) { print " selected "; } |
||
print 'value="'.$n.'">'.$n.'</option>'; |
||
} |
||
?></select></td> |
||
</tr> |
</tr> | |
<tr> |
<tr> | |
<th>Legend Font</th> |
<th>Legend Font</th> | |
<td><select name="mapstyle_legendfont"><?php |
<td><?php echo get_fontlist($map,'mapstyle_legendfont',$map->keyfont); ?></td> | |
for($i=1; $i<6; $i++) |
||
{ |
||
print '<option '; |
||
if($map->keyfont==$i) { print "selected "; } |
||
print 'value="'.$i.'">'.$i.'</option>'; |
||
} |
||
foreach ($map->fonts as $n => $font) |
||
{ |
||
print '<option '; |
||
if($map->keyfont == $n) { print " selected "; } |
||
print 'value="'.$n.'">'.$n.'</option>'; |
||
} |
||
?></select></td> |
||
</tr> |
</tr> | |
<tr> |
<tr> | |
<th>Font Samples:</th> |
<th>Font Samples:</th> | |
<td><img src="?action=font_samples&mapname=<?php echo $mapname?>" /><br />(Drawn using your PHP install)</td> |
<td><div class="fontsamples" ><img src="?action=font_samples&mapname=<?php echo $mapname?>" /></div><br />(Drawn using your PHP install)</td> | |
</tr> |
</tr> | |
</table> |
</table> | |
</div> |
</div> | |
|
| |
<div class="dlgHelp" id="mapstyle_help"> |
<div class="dlgHelp" id="mapstyle_help"> |