<?php
/**
* phpChangeLog main index
*
* This is the main phpChangeLog script
*/
# For debugging, do full error_reporting
error_reporting(2500);
# Define our own file & path
$thisfile = $_SERVER['PHP_SELF'];
# start a session (or resume an existing one)
session_start();
if(empty($_SESSION['maintainer'])) {
echo "<meta http-equiv=\"Refresh\" content=\"0; URL=./\">";
die();
}
$selected_db = $_SESSION['database'];
# set root directory for this script
$rootdoc = ".";
# include the configuration file
require ("conf/config.inc.php");
require ("functions/functions.inc.php");
require ("mysql/mysql_process.inc.php");
require ("html/html_header.inc.php");
# If we just want normal output, print a nice table
if (!isset($_GET['printversion'])) {
echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n";
echo " <tr>\n";
echo " <td width=\"150\">\n";
echo " <img src=\"img/phpChangeLog-logo-small.gif\" border=\"0\" alt=\"phpChangeLog\" />\n";
echo " </td>\n";
echo " <td align=\"right\">\n";
# if a project is selected, show the name of it. Else, show that there is no project
# selected
if (isset($_GET['project'])) {
show_selected_project($_GET['project']);
} else {
echo " No project selected<br />\n";
echo " User logged in :" .$_SESSION['maintainer'];
echo " <a class=\"link\" href=\"./index.php?logout=TRUE\">[logout]</a>\n";
}
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n";
echo " <tr>\n";
echo " <td width=\"100\" valign=\"top\">\n";
### MENU
show_items("projects", $thisfile);
show_items("maintainers", $thisfile);
echo " </td>\n";
echo " <td valign=\"top\">\n";
#end if !printversion
}
### CONTENT
# If the user wants to add a maintainer or a project, show the input fields
# The necessary html is in ./functions/functions.inc.php
if (isset($_GET['render'])) {
if ($_GET['render'] == "addmaintainer") {
$type = "maintainer";
show_add_type($type, $thisfile);
} elseif ($_GET['render'] == "addproject") {
$type = "project";
show_add_type($type, $thisfile);
}
}
# If the user wants to edit a maintainer, show the menu
if (isset($_REQUEST['edit_maintainer'])) {
if (!isset($_POST['edit_maintainer_do'])) {
$maintainer = mysql_fetch_object(mysql_query("SELECT * FROM $_SESSION[database]_maintainers WHERE id = '$_GET[edit_maintainer]'"));
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"400\">\n";
echo " <tr>\n";
echo " <form method=\"post\" action=\"$thisfile\">\n";
echo " <td><b>Edit maintainer</b></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td>Username</td><td style=\"color: black; \">" . $maintainer->maintainer . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td>Password</td><td style=\"color: black; \"><input type=\"password\" name=\"password\">\n";
echo " <input type=\"submit\" value=\"Change\">\n";
echo " <input type=\"hidden\" name=\"edit_maintainer\" value=\"TRUE\">\n";
echo " <input type=\"hidden\" name=\"edit_maintainer_do\" value=\"TRUE\"></td>\n";
echo " </tr>\n";
echo "</table>\n";
} else {
echo $return;
}
}
# If we want to see a changelog, show it
if ((isset($_GET['render']) && $_GET['render'] == "getchlog")
|| (isset($_POST['render']) && $_POST['render'] == "getchlog")) {
$proj_db = $_SESSION['database'] ."_projects";
$sql_get_projects = mysql_query("SELECT * FROM $proj_db ORDER BY project");
if (isset($_GET['id'])) {
$chlog_id = $_GET['id'];
} elseif (isset($id)) {
$chlog_id = $id;
}
# If we just want normal output, show input fields for ChangeLog additions
if (!isset($_GET['printversion'])) {
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"500\">\n";
echo " <tr>\n";
echo " <form method=\"post\" action=\"$thisfile\">\n";
## echo " <td><b>Maintainer</b></td>\n";
echo " <td><b>ChangeLog addition</b></td>\n";
echo " </tr>\n";
echo " <tr>\n";
## echo " <td valign=\"top\" align=\"left\" width=\"100\">\n";
## $session_mntnr = $_SESSION['maintainer'];
## echo $_SESSION['maintainer']."\n";
echo " <input type=\"hidden\" name=\"maintainer\" value=\"$session_mntnr\" />\n";
echo " </td>\n";
echo " <td valign=\"top\">\n";
echo " <textarea name=\"comment\" cols=\"58\" rows=\"2\"></textarea>\n";
echo " </td>\n";
echo " <td valign=\"top\">\n";
echo " <input type=\"hidden\" name=\"projid\" value=\"$chlog_id\" />\n";
echo " <input type=\"hidden\" name=\"render\" value=\"getchlog\" />\n";
echo " <input type=\"hidden\" name=\"addchlog\" value=\"TRUE\" />\n";
echo " <input type=\"submit\" value=\"add\" />\n";
echo " </td>\n";
echo " </td>\n";
echo " <td>\n";
echo " </form>\n";
echo " </tr>\n";
echo "</table>\n";
}
# Display main content
echo "<br />\n";
echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" class=\"showcontent\">\n";
echo " <tr class=\"showcontent\">\n";
echo " <td>\n";
# If we want normal output, we want the 'printer version' link on it, else
# just show a 'back' link
if (!isset($_GET['printversion'])) {
echo "<a class=\"link\" href=\"$thisfile?render=getchlog&id=$chlog_id&";
echo "project=$chlog_id&printversion=TRUE\">[printer version]</a>\n";
echo "<br /><br />\n";
} else {
echo "<a class=\"link\" href=\"$thisfile?render=getchlog&id=$chlog_id&";
echo "project=$chlog_id\">[back]</a>\n";
echo "<br /><br />\n";
}
# If we do want a printerversion, show a nice header with date and time on it
if (isset($_GET['printversion'])) {
if (isset($project)) {
$proj_db = $_SESSION['database'] ."_projects";
$sql_get_projects = mysql_query("SELECT * FROM $proj_db WHERE id = '$project'");
$record = mysql_fetch_object($sql_get_projects);
echo "<b><class=\"print\"><h1>ChangeLog for $record->project</h1><br />\n";
echo "<i>printed at ". date("d M Y H:i") ."</b></i><br /><br /><br /> \n";
}
}
# Show all ChangeLog contents for the selected project
$chlog_db = $_SESSION['database'] ."_changelog";
$sql_getchlog = mysql_query("SELECT * FROM $chlog_db WHERE project_id = '$chlog_id' ORDER BY date DESC, id DESC");
while ($record = mysql_fetch_object($sql_getchlog)) {
$year_get = substr("$record->date", 0, 4);
$month_get = substr("$record->date", 4, 2);
$day_get = substr("$record->date", 6, 2);
$hour_get = substr("$record->date", 8, 2);
$minute_get = substr("$record->date", 10, 2);
$mntnr_db = $_SESSION['database'] ."_maintainers";
$sql_get_mntnr = mysql_query("SELECT * FROM $mntnr_db WHERE id = '$record->maintainer_id'");
$get_mntnr = mysql_fetch_object($sql_get_mntnr);
if (strlen($get_mntnr->maintainer) < 1) {
$get_mntnr->maintainer = "<i>deleted maintainer</i>";
}
echo "<b><style=\"align\">$day_get-$month_get-$year_get $hour_get:$minute_get, record #$record->id > $get_mntnr->maintainer wrote:</p></b><br />\n";
$comment = html_remove($record->comment);
echo nl2br ($comment);
echo "<br /><br />\n";
}
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
# get maintainers' projects
} elseif (isset($_GET['render']) && $_GET['render'] == "getprmnt") {
if (isset($_GET['id'])) {
$mntnrid = $_GET['id'];
$mntnr_db = $_SESSION['database'] ."_maintainers";
$get_mntnr = mysql_fetch_object(mysql_query("SELECT maintainer FROM $mntnr_db WHERE id = '$mntnrid'"));
$chlog_db = $selected_db ."_changelog";
$get_mntnrprj = mysql_query("SELECT project_id FROM $chlog_db WHERE
maintainer_id = '$mntnrid' GROUP BY project_id");
echo "<b>Maintainer '$get_mntnr->maintainer' is working on the following projects</b><br /><br />\n";
while ($mntnrprj = mysql_fetch_object($get_mntnrprj)) {
$proj_db = $selected_db ."_projects";
$get_prj = mysql_fetch_object(mysql_query("SELECT project FROM $proj_db
WHERE id = '$mntnrprj->project_id'"));
echo "<a class=\"link\" href=\"$thisfile?render=getchlog&id=$mntnrprj->project_id&";
echo "project=$mntnrprj->project_id\">$get_prj->project</a><br />\n";
}
} else {
die("Not a valid render option! \n");
}
}
echo " </td> \n";
echo " </tr>\n";
echo "</table>\n";
?>
</body>
</html>