$message

\n\n" . $content; $template = new Template(); $template->assign_var('STYLESHEET', $stylesheet); $template->assign_var('CONTENT', $content); $template->assign_var('VERSION', SLB_VERSION); $template->set_filenames(array('setup' => 'setup.tpl')); $template->pparse('setup'); die(); } /// Display an error message in the template, and die. function slb_die($error, $show_main = true) { $content = ''; $message = "
$error
"; if($show_main) $content .= slb_main_page(); slb_output($content, $message); die(); } /// Validate the submitted password. if(isset($_POST['auth'])) { sleep(1); // This isn't secure, but better than nothing. if($_POST['auth'] == $db_password) $_SESSION['authed'] = true; else slb_die('Incorrect password.', false); } /// Show login form if not authenticated. if(!isset($_SESSION['authed'])) { $content = << CONTENT; slb_output($content, 'Please enter the same password used for database access.'); } /// Build the changelog table for viewing/editing with the new changelog form. function slb_main_page() { global $changelogs; $content = "

Changelogs:

\n\n"; if(count($changelogs) == 0) $content .= "

No changelogs have been setup.

\n\n"; else { $content .= '' . "\n" . "\n"; foreach($changelogs as $id => $cl) { $content .= << CONTENT; } $content .= "\n
NameSVN URLRevisionAction
${cl['title']}${cl['svn']}${cl['latest']} Edit Delete
"; } $content .= "\n\n" . slb_changelog_form(); return $content; } /// Build the XHTML form for adding or editing a changelog. function slb_changelog_form($id = false) { global $changelogs; $id_input = ''; $header = 'Add New'; $submit_value = 'Add'; $prefix_input = ""; $cl = array('title' => '', 'table_prefix' => '', 'svn' => '', 'summary_limit' => '10', 'trunk' => '', 'tags' => '', 'branches' => '', 'diff_url' => ''); if($id !== false) { $id_input = ''; $cl = $changelogs[$id]; $header = 'Editing ' . $cl['title']; $submit_value = 'Update'; $prefix_input = "${cl['table_prefix']} (need to create a new changelog to change for now)"; } return <<
$header: $id_input $prefix_input
FORM; } /// User submitted a new changelog, or changes to an existing one. if(isset($_POST['edit'])) { $newcl = true; if(isset($_POST['cl_id'])) { $newcl = false; $id = $_POST['cl_id']; } $name = $_POST['name']; $prefix = $_POST['prefix']; $svn_url = $_POST['svn_url']; $summary_limit = $_POST['summary_limit']; $trunk = $_POST['trunk']; $tags = $_POST['tags']; $branches = $_POST['branches']; $diff_url = $_POST['diff_url']; if($newcl) { foreach($changelogs as $id => $cl) if($cl['table_prefix'] == $prefix) slb_die('The given table prefix is already in use.'); // Add new tables with prefix. if(($sql_authors = file_get_contents('sql/authors.sql')) === false || ($sql_changes = file_get_contents('sql/changes.sql')) === false || ($sql_commits = file_get_contents('sql/commits.sql')) === false) slb_die('Error reading SQL table files, please check permissions.'); $sql_authors = str_replace('{PREFIX}', $prefix, $sql_authors); $sql_changes = str_replace('{PREFIX}', $prefix, $sql_changes); $sql_commits = str_replace('{PREFIX}', $prefix, $sql_commits); if(!mysql_query($sql_authors) || !mysql_query($sql_changes) || !mysql_query($sql_commits)) slb_die(mysql_error()); // Insert new changelog into settings. if(!mysql_query("INSERT INTO `changelogs` (`name`, `table_prefix`, `svn_url`, `summary_limit`, `trunk`, `tags`, `branches`, `diff_url`)" . "VALUES (\"$name\", \"$prefix\", \"$svn_url\", $summary_limit, \"$trunk\", \"$tags\", \"$branches\", \"$diff_url\")")) slb_die(mysql_error()); slb_read_settings(); slb_output(slb_main_page(), $name . ' changelog added successfully.'); } else if(isset($id)) { // Update existing changelog settings in the database. if(!mysql_query("UPDATE `changelogs` SET `name` = \"$name\", `svn_url` = \"$svn_url\", " . "`summary_limit` = $summary_limit, `trunk` = \"$trunk\", `tags` = \"$tags\", " . "`branches` = \"$branches\", `diff_url` = \"$diff_url\" WHERE `id` = $id")) slb_die(mysql_error()); slb_read_settings(); slb_output(slb_main_page(), $name . ' changelog updated successfully.'); } slb_die('Error adding/updating changelog.'); } /// User is requesting deletion of a changelog. else if(isset($_GET['delete'])) { $id = $_GET['t']; $cl = $changelogs[$id]; $name = $cl['title']; if(!mysql_query("DROP TABLE `${cl['authors_table']}`, `${cl['changes_table']}`, `${cl['commits_table']}`")) slb_die(mysql_error()); if(!mysql_query("DELETE FROM `changelogs` WHERE `id` = $id")) slb_die(mysql_error()); slb_read_settings(); slb_output(slb_main_page(), $name . ' changelog has been removed.'); } /// User submitted full name changes to a changelog. else if(isset($_POST['dev_update'])) { $id = $_POST['cl_id']; $cl = $changelogs[$id]; $result = mysql_query("SELECT * FROM `${cl['authors_table']}`"); while($row = mysql_fetch_assoc($result)) { $fullname = addslashes($_POST['fn_'.$row['username']]); if(!mysql_query("UPDATE `${cl['authors_table']}` SET `fullname` = \"$fullname\" WHERE `username` = \"${row['username']}\"")) slb_die(mysql_error()); } slb_output(slb_main_page(), "Updated developers for ${cl['title']} successfully."); } /// User requested to edit an existing changelog, show the forms. if(isset($_GET['edit'])) { $id = $_GET['t']; $cl = $changelogs[$id]; $content = "

Back to Main

\n\n"; $content .= slb_changelog_form($id); $content .= "\n\n

Developers:

\n\n"; if(!($result = mysql_query("SELECT * FROM `${cl['authors_table']}` ORDER BY `username`"))) slb_die(mysql_error()); if(mysql_num_rows($result) == 0) $content .= "

No developers to edit, please run an update first.

"; else { $content .= << CONTENT; while($row = mysql_fetch_assoc($result)) { $active = $row['active'] ? 'Yes' : 'No'; $fullname = stripslashes(htmlspecialchars($row['fullname'])); $content .= << CONTENT; } $content .= << CONTENT; } slb_output($content); } // If we're still running here, we default to the main page. slb_output(slb_main_page()); ?>
UsernameFull NameCommitsActive
${row['username']} ${row['commits']}$active