diff --git a/app/classes/controller.php b/app/classes/controller.php index deb07b9..3de2d2f 100644 --- a/app/classes/controller.php +++ b/app/classes/controller.php @@ -28,7 +28,8 @@ abstract class Controller extends \miniMVC\Controller { public function __construct() { parent::__construct(); - $this->load_model('meta\Model'); + $this->load_model('meta\model'); + $this->load_model('meta\user_model'); $this->page->build_header(); } diff --git a/app/config/config.php b/app/config/config.php index 0eb3e60..fc291f4 100644 --- a/app/config/config.php +++ b/app/config/config.php @@ -107,7 +107,7 @@ define('DEFAULT_TITLE', "meta"); | Default css group |-------------------------------------------------------------------------- | -| Default css group +| Default css group to show if none explicity chose | */ define('DEFAULT_CSS_GROUP', "css"); @@ -117,9 +117,21 @@ define('DEFAULT_CSS_GROUP', "css"); | Default js group |-------------------------------------------------------------------------- | -| Default js group +| Default js group to show if none explicitly chosen | */ define('DEFAULT_JS_GROUP', "js"); +/* +|-------------------------------------------------------------------------- +| Debug backtrace +|-------------------------------------------------------------------------- +| +| Whether or not to show a backtrace for php errors +| +| Must be defined as TRUE for the backtrace to display. +| +*/ +define('SHOW_DEBUG_BACKTRACE', TRUE); + // End of config.php \ No newline at end of file diff --git a/app/config/routes.php b/app/config/routes.php index f3f1476..3c052e5 100644 --- a/app/config/routes.php +++ b/app/config/routes.php @@ -38,6 +38,9 @@ return array( 'category' => 'meta/category/index', 'category/add' => 'meta/category/add', 'category/detail' => 'meta/category/detail', + 'section' => 'meta/section/index', + 'section/add' => 'meta/section/add', + 'section/detail' => 'meta/section/detail', '404_route' => '', ); diff --git a/app/modules/meta/controllers/section.php b/app/modules/meta/controllers/section.php index 01c375a..e2a1daf 100644 --- a/app/modules/meta/controllers/section.php +++ b/app/modules/meta/controllers/section.php @@ -15,6 +15,8 @@ /** * Section Controller + * + * @package meta */ class section extends meta\controller { @@ -26,18 +28,63 @@ class section extends meta\controller { parent::__construct(); } + /** + * Default controller method + */ public function index() { - + $this->detail(); } /** - * Adds a new section to the current category + * Adds a new category */ public function add() { + // Strip away tags for the sake of security + $name = strip_tags($_POST['section']); + $id = (int) $_POST['category_id']; + // Make sure the name doesn't already exist. If it does, show an error. + $res = $this->model->add_section($name, $id); + + if ($res === TRUE) + { + $this->page->set_message('success', 'Added new section'); + } + else + { + $this->page->set_message('error', 'Section already exists for this category'); + } + + // Render the basic page + $this->detail(-1); } + + /** + * Returns the sections / editing options for a category + */ + public function detail($id = 0) + { + if ($id === 0) + { + $id = (int) miniMVC\get_last_segment(); + } + + if ($id === 0) + { + miniMVC\show_404(); + } + + $data = array( + 'section' => $this->model->get_section_by_id($id), + 'data' => $this->model->get_data($id), + 'section_id' => $id + ); + + $this->load_view('section_detail', $data); + } + } // End of section.php \ No newline at end of file diff --git a/app/modules/meta/controllers/welcome.php b/app/modules/meta/controllers/welcome.php index 069f9ef..07f0460 100644 --- a/app/modules/meta/controllers/welcome.php +++ b/app/modules/meta/controllers/welcome.php @@ -18,7 +18,7 @@ * * @package meta */ -class welcome extends \miniMVC\Controller { +class welcome extends \meta\controller { /** * Initialize the constructor @@ -28,10 +28,6 @@ class welcome extends \miniMVC\Controller { public function __construct() { parent::__construct(); - - $this->load_model('meta\model'); - $this->load_model('meta\user_model'); - } // -------------------------------------------------------------------------- @@ -56,7 +52,18 @@ class welcome extends \miniMVC\Controller { */ public function login() { - + $this->page->render('login'); + } + + // -------------------------------------------------------------------------- + + /** + * Display an outline of the data for a table of contents + */ + public function outline() + { + $outline_data = $this->model->get_outline_data(); + $this->page->render('outline', array('outline' => $outline_data)); } } diff --git a/app/modules/meta/models/model.php b/app/modules/meta/models/model.php index 8ef9b59..16ac208 100644 --- a/app/modules/meta/models/model.php +++ b/app/modules/meta/models/model.php @@ -20,7 +20,7 @@ namespace meta; * * @package meta */ -class Model extends \miniMVC\Model { +class model extends \miniMVC\Model { /** * Reference to database connection @@ -43,7 +43,7 @@ class Model extends \miniMVC\Model { { parent::__construct(); - //$this->session =& \miniMVC\Session::get_instance(); + $this->session =& \miniMVC\Session::get_instance(); $this->db =& \miniMVC\db::get_instance(); } @@ -405,6 +405,77 @@ class Model extends \miniMVC\Model { return $data; } + + // -------------------------------------------------------------------------- + + /** + * Get data for a full outline + * + * @return array + */ + public function get_outline_data() + { + // Get the genres + $g_query = $this->db->from('genre') + ->get(); + + $genres = array(); + + while ($row = $g_query->fetch(\PDO::FETCH_ASSOC)) + { + $genres[$row['id']] = $row['genre']; + } + + // Get the categories + $c_query = $this->db->from('category') + ->get(); + + $categories = array(); + + while($row = $c_query->fetch(\PDO::FETCH_ASSOC)) + { + $categories[$row['genre_id']][$row['id']] = $row['category']; + } + + // Get the sections + $s_query = $this->db->from('section') + ->get(); + + $sections = array(); + + while($row = $s_query->fetch(\PDO::FETCH_ASSOC)) + { + $sections[$row['category_id']][$row['id']] = $row['section']; + } + + + // Organize into a nested array + foreach($genres as $genre_id => $genre) + { + $return[$genre_id][$genre] = array(); + $g =& $return[$genre_id][$genre]; + + // Categories for this genre + if (isset($categories[$genre_id])) + { + $g = $categories[$genre_id]; + + foreach($categories[$genre_id] as $category_id => $category) + { + $g[$category_id] = array($category => array()); + $c =& $g[$category_id][$category]; + + // Sections for this category + if (isset($sections[$category_id])) + { + $c = $sections[$category_id]; + } + } + } + } + + return $return; + } } diff --git a/app/modules/meta/models/user_model.php b/app/modules/meta/models/user_model.php index 25bdd98..b24c71f 100644 --- a/app/modules/meta/models/user_model.php +++ b/app/modules/meta/models/user_model.php @@ -22,12 +22,26 @@ namespace meta; */ class user_model extends \miniMVC\Model { + /** + * Reference to database connection + * + * @var Query_Builder + */ + protected $db; + /** * Reference to bcrypt object * * @var Bcrypt */ protected $bcrypt; + + /** + * Reference to session + * + * @var Session + */ + protected $session; /** * Initialize the User model @@ -37,8 +51,24 @@ class user_model extends \miniMVC\Model { parent::__construct(); $this->bcrypt = new \Bcrypt(15); + $this->db =& \miniMVC\db::get_instance(); + $this->session =& \miniMVC\Session::get_instance(); } + // -------------------------------------------------------------------------- + + /** + * Add a user for access + * + * @param string + * @param string + * @param string + */ + public function add_user($username, $pass1, $pass2) + { + + } + // -------------------------------------------------------------------------- /** diff --git a/app/modules/meta/views/category_detail.php b/app/modules/meta/views/category_detail.php index e298b1e..0ecdb9a 100644 --- a/app/modules/meta/views/category_detail.php +++ b/app/modules/meta/views/category_detail.php @@ -1,4 +1,3 @@ -

meta

Category Sections

diff --git a/app/modules/meta/views/genre_detail.php b/app/modules/meta/views/genre_detail.php index dd13578..f3a261d 100644 --- a/app/modules/meta/views/genre_detail.php +++ b/app/modules/meta/views/genre_detail.php @@ -1,4 +1,3 @@ -

meta

Genre Categories

diff --git a/app/modules/meta/views/genres.php b/app/modules/meta/views/genres.php index e20191b..0f59f9e 100644 --- a/app/modules/meta/views/genres.php +++ b/app/modules/meta/views/genres.php @@ -1,4 +1,3 @@ -

Meta

Genres

*/ ?> diff --git a/app/views/header.php b/app/views/header.php index 4bb3b22..d5467ce 100644 --- a/app/views/header.php +++ b/app/views/header.php @@ -8,4 +8,5 @@ -> \ No newline at end of file +> +

Meta

\ No newline at end of file diff --git a/sys/core/Page.php b/sys/core/Page.php index 7dbaa77..55eb562 100644 --- a/sys/core/Page.php +++ b/sys/core/Page.php @@ -133,6 +133,11 @@ class Page { */ public function __destruct() { + if (headers_sent()) + { + die(); + } + if ( ! empty($this->headers)) { // Set headers @@ -151,7 +156,7 @@ class Page { if ( ! empty($this->buffer)) { - ob_start('ob_gzhandler'); + //ob_start('ob_gzhandler'); echo $this->buffer;