blob: 8346a6719dc73ffdc24bc12c882d39b47cee68b9 [file] [log] [blame]
<?php
/*******************************************************************************
* Copyright (c) 2006-2013 Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Matt Ward (Eclipse Foundation) - initial API and implementation
* Denis Roy (Eclipse Foundation) - 2013 update
*******************************************************************************/
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/nav.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menu.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/evt_log.class.php");
# Add'l requires for Bugzilla
require_once "/home/data/httpd/eclipse-php-classes/system/dbconnection.class.php";
require_once("/home/data/httpd/eclipse-php-classes/system/dbconnection_bugs_rw.class.php");
require_once("/home/data/httpd/eclipse-php-classes/system/dbconnection_foundation_ro.class.php");
$App = new App(); $Menu = new Menu();
$App->runStdWebAppCacheable();
include("_projectCommon.php");
$Menu->addMenuItem("Return to project overview", "edit_bugzilla_project.php", "_self");
//turn on/off verbose debuging
define("DEBUG",0);
//turn on(1) or off(0) actual inserts
define("do_inserts",1);
$Session = $App->useSession(true);
$pageTitle = "Bugzilla Manager";
$pageKeywords = "";
$pageAuthor = "Eclipse Foundation, Inc.";
# Begin buffered output
ob_start();
?>
<link rel="stylesheet" type="text/css" href="../css/stylesheet.css" />
<div id="maincontent" style="padding:8px;">
<h1 style="padding-top:10px; padding-bottom:20px;"><?= $pageTitle ?></h1>
<?php
include "details.html";
if ( checkpost($App->getHTTPParameter('submit')) || checkpost($App->getHTTPParameter('edit')) ) {
$Menu->addMenuItem("Show all components", "edit_bugzilla_components.php", "_self");
}
//connect to the foundation db in
$fdbc = new DBConnectionFoundation();
$fdbh = $fdbc->connect();
$bdbc = new DBConnectionBugsRW();
$bdbh = $bdbc->connect();
//global error var
$global_error = 0;
//set the global log options
$evt_log = new EvtLog();
$evt_log->setLogTable("__bugs");
$evt_log->setLogAction("EDIT_COMPONENT");
$evt_log->setuid($_SESSION['uid']);
$evt_log->setPK2($_SESSION['project']);
/******************
*name: getlogin
*function: given a bugzill user id returns the email address(login_name)
*I/O: takes the id, returns the address
*
*Date: Feb 14/06
*By: M. Ward.
*******************/
function getlogin( $id, $dbh ){
//if there is nothing in the id then exit now.
if( !checkpost($id))
return "";
$loginquery = "select login_name from profiles where userid=\"" . $id . "\";";
debug_msg($loginquery,3);
$loginresult = mysql_query($loginquery, $dbh);
if($loginresult == FALSE){
debug_msg(mysql_error(), 0);
debug_msg("Please contact the Webmaster about this error. Thank you.",0);
return "NA";
}
$data = mysql_fetch_array($loginresult);
return $data['login_name'];
}
/******************
*name: checklogin
*function: given an email address check that bugzilla has a corresponding login
*I/O: takes the email, returns 1 on true, 0 on fail
*
*Date: Feb 15/06
*By: M. Ward.
*******************/
function checklogin( $address, $dbh ){
$loginquery = "select userid from profiles where login_name=\"" . $address . "\";";
debug_msg($loginquery,3);
$loginresult = mysql_query($loginquery, $dbh);
if($loginresult == FALSE){
debug_msg(mysql_error(), 0);
debug_msg("Please contact the Webmaster about this error. Thank you.",0);
return "0";
}
$data = mysql_fetch_array($loginresult);
return $data['userid'];
}
/*****************************
*
* Name: do_postwork
* Function: does the checks and data inserts. Putting this stuff here lets me use the return function without screwing up the page.
*
* I/O: needs to be passed the db handle.
*
* By: M. Ward
* Date: Feb 22/06
*
******************************/
function do_postwork( ) {
global $bdbh;
global $fdbh;
global $evt_log;
//clear these vars
$new_owner = "NULL";
$new_qacontact = "NULL";
debug_msg("In save edit section",2);
//need to check that the email addresses are 'valid' syntacticly
if ( checkpost($_POST['owner']) ) {
//check that the owner has a valid bugs login
if( ($new_owner = checklogin($_POST['owner'], $bdbh ) ) <= 0 ) {
$global_error = 1;
debug_msg("<h3>The default owner must have a valid bugzilla account</h3>", 0);
debug_msg("Use your browsers back button to correct the entry",0);
return;
}
} else {
debug_msg("<h3>You must enter an initial owner.</h3>",0);
debug_msg("Use your browsers back button to correct the entry",0);
return;
}
//need to check that the email addresses are 'valid' syntacticly
if ( checkpost($_POST['qaowner']) ) {
//check that the owner has a valid bugs login
if( ($new_qacontact = checklogin($_POST['qaowner'], $bdbh ) ) <= 0 ) {
$global_error = 1;
debug_msg("<h3>The default Q&A contact must have a valid bugzilla account</h3>", 0);
debug_msg("Use your browsers back button to correct the entry",0);
return;
}
} else { //clear the default qa contact
$new_qacontact = "NULL";
}
//need to check that there is a description
if ( !checkpost($_POST['component_description']) ) {
$global_error = 1;
debug_msg("<h3>You must provide a description for your component</h3>", 0);
debug_msg("Use your browsers back button to correct the entry",0);
return;
}
//check the default cc list
if ( checkpost($_POST['assigned_cc']) ) {
//replace \r with ,
$cc_bulk = ereg_replace("\r\n",",", $_POST['assigned_cc'] );
$cc_bulk = ereg_replace(" ","", $cc_bulk );
$cc_email = split(",",$cc_bulk);
debug_msg("CC Email[0]: " . $cc_email[0], 4);
//loop through and check for bugzilla accounts and add those that are into a list
foreach( $cc_email as $address) {
if ( ($cc_user_id = checklogin($address, $bdbh ) ) >= 1 ) {
debug_msg("Checking if I should add " . $cc_user_id . " to the cc list",4);
//remove(fail to add duplicate users
if( in_array( $cc_user_id,$cc_insert_list) === FALSE ){
$cc_insert_list[]=$cc_user_id;
debug_msg("Added " . $cc_insert_list[0] . " to the cc list",4);
debug_msg("Size of CC list: " . count($cc_insert_list), 4);
}
}
}
}
//change up the project settings, in case this is a special project
if( checkpost($_SESSION['projisclass'] ) ) {
$workingproject = $_SESSION['projisclass'];
//check that the user is associated with this project
$query = "SELECT count(*) ProjectID FROM Projects WHERE ( ProjectID IN (SELECT ProjectID FROM PeopleProjects WHERE PersonID ='" . $_SESSION['uid'] . "' AND";
$query .= " ( Relation IN ('PM','PD','PL' ) OR ( Relation='CM' AND EditBugs=1 ) ) AND ProjectID like'" . $workingproject . "%' AND (InactiveDate is NULL OR InactiveDate >= CURRENT_DATE()) ) OR ";
$query .= " ( ParentProjectID IN (SELECT ProjectID FROM PeopleProjects WHERE PersonID = '" . $_SESSION['uid'] . "' AND Relation IN ('PM','PD') AND ";
$query .= " (InactiveDate is NULL OR InactiveDate >= CURRENT_DATE())) AND ProjectID like '" . $workingproject . "%' ) ) AND BugsName IS NOT NULL; ";
} else {
$workingproject = $_SESSION['project'];
//check that the user is associated with this project
$query = "SELECT count(*) ProjectID FROM Projects WHERE ( ProjectID IN (SELECT ProjectID FROM PeopleProjects WHERE PersonID ='" . $_SESSION['uid'] . "' AND";
$query .= " ( Relation IN ('PM','PD','PL' ) OR ( Relation='CM' AND EditBugs=1 ) ) AND ProjectID='" . $workingproject . "' AND (InactiveDate is NULL OR InactiveDate >= CURRENT_DATE()) ) OR ";
$query .= " ( ParentProjectID IN (SELECT ProjectID FROM PeopleProjects WHERE PersonID = '" . $_SESSION['uid'] . "' AND Relation IN ('PM','PD') AND ";
$query .= " (InactiveDate is NULL OR InactiveDate >= CURRENT_DATE())) AND ProjectID='" . $workingproject . "' ) ) AND BugsName IS NOT NULL; ";
}
debug_msg($query,3);
$result = mysql_query($query, $fdbh);
if($result == FALSE) {
debug_msg(mysql_error(), 0);
debug_msg("Please contact the Webmaster about this error. Thank you.",0);
return;
}
$data = mysql_fetch_array($result);
if( $data['ProjectID'] >= 1) {
if( checkpost($_POST['basename'] ) && $_POST['basename'] != "new" ) {
debug_msg("Updating the component.",1);
//build the update command
$bugsquery = "update components ";
$bugsquery .= "set description=\"" . $_POST['component_description'] ."\",";
$bugsquery .= " initialowner=\"" . $new_owner . "\"";
//The 3.4 Innodb tables don't like it when you explicitly set NULL in quotes
if ( $new_qacontact != "NULL") {
$bugsquery .= ", initialqacontact=\"" . $new_qacontact . "\" ";
}
$bugsquery .= "where product_id=\"" . $_SESSION['main_product_id'] ."\"";
$bugsquery .= " AND id=\"" . $_POST['localid'] ."\";";
//set a key for the logs
$evt_log->setPK1($_POST['basename']);
$cc_query = "select id from components where id=\"" . $_POST['localid'] . "\" AND product_id=\"" . $_SESSION['main_product_id'] . "\";";
} else {
debug_msg("Adding the component.",3);
//build the insert command
$bugsquery = "insert into components (name,description,initialowner,initialqacontact,product_id) ";
$bugsquery .= " VALUES (";
$bugsquery .= "\"" . $_POST['name'] . "\",";
$bugsquery .= "\"" . $_POST['component_description'] . "\",";
$bugsquery .= $new_owner . ",";
$bugsquery .= $new_qacontact . ",";
$bugsquery .= "\"" . $_SESSION['main_product_id'] . "\"";
$bugsquery .= ");";
//set a key for the logs
$evt_log->setPK1($_POST['name']);
$cc_query = "select id from components where name=\"" . $_POST['name'] . "\" AND product_id=\"" . $_SESSION['main_product_id'] . "\";";
}
debug_msg($bugsquery,3);
if( do_inserts == 1) {
$result = mysql_query($bugsquery,$bdbh);
if( $result == FALSE ){
debug_msg(mysql_error(), 0);
debug_msg("Please contact the Webmaster about this error. Thank you.",0);
return;
}
//clear the current cc list, this needs to be done everytime. If there were people in the list,
//and to delete the entry box than the input var is 'unset' so it didn't get into this when it was
//below
debug_msg($cc_query,3);
$result = mysql_query($cc_query,$bdbh);
if( $result == FALSE ){
debug_msg(mysql_error(), 0);
debug_msg("Please contact the Webmaster about this error. Thank you.",0);
return;
}
$component = mysql_fetch_array($result);
$cc_query = "delete from component_cc where component_id=" .$component['id'] . ";";
debug_msg($cc_query,3);
$result = mysql_query($cc_query,$bdbh);
if( $result == FALSE ){
debug_msg(mysql_error(), 0);
debug_msg("Please contact the Webmaster about this error. Thank you.",0);
return;
}
//Added for the default component cc list in bugz 3.0, this is done here since it has to be done
//here for any new components.
$cc_count = count( $cc_insert_list );
if ( $cc_count > 0 ) {
//build new cc list
$cc_query = "insert into component_cc (user_id,component_id) VALUES ";
//loop through the list created above and insert stuff
foreach( $cc_insert_list as $cc_member ) {
debug_msg("In CClist loop, adding: ". $cc_member, 4);
$cc_query .= "(" . $cc_member . "," . $component['id'] . ")";
if ( $cc_count > 1 ){
$cc_query .=",";
$cc_count--;
}
}
$cc_query .=";";
debug_msg($cc_query,3);
//now run the cc list insert query
$result = mysql_query($cc_query,$bdbh);
if( $result == FALSE ){
debug_msg(mysql_error(), 0);
debug_msg("Please contact the Webmaster about this error. Thank you.",0);
return;
}
}
//log the event
$evt_log->insertModLog($_SESSION['uid']);
} else {
debug_msg("If I was doing inserts I would have done: " . $bugsquery, 0 );
}
//write out a done message
if( $_POST['basename'] != "new" )
$html = "</br><h3>Updated component.</h3>";
else
$html = "</br><h3>Added component.</h3>";
}
$html .="</br><a href=\"edit_bugzilla_components.php\">Return to the list of components</a>";
$html .="</br><a href=\"edit_bugzilla_components.php?edit=new\">Add another Component</a>";
}
if ( $App->getDBReadOnly() ) {
$html = "<h3>The database is currently offline for maintanence. Please try again later</h3>";
} else {
debug_msg("Session project:" . $_SESSION['project'] ." ", 1 );
//check to see if this page is being called due to an internal post command.
if( checkpost($App->getHTTPParameter('submit')) ){
do_postwork();
} else if ( checkpost($App->getHTTPParameter('edit')) ) { //have we been asked to add a new component?
debug_msg("In add new section",2);
showwarning();
if($_GET['edit'] != 'new' ){
$html = "<h3>Edit component</h3></br>";
//insert the white space back into the name, since we had to take it out earlier.
$name = $_GET['edit'];
debug_msg("Decoded name is: ". $name,4);
//load specific component data
$bugsquery = "select * from components where name=\"" . $name . "\"";
$bugsquery .= "AND product_id=\"" . $_SESSION['main_product_id'] . "\";";
debug_msg($bugsquery,3);
$result = mysql_query($bugsquery, $bdbh);
if($result == FALSE ) {
debug_msg(mysql_error(), 0);
debug_msg("Please contact the Webmaster about this error. Thank you.",0);
return;
}
$data = mysql_fetch_array($result);
$name = $data['name'];
$description = $data['description'];
$assigned_to = getlogin( $data['initialowner'], $bdbh);
$assigned_toqa = getlogin( $data['initialqacontact'], $bdbh);
$component_id = $data['id'];
//Added for the default component cc list in bugz 3.0
$cc_query = "select user_id from component_cc where component_id = \"" . $component_id ."\";";
debug_msg($cc_query,3);
$cc_result = mysql_query($cc_query, $bdbh);
if($cc_result === FALSE) {
debug_msg(mysql_error(), 0);
debug_msg("Please contact the Webmaster about this error. Thank you.",0);
}
//Check if there is actually anything to show
$cc_rows = mysql_num_rows($cc_result);
if ( $cc_rows >= 1) {
while($cc_row = mysql_fetch_array($cc_result)) {
$cc_list .= getlogin($cc_row['user_id'], $bdbh );
if ( $cc_rows > 1 ) {
$cc_list .= ",";
$cc_rows--;
}
}
}
debug_msg("CC_list: " . $cc_list,4);
} else
$html = "<h3>Add a new component for " . $_SESSION['project_name'] . "</h3></br>";
//now if we're sending this back at ourselves because something was fucked up
//reset the php vars to match the post vars
if( checkpost($_POST['name']) )
$name = $_POST['name'];
if( checkpost($_POST['component_description']) )
$description = $_POST['component_description'];
if( checkpost($_POST['owner']) )
$assigned_to = $_POST['owner'];
if( checkpost($_POST['assigned_cc']) )
$cc_list = $_POST['assigned_cc'];
$html .= "<p> Fields marked with an <font face=\"Arial\" color=\"#FF0000\">*</font> are required </p>\n\r";
//build the input form
$html .= "<form name=\"new_component\" method=\"post\" action=\"edit_bugzilla_components.php\" >\n\r";
$html .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >\n\r";
if($_GET['edit'] != 'new')
$html .= "<tr><td>Name</td><td>". $name . "</td></tr>\n\r";
else
$html .= "<tr><td><font face=\"Arial\" color=\"#FF0000\">*</font> Name</td><td><input type=\"text\" name=\"name\" value=\"\"></td></tr>\n\r";
$html .= "<tr><td>Description </td><td><textarea rows=\"5\" cols=\"40\" name=\"component_description\">" . $description ."</textarea></td></tr>\n\r";
$html .= "<tr><td><font face=\"Arial\" color=\"#FF0000\">*</font> Default Assignee </td><td><input type=\"text\" size=\"30\" name=\"owner\" value=\"" . $assigned_to . "\"></td></tr>\n\r";
$html .= "<tr><td></td><td class=\"micro\">If you wish to use an generic inbox with an @eclipse.org address for the default assignee,</br> please contact Webmaster@eclipse.org to have the inbox created first.</br> Note the default assignee MUST be a valid bugzilla account</td></tr>\n\r";
$html .= "<tr><td>Default Q&A Contact </td><td><input type=\"text\" size=\"30\" name=\"qaowner\" value=\"" . $assigned_toqa . "\"></td></tr>\n\r";
$html .= "<tr><td>Default CC list </td><td><textarea rows=\"5\" cols=\"40\" name=\"assigned_cc\">" . $cc_list ."</textarea></td></tr>\n\r";
$html .= "<tr><td></td><td class=\"micro\">Note the cc users MUST have a valid bugzilla account. </br> Separate entries with a , ie: someuser@bar.com,otheruser@foo.com</td></tr>\n\r";
$html .= "</table>\n\r<input type=\"submit\" name=\"submit\" value=\"Save Component\" >\n\r";
$html .= "<input type=\"hidden\" name=\"saveedit\" value=\"" . $_SESSION['secondary_product_id'] . "\">";
$html .= "<input type=\"hidden\" name=\"basename\" value=\"" . $_GET['edit'] . "\">";
$html .= "<input type=\"hidden\" name=\"localid\" value=\"" . $component_id . "\">";
$html .= "</form>\n\r";
$html .= "</br><a href=\"edit_bugzilla_components.php\">View all components</a>";
} else {
debug_msg("bypassing post section", 2);
//get the info from the bugs database
$bugsquery = "select * from components where product_id = \"" . $_SESSION['main_product_id'] ."\";";
debug_msg($bugsquery,3);
$result = mysql_query($bugsquery, $bdbh);
if($result == FALSE) {
debug_msg(mysql_error(), 0);
debug_msg("Please contact the Webmaster about this error. Thank you.",0);
}
//now build the html
$html = "<h3>Bugzilla components for " . $_SESSION['project_name'] . "</h3></br>";
$html .="<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"normal\">\n\r";
$html .="<tr class=\"list_column_header\" height=\" " . $App->getDefaultRowHeight() . " \">\n\r";
$html .="<td align=\"left\"><b>Name</b></td>\n\r<td align=\"left\"><b>Description</b></td>\n\r";
$html .="<td align=\"left\"><b>Default owner</b></td>\n\r<td nowrap='nowrap'><b>Default Q&A contact</b></td>\n\r<td nowrap='nowrap'><b>Default CC list</b></td></tr>\n\r";
$count = 0;
while($row = mysql_fetch_array($result)) {
//clean whitespace out of the name
$name = urlencode( $row['name'] );
debug_msg(" cleaned name is: " .$name, 4);
$html .="<tr height=\" " . $App->getDefaultRowHeight() . "\" class=\"data" . $count % 2 ."\">\n\r";
$html .="<td><a href=edit_bugzilla_components.php?edit=" . $name .">" . $row['name'] ."</a></td>\n\r";
$html .="<td>" . $row['description'] ."</td> \n\r";
$html .="<td nowrap='nowrap'>" . getlogin($row['initialowner'], $bdbh ) . "</td>\n\r";
$html .="<td nowrap='nowrap'>" . getlogin($row['initialqacontact'], $bdbh ) . "</td>\n\r";
//Added for the default component cc list in bugz 3.0
$cc_query = "select user_id from component_cc where component_id = \"" . $row['id'] ."\";";
debug_msg($cc_query,3);
$cc_result = mysql_query($cc_query, $bdbh);
if($cc_result === FALSE) {
debug_msg(mysql_error(), 0);
debug_msg("Please contact the Webmaster about this error. Thank you.",0);
}
//Check if there is actually anything to show
$cc_rows = mysql_num_rows($cc_result);
$html .="<td nowrap='nowrap'>" ;
if ( $cc_rows >= 1) {
while($cc_row = mysql_fetch_array($cc_result)) {
$html .= getlogin($cc_row['user_id'], $bdbh );
//append a , between entries
if ( $cc_rows > 1 ) {
$html .= " </br> ";
$cc_rows--;
}
}
}
$html .=" </td></tr>\n\r";
$count++;
}
$html .= "</table>\n\r</br><a href=\"edit_bugzilla_components.php?edit=new\">Add New Component</a>";
} //end of default section
//add a link for the 'other products'
if( checkpost($_SESSION['projisclass'] ) == 1 ){
$html .="</br><a href=\"edit_bugzilla_project.php?issp=1\">Return to product overview</a>";
$html .="</br><a href=\"edit_bugzilla_project.php\">Select another product</a>";
} else {
$html .="</br><a href=\"edit_bugzilla_project.php?issp=1\">Return to project overview</a>";
}
}
echo $html;
echo "</div>";
$html = ob_get_contents();
ob_end_clean();
$App->generatePage($theme, $Menu, null, $pageAuthor, $pageKeywords, $pageTitle, $html);
?>