Permalink
Browse files

Added Sub Folders

  • Loading branch information...
1 parent dd75332 commit 888226cd0258a5a417d06d3c535fe55b6caa1e15 @ritec committed Dec 25, 2012
View
BIN includes/.DS_Store
Binary file not shown.
View
15 includes/connection.php
@@ -0,0 +1,15 @@
+<?php
+require("constants.php");
+
+// 1. Create a database connection
+$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
+if (!$connection) {
+ die("Database connection failed: " . mysql_error());
+}
+
+// 2. Select a database to use
+$db_select = mysql_select_db(DB_NAME,$connection);
+if (!$db_select) {
+ die("Database selection failed: " . mysql_error());
+}
+?>
View
9 includes/constants.php
@@ -0,0 +1,9 @@
+<?php
+
+// Database Constants
+define("DB_SERVER", "localhost");
+define("DB_USER", "root");
+define("DB_PASS", "OtlPHP07");
+define("DB_NAME", "widget_corp");
+
+?>
View
8 includes/footer.php
@@ -0,0 +1,8 @@
+ </div>
+ <div id="footer">Copyright 2007, Widget Corp</div>
+ </body>
+</html>
+<?php
+ // 5. Close connection
+ mysql_close($connection);
+?>
View
29 includes/form_functions.php
@@ -0,0 +1,29 @@
+<?php
+function check_required_fields($required_array) {
+ $field_errors = array();
+ foreach($required_array as $fieldname) {
+ if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && !is_numeric($_POST[$fieldname]))) {
+ $field_errors[] = $fieldname;
+ }
+ }
+ return $field_errors;
+}
+
+function check_max_field_lengths($field_length_array) {
+ $field_errors = array();
+ foreach($field_length_array as $fieldname => $maxlength ) {
+ if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $field_errors[] = $fieldname; }
+ }
+ return $field_errors;
+}
+
+function display_errors($error_array) {
+ echo "<p class=\"errors\">";
+ echo "Please review the following fields:<br />";
+ foreach($error_array as $error) {
+ echo " - " . $error . "<br />";
+ }
+ echo "</p>";
+}
+
+?>
View
163 includes/functions.php
@@ -0,0 +1,163 @@
+<?php
+ // This file is the place to store all basic functions
+
+ function mysql_prep( $value ) {
+ $magic_quotes_active = get_magic_quotes_gpc();
+ $new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
+ if( $new_enough_php ) { // PHP v4.3.0 or higher
+ // undo any magic quote effects so mysql_real_escape_string can do the work
+ if( $magic_quotes_active ) { $value = stripslashes( $value ); }
+ $value = mysql_real_escape_string( $value );
+ } else { // before PHP v4.3.0
+ // if magic quotes aren't already on then add slashes manually
+ if( !$magic_quotes_active ) { $value = addslashes( $value ); }
+ // if magic quotes are active, then the slashes already exist
+ }
+ return $value;
+ }
+
+ function redirect_to( $location = NULL ) {
+ if ($location != NULL) {
+ header("Location: {$location}");
+ exit;
+ }
+ }
+
+ function confirm_query($result_set) {
+ if (!$result_set) {
+ die("Database query failed: " . mysql_error());
+ }
+ }
+
+ function get_all_subjects($public = true) {
+ global $connection;
+ $query = "SELECT *
+ FROM subjects ";
+ if ($public) {
+ $query .= "WHERE visible = 1 ";
+ }
+ $query .= "ORDER BY position ASC";
+ $subject_set = mysql_query($query, $connection);
+ confirm_query($subject_set);
+ return $subject_set;
+ }
+
+ function get_pages_for_subject($subject_id, $public = true) {
+ global $connection;
+ $query = "SELECT *
+ FROM pages ";
+ $query .= "WHERE subject_id = {$subject_id} ";
+ if ($public) {
+ $query .= "AND visible = 1 ";
+ }
+ $query .= "ORDER BY position ASC";
+ $page_set = mysql_query($query, $connection);
+ confirm_query($page_set);
+ return $page_set;
+ }
+
+ function get_subject_by_id($subject_id) {
+ global $connection;
+ $query = "SELECT * ";
+ $query .= "FROM subjects ";
+ $query .= "WHERE id=" . $subject_id ." ";
+ $query .= "LIMIT 1";
+ $result_set = mysql_query($query, $connection);
+ confirm_query($result_set);
+ // REMEMBER:
+ // if no rows are returned, fetch_array will return false
+ if ($subject = mysql_fetch_array($result_set)) {
+ return $subject;
+ } else {
+ return NULL;
+ }
+ }
+
+ function get_page_by_id($page_id) {
+ global $connection;
+ $query = "SELECT * ";
+ $query .= "FROM pages ";
+ $query .= "WHERE id=" . $page_id ." ";
+ $query .= "LIMIT 1";
+ $result_set = mysql_query($query, $connection);
+ confirm_query($result_set);
+ // REMEMBER:
+ // if no rows are returned, fetch_array will return false
+ if ($page = mysql_fetch_array($result_set)) {
+ return $page;
+ } else {
+ return NULL;
+ }
+ }
+
+ function get_default_page($subject_id) {
+ // Get all visible pages
+ $page_set = get_pages_for_subject($subject_id, true);
+ if ($first_page = mysql_fetch_array($page_set)) {
+ return $first_page;
+ } else {
+ return NULL;
+ }
+ }
+
+ function find_selected_page() {
+ global $sel_subject;
+ global $sel_page;
+ if (isset($_GET['subj'])) {
+ $sel_subject = get_subject_by_id($_GET['subj']);
+ $sel_page = get_default_page($sel_subject['id']);
+ } elseif (isset($_GET['page'])) {
+ $sel_subject = NULL;
+ $sel_page = get_page_by_id($_GET['page']);
+ } else {
+ $sel_subject = NULL;
+ $sel_page = NULL;
+ }
+ }
+
+ function navigation($sel_subject, $sel_page, $public = false) {
+ $output = "<ul class=\"subjects\">";
+ $subject_set = get_all_subjects($public);
+ while ($subject = mysql_fetch_array($subject_set)) {
+ $output .= "<li";
+ if ($subject["id"] == $sel_subject['id']) { $output .= " class=\"selected\""; }
+ $output .= "><a href=\"edit_subject.php?subj=" . urlencode($subject["id"]) .
+ "\">{$subject["menu_name"]}</a></li>";
+ $page_set = get_pages_for_subject($subject["id"], $public);
+ $output .= "<ul class=\"pages\">";
+ while ($page = mysql_fetch_array($page_set)) {
+ $output .= "<li";
+ if ($page["id"] == $sel_page['id']) { $output .= " class=\"selected\""; }
+ $output .= "><a href=\"content.php?page=" . urlencode($page["id"]) .
+ "\">{$page["menu_name"]}</a></li>";
+ }
+ $output .= "</ul>";
+ }
+ $output .= "</ul>";
+ return $output;
+ }
+
+ function public_navigation($sel_subject, $sel_page, $public = true) {
+ $output = "<ul class=\"subjects\">";
+ $subject_set = get_all_subjects($public);
+ while ($subject = mysql_fetch_array($subject_set)) {
+ $output .= "<li";
+ if ($subject["id"] == $sel_subject['id']) { $output .= " class=\"selected\""; }
+ $output .= "><a href=\"index.php?subj=" . urlencode($subject["id"]) .
+ "\">{$subject["menu_name"]}</a></li>";
+ if ($subject["id"] == $sel_subject['id']) {
+ $page_set = get_pages_for_subject($subject["id"], $public);
+ $output .= "<ul class=\"pages\">";
+ while ($page = mysql_fetch_array($page_set)) {
+ $output .= "<li";
+ if ($page["id"] == $sel_page['id']) { $output .= " class=\"selected\""; }
+ $output .= "><a href=\"index.php?page=" . urlencode($page["id"]) .
+ "\">{$page["menu_name"]}</a></li>";
+ }
+ $output .= "</ul>";
+ }
+ }
+ $output .= "</ul>";
+ return $output;
+ }
+?>
View
10 includes/header.php
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>Widget Corp</title>
+ <link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" />
+ </head>
+ <body>
+ <div id="header">
+ <h1>Widget Corp</h1>
+ </div>
+ <div id="main">
View
13 includes/session.php
@@ -0,0 +1,13 @@
+<?php
+ session_start();
+
+ function logged_in() {
+ return isset($_SESSION['user_id']);
+ }
+
+ function confirm_logged_in() {
+ if (!logged_in()) {
+ redirect_to("login.php");
+ }
+ }
+?>
View
37 stylesheets/public.css
@@ -0,0 +1,37 @@
+/* Site Colors:
+ #1A446C - blue grey
+ #689DC1 - light blue
+ #D4E6F4 - very light blue
+ #EEE4B9 - light tan
+ #8D0D19 - burgundy
+*/
+
+html { height: 100%; width: 100%; }
+body { width: 100%; height: 100%; margin: 0px; padding: 0px; border: 0px;
+ font-family: Verdana, Arial, Helvetica, sans-serif; background: #D4E6F4;
+ font-size: 13px; line-height: 15px; }
+img { border: none; }
+table, tr, td { border-collapse: collapse; vertical-align: top; font-size: 13px; line-height: 15px;}
+a { color: #8D0D19;}
+
+#header { height: 70px; margin: 0px; padding: 0px; text-align: left;
+ background: #1A446C; color: #D4E6F4; }
+#header h1 { padding: 1em; margin: 0px;}
+#main { margin: 0px; padding: 0px; height: 600px; width: 100%; background: #EEE4B9; }
+#structure { height: 600px; width: 100%; }
+#footer { height: 2em; margin: 0px; padding: 1em; text-align: center;
+ background: #1A446C; color: #D4E6F4; }
+
+/* Navigation */
+#navigation { width: 150px; padding: 1em 2em; color: #D4E6F4; background: #8D0D19; }
+#navigation a { color: #D4E6F4; text-decoration: none; }
+ul.subjects { padding-left: 0; list-style: none; }
+ul.pages { padding-left: 2em; list-style: square; }
+.selected { font-weight: bold; }
+
+/* Page Content */
+#page { padding-left: 2em; vertical-align: top; background: #EEE4B9; }
+#page h2 { color: #8D0D19; margin-top: 1em;}
+#page h3 { color: #8D0D19; }
+
+

0 comments on commit 888226c

Please sign in to comment.