blob: be259ebef96a1f2c25df9c1cff7699b8a1c1f528 [file] [log] [blame]
<?php
// -----------------------------------------------------------------------------------------------
// shared_functions.php - functions shared between several files in the projects directory
//
// AUTHOR: Karl Matthias
// DATE: 2007-12-19
// HISTORY: 2008-10-07 Modified for new DB API
// -----------------------------------------------------------------------------------------------
// Die, but look like Phoenix. Assumes exiting output buffering.
function nice_die($str) {
global $App;
global $theme;
global $Menu;
global $Nav;
global $pageAuthor;
global $pageKeywords;
global $pageTitle;
echo "<p style='color: red;'>$str</p>";
$html = ob_get_contents();
ob_end_clean();
# Generate the web page
$App->generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords, $pageTitle, $html);
exit(1);
}
// These depend on project_summary.css
function box_header($color, $str, $icon, $float = false, $fullwidth = false, $class = false) {
$str = preg_replace('/<.*?>/', '', $str);
$str = preg_replace('/<li>/', '<li class="myli">', $str);
if($class !== false) {
$use_class = $class;
} else {
if($fullwidth == false) {
$use_class = 'half';
} else {
$use_class = 'full';
}
}
?>
<div class="<?= $use_class ?>" <?= $float == true ? 'style="float: right"' : 'style="float: left"'?>>
<b class="<?= $color ?>">
<b class="<?= $color ?>1"><b></b></b>
<b class="<?= $color ?>2"><b></b></b>
<b class="<?= $color ?>3"></b>
<b class="<?= $color ?>4"></b>
<b class="<?= $color ?>5"></b></b>
<div class="<?= $color ?>fg"><?= $icon == '' ? '' : "<img src='$icon' style='float: left; padding-left: 1ex;'>"; ?><?php if(strlen($str) > 0 ) { ?><span class="boxheader"><?= $str ?></span><?php } else { ?> <div style="height: 1px; visibility: hidden;">.</div> <?php } ?>
<br/>
<?php
}
// These depend on project_summary.css
function box_footer($color) {
?><div style="height: 1px; visibility: hidden;">.</div></div>
<b class="<?= $color ?>">
<b class="<?= $color ?>5"></b>
<b class="<?= $color ?>4"></b>
<b class="<?= $color ?>3"></b>
<b class="<?= $color ?>2"><b></b></b>
<b class="<?= $color ?>1"><b></b></b></b>
</div>
<?php
}
function get_foundation_connection() {
global $fdbh;
if(mysql_select_db('eclipsefoundation', $fdbh)) {
return;
}
// Get a Foundation DB connection
$dbconnect = new DBConnectionFoundation();
$fdbh = $dbconnect->connect();
mysql_error_check();
}
function get_portal_connection() {
global $pdbh;
if(mysql_select_db('myfoundation_prod', $pdbh)) {
return;
}
// Get a Foundation DB connection
$dbconnect = new DBConnectionPortalRW();
$pdbh = $dbconnect->connect();
mysql_error_check();
}
// Generic MYSQL error checker
function mysql_error_check() {
if(mysql_errno() != 0) {
nice_die("SQL Error: " . mysql_errno() . " " . mysql_error());
}
}
// Return a component list as a comma-separated string
function component_for_committer($personid, $projectid) {
global $App;
get_foundation_connection();
$result = $App->foundation_sql("SELECT Projects.ProjectID FROM Projects, PeopleProjects
WHERE Projects.ProjectID = PeopleProjects.ProjectID
AND PersonID = '$personid'
AND ParentProjectID = '$projectid'
AND Relation = 'CM'
AND InactiveDate IS NULL
AND IsComponent = 1");
if(mysql_num_rows($result) < 1) {
return '';
}
while($row = mysql_fetch_assoc($result)) {
$components[] = substr(strrchr($row['ProjectID'], '.'), 1);
}
return (join(", ", $components));
}
// Return nicely formatted list of components for the project, and committers on each if any
function committers_for_project($projectid, $release_logos = false) {
global $App;
/*
* Get the set-actives
*/
$setactives = array();
$tmp = $App->portal_sql( "SELECT PersonID FROM PeopleProjectActives
WHERE ProjectID = '$projectid'
AND DATEDIFF(NOW(),ActiveDate) < 180
");
while( $row = mysql_fetch_array($tmp) ) {
$setactives[$row[0]] = 1;
}
$result = $App->foundation_sql("SELECT DISTINCT(ProjectID)
FROM Projects
WHERE ParentProjectID = '$projectid'
AND IsActive
ORDER BY ProjectID");
$components = array();
while($row = mysql_fetch_assoc($result)) {
$componentname = substr(strrchr($row['ProjectID'], '.'), 1);
$component = $row['ProjectID'];
$components[] = "<a href='?projectid=$component'>$componentname</a>";
}
if(sizeof($components) > 0) {
echo "<b style='color: gray; padding-left: 1em;'>sub-projects: </b>";
echo implode(', ', $components);
}
$result = $App->foundation_sql("
SELECT DISTINCT(People.PersonID), FName, LName, OrganizationID, PeopleProjects.Relation AS Rel
FROM PeopleProjects, Projects, People
LEFT JOIN OrganizationContacts
ON OrganizationContacts.PersonID = People.PersonID
WHERE PeopleProjects.Relation in ('CM','CE')
AND InactiveDate is NULL
AND People.PersonID = PeopleProjects.PersonID
AND Projects.ProjectID = PeopleProjects.ProjectID
AND (
Projects.ProjectID = '$projectid'
OR (
ParentProjectID = '$projectid'
AND IsComponent = 1)
)
ORDER BY LName");
if(mysql_num_rows($result) < 1) {
echo "<p><em>There are no committers on the project.</em>";
if(strpos($projectid, '.') === false) {
echo " <em>Top level projects do not always have committers.</em>";
}
echo "</p>";
return;
}
$blob = file("http://dash.eclipse.org/dash/commits/web-api/commits-index.php?projectid=$projectid");
$counts = array();
foreach( $blob as $line ) {
$words = split( "\t", $line );
if( substr($words[0],0,1) == '#' ) {
continue;
}
$counts[$words[0]][$words[2]] = $words[1];
}
echo "<br/>";
$active_period = 3;
$participating_period = 9;
$activerows = array();
$participatingrows = array();
$inactiverows = array();
$emeritusrows = array();
while($row = mysql_fetch_assoc($result)) {
// XXX COMMENTED OUT for standardized groups... further changes may be needed.
// $components = component_for_committer($row['PersonID'], $projectid);
// if(strlen($components) > 0) {
// $components = "<span style='color: gray'>$components</span> ";
// }
// XXX Components field commented out for standardized groups... further changes may be needed
$rec = array( $row['PersonID'] , $row['FName'] , $row['LName']); // , $components );
if( $row['Rel'] == 'CM' ) {
if( isset($counts[$row['PersonID']][$active_period])
|| isset($setactives[$row['PersonID']]) ) {
$activerows[] = $rec;
if($row['OrganizationID'] != '') {
$companies[$row['OrganizationID']] = 1;
}
} else if( isset($counts[$row['PersonID']][$participating_period]) ) {
$participatingrows[] = $rec;
} else {
$inactiverows[] = $rec;
}
} else {
$emeritusrows[] = $rec;
}
$peoplerows[] = $rec;
}
if( $release_logos && count($companies) > 0 ) {
echo "<div style='padding-right: 5px; padding-top: 30px; float: right;'>";
$companies = array_keys( $companies );
shuffle( $companies );
foreach ( $companies as $orgid ) {
echo "<img src=\"http://www.eclipse.org/membership/scripts/get_image.php?id=" . $orgid . "&size=small\"/><p>";
}
echo "</div>";
}
echo "<table id='committerstable' width='100%'>";
echo "<tr><td colspan='2' style='padding-top: 5px;'><span style='font-size: large; font-weight: bold; margin-left: -8px; color: #666;'><acronym title='Committers who have written code in the last three months.'>Active</acronym>:</span></td></tr>";
foreach ( $activerows as $rec ) {
echo "<tr>";
output_one_person( $rec );
echo "</tr>";
}
if( count($participatingrows) > 0 ) {
echo "<tr><td colspan='2' style='padding-top: 10px;'><span style='font-size: large; font-weight: bold; margin-left: -8px; color: #666;'><acronym title='Committers who have written code in the last nine months.'>Participating</acronym>:</span></td></tr>";
foreach ( $participatingrows as $rec ) {
echo "<tr>";
output_one_person( $rec );
echo "</tr>";
}
}
if( count($inactiverows) > 0 ) {
echo "<tr><td colspan='2' style='padding-top: 10px;'><span style='font-size: large; font-weight: bold; margin-left: -8px; color: #666;'><acronym title='Committers who have not written code for more than nine months.'>Inactive</acronym>:</span></td></tr>";
foreach ( $inactiverows as $rec ) {
echo "<tr>";
output_one_person( $rec );
echo "</tr>";
}
}
if( count($emeritusrows) > 0 ) {
echo "<tr><td colspan='2' style='padding-top: 10px;'><span style='font-size: large; font-weight: bold; margin-left: -8px; color: #666;'><acronym title='Former committers who made significant contributions to the project.'>Emeritus</acronym>:</span></td></tr>";
foreach ( $emeritusrows as $rec ) {
echo "<tr>";
output_one_person( $rec );
echo "</tr>";
}
}
echo "</table>";
return mysql_num_rows($result);
}
function output_one_person($rec) {
echo "<td> <a href='lists.php?list=projectsforcommitter&param=" . $rec[0] ."'>" . $rec[1] . " " . $rec[2] . "</a> " . $rec[3] . "</td>";
}
function leads_for_project($param) {
global $App;
$result = $App->foundation_sql("SELECT People.PersonID, FName, LName FROM People, PeopleProjects " .
"WHERE Relation = 'PL' " .
"AND InactiveDate is NULL " .
"AND ProjectID = '$param' " .
"AND People.PersonID = PeopleProjects.PersonID " .
"ORDER BY LName");
if(mysql_num_rows($result) == 0 && !(strpos($projectid, '.') === false) ) {
echo "<p><em>The project appears not to have a lead.</em>";
echo "</p>";
}
echo "<br/><table>";
while($row = mysql_fetch_assoc($result)) {
echo "<tr><td> <a href='lists.php?list=projectsforcommitter&param=" . $row['PersonID'] ."'>" . $row['FName'] . " " . $row['LName'] . "</a></td></tr>";
}
echo "</table>";
}
// Generate PMC list for a project or its toplevel
function pmc_for_project($projectid) {
global $App;
if(strpos($projectid, '.') !== false) {
$projectid = substr($projectid, 0, strpos($projectid, '.')); // get the top level
}
$sql = "SELECT People.PersonID, FName, LName, Description
FROM People, PeopleProjects, SYS_Relations
WHERE People.PersonID = PeopleProjects.PersonID
AND ProjectID = '$projectid'
AND PeopleProjects.Relation = SYS_Relations.Relation
AND PeopleProjects.Relation IN ('PM', 'PD')
AND InactiveDate IS NULL
ORDER BY PeopleProjects.Relation, LName, FName";
$result = $App->foundation_sql($sql);
if(mysql_num_rows($result) < 1) {
echo "<p><em>No PMC is defined.</em></p>";
}
$namedata = array();
$reldata = array();
while($row = mysql_fetch_assoc($result)) {
$namedata[$row['PersonID']] = $row['FName'] . " " . $row['LName'];
$reldata[$row['PersonID']][] = $row['Description'];
}
echo "<table>";
foreach( $namedata as $id => $name ) {
echo "<tr><td> <a class='mya' href='lists.php?list=projectsforcommitter&param=" . $id ."'>" . $name . "</a></td><td>";
echo implode( ", ", $reldata[$id] );
echo "</tr>";
}
echo "</table>";
}
// Get the Bugzilla product ID for a project
function bugzilla_for_project($project,$projectid) {
$obj = $project->bugzillas;
$obj = $obj[0];
if( $obj->productname ) {
$str = $obj->productname;
if( strpos( $str, '%' ) === false )
return $str;
else
return urldecode($str);
} else {
switch($projectid) {
case 'webtools':
return "Web Tools";
default:
preg_match('/\.(.+)/', $projectid, $matches);
if(isset($matches[1])) {
return $matches[1];
} else {
return $projectid;
}
}
}
}
?>