Added support for uploading two map images for each section
git-svn-id: https://rosehill.googlecode.com/svn/branches/php@18 100bd78a-fc82-11de-b5bc-ffd2847a4b57
|
@ -44,6 +44,7 @@ echo "
|
|||
<tr><td>$editButton</td>
|
||||
<td>$code</td>
|
||||
<td>$name</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
?>
|
||||
<h1>Update Section</h1>
|
||||
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
|
||||
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" enctype="multipart/form-data">
|
||||
<fieldset><legend>Section Info</legend>
|
||||
<input name="section_id" type="hidden" value="<?php echo $this->section->getId(); ?>" />
|
||||
<table>
|
||||
|
@ -30,4 +30,27 @@
|
|||
Cancel
|
||||
</button>
|
||||
</fieldset>
|
||||
|
||||
<fieldset><legend>Maps</legend>
|
||||
<div>
|
||||
<label for="highlight_map">Highlight Map</lable>
|
||||
<input type="file" name="highlight_map" id="highlight_map" />
|
||||
</div>
|
||||
<?php
|
||||
$highlight = $this->section->getMap('highlight');
|
||||
if ($highlight) {
|
||||
echo "<div><img src=\"$highlight\" /></div>";
|
||||
}
|
||||
?>
|
||||
<div>
|
||||
<label for="zoom_map">Zoomed Map</lable>
|
||||
<input type="file" name="zoom_map" id="zoom_map" />
|
||||
</div>
|
||||
<?php
|
||||
$zoom = $this->section->getMap('zoom');
|
||||
if ($zoom) {
|
||||
echo "<div><img src=\"$zoom\" /></div>";
|
||||
}
|
||||
?>
|
||||
</fieldset>
|
||||
</form>
|
|
@ -178,7 +178,6 @@ class Cemetery
|
|||
*
|
||||
* Available map types are:
|
||||
* full, thumb - for the main map
|
||||
* highlight, zoom - for the section maps
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
class Interment
|
||||
{
|
||||
private $id;
|
||||
private $section;
|
||||
private $section_id;
|
||||
private $lot;
|
||||
private $book;
|
||||
private $pageNumber;
|
||||
|
@ -23,6 +23,7 @@ class Interment
|
|||
private $notes;
|
||||
private $lot2;
|
||||
|
||||
private $section;
|
||||
private $cemetery;
|
||||
|
||||
/**
|
||||
|
@ -87,7 +88,7 @@ class Interment
|
|||
$this->validate();
|
||||
|
||||
$data = array();
|
||||
$data['section'] = $this->section ? $this->section : null;
|
||||
$data['section_id'] = $this->section_id ? $this->section_id : null;
|
||||
$data['lot'] = $this->lot ? $this->lot : null;
|
||||
$data['book'] = $this->book ? $this->book : null;
|
||||
$data['pageNumber'] = $this->pageNumber ? $this->pageNumber : null;
|
||||
|
@ -137,11 +138,11 @@ class Interment
|
|||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return int
|
||||
*/
|
||||
public function getSection()
|
||||
public function getSection_id()
|
||||
{
|
||||
return $this->section;
|
||||
return $this->section_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -281,16 +282,40 @@ class Interment
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Section
|
||||
*/
|
||||
public function getSection()
|
||||
{
|
||||
if ($this->section_id) {
|
||||
if (!$this->section) {
|
||||
$this->section = new Section($this->section_id);
|
||||
}
|
||||
return $this->section;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
//----------------------------------------------------------------
|
||||
// Generic Setters
|
||||
//----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param int $int
|
||||
*/
|
||||
public function setSection($string)
|
||||
public function setSection_id($int)
|
||||
{
|
||||
$this->section = trim($string);
|
||||
$this->section = new Section($int);
|
||||
$this->section_id = $int;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Section $section
|
||||
*/
|
||||
public function setSection($section)
|
||||
{
|
||||
$this->section_id = $section->getId();
|
||||
$this->section = $section;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -427,7 +452,6 @@ class Interment
|
|||
$this->lot2 = trim($string);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Custom Functions
|
||||
// We recommend adding all your custom code down here at the bottom
|
||||
|
@ -457,20 +481,4 @@ class Interment
|
|||
}
|
||||
return implode(' ',$name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSectionMapURL($section,$type='highlight')
|
||||
{
|
||||
$section = preg_replace('/[^a-z\-]/','',strtolower($section));
|
||||
$type = $type=='highlight' ? 'highlight' : 'zoom';
|
||||
|
||||
$mapDirectory = "images/cemeteries/{$this->cemetery_id}";
|
||||
$filename = "$type/$section.jpg";
|
||||
|
||||
if (file_exists(APPLICATION_HOME."/html/$mapDirectory/$filename")) {
|
||||
return BASE_URL."$mapDirectory/$filename";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2010 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
*/
|
||||
class Map
|
||||
{
|
||||
public static $extensions = array(
|
||||
'jpg'=>array('mime_type'=>'image/jpeg','media_type'=>'image'),
|
||||
'gif'=>array('mime_type'=>'image/gif','media_type'=>'image'),
|
||||
'png'=>array('mime_type'=>'image/png','media_type'=>'image'),
|
||||
'tiff'=>array('mime_type'=>'image/tiff','media_type'=>'image')
|
||||
);
|
||||
|
||||
/**
|
||||
* @param string $directory Where to store the file
|
||||
* @param array|string $file Either an entry from $_FILES or a path to a file
|
||||
* @param int $id The unique ID for the object the map is for
|
||||
*/
|
||||
public static function saveFile($directory,$file,$id)
|
||||
{
|
||||
// Handle passing in either a $_FILES array or just a path to a file
|
||||
$tempFile = is_array($file) ? $file['tmp_name'] : $file;
|
||||
if (!$tempFile) {
|
||||
throw new Exception('media/uploadFailed');
|
||||
}
|
||||
|
||||
# Find out the mime type for this file
|
||||
$filename = is_array($file) ? basename($file['name']) : basename($file);
|
||||
preg_match("/[^.]+$/",$filename,$matches);
|
||||
$extension = strtolower($matches[0]);
|
||||
|
||||
// Make sure it's a known file type
|
||||
if (!array_key_exists(strtolower($extension),self::$extensions)) {
|
||||
throw new Exception('unknownFileType');
|
||||
}
|
||||
|
||||
// Move the file where it's supposed to go
|
||||
if (!is_dir($directory)) {
|
||||
mkdir($directory,0777,true);
|
||||
}
|
||||
$newFile = "$directory/$id.$extension";
|
||||
echo "Saving $newFile\n";
|
||||
rename($tempFile,$newFile);
|
||||
chmod($newFile,0666);
|
||||
|
||||
if (!is_file($newFile)) {
|
||||
echo "$newFile was not saved\n";
|
||||
throw new Exception('media/uploadFailed');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -196,4 +196,41 @@ class Section
|
|||
{
|
||||
return $this->name ? $this->name : $this->code;
|
||||
}
|
||||
|
||||
private function getMapDirectory()
|
||||
{
|
||||
return 'images/cemeteries/'.$this->cemetery_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL to the map image
|
||||
*
|
||||
* @param string $type Either 'highlight' or 'zoom'
|
||||
* @return string
|
||||
*/
|
||||
public function getMap($type='highlight')
|
||||
{
|
||||
$imageDir = $this->getMapDirectory();
|
||||
$type = $type=='highlight' ? 'highlight' : 'zoom';
|
||||
|
||||
$glob = glob(APPLICATION_HOME."/html/$imageDir/$type/{$this->id}.*");
|
||||
if (count($glob)) {
|
||||
$filename = basename($glob[0]);
|
||||
return BASE_URL."/$imageDir/$type/$filename";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $file Either an entry from $_FILES or a path to a file
|
||||
*/
|
||||
public function saveMap($file,$type)
|
||||
{
|
||||
$imageDir = $this->getMapDirectory();
|
||||
$type = $type=='highlight' ? 'highlight' : 'zoom';
|
||||
|
||||
$directory = APPLICATION_HOME."/html/$imageDir/$type";
|
||||
|
||||
echo "Saving $type map to $directory\n";
|
||||
Map::saveFile($directory,$file,$this->id);
|
||||
}
|
||||
}
|
||||
|
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 163 KiB After Width: | Height: | Size: 163 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 161 KiB After Width: | Height: | Size: 161 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
|
@ -18,7 +18,13 @@ $search = array();
|
|||
foreach ($_GET as $field=>$value) {
|
||||
if ($value) {
|
||||
if (false !== strpos($field,'section')) {
|
||||
$search['section'] = $value;
|
||||
try {
|
||||
$section = new Section($value);
|
||||
$search['section_id'] = $section->getId();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// Just ignore any unknown sections
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (in_array($field,$knownFields)) {
|
||||
|
|
|
@ -12,18 +12,29 @@ if (!userIsAllowed('Sections')) {
|
|||
}
|
||||
|
||||
$section = new Section($_REQUEST['section_id']);
|
||||
if (isset($_POST['section'])) {
|
||||
if (isset($_POST['section_id'])) {
|
||||
$section->setCode($_POST['code']);
|
||||
$section->setName($_POST['name']);
|
||||
|
||||
try {
|
||||
$section->save();
|
||||
header('Location: '.$section->getCemetery()->getURL());
|
||||
if (isset($_FILES)) {
|
||||
echo "Found files\n";
|
||||
print_r($_FILES);
|
||||
if (isset($_FILES['highlight_map']) && $_FILES['highlight_map']['tmp_name']) {
|
||||
$section->saveMap($_FILES['highlight_map'],'highlight');
|
||||
}
|
||||
if (isset($_FILES['zoom_map']) && $_FILES['zoom_map']['tmp_name']) {
|
||||
$section->saveMap($_FILES['zoom_map'],'zoom');
|
||||
}
|
||||
}
|
||||
#header('Location: '.$section->getCemetery()->getURL());
|
||||
exit();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$_SESSION['errorMessages'][] = $e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$template = new Template();
|
||||
|
|