"; $FormFile = "forums.form.php"; $TitleText = "Forum"; $OrderBy = "forum_name"; $Sequence = 'N'; // Get forum number if set unset($forum); if (array_key_exists('forum',$_GET)) $forum = $_GET['forum']; if (array_key_exists('forum',$_POST)) $forum = $_POST['forum']; $forum_title = ""; if (isset($forum)) { $query = "select forum_title from forums " . "where school_num = $school_num " . "and record_num = $forum"; $forum_title = " - " . db_getVal($query); } // Get topic number if set unset($topic); if (array_key_exists('topic',$_GET)) $topic = $_GET['topic']; if (array_key_exists('topic',$_POST)) $topic = $_POST['topic']; if (array_key_exists('naction',$_GET)) $naction = $_GET['naction']; if (array_key_exists('naction',$_POST)) $naction = $_POST['naction']; switch (strtolower($naction)) { case "add": $AllowedUserTypes = array('SuperUser','System Administrator','Communications Administrator','Administration Team'); if (checkPermission($AllowedUserTypes) != 1) break; $PageTitle = "Create a New $TitleText"; $ButtonText = "Add $TitleText"; $next_naction = "insert"; $active = 'Y'; include $FormFile; break; case "insert": $AllowedUserTypes = array('SuperUser','System Administrator','Communications Administrator','Administration Team'); if (checkPermission($AllowedUserTypes) != 1) break; extract($_POST); // Verify form data if (strlen($forum_title) == 0) { $error_message = "A Forum Title is Required"; $PageTitle = "Create a New $TitleText"; $ButtonText = "Add $TitleText"; $next_naction = "insert"; $active = 'Y'; include $FormFile; break; } // Get new sequence number if ($Sequence == 'Y') { $query = "select max(sequence) sequence from $CurrentTable"; $results = db_query($query); $row = db_fetch_array($results); $sequence = intval($row['sequence']) + 1; } // Setup default values $created = date("Y-m-d",time()); $created_by = $_SESSION['UserInfo']['record_num']; $topics = 0; $posts = 0; // Insert primary record $table = new Table("$CurrentTable"); $query = $table->BuildInsert(); db_query($query); $topic = db_insert_id(); $form_message = "$TitleText Has Been Inserted"; $naction = "list"; break; case "edit": $AllowedUserTypes = array('SuperUser','System Administrator','Communications Administrator','Administration Team'); if (checkPermission($AllowedUserTypes) != 1) break; $PageTitle = "Edit an Existing $TitleText"; $ButtonText = "Update $TitleText"; $next_naction = "update"; // Get current record $record_num = intval($_GET['record_num']); $query = "select * from $CurrentTable where record_num = $record_num"; $results = db_query($query); if (db_num_rows($results) == 1) { $row = db_fetch_array($results); extract($row); $schedule_num = $record_num; include $FormFile; } else { $error_message = "Error: Record Not Found"; } break; case "update": $AllowedUserTypes = array('SuperUser','System Administrator','Communications Administrator','Administration Team'); if (checkPermission($AllowedUserTypes) != 1) break; extract($_POST); $table = new Table("$CurrentTable"); $query = $table->BuildUpdate(); db_query($query); $form_message = "$TitleText Has Been Updated"; $naction = "list"; break; case "delete": $AllowedUserTypes = array('SuperUser','System Administrator','Communications Administrator','Administration Team'); if (checkPermission($AllowedUserTypes) != 1) break; $record_num = intval($_GET['record_num']); $query = "select * from $CurrentTable where record_num = $record_num"; $results = db_query($query); if (db_num_rows($results) == 1) { $row = db_fetch_array($results); extract($row); $dFields = explode(",",$DeleteField); $dTitle = "$TitleText "; for ($i = 0; $i < count($dFields); $i++) { $dTitle .= $row[$dFields[$i]] . $dSeparator; } include "delete.form.php"; } else { $error_message = "Error: Record Not Found"; } break; case "delete-confirmed": $AllowedUserTypes = array('SuperUser','System Administrator','Communications Administrator','Administration Team'); if (checkPermission($AllowedUserTypes) != 1) break; $record_num = intval($_GET['record_num']); // Delete the current record $query = "delete from $CurrentTable where record_num = $record_num"; db_query($query); $form_message = "$TitleText Has Been Deleted"; $naction = "list"; break; case "up": case "down": $AllowedUserTypes = array('SuperUser','System Administrator','Communications Administrator','Administration Team'); if (checkPermission($AllowedUserTypes) != 1) break; // Get current record $record_num = intval($_GET['record_num']); $query = "select * from $CurrentTable where record_num = $record_num"; $results = db_query($query); $row = db_fetch_array($results); $sequence = $row['sequence']; if ($naction == 'up') $nsequence = $sequence - 1; if ($naction == 'down') $nsequence = $sequence + 1; // Update other record $query = "update $CurrentTable set sequence = $sequence where sequence = $nsequence"; db_query($query); // Update current record $query = "update $CurrentTable set sequence = $nsequence where record_num = $record_num"; db_query($query); $naction = "list"; break; case "new-topic": case "new-thread": extract($_POST); $forum_num = $forum; $posted_by = $_SESSION['UserInfo']['record_num']; $posted_time = time(); $last_post_time = $posted_time; $top_thread_id = 0; if (isset($topic) && $topic != 0) $top_thread_id = $topic; $thread_views = 0; $thread_status = 'Open'; $post_status = 'Active'; // Insert forum thread record $table = new Table("forum_threads"); $query = $table->BuildInsert(); db_query($query); // Update the forums record if ($top_thread_id == 0) { $query = "update forums " . "set topics = topics + 1, " . "posts = posts + 1 " . "where school_num = $school_num " . "and record_num = $forum"; db_query($query); } else { $query = "update forums " . "set posts = posts + 1 " . "where school_num = $school_num " . "and record_num = $forum"; db_query($query); } $form_message = "Forum Topic Has Been Created"; if ($naction == 'new-thread') $form_message = "Your Reply has Been Posted"; $naction = "list"; break; case "edit-thread": $naction = "list"; $error_message = "Error: Message Not Found"; unset($reply); if (array_key_exists('reply',$_GET)) $reply = $_GET['reply']; if (!isset($reply)) break; // Check if this reply can be edited by the current user $user_num = intval($_SESSION['UserInfo']['record_num']); $query = "select * from forum_threads " . "where school_num = $school_num " . "and posted_by = $user_num " . "and record_num = $reply"; $results = db_query($query); if (db_num_rows($results) == 0) break; $error_message = ""; $row = db_fetch_array($results); extract($row); $TitleText = "Edit Forum Topic"; $ButtonText = "Update Message"; $next_naction = "update-thread"; include "forums.topic-form.php"; break; case "update-thread": extract($_POST); $naction = "list"; $error_message = "Error: Message Not Found"; // Check if this reply can be edited by the current user $user_num = intval($_SESSION['UserInfo']['record_num']); $query = "select * from forum_threads " . "where school_num = $school_num " . "and posted_by = $user_num " . "and record_num = $reply"; $results = db_query($query); if (db_num_rows($results) == 0) break; unset($error_message); $forum_threads = new Table("forum_threads"); $record_num = $reply; $query = $forum_threads->BuildUpdate(); db_query($query); $form_message = "Message Has Been Updated"; break; default: $naction = "list"; break; } // // List all records if naction is "list" // if ($naction == "list" || $naction == 'list-all') { if ($Sequence == 'Y') { // Resequence the records $query = "select * from $CurrentTable where sequence > 0 order by sequence"; $results = db_query($query); if (db_num_rows($results)) { $count = 1; while ($row = db_fetch_array($results)) { $rnum = $row['record_num']; $query = "update $CurrentTable set sequence = $count where record_num = $rnum"; db_query($query); $count++; } } } // Get forum records to display $fwhere = ""; if (isset($forum) && strlen($forum) > 0) $fwhere = "and record_num = $forum "; $query = "select * " . "from forums " . "where school_num = $school_num " . "and status != 'Deleted' " . $fwhere . "order by forum_title"; $results = db_query($query); if (db_num_rows($results) == 0) { echo("
\n"); echo("

There are no Forums Defined

\n"); } else { include "forums.list-forums.php"; if (isset($forum) && strlen($forum) > 0) { // If the forum is set then display the posts in the forum // If the topic is set then display only that topic $twhere = ""; if (isset($topic) && strlen($topic) > 0) $twhere = "and record_num = $topic "; // Get set of posts to display $query = "select * " . "from forum_threads " . "where school_num = $school_num " . "and forum_num = $forum " . "and thread_status != 'Deleted' " . "and top_thread_id = 0 " . $twhere . "order by last_post_time desc"; $results = db_query($query); include "forums.list-topics.php"; if (isset($topic) && $topic > 0) { include "forums.list-threads.php"; } } } } if ($school_record['other_modules'] == 'Y') { include "bottom-buttons.php"; } endTemplate(); ?>