diff --git a/Controllers/SectionsController.php b/Controllers/SectionsController.php
new file mode 100644
index 0000000..dccbfd3
--- /dev/null
+++ b/Controllers/SectionsController.php
@@ -0,0 +1,71 @@
+
+ */
+namespace Application\Controllers;
+use Application\Models\Cemetery;
+use Application\Models\Section;
+use Blossom\Classes\Controller;
+use Blossom\Classes\Block;
+
+class SectionsController extends Controller
+{
+ public function index() { }
+
+ public function update()
+ {
+ if (!empty($_REQUEST['section_id'])) {
+ try {
+ $section = new Section($_REQUEST['section_id']);
+ }
+ catch (\Exception $e) {
+ $_SESSION['errorMessages'][] = $e;
+ }
+ }
+ else {
+ if (!empty($_REQUEST['cemetery_id'])) {
+ try {
+ $section = new Section();
+ $section->setCemetery_id($_REQUEST['cemetery_id']);
+ }
+ catch (\Exception $e) {
+ $_SESSION['errorMessages'][] = $e;
+ }
+ }
+ else {
+ $_SESSION['errorMessages'][] = new \Exception('cemeteries/unknownCemetery');
+ }
+ }
+
+ if (!isset($section)) {
+ header('Location: '.BASE_URL.'/cemeteries');
+ exit();
+ }
+
+ if (isset($_POST['code'])) {
+ try {
+ $section->handleUpdate($_POST);
+ $section->save();
+
+ if (isset($_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: '.BASE_URL.'/cemeteries/view?cemetery_id='.$section->getCemetery_id());
+ exit();
+ }
+ catch (\Exception $e) {
+ $_SESSION['errorMessages'][] = $e;
+ }
+ }
+
+ $this->template->blocks[] = new Block('sections/updateForm.inc', ['section'=>$section]);
+ }
+}
diff --git a/Models/Section.php b/Models/Section.php
new file mode 100644
index 0000000..166d4dc
--- /dev/null
+++ b/Models/Section.php
@@ -0,0 +1,127 @@
+
+ */
+namespace Application\Models;
+use Blossom\Classes\ActiveRecord;
+use Blossom\Classes\Database;
+use Blossom\Classes\ExternalIdentity;
+
+class Section extends ActiveRecord
+{
+ protected $tablename = 'sections';
+
+ protected $cemetery;
+
+ /**
+ * Populates the object with data
+ *
+ * Passing in an associative array of data will populate this object without
+ * hitting the database.
+ *
+ * Passing in a scalar will load the data from the database.
+ * This will load all fields in the table as properties of this class.
+ * You may want to replace this with, or add your own extra, custom loading
+ *
+ * @param int|string|array $id (ID, email, username)
+ */
+ public function __construct($id=null)
+ {
+ if ($id) {
+ if (is_array($id)) {
+ $this->exchangeArray($id);
+ }
+ else {
+ $zend_db = Database::getConnection();
+ $sql = 'select * from sections where id=?';
+ $result = $zend_db->createStatement($sql)->execute([$id]);
+ if (count($result)) {
+ $this->exchangeArray($result->current());
+ }
+ else {
+ throw new \Exception('sections/unknownSection');
+ }
+ }
+ }
+ else {
+ // This is where the code goes to generate a new, empty instance.
+ // Set any default values for properties that need it here
+ }
+ }
+
+ public function validate()
+ {
+ if (!$this->getCemetery_id() || !$this->getCode()) {
+ throw new Excepction('missingRequiredFields');
+ }
+ }
+
+ public function save() { parent::save(); }
+
+ //----------------------------------------------------------------
+ // Generic Getters and Setters
+ //----------------------------------------------------------------
+ public function getId() { return parent::get('id'); }
+ public function getCode() { return parent::get('code'); }
+ public function getName() { return parent::get('name'); }
+ public function getCemetery_id() { return parent::get('cemetery_id'); }
+ public function getCemetery() { return parent::getForeignKeyObject(__namespace__.'\Cemetery', 'cemetery_id'); }
+
+ public function setCode($s) { parent::set('code', $s); }
+ public function setName($s) { parent::set('name', $s); }
+ public function setCemetery_id($i) { parent::setForeignKeyField (__namespace__.'\Cemetery', 'cemetery_id', $i); }
+ public function setCemetery ($o) { parent::setForeignKeyObject(__namespace__.'\Cemetery', 'cemetery_id', $o); }
+
+ public function handleUpdate($post)
+ {
+ $this->setCode($post['code']);
+ $this->setName($post['name']);
+ $this->setCemetery_id($post['cemetery_id']);
+ }
+
+ //----------------------------------------------------------------
+ // Custom Functions
+ //----------------------------------------------------------------
+ public function __toString()
+ {
+ return $this->getName() ? $this->getName() : $this->getCode();
+ }
+
+ private function getMapDirectory()
+ {
+ return 'images/cemeteries/'.$this->getCemetery_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."/public/$imageDir/$type/{$this->getId()}.*");
+ if (count($glob)) {
+ $filename = basename($glob[0]);
+ return BASE_URI."/$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."/public/$imageDir/$type";
+
+ Map::saveFile($directory, $file, $this->getId());
+ }
+}
diff --git a/Models/SectionsTable.php b/Models/SectionsTable.php
new file mode 100644
index 0000000..fc26da0
--- /dev/null
+++ b/Models/SectionsTable.php
@@ -0,0 +1,15 @@
+
+ */
+namespace Application\Models;
+
+use Blossom\Classes\TableGateway;
+use Zend\Db\Sql\Select;
+
+class SectionsTable extends TableGateway
+{
+ public function __construct() { parent::__construct('sections', __namespace__.'\Section'); }
+}
diff --git a/blocks/html/cemeteries/updateForm.inc b/blocks/html/cemeteries/updateForm.inc
index 071bcad..2b49930 100644
--- a/blocks/html/cemeteries/updateForm.inc
+++ b/blocks/html/cemeteries/updateForm.inc
@@ -1,38 +1,38 @@
* @param Cemetery $this->cemetery
*/
+use Blossom\Classes\View;
+
+$name = View::escape($this->cemetery->getName());
+$googleMapURL = View::escape($this->cemetery->getGoogleMapURL());
+
+$title = $this->cemetery->getId() ? $this->translate('edit_cemetery') : $this->translate('add_cemetery');
?>
-
Update Cemetery
-
diff --git a/blocks/html/sections/addSectionForm.inc b/blocks/html/sections/addSectionForm.inc
deleted file mode 100644
index 4649042..0000000
--- a/blocks/html/sections/addSectionForm.inc
+++ /dev/null
@@ -1,42 +0,0 @@
-
- * @param Cemetery $this->cemetery
- */
-?>
-Add Section
-
\ No newline at end of file
diff --git a/blocks/html/sections/updateForm.inc b/blocks/html/sections/updateForm.inc
new file mode 100644
index 0000000..d26c60b
--- /dev/null
+++ b/blocks/html/sections/updateForm.inc
@@ -0,0 +1,58 @@
+
+ * @param Section $this->section
+ */
+use Blossom\Classes\View;
+
+$code = View::escape($this->section->getCode());
+$name = View::escape($this->section->getName());
+
+$title = $this->section->getId() ? $this->translate('edit_section') : $this->translate('add_section');
+?>
+
+
diff --git a/blocks/html/sections/updateSectionForm.inc b/blocks/html/sections/updateSectionForm.inc
deleted file mode 100644
index 731550e..0000000
--- a/blocks/html/sections/updateSectionForm.inc
+++ /dev/null
@@ -1,56 +0,0 @@
-
- * @param Section $this->section
- */
-?>
-Update Section
-
\ No newline at end of file
diff --git a/classes/Section.php b/classes/Section.php
deleted file mode 100644
index f041361..0000000
--- a/classes/Section.php
+++ /dev/null
@@ -1,235 +0,0 @@
-
- */
-class Section
-{
- private $id;
- private $cemetery_id;
- private $code;
- private $name;
-
- private $cemetery;
-
- /**
- * Populates the object with data
- *
- * Passing in an associative array of data will populate this object without
- * hitting the database.
- *
- * Passing in a scalar will load the data from the database.
- * This will load all fields in the table as properties of this class.
- * You may want to replace this with, or add your own extra, custom loading
- *
- * @param int|array $id
- */
- public function __construct($id=null)
- {
- if ($id) {
- if (is_array($id)) {
- $result = $id;
- }
- else {
- $zend_db = Database::getConnection();
- $sql = 'select * from sections where id=?';
- $result = $zend_db->fetchRow($sql,array($id));
- }
-
- if ($result) {
- foreach ($result as $field=>$value) {
- if ($value) {
- $this->$field = $value;
- }
- }
- }
- else {
- throw new Exception('sections/unknownSection');
- }
- }
- else {
- // This is where the code goes to generate a new, empty instance.
- // Set any default values for properties that need it here
- }
- }
-
- /**
- * Throws an exception if anything's wrong
- * @throws Exception $e
- */
- public function validate()
- {
- // Check for required fields here. Throw an exception if anything is missing.
- if (!$this->cemetery_id || !$this->code) {
- throw new Excepction('missingRequiredFields');
- }
- }
-
- /**
- * Saves this record back to the database
- */
- public function save()
- {
- $this->validate();
-
- $data = array();
- $data['cemetery_id'] = $this->cemetery_id;
- $data['code'] = $this->code;
- $data['name'] = $this->name ? $this->name : null;
-
- if ($this->id) {
- $this->update($data);
- }
- else {
- $this->insert($data);
- }
- }
-
- private function update($data)
- {
- $zend_db = Database::getConnection();
- $zend_db->update('sections',$data,"id='{$this->id}'");
- }
-
- private function insert($data)
- {
- $zend_db = Database::getConnection();
- $zend_db->insert('sections',$data);
- $this->id = $zend_db->lastInsertId('sections','id');
- }
-
- //----------------------------------------------------------------
- // Generic Getters
- //----------------------------------------------------------------
-
- /**
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
-
- /**
- * @return int
- */
- public function getCemetery_id()
- {
- return $this->cemetery_id;
- }
-
- /**
- * @return string
- */
- public function getCode()
- {
- return $this->code;
- }
-
- /**
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
-
- /**
- * @return Cemetery
- */
- public function getCemetery()
- {
- if ($this->cemetery_id) {
- if (!$this->cemetery) {
- $this->cemetery = new Cemetery($this->cemetery_id);
- }
- return $this->cemetery;
- }
- return null;
- }
-
- //----------------------------------------------------------------
- // Generic Setters
- //----------------------------------------------------------------
-
- /**
- * @param int $int
- */
- public function setCemetery_id($int)
- {
- $this->cemetery = new Cemetery($int);
- $this->cemetery_id = $int;
- }
-
- /**
- * @param string $string
- */
- public function setCode($string)
- {
- $this->code = trim($string);
- }
-
- /**
- * @param string $string
- */
- public function setName($string)
- {
- $this->name = trim($string);
- }
-
- /**
- * @param Cemetery $cemetery
- */
- public function setCemetery($cemetery)
- {
- $this->cemetery_id = $cemetery->getId();
- $this->cemetery = $cemetery;
- }
-
-
- //----------------------------------------------------------------
- // Custom Functions
- // We recommend adding all your custom code down here at the bottom
- //----------------------------------------------------------------
- public function __toString()
- {
- 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";
-
- Map::saveFile($directory,$file,$this->id);
- }
-}
diff --git a/classes/SectionList.php b/classes/SectionList.php
deleted file mode 100644
index 48968cc..0000000
--- a/classes/SectionList.php
+++ /dev/null
@@ -1,86 +0,0 @@
-
- */
-class SectionList extends ZendDbResultIterator
-{
- /**
- * Creates a basic select statement for the collection.
- *
- * Populates the collection if you pass in $fields
- * Setting itemsPerPage turns on pagination mode
- * In pagination mode, this will only load the results for one page
- *
- * @param array $fields
- * @param int $itemsPerPage Turns on Pagination
- * @param int $currentPage
- */
- public function __construct($fields=null,$itemsPerPage=null,$currentPage=null)
- {
- parent::__construct($itemsPerPage,$currentPage);
- if (is_array($fields)) {
- $this->find($fields);
- }
- }
-
- /**
- * Populates the collection
- *
- * @param array $fields
- * @param string|array $order Multi-column sort should be given as an array
- * @param int $limit
- * @param string|array $groupBy Multi-column group by should be given as an array
- */
- public function find($fields=null,$order='code',$limit=null,$groupBy=null)
- {
- $this->select->from('sections');
-
- // Finding on fields from the sections table is handled here
- if (count($fields)) {
- foreach ($fields as $key=>$value) {
- $this->select->where("$key=?",$value);
- }
- }
-
- // Finding on fields from other tables requires joining those tables.
- // You can handle fields from other tables by adding the joins here
- // If you add more joins you probably want to make sure that the
- // above foreach only handles fields from the sections table.
-
- $this->select->order($order);
- if ($limit) {
- $this->select->limit($limit);
- }
- if ($groupBy) {
- $this->select->group($groupBy);
- }
- $this->populateList();
- }
-
- /**
- * Hydrates all the Section objects from a database result set
- *
- * This is a callback function, called from ZendDbResultIterator. It is
- * called once per row of the result.
- *
- * @param int $key The index of the result row to load
- * @return Section
- */
- protected function loadResult($key)
- {
- return new Section($this->result[$key]);
- }
-}
diff --git a/html/cemeteries/addCemetery.php b/html/cemeteries/addCemetery.php
deleted file mode 100644
index 0936ddd..0000000
--- a/html/cemeteries/addCemetery.php
+++ /dev/null
@@ -1,40 +0,0 @@
-
- */
-if (!userIsAllowed('Cemeteries')) {
- $_SESSION['errorMessages'][] = new Exception('noAccessAllowed');
- header('Location: '.BASE_URL.'/cemeteries');
- exit();
-}
-
-if (isset($_POST['cemetery'])) {
- $cemetery = new Cemetery();
- foreach ($_POST['cemetery'] as $field=>$value) {
- $set = 'set'.ucfirst($field);
- $cemetery->$set($value);
- }
-
- try {
- $cemetery->save();
- if (isset($_FILES)) {
- if (isset($_FILES['map']) && $_FILES['map']['tmp_name']) {
- $cemetery->saveMap($_FILES['map'],'full');
- }
- if (isset($_FILES['thumbnail']) && $_FILES['thumbnail']['tmp_name']) {
- $section->saveMap($_FILES['thumbnail'],'thumbnail');
- }
- }
- header('Location: '.BASE_URL.'/cemeteries');
- exit();
- }
- catch(Exception $e) {
- $_SESSION['errorMessages'][] = $e;
- }
-}
-
-$template = new Template();
-$template->blocks[] = new Block('cemeteries/addCemeteryForm.inc');
-echo $template->render();
\ No newline at end of file
diff --git a/html/cemeteries/home.php b/html/cemeteries/home.php
deleted file mode 100644
index ace4835..0000000
--- a/html/cemeteries/home.php
+++ /dev/null
@@ -1,12 +0,0 @@
-
- */
-$cemeteryList = new CemeteryList();
-$cemeteryList->find();
-
-$template = isset($_GET['format']) ? new Template('default',$_GET['format']) : new Template();
-$template->blocks[] = new Block('cemeteries/cemeteryList.inc',array('cemeteryList'=>$cemeteryList));
-echo $template->render();
\ No newline at end of file
diff --git a/html/cemeteries/updateCemetery.php b/html/cemeteries/updateCemetery.php
deleted file mode 100644
index 7a5b0b4..0000000
--- a/html/cemeteries/updateCemetery.php
+++ /dev/null
@@ -1,40 +0,0 @@
-
- */
-if (!userIsAllowed('Cemeteries')) {
- $_SESSION['errorMessages'][] = new Exception('noAccessAllowed');
- header('Location: '.BASE_URL.'/cemeteries');
- exit();
-}
-
-$cemetery = new Cemetery($_REQUEST['cemetery_id']);
-if (isset($_POST['cemetery'])) {
- foreach ($_POST['cemetery'] as $field=>$value) {
- $set = 'set'.ucfirst($field);
- $cemetery->$set($value);
- }
-
- try {
- $cemetery->save();
- if (isset($_FILES)) {
- if (isset($_FILES['map']) && $_FILES['map']['tmp_name']) {
- $cemetery->saveMap($_FILES['map'],'full');
- }
- if (isset($_FILES['thumbnail']) && $_FILES['thumbnail']['tmp_name']) {
- $section->saveMap($_FILES['thumbnail'],'thumbnail');
- }
- }
- header('Location: '.BASE_URL.'/cemeteries');
- exit();
- }
- catch (Exception $e) {
- $_SESSION['errorMessages'][] = $e;
- }
-}
-
-$template = new Template();
-$template->blocks[] = new Block('cemeteries/updateCemeteryForm.inc',array('cemetery'=>$cemetery));
-echo $template->render();
\ No newline at end of file
diff --git a/html/cemeteries/viewCemetery.php b/html/cemeteries/viewCemetery.php
deleted file mode 100644
index 81c48d0..0000000
--- a/html/cemeteries/viewCemetery.php
+++ /dev/null
@@ -1,26 +0,0 @@
-
- * @param $_GET cemetery_id
- * @param $_GET section (optional)
- */
-try {
- if (!isset($_GET['cemetery_id']) || !$_GET['cemetery_id']) {
- throw new Exception('cemeteries/unknownCemetery');
- }
- $cemetery = new Cemetery($_GET['cemetery_id']);
-}
-catch (Exception $e) {
- $_SESSION['errorMessages'][] = $e;
- header('Location: '.BASE_URL);
- exit();
-}
-
-
-$template = isset($_GET['format'])
- ? new Template('default',$_GET['format'])
- : $template = new Template();
-$template->blocks[] = new Block('cemeteries/cemeteryInfo.inc',array('cemetery'=>$cemetery));
-echo $template->render();
diff --git a/language/en_US.mo b/language/en_US.mo
index 2855536..bfb6b73 100644
Binary files a/language/en_US.mo and b/language/en_US.mo differ
diff --git a/language/en_US.po b/language/en_US.po
index 9709d90..9ce0806 100644
--- a/language/en_US.po
+++ b/language/en_US.po
@@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: uReport 1.9\n"
"Report-Msgid-Bugs-To: dev@bloomington.in.gov\n"
"POT-Creation-Date: 2013-09-20 16:33-0400\n"
-"PO-Revision-Date: 2014-08-18 16:18-0500\n"
+"PO-Revision-Date: 2014-08-19 11:42-0500\n"
"Last-Translator: Cliff Ingham \n"
"Language-Team: City of Bloomington \n"
"MIME-Version: 1.0\n"
@@ -59,6 +59,9 @@ msgstr "Help"
msgid "name"
msgstr "Name"
+msgid "code"
+msgstr "Code"
+
msgid "firstname"
msgstr "First Name"
@@ -120,7 +123,41 @@ msgid_plural "cemeteries"
msgstr[0] "Cemetery"
msgstr[1] "Cemeteries"
+msgid "add_cemetery"
+msgstr "Add Cemetery"
+
+msgid "edit_cemetery"
+msgstr "Edit Cemetery"
+
+msgid "info_cemetery"
+msgstr "Cemetery Info"
+
msgid "deed"
msgid_plural "deeds"
msgstr[0] "Deed"
msgstr[1] "Deeds"
+
+msgid "section"
+msgid_plural "sections"
+msgstr[0] "Section"
+msgstr[1] "Sections"
+
+msgid "add_section"
+msgstr "Add Section"
+
+msgid "edit_section"
+msgstr "Edit Section"
+
+msgid "info_section"
+msgstr "Section Info"
+
+msgid "map"
+msgid_plural "maps"
+msgstr[0] "Map"
+msgstr[1] "Maps"
+
+msgid "map_highlight"
+msgstr "Highlight Map"
+
+msgid "map_zoomed"
+msgstr "Zoomed Map"
diff --git a/templates/html/helpers/SaveAndCancelButtons.php b/templates/html/helpers/SaveAndCancelButtons.php
index 45ffbac..7d63963 100644
--- a/templates/html/helpers/SaveAndCancelButtons.php
+++ b/templates/html/helpers/SaveAndCancelButtons.php
@@ -20,8 +20,8 @@ class SaveAndCancelButtons
public function saveAndCancelButtons($cancelURL)
{
return "
-
- {$this->template->_('labels.cancel')}
+
+ {$this->template->_('cancel')}
";
}
}