<?php
#replaces bothrorg.html

echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
echo '<HTML>';

include 'allhere.php';

#----------------------------------------------
#begin setup
if ($_SERVER[SERVER_ADDR]!=$_SERVER[SERVER_NAME])
	{$findserver=$_SERVER[SERVER_NAME]. ':' .$_SERVER[SERVER_PORT];}
else
	{$findserver=$_SERVER[SERVER_ADDR]. ':' .$_SERVER[SERVER_PORT];}
if ($_SERVER[HTTPS]=='on')
	{$thisserver = 'https://' .$findserver;}
else
	{$thisserver = 'http://' .$findserver;}
#echo '<p>ts ' .$thisserver; #ok

$data_base='bidp'; #mysql
$table1='direct';
$table2='countrycodes';

$connect="pear_connect";

include 'all.php';
require 'DB.php';

$connect() #mysql not mysqli
	or die("<p>Could not connect to mysql");
$link=$connect() #pear for mysql
	or die("<p>Could not link to mysql");
$link->setFetchMode(DB_FETCHMODE_ASSOC);
#end setup
#----------------------------------------------


?>
<HEAD>
	<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
	<TITLE>BIDP organisation lists: related</TITLE>
	<META NAME="GENERATOR" CONTENT="LibreOffice 3.3  (Linux)">
	<META NAME="AUTHOR" CONTENT="David Young">
	<META NAME="CREATED" CONTENT="19991207;20451100">
	<META NAME="CHANGED" CONTENT="20111004;12494800">
	

<?php
#----------------------------------------------
echo $stylebidp;

echo '<table width=100% bgcolor="yellow">';
echo "<tr><td><IMG SRC=\"$thisserver/data/images/180609-novologo.gif\" NAME=\"novologo1\" ALIGN=LEFT WIDTH=250 HEIGHT=100 BORDER=0></td></tr>";
echo '</table>';
echo '<H1><FONT COLOR="red">Other organisations specifically or broadly relating to development in Botswana.</FONT></H1>';
echo '</HEAD>';

$sadc=$link->getAll("SELECT cc FROM $table2 WHERE sadc=1 and cc!='bw' ORDER BY countryname");
$countsadc=count($sadc);

$africa=$link->getAll("SELECT cc FROM $table2 WHERE africa=1 and cc!='bw' ORDER BY countryname");
$countafrica=count($africa); #number of countries in africa 28fe19
#$allafrica=$countafrica+1;
#echo '<p>aa=' .$allafrica; #53 at 28fe19

$world=$link->getAll("SELECT cc FROM $table2 WHERE africa != 1 ORDER BY countryname");
$countccworld=count($world); #number of countries outside africa includes continents, strays but not africa 28fe19
#echo '<p>ccw=' .$countccworld;
#echo '<p>';
#print_r($world); #ok 196 at 28fe19


echo '<BODY BGCOLOR="#cccccc">';
#----------------------------------------------


#----------------------------------------------
#begin first display
echo '<H2><font color="orange">National</font></H2>';

$getnational=$link->getAll("SELECT * FROM bidp.direct WHERE jurisdiction='bw' AND name>'' AND category LIKE '%related%'  ORDER BY name"); #AND exist='y' AND LEFT(deleted,10) < '1984-07-01'
$countnational=count($getnational); #actual related sites

#echo '<p>countnational=' .$countnational;
#echo '<p>';
#print_r($getnational);

echo '<tr><td colspan=5><hr></td></tr>';
echo '<table>';
#echo $heading;
$a=0;
for ($a=0; $a<$countnational; $a++)
{
	echo '<tr>';
	echo '<td>' .$getnational[$a]['name']. '</td><td>' .$getnational[$a]['address1']. '</td><td>' .$getnational[$a]['address2']. '</td><td>' .$getnational[$a]['address3']. '</td><td>' .$getnational[$a]['phonework']. '</td>';
	echo '<tr>';
}
#echo '</table>';
echo '<tr><td colspan=5><hr></td></tr>';
#end first display
#----------------------------------------------


#----------------------------------------------
#begin second display
echo '<tr><td colspan=5><H2><font color="orange">Rest of SADC</font></H2></td></tr>';
#print_r($sadc); #ok

$getregional=$link->getAll("SELECT * FROM bidp.direct WHERE jurisdiction != 'bw' AND (category LIKE '%related%') AND name>'' ORDER BY name"); #actual related sites

echo '<hr>';
#echo '<p>cs=' .$countsadc; #ok 27fe19

#echo '<table width=100%>';
#echo $heading;
$thiscode='';
$a=0;
$sadccodes='';
for ($a=0; $a<$countsadc; $a++)
{
	$thiscode=$sadc[$a]['cc'];
	#echo '<tr>';
	#echo '<td>cc=' .$thiscode. '</td>'; #ok
	$getsadc=$link->getAll("SELECT * FROM bidp.direct WHERE jurisdiction != 'bw' AND jurisdiction='$thiscode' AND (category LIKE '%related%') AND name>'' ORDER BY name");
	$countgetsadc=count($getsadc); #actual related orgs for geogroup sadc
	
	#echo '<td>gs=';
	#print_r($getsadc);
	#echo '</td>';
	
	if ($countgetsadc>0) #there is at least 1 record
	{
		$sadclist='';
		#echo "<tr>";
		#echo "<td>csc=$countgetsadc</td>";
		#echo '<td>gs=>';
		#print_r($getsadc);
		#echo '</td>';
		#echo "<tr><td>a=$a</td>"; #ok
		$r=0;
		for ($r=0; $r<$countgetsadc; $r++)
		{
			#echo '<tr>';
			#echo "<td>$r $thiscode</td>"; #ok 28fe19
			#echo '<td>yes</td>'; #ok 28fe19
			$makesadc=$link->getAll("SELECT name, address1, address2, address3, phonework, jurisdiction FROM bidp.direct WHERE jurisdiction='$thiscode' AND (category LIKE '%related%') AND name>''"); #actual related orgs list for this jurisdiction
			#echo '<td>ms>>';
			#print_r($makesadc);
			#echo '</td>';
			
			$rname=$makesadc[$r]['name'];
			#echo "<td>rn=$rname</td>"; #ok 28fe19
			$rad1=$getsadc[$r]['address1'];
			$rad2=$getsadc[$r]['address2'];
			$rad3=$getsadc[$r]['address3'];
			$rjur=$getsadc[$r]['jurisdiction'];
			$rwphone=$getsadc[$a]['workphone'];
			#echo '</tr>';
			if ($r==0)
				{$sadclist = "<tr><td>$rname</td><td>$rad1</td><td>$rad2</td><td>$rad3</td><td>$rwphone</td></tr>";}
			else
				{$sadclist = $sadclist."<tr><td>$rname</td><td>$rad1</td><td>$rad2</td><td>$rad3</td><td>$rwphone</td></tr>";}			
		}
		echo $sadclist;
	}	
}
#echo '</table>';
echo '<tr><td colspan=5><hr></td></tr>';
#end second display
#----------------------------------------------


#----------------------------------------------
#begin third display
echo '<tr><td colspan=5><H2><font color="orange">Rest of Africa</font></H2></td></tr>';

##echo '<p>show africa=';
##print_r($africa);

$getcontinental=$link->getAll("SELECT * FROM bidp.direct WHERE jurisdiction != 'bw' AND (category LIKE '%related%') AND name>'' ORDER BY name"); 
$countcontinental=count($getcontinental); #all except bw

#echo '<p>countcontinental=' .$countcontinental;
#echo '<p>';
#print_r($getcontinental);

echo '<tr><td colspan=5><hr></td></tr>';
#echo '<p>cs=' .$countafrica; #ok 27fe19

#echo '<table width=100%>';
#echo $heading;
$thiscode='';
$a=0;
$africacodes='';
for ($a=0; $a<$countafrica; $a++)
{
	$thiscode=$africa[$a]['cc']; #all codes in africa
	#echo '<tr>';
	#echo '<td>cc=' .$thiscode. '</td>'; #ok
	$getafrica=$link->getAll("SELECT * FROM bidp.direct WHERE jurisdiction != 'bw' AND jurisdiction='$thiscode' AND (category LIKE '%related%') AND name>'' ORDER BY name");
	$countgetafrica=count($getafrica); #actual related sites this geogroup
	
	#echo '<td>gs=';
	#print_r($getsadc);
	#echo '</td>';
	
	if ($countgetafrica>0) #there is at least 1 record
	{
		$africalist='';
		#echo "<tr>";
		#echo "<td>csc=$countgetsadc</td>";
		#echo '<td>gs=>';
		#print_r($getsadc);
		#echo '</td>';
		#echo "<tr><td>a=$a</td>"; #ok
		$r=0;
		for ($r=0; $r<$countgetafrica; $r++)
		{
			#echo '<tr>';
			#echo "<td>$r $thiscode</td>"; #ok 28fe19
			#echo '<td>yes</td>'; #ok 28fe19
			$makeafrica=$link->getAll("SELECT name, address1, address2, address3, phonework, jurisdiction FROM bidp.direct WHERE jurisdiction='$thiscode' AND (category LIKE '%related%') AND name>''"); #actual related sites this jurisdiction
			
			#echo '<td>ms>>';
			#print_r($makesadc);
			#echo '</td>';
			
			$cname=$makeafrica[$r]['name'];
			#echo "<td>rn=$rname</td>"; #ok 28fe19
			$cad1=$makeafrica[$r]['address1'];
			$cad2=$makeafrica[$r]['address2'];
			$cad3=$makeafrica[$r]['address3'];
			$cjur=$getafrica[$r]['jurisdiction'];
			$cwphone=$makeafrica[$a]['workphone'];
			#echo '</tr>';
			if ($r==0)
				{$africalist = "<tr><td>$cname</td><td>$cad1</td><td>$cad2</td><td>$cad3</td><td>$cwphone</td></tr>";}
			else
				{$africalist = $africalist."<tr><td>$cname</td><td>$cad1</td><td>$cad2</td><td>$cad3</td><td>$cwphone</td></tr>";}			
		}
		echo $africalist;
	}	
}
#echo '</table>';
echo '<tr><td colspan=5><hr></td></tr>';
#end third display
#----------------------------------------------


#----------------------------------------------
#begin 4th display
echo '<td colspan=5><H2><font color="orange">Diaspora</font></H2></td></tr>';

#echo '<p>show world=';
#print_r($world); #ok 28fe19
$getworld=$link->getAll("SELECT * FROM bidp.direct WHERE  (category LIKE '%related%') AND name>'' ORDER BY name"); 
$countworld=count($getworld); #actual related sites, named in whole world 28fe19



echo '<tr><td colspan=5><hr></td></tr>';
#echo '<tr><td>cwc=' .$countccworld. '</td></tr>'; #ok 27fe19 number of codes

#echo '<table width=100%>';
#echo $heading;
$thiscode='';
$a=0;
$worldcodes='';
for ($a=0; $a<$countccworld; $a++)
{
	$thiscode=$world[$a]['cc']; #all non-africa list of codes
	#echo '<tr>';
	#echo '<tr><td>cc=' .$thiscode. '</td></tr>'; #ok but not all: why not?
	
	$getworld=$link->getAll("SELECT * FROM bidp.direct WHERE   jurisdiction='$thiscode' AND (category LIKE '%related%') AND name>'' ORDER BY name"); #actual related orgs for any non-africa codes
	$countgetworld=count($getworld);
	#$countgetworld=$countgetworld-$countcontinental;
	
	#echo '<td>gw=';
	#print_r($getworld);
	#echo '</td>';
	
	if ($countgetworld>0) #there is at least 1 record
	{
		$worldlist='';
		#echo "<tr>";
		#echo "<td>cgw=$countgetworld</td>";
		#echo '<td>gw=>';
		#print_r($getworld);
		#echo '</td>';
		#echo "<tr><td>a=$a</td>"; #ok
		$r=0;
		for ($r=0; $r<$countgetworld; $r++)
		{
			#echo '<tr>';
			#echo "<td>$r $thiscode</td>"; #ok 28fe19
			#echo '<td>yes</td>'; #ok 28fe19
			$makeworld=$link->getAll("SELECT name, address1, address2, address3, phonework, jurisdiction FROM bidp.direct WHERE jurisdiction='$thiscode' AND (category LIKE '%related%') AND name>''"); #actual related orgs for this geocode
			
			#echo '<td>ms>>';
			#print_r($makesadc);
			#echo '</td>';
			$wname=$makeworld[$r]['name'];
			#echo "<td>rn=$rname</td>"; #ok 28fe19
			$wad1=$makeworld[$r]['address1'];
			$wad2=$makeworld[$r]['address2'];
			$wad3=$makeworld[$r]['address3'];
			$wjur=$makeworld[$r]['jurisdiction'];
			$wwphone=$makeworld[$a]['workphone'];			

			if ($r==0)
				{$worldlist = "<tr><td>$wname</td><td>$wad1</td><td>$wad2</td><td>$wad3</td><td>$wwphone</td></tr>";}
			else
				{$worldlist = $worldlist."<tr><td>$wname</td><td>$wad1</td><td>$wad2</td><td>$wad3</td><td>$wwphone</td></tr>";}
		}
		echo $worldlist;
	}	
}
echo '</table>';
echo '<hr>';
#end 4th display
#----------------------------------------------


echo '<p><FONT SIZE=1 STYLE="font-size: 8pt">Please advise the secretary if links are broken; They are as current as our resources permit.</FONT>';
echo $madehere;
echo '<p>Started  before 8se11';
echo '</BODY>';
echo '</HTML>';
?>