2012-06-14 16:33:16 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* meta
|
|
|
|
*
|
|
|
|
* Hierarchial data tool
|
|
|
|
*
|
|
|
|
* @package meta
|
|
|
|
* @author Timothy J. Warren
|
|
|
|
* @copyright Copyright (c) 2012
|
|
|
|
* @link https://github.com/aviat4ion/meta
|
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Section Controller
|
2012-08-22 21:28:54 -04:00
|
|
|
*
|
|
|
|
* @package meta
|
2012-06-14 16:33:16 -04:00
|
|
|
*/
|
2015-06-04 15:46:30 -04:00
|
|
|
class section extends \miniMVC\Controller {
|
2012-06-14 16:33:16 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
2012-07-12 10:31:08 -04:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2012-08-22 21:28:54 -04:00
|
|
|
/**
|
|
|
|
* Default controller method
|
|
|
|
*/
|
2015-06-04 14:30:42 -04:00
|
|
|
public function detail($id=0)
|
2012-07-12 10:31:08 -04:00
|
|
|
{
|
2012-08-31 16:18:23 -04:00
|
|
|
if ($id === 0)
|
|
|
|
{
|
|
|
|
$id = (int) miniMVC\get_last_segment();
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array(
|
2012-09-12 10:36:43 -04:00
|
|
|
'section' => $this->data_model->get_section_by_id($id),
|
|
|
|
'sdata' => $this->data_model->get_data($id),
|
|
|
|
'p' => $this->data_model->get_path_by_section($id),
|
2012-08-31 16:18:23 -04:00
|
|
|
'section_id' => $id
|
|
|
|
);
|
|
|
|
|
2015-06-04 16:25:47 -04:00
|
|
|
if (empty($data['section']))
|
|
|
|
{
|
|
|
|
$this->page->render_message('error', "Section doesn't exist.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-04 14:30:42 -04:00
|
|
|
$this->render('section_detail', $data);
|
2012-07-12 10:31:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-09-05 11:46:51 -04:00
|
|
|
* Adds a data item to the current section
|
2012-07-12 10:31:08 -04:00
|
|
|
*/
|
2012-09-05 11:46:51 -04:00
|
|
|
public function add_data()
|
2012-06-14 16:33:16 -04:00
|
|
|
{
|
2012-09-05 11:46:51 -04:00
|
|
|
$section_id = (int) $_POST['section_id'];
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-08-22 21:28:54 -04:00
|
|
|
|
2012-09-05 11:46:51 -04:00
|
|
|
$keys = filter_var_array($_POST['name'], FILTER_SANITIZE_STRING);
|
2012-09-10 11:45:39 -04:00
|
|
|
|
|
|
|
// Raw to allow use of HTML formatting
|
|
|
|
// Prepared statements keep the database safe here.
|
|
|
|
$vals = $_POST['val'];
|
2012-09-05 11:46:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
$data = array_combine($keys, $vals);
|
|
|
|
|
2012-09-12 10:36:43 -04:00
|
|
|
$res = $this->data_model->add_data($section_id, $data);
|
2012-09-05 11:46:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
($res)
|
|
|
|
? $this->page->set_message('success', 'Added data')
|
|
|
|
: $this->page->set_message('error', 'Data already exists');
|
2012-08-22 21:28:54 -04:00
|
|
|
|
2015-06-04 14:30:42 -04:00
|
|
|
$this->detail($section_id);
|
2012-08-22 21:28:54 -04:00
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// End of section.php
|