Location: PHPKode > projects > Testlink in Chinese > metrics/metricsSelection.php
<?php

////////////////////////////////////////////////////////////////////////////////
//File:     metricsSelection.php
//Author:   Chad Rosen
//Purpose:  This page shows the data from a build
////////////////////////////////////////////////////////////////////////////////


require_once("../functions/header.php");

  session_start();
  doDBConnect();
  doHeader();

?>

<LINK REL="stylesheet" TYPE="text/css" HREF="kenny.css">

<?

//Display the most recent build

$sql="select distinct(build) from build,project where build.projid='" . $_SESSION['project'] . "' order by build desc";

$result = mysql_query($sql); //Run the query
$countersel = 0;
while ($myrow = mysql_fetch_row($result)) 

{	
	$builds[] = $myrow[0];
	$countersel++;
}

$isel = 0;

while($isel < $countersel)
{
    $build=$builds[$isel];
    
    ////////////////////////////////////////////////////////////////////////////////
//File:     priority.php
//Author:   Chad Rosen
//Purpose:  This page this generates stats based on priority
////////////////////////////////////////////////////////////////////////////////

//Grabbing the all of the priority information

$sql = "select priority from project,priority where project.id = '" . $_SESSION['project'] . "' and project.id = priority.projid";

$result = mysql_query($sql); //Run the query

while ($myrow = mysql_fetch_row($result)) 
{

	$priority[] = $myrow[0];

}

//Sets the priority of L,M,H 1,2,3 to whatever the user has selected in the priority table

$L1 = $priority[0]; 
$L2 = $priority[1];
$L3 = $priority[2];
$M1 = $priority[3];
$M2 = $priority[4];
$M3 = $priority[5];
$H1 = $priority[6];
$H2 = $priority[7];
$H3 = $priority[8];

//Initializing variables

$totalA = 0;
$passA = 0;
$failA = 0;
$blockedA = 0;
$totalB = 0;
$passB = 0;
$failB = 0;
$blockedB = 0;
$totalC = 0;
$passC = 0;
$failC = 0;
$blockedC = 0;

//Begin code to display the component

$sql = "select category.risk, category.id, category.importance from project,component, category where project.id = '" . $_SESSION['project'] . "' and project.id = component.projid and component.id = category.compid";

$result = mysql_query($sql);

while ($myrow = mysql_fetch_row($result)) 
{

	//Code to grab the entire amount of test cases per project
	
	$sql = "select count(testcase.id) from project,component,category,testcase where project.id = '" . $_SESSION['project'] . "' and category.id='" . $myrow[1] . "' and project.id = component.projid and component.id = category.compid and category.id = testcase.catid";


	$totalTCResult = mysql_query($sql);

	$totalTCs = mysql_fetch_row($totalTCResult);

	//Code to grab the results of the test case execution

	$sql = "select tcid,status from results,project,component,category,testcase where project.id = '" . $_SESSION['project'] . "' and category.id='" . $myrow[1] . "' and project.id = component.projid and component.id = category.compid and category.id = testcase.catid and testcase.id = results.tcid and build='" . $build . "'";

	//echo $sql . "<br>";

	$totalResult = mysql_query($sql);

	//Setting the results to an array.. Only taking the most recent results and displaying them
	
	while($totalRow = mysql_fetch_row($totalResult))
	{
		//echo $totalRow[0] . " " . $totalRow[1] . "<br>";

		//This is a test.. I've got a problem if the user goes and sets a previous p,f,b value to a 'n' value. The program then sees the most recent value as an not run. I think we want the user to then see the most recent p,f,b value
		
		
		
		$testCaseArray[$totalRow[0]] = $totalRow[1];


	}

	//This is the code that determines the pass,fail,blocked amounts

	$arrayCounter = 0; //Counter

	//Initializing variables

	$pass = 0;
	$fail = 0;
	$blocked = 0;
	$notRun = 0;


//I had to write this code so that the loop before would work.. I'm sure there is a better way to do it but hell if I know how to figure it out..
	

if(count($testCaseArray) > 0)
	{

		//This loop will cycle through the arrays and count the amount of p,f,b,n

		foreach($testCaseArray as $tc)
		{

			if($tc == 'p')
			{
				
				$pass++;
				

			}

			elseif($tc == 'f')
			{

				$fail++;

			}

			elseif($tc == 'b')

			{

				$blocked++;

			}
			elseif($tc == 'n')

			{

				$notRun++;

			}


		}//end foreach

	}//end if

	unset($testCaseArray);

	$priStatus = $myrow[2] . $myrow[0]; //Concatenate the importance and priority together

//This next section figures out how many priority A,B and C test cases there and adds them together

	if($priStatus == 'L1' && $L1 == "a")
	{

		$totalA = $totalA + $totalTCs[0];
		$passA = $passA + $pass;
		$failA = $failA + $fail;
		$blockedA = $blockedA + $blocked;

	}elseif($priStatus == 'L1' && $L1 == "b")
	{
		$totalB = $totalB + $totalTCs[0];
		$passB = $passB + $pass;
		$failB = $failB + $fail;
		$blockedB = $blockedB + $blocked;

	}elseif($priStatus == 'L1' && $L1 == "c")
	{

		$totalC = $totalC + $totalTCs[0];
		$passC = $passC + $pass;
		$failC = $failC + $fail;
		$blockedC = $blockedC + $blocked;


	}elseif($priStatus == 'L2' && $L2 == "a")
	{

		$totalA = $totalA + $totalTCs[0];
		$passA = $passA + $pass;
		$failA = $failA + $fail;
		$blockedA = $blockedA + $blocked;

	}elseif($priStatus == 'L2' && $L2 == "b")
	{
		$totalB = $totalB + $totalTCs[0];
		$passB = $passB + $pass;
		$failB = $failB + $fail;
		$blockedB = $blockedB + $blocked;

	}elseif($priStatus == 'L2' && $L2 == "c")
	{

		$totalC = $totalC + $totalTCs[0];
		$passC = $passC + $pass;
		$failC = $failC + $fail;
		$blockedC = $blockedC + $blocked;


	}elseif($priStatus == 'L3' && $L3 == "a")
	{

		$totalA = $totalA + $totalTCs[0];
		$passA = $passA + $pass;
		$failA = $failA + $fail;
		$blockedA = $blockedA + $blocked;

	}elseif($priStatus == 'L3' && $L3 == "b")
	{
		$totalB = $totalB + $totalTCs[0];
		$passB = $passB + $pass;
		$failB = $failB + $fail;
		$blockedB = $blockedB + $blocked;

	}elseif($priStatus == 'L3' && $L3 == "c")
	{

		$totalC = $totalC + $totalTCs[0];
		$passC = $passC + $pass;
		$failC = $failC + $fail;
		$blockedC = $blockedC + $blocked;


	}elseif($priStatus == 'M1' && $M1 == "a")
	{

		$totalA = $totalA + $totalTCs[0];
		$passA = $passA + $pass;
		$failA = $failA + $fail;
		$blockedA = $blockedA + $blocked;

	}elseif($priStatus == 'M1' && $M1 == "b")
	{
		$totalB = $totalB + $totalTCs[0];
		$passB = $passB + $pass;
		$failB = $failB + $fail;
		$blockedB = $blockedB + $blocked;

	}elseif($priStatus == 'M1' && $M1 == "c")
	{

		$totalC = $totalC + $totalTCs[0];
		$passC = $passC + $pass;
		$failC = $failC + $fail;
		$blockedC = $blockedC + $blocked;


	}elseif($priStatus == 'M2' && $M2 == "a")
	{

		$totalA = $totalA + $totalTCs[0];
		$passA = $passA + $pass;
		$failA = $failA + $fail;
		$blockedA = $blockedA + $blocked;

	}elseif($priStatus == 'M2' && $M2 == "b")
	{
		$totalB = $totalB + $totalTCs[0];
		$passB = $passB + $pass;
		$failB = $failB + $fail;
		$blockedB = $blockedB + $blocked;

	}elseif($priStatus == 'M2' && $M2 == "c")
	{

		$totalC = $totalC + $totalTCs[0];
		$passC = $passC + $pass;
		$failC = $failC + $fail;
		$blockedC = $blockedC + $blocked;


	}elseif($priStatus == 'M3' && $M3 == "a")
	{

		$totalA = $totalA + $totalTCs[0];
		$passA = $passA + $pass;
		$failA = $failA + $fail;
		$blockedA = $blockedA + $blocked;

	}elseif($priStatus == 'M3' && $M3 == "b")
	{
		$totalB = $totalB + $totalTCs[0];
		$passB = $passB + $pass;
		$failB = $failB + $fail;
		$blockedB = $blockedB + $blocked;

	}elseif($priStatus == 'M3' && $M3 == "c")
	{

		$totalC = $totalC + $totalTCs[0];
		$passC = $passC + $pass;
		$failC = $failC + $fail;
		$blockedC = $blockedC + $blocked;


	}elseif($priStatus == 'H1' && $H1 == "a")
	{

		$totalA = $totalA + $totalTCs[0];
		$passA = $passA + $pass;
		$failA = $failA + $fail;
		$blockedA = $blockedA + $blocked;

	}elseif($priStatus == 'H1' && $H1 == "b")
	{
		$totalB = $totalB + $totalTCs[0];
		$passB = $passB + $pass;
		$failB = $failB + $fail;
		$blockedB = $blockedB + $blocked;

	}elseif($priStatus == 'H1' && $H1 == "c")
	{

		$totalC = $totalC + $totalTCs[0];
		$passC = $passC + $pass;
		$failC = $failC + $fail;
		$blockedC = $blockedC + $blocked;


	}elseif($priStatus == 'H2' && $H2 == "a")
	{

		$totalA = $totalA + $totalTCs[0];
		$passA = $passA + $pass;
		$failA = $failA + $fail;
		$blockedA = $blockedA + $blocked;

	}elseif($priStatus == 'H2' && $H2 == "b")
	{
		$totalB = $totalB + $totalTCs[0];
		$passB = $passB + $pass;
		$failB = $failB + $fail;
		$blockedB = $blockedB + $blocked;

	}elseif($priStatus == 'H2' && $H2 == "c")
	{

		$totalC = $totalC + $totalTCs[0];
		$passC = $passC + $pass;
		$failC = $failC + $fail;
		$blockedC = $blockedC + $blocked;


	}elseif($priStatus == 'H3' && $H3 == "a")
	{

		$totalA = $totalA + $totalTCs[0];
		$passA = $passA + $pass;
		$failA = $failA + $fail;
		$blockedA = $blockedA + $blocked;

	}elseif($priStatus == 'H3' && $H3 == "b")
	{
		$totalB = $totalB + $totalTCs[0];
		$passB = $passB + $pass;
		$failB = $failB + $fail;
		$blockedB = $blockedB + $blocked;

	}elseif($priStatus == 'H3' && $H3 == "c")
	{

		$totalC = $totalC + $totalTCs[0];
		$passC = $passC + $pass;
		$failC = $failC + $fail;
		$blockedC = $blockedC + $blocked;


	}

}

	$notRunTCsA = $totalA - ($passA + $failA + $blockedA); //Getting the not run TCs
	
	if($totalA == 0)
	{
		$percentCompleteA = 0;

	}else
	{
		$percentCompleteA = ($passA + $failA + $blockedA) / $totalA; //Getting total percent complete
		$percentCompleteA = round((100 * ($percentCompleteA)),2); //Rounding the number so it looks pretty
	}


	$notRunTCsB = $totalB - ($passB + $failB + $blockedB); //Getting the not run TCs

	if($totalB == 0)
	{
		$percentCompleteB = 0;

	}else
	{
		$percentCompleteB = ($passB + $failB + $blockedB) / $totalB; //Getting total percent complete
		$percentCompleteB = round((100 * ($percentCompleteB)),2); //Rounding the number so it looks pretty

	}

	$notRunTCsC = $totalC - ($passC + $failC + $blockedC); //Getting the not run TCs
	
	if($totalC == 0)
	{
		$percentCompleteC= 0;

	}else
	{
		$percentCompleteC = ($passC + $failC + $blockedC) / $totalC; //Getting total percent complete
		$percentCompleteC = round((100 * ($percentCompleteC)),2); //Rounding the number so it looks pretty
	}


//This next section gets the milestones information

$sql = "select name,date,A,B,C from milestone where projid='" . $_SESSION['project'] . "' and to_days(date) >= to_days(now()) order by date limit 1";

//echo $sql;

$result = mysql_query($sql); //Run the query

$numRows = mysql_num_rows($result); //How many rows

//Check to see if there are any milestone rows

if($numRows > 0)
{

	$currentMilestone = mysql_fetch_row($result);

	$Mname=$currentMilestone[0];
	$Mdate=$currentMilestone[1];
	$MA=$currentMilestone[2];
	$MB=$currentMilestone[3];
	$MC=$currentMilestone[4];

	//This next section figures out if the status is red yellow or green..

	//Priority A's

	//Check to see if milestone is set to zero. Will cause division error

	if($MA == 0 || $totalA ==0)
	{
	
		$AStatus = "-";

	}else
	{
		if(($percentCompleteA / $MA) >= .9)
		{
			$AStatus = "<font color='#669933'>ÂÌÉ«</font>";

		}

		elseif(($percentCompleteA / $MA) >= .8)
		{
			$AStatus = '<font color="#FFCC00">»ÆÉ«</font>';
		}

		else
		{
			$AStatus = '<font color="#FF0000">ºìÉ«</font>';
		}
	}

	//Priority B's

	if($MB == 0 || $totalB ==0)
	{
	
		$BStatus = "-";
	}else
	{
		if(($percentCompleteB / $MB) >= .9)
		{
			$BStatus = "<font color='#669933'>ÂÌÉ«</font>";

		}

		elseif(($percentCompleteB/ $MB) >= .8)
		{
			$BStatus = '<font color="#FFCC00">»ÆÉ«</font>';
		}

		else
		{
			$BStatus = '<font color="#FF0000">ºìÉ«</font>';
		}

	}

	//Priority C's

	if($MC == 0 || $totalC ==0)
	{
	
		$CStatus = "-";
	}else
	{
		if(($percentCompleteC / $MC) >= .9)
		{
			$CStatus = "<font color='#669933'>ÂÌÉ«</font>";

		}

		elseif(($percentCompleteC / $MC) >= .8)
		{
			$CStatus = '<font color="#FFCC00">»ÆÉ«</font>';
		}

		else
		{
			$CStatus = '<font color="#FF0000">ºìÉ«</font>';
		}
	}
	
}else//If there are no milestone rows then I want to display this data
	{
	
		

		$Mname= "None";
		$Mdate= "None";
		$MA= "-";
		$MB= "-";
		$MC= "-";
		$AStatus= "-"; 
	    $BStatus= "-";
        $CStatus= "-";

	}
	
	
	
    echo "<font size='4'>¹¹¼þ " . $build . " µÄ½á¹û</font><br>";
    
    
    //require_once section. These require_onces will show the entire project information on the screen
    
    
    
    //Display the priority table
    
    echo "<br><table class=userinfotable width=100%><tr><td bgcolor='#99CCFF' class='subTitle'>ÓÅÏȼ¶×´Ì¬</td></tr>";
    
    //Displays the most current Milestone and Date
    
    echo "<tr><td><b>µ±Ç°Àï³Ì±®: </b>" . $Mname . "<br><b>½áÊøÈÕÆÚ: </b>" . $Mdate . "</td></tr></table>";
    
    //I want a new table for the name of the display data
    
    echo "<table width='100%' class=userinfotable>";
    
    //Setting up the header row
    
    echo "<tr><td width='11%' class=tctablehdrCenter >ÓÅÏȼ¶</td><td width='11%' class=tctablehdrCenter>×ܼÆ</td><td width='11%' class=tctablehdrCenter>״̬</td><td width='11%' class=tctablehdrCenter>ͨ¹ý</td><td width='11%' class=tctablehdrCenter>ʧ°Ü</td><td width='11%' class=tctablehdrCenter>×èÈû</td><td width='11%' class=tctablehdrCenter>δÔËÐÐ</td><td width='11%' class=tctablehdrCenter>ÒÑÍê³É(%)</td><td class=tctablehdrCenter>Àï³Ì±®Ä¿±ê</td></tr>";
    
    
    //Finally, the display
    
    echo "<tr><td bgcolor='#CCCCCC' class='boldFont' align='center'>A</td><td class='font' align='center'>" . $totalA . "</td><td class='font' align='center'>" . $AStatus . "</td><td class='font' align='center'>" . $passA . "</td><td class='font' align='center'>" . $failA . "</td><td class='font' align='center'>" . $blockedA . "</td><td class='font' align='center'>" . $notRunTCsA . "</td><td class='font' align='center'>" . $percentCompleteA . "%</td><td class='font' align='center'>" . $MA . "%</td></tr>";
    
    echo "<tr><td bgcolor='#CCCCCC' class='boldFont' align='center'>B</td><td class='font' align='center'>" . $totalB . "</td><td class='font' align='center'>" . $BStatus . "</td><td class='font' align='center'>" . $passB . "</td><td class='font' align='center'>" . $failB . "</td><td class='font' align='center'>" . $blockedB . "</td><td class='font' align='center'>"  . $notRunTCsB . "</td><td class='font' align='center'>" . $percentCompleteB . "%</td><td class='font' align='center'>" . $MB . "%</td></tr>";
    
    echo "<tr><td bgcolor='#CCCCCC' class='boldFont' align='center'>C</td><td class='font' align='center'>" . $totalC . "</td><td class='font' align='center'>" . $CStatus . "</td><td class='font' align='center'>" . $passC . "</td><td class='font' align='center'>" . $failC . "</td><td class='font' align='center'>" . $blockedC . "</td><td class='font' align='center'>"  . $notRunTCsC. "</td><td class='font' align='center'>" . $percentCompleteC . "%</td><td class='font' align='center'>" . $MC . "%</td></tr>";
    
    
    echo "</table>";
    
    
    ////////////////////////////////////////////////////////////////////////////////
//File:     totalComponent.php
//Author:   Chad Rosen
//Purpose:  This page displays test cases by component.
////////////////////////////////////////////////////////////////////////////////

////The table and the top row

echo "<br><table width='100%' class=userinfotable><tr><td bgcolor='#99CCFF' class='subTitle'>×é¼þ״̬</td></tr></table>";

echo "<table width='100%' class=userinfotable>";

echo "<tr><td width='14%' class=tctablehdrCenter>×é¼þ</td><td width='14%' class=tctablehdrCenter>×ܼÆ</td><td width='14%' class=tctablehdrCenter>ͨ¹ý</td><td width='14%' class=tctablehdrCenter>ʧ°Ü</td><td width='14%' class=tctablehdrCenter>×èÈû</td><td width='14%' class=tctablehdrCenter>δÔËÐÐ</td><td width='14%' class=tctablehdrCenter>ÒÑÍê³É(%)</td></tr>";

//Begin code to display the component


$sql = "select component.name, component.id from project,component where project.id = '" . $_SESSION['project'] . "' and project.id = component.projid";
//$sql = "select component.name, component.id from project,component,results,testcase,category,build where project.id='" . $_SESSION['project'] . "' and project.id=component.projid and component.id=category.compid and category.id=testcase.catid and testcase.id=results.tcid and results.build=build.build and build.build='104';
$result = mysql_query($sql);

while ($myrow = mysql_fetch_row($result)) 
{

	//Code to grab the entire amount of test cases per project
	
	$sql = "select count(testcase.id) from project,component,category,testcase where project.id = '" . $_SESSION['project'] . "' and component.id='" . $myrow[1] . "' and project.id = component.projid and component.id = category.compid and category.id = testcase.catid";

	$totalTCResult = mysql_query($sql);

	$totalTCs = mysql_fetch_row($totalTCResult);

	//Code to grab the results of the test case execution

	$sql = "select tcid,status from results,project,component,category,testcase where project.id = '" . $_SESSION['project'] . "' and component.id='" . $myrow[1] . "' and project.id = component.projid and component.id = category.compid and category.id = testcase.catid and testcase.id = results.tcid and build='" . $build . "'";

	$totalResult = mysql_query($sql);

	//Setting the results to an array.. Only taking the most recent results and displaying them
	
	while($totalRow = mysql_fetch_row($totalResult))
	{

		//This is a test.. I've got a problem if the user goes and sets a previous p,f,b value to a 'n' value. The program then sees the most recent value as an not run. I think we want the user to then see the most recent p,f,b value
		
		//if($totalRow[1] == 'n')
		//{

		//}
		//else
		//{
		
		$testCaseArray[$totalRow[0]] = $totalRow[1];
		
		//}

	}



	//This is the code that determines the pass,fail,blocked amounts

	$arrayCounter = 0; //Counter

	//Initializing variables

	$pass = 0;
	$fail = 0;
	$blocked = 0;
	$notRun = 0;


	//I had to write this code so that the loop before would work.. I'm sure there is a better way to do it but hell if I know how to figure it out..
	
	if(count($testCaseArray) > 0)
	{

		foreach($testCaseArray as $tc)
		{

			if($tc == 'p')
			{
				
				$pass++;
				

			}

			elseif($tc == 'f')
			{

				$fail++;

			}

			elseif($tc == 'b')

			{

				$blocked++;

			}
			elseif($tc == 'n')

			{

				$notRun++;

			}

			unset($testCaseArray);


		}//end foreach

	}//end if


	//This loop will cycle through the arrays and count the amount of p,f,b,n
	

	if($totalTCs[0] == 0)
	{
		$percentComplete= 0;

	}else
	{
		$percentComplete = ($pass + $fail + $blocked) / $totalTCs[0]; //Getting total percent complete
		$percentComplete = round((100 * ($percentComplete)),2); //Rounding the number so it looks pretty
	}


		
	$notRunTCs = $totalTCs[0] - ($pass + $fail + $blocked); //Getting the not run TCs

	
	

	//Displaying the results
				
	echo "<td  bgcolor='#CCCCCC' class='boldFont' align='center'>" . $myrow[0] . "</td>"; //displaying the component name
	
	echo "<td class='font' align='center'>" . $totalTCs[0] . "</td>";

	echo "<td class='font' align='center'>" . $pass . "</td>";

	echo "<td class='font' align='center'>" . $fail . "</td>";

	echo "<td class='font' align='center'>" . $blocked . "</td>";

	echo "<td class='font' align='center'>" . $notRunTCs . "</td>"; //<td>" .  round((100 * ($notRun/$total)),2) . "</td>";

	echo "<td class='font' align='center'>" . $percentComplete . "</td></tr>";


}

echo "</table><br>";
    
    ////////////////////////////////////////////////////////////////////////////////
//File:     owner.php
//Author:   Chad Rosen
//Purpose:  This page does something associated with owner and stats????
////////////////////////////////////////////////////////////////////////////////

echo "<table width='100%' class=userinfotable><tr><td bgcolor='#99CCFF' class='subTitle'>ËùÓÐÕß״̬</td></tr></table>";

echo "<table class=userinfotable width='100%'>";

echo "<tr><td width='14%' class=tctablehdrCenter>ËùÓÐÕß</td><td width='14%' class=tctablehdrCenter>×ܼÆ</td><td width='14%' class=tctablehdrCenter>ͨ¹ý</td><td width='14%' class=tctablehdrCenter>ʧ°Ü</td><td width='14%' class=tctablehdrCenter>×èÈû</td><td width='14%' class=tctablehdrCenter>δÔËÐÐ</td><td width='14%' class=tctablehdrCenter>ÒÑÍê³É(%)</td></tr>";


$sql = "select category.owner, category.id from project,component, category where project.id = '" . $_SESSION['project'] . "' and project.id = component.projid and component.id = category.compid group by owner";

//Begin code to display the component


$result = mysql_query($sql);

while ($myrow = mysql_fetch_row($result)) 
{

	//Code to grab the entire amount of test cases per project
	
	$sql = "select count(testcase.id) from project,component,category,testcase where project.id = '" . $_SESSION['project'] . "' and project.id = component.projid and category.owner ='" . $myrow[0] . "' and component.id = category.compid and category.id = testcase.catid";

	$totalTCResult = mysql_query($sql);

	$totalTCs = mysql_fetch_row($totalTCResult);

	//Code to grab the results of the test case execution

	$sql = "select tcid,status from results,project,component,category,testcase where project.id = '" . $_SESSION['project'] . "' and category.owner='" . $myrow[0] . "' and project.id = component.projid and component.id = category.compid and category.id = testcase.catid and testcase.id = results.tcid and build='" . $build . "'";

	$totalResult = mysql_query($sql);

	//Setting the results to an array.. Only taking the most recent results and displaying them
	
	while($totalRow = mysql_fetch_row($totalResult))
	{
		//echo $totalRow[0] . " " . $totalRow[1] . "<br>";

		//This is a test.. I've got a problem if the user goes and sets a previous p,f,b value to a 'n' value. The program then sees the most recent value as an not run. I think we want the user to then see the most recent p,f,b value
		
		
		
		$testCaseArray[$totalRow[0]] = $totalRow[1];
		


	}



	//This is the code that determines the pass,fail,blocked amounts

	$arrayCounter = 0; //Counter

	//Initializing variables

	$pass = 0;
	$fail = 0;
	$blocked = 0;
	$notRun = 0;


	//I had to write this code so that the loop before would work.. I'm sure there is a better way to do it but hell if I know how to figure it out..

if(count($testCaseArray) > 0)
	{


		//This loop will cycle through the arrays and count the amount of p,f,b,n

		foreach($testCaseArray as $tc)
		{

			if($tc == 'p')
			{
				
				$pass++;
				

			}

			elseif($tc == 'f')
			{

				$fail++;

			}

			elseif($tc == 'b')

			{

				$blocked++;

			}
            elseif($tc == 'n')

			{

				$notRun++;

			}

		}//end foreach

	}//end if

/*

	while($arrayCounter < $TTRC[0])
	{

		if($testCaseArray[$arrayCounter] == 'p')
		{
			
			$pass++;
			

		}

		elseif($testCaseArray[$arrayCounter] == 'f')
		{

			$fail++;

		}

		elseif($testCaseArray[$arrayCounter] == 'b')

		{

			$blocked++;

		}
	

		$arrayCounter++; //increment the counter

	}
*/

		//destroy the testCaseArray variable

		unset($testCaseArray);

		
		$notRunTCs = $totalTCs[0] - ($pass + $fail + $blocked); //Getting the not run TCs

		
		if($totalTCs[0] == 0) //if we try to divide by 0 we get an error
		{
			$percentComplete = 0;

		}else
		{
	
			$percentComplete = ($pass + $fail + $blocked) / $totalTCs[0]; //Getting total percent complete
			$percentComplete = round((100 * ($percentComplete)),2); //Rounding the number so it looks pretty
		
		}		

		//Displaying the results
					
		echo "<td  bgcolor='#CCCCCC' class='boldFont' align='center'>" . $myrow[0] . "</td>"; //displaying the component name
		
		echo "<td class='font' align='center'>" . $totalTCs[0] . "</td>";

		echo "<td class='font' align='center'>" . $pass . "</td>";

		echo "<td class='font' align='center'>" . $fail . "</td>";

		echo "<td class='font' align='center'>" . $blocked . "</td>";

		echo "<td class='font' align='center'>" . $notRunTCs . "</td>";

		echo "<td class='font' align='center'>" . $percentComplete . "</td></tr>";

	//}

	//$owner = $myrow[0];


	//$counter++;

}

echo "</table><br>";
    
////////////////////////////////////////////////////////////////////////////////
//File:     keywords.php
//Author:   Chad Rosen
//Purpose:  This page generates reports by keyword.
////////////////////////////////////////////////////////////////////////////////


//require_once("../functions/header.php");

  //session_start();
  //doDBConnect();
  //doHeader();

	require_once("../functions/csvSplit.php");

		$sqlKeyword = "select keywords from project, component, category, testcase where project.id = " .  $_SESSION['project'] . " and project.id = component.projid and component.id = category.compid and category.id = testcase.catid order by keywords";

		//echo $sqlKeyword;

		//Execute the query

		$resultKeyword = mysql_query($sqlKeyword);

		//Loop through each of the testcases

		while ($myrowKeyword = mysql_fetch_row($resultKeyword)) 
			{

				//This next function calls the csv_split function which can be found at the very bottom of this page
				//The function takes a string of comma seperated values and returns them as an array

				$keyArray = csv_split($myrowKeyword[0]);

				//Take the array that is created from the keywords and add it to another array named result2

				$result2 = array_merge ($result2, $keyArray);


			}//END WHILE

	

		//I need to make sure there are elements in the result 2 array. I was getting an error when I didn't check


		if(count($result2) > 0) 
		{

			//This next function takes the giant array that we created, which is full of duplicate values, and
			//only keeps the unique values. LONG LIVE PHP!

			$result3 = array_unique ($result2);

			//In order to loop through the array I need to change the keys of the array so that they are numerically in order

			$i=0;

			foreach ($result3 as $key)
			{
		
				$result4[$i] = $key;
				$i++;

			}

		}


	echo "<table width='100%' class=userinfotable><tr><td bgcolor='#99CCFF' class='subTitle'>¹Ø¼ü×Ö״̬</td></tr></table>";

	echo "<table class=userinfotable width='100%'>";

	echo "<tr><td width='14%' class=tctablehdrCenter>¹Ø¼ü×Ö</td><td width='14%' class=tctablehdrCenter>×ܼÆ</td><td width='14%' class=tctablehdrCenter>ͨ¹ý</td><td width='14%' class=tctablehdrCenter>ʧ°Ü</td><td width='14%' class=tctablehdrCenter>×èÈû</td><td width='14%' class=tctablehdrCenter>δÔËÐÐ</td><td width='14%' class=tctablehdrCenter>ÒÑÍê³É(%)</td></tr>";


		for ($i = 0; $i < count($result4); $i++)
		{

			//For some reason I'm getting a space.. Now I'll ignore any spaces

			if($result4[$i] != "")
			{
				
				
				//Code to grab the entire amount of test cases per project
	
				$sql = "select count(testcase.id) from project,component,category,testcase where project.id = '" . $_SESSION['project'] . "' and project.id = component.projid and component.id = category.compid and category.id = testcase.catid and keywords like '%" . $result4[$i] . "%'";

				//echo $sql . "<br><br>";

				$totalTCResult = mysql_query($sql);

				$totalTCs = mysql_fetch_row($totalTCResult);

				//Code to grab the results of the test case execution

				$sql = "select tcid,status from results,project,component,category,testcase where project.id = '" . $_SESSION['project'] . "' and project.id = component.projid and component.id = category.compid and category.id = testcase.catid and testcase.id = results.tcid and keywords like '%" . $result4[$i] . "%' and build='" . $build . "'";

				$totalResult = mysql_query($sql);

				//Setting the results to an array.. Only taking the most recent results and displaying them
	
				while($totalRow = mysql_fetch_row($totalResult))
				{

				//This is a test.. I've got a problem if the user goes and sets a previous p,f,b value to a 'n' value. The program then sees the most recent value as an not run. I think we want the user to then see the most recent p,f,b value
		
				
				
				$testCaseArray[$totalRow[0]] = $totalRow[1];
				


				}



			//This is the code that determines the pass,fail,blocked amounts

			$arrayCounter = 0; //Counter

			//Initializing variables

			$pass = 0;
			$fail = 0;
			$blocked = 0;
			$notRun = 0;


			//I had to write this code so that the loop before would work.. I'm sure there is a better way to do it but hell if I know how to figure it out..
			
		//	$sqlC = "select max(testcase.id) from testcase";

		//	$TTR = mysql_query($sqlC);

		//	$TTRC = mysql_fetch_row($TTR);

if(count($testCaseArray) > 0)
{

	foreach($testCaseArray as $tc)
	{

		if($tc == 'p')
		{
			
			$pass++;
			

		}

		elseif($tc == 'f')
		{

			$fail++;

		}

		elseif($tc == 'b')

		{

			$blocked++;

		}
		elseif($tc == 'n')

		{
			$notRun++;

		}


	}//end for each

}//end if



				//destroy the testCaseArray variable

				unset($testCaseArray);

				
				$notRunTCs = $totalTCs[0] - ($pass + $fail + $blocked); //Getting the not run TCs

				
				if($totalTCs[0] == 0) //if we try to divide by 0 we get an error
				{
					$percentComplete = 0;

				}else
				{
			
					$percentComplete = ($pass + $fail + $blocked) / $totalTCs[0]; //Getting total percent complete
					$percentComplete = round((100 * ($percentComplete)),2); //Rounding the number so it looks pretty
				
				}		

				//Displaying the results
							
				echo "<td  bgcolor='#CCCCCC' class='boldFont' align='center'>" . $result4[$i] . "</td>"; //displaying the component name
				
				echo "<td class='font' align='center'>" . $totalTCs[0] . "</td>";

				echo "<td class='font' align='center'>" . $pass . "</td>";

				echo "<td class='font' align='center'>" . $fail . "</td>";

				echo "<td class='font' align='center'>" . $blocked . "</td>";

				echo "<td class='font' align='center'>" . $notRunTCs . "</td>";

				echo "<td class='font' align='center'>" . $percentComplete . "</td></tr>";


				//$counter++;

			}
				
				
				
				//echo "<tr><td>" . $result4[$i];
			}//
		echo "</table>";
$isel++;
}
?>
Return current item: Testlink in Chinese