| Current Path : /var/www/cesa.co.za/php/ |
| Current File : /var/www/cesa.co.za/php/querynlcmatrix.php4 |
<?php
// Database Connection String
require_once("template.php");
$options = array("filename"=>$templatefilename, "debug"=>0, "die_on_bad_params"=>0, "global_vars"=>1);
$template =& new Template($options);
$bRecordsFound = 0;
$bRecordsFoundThis = 0;
function GetSection($clientbodytypeA, $spriority)
{
global $clientarray;
global $memberarray;
global $ClientBodyName;
global $bRecordsFound;
global $bRecordsFoundThis;
$bRecordsFoundThis = 0;
$sql = "SELECT NLCClientBody.ClientBodyID, NLCClientBody.ClientBodyName, NLCClientBody.ClientBodyURL, NLCClientBody.ClientBodyEmail, NLCClientBody.ClientBodyTel,
NLCMembers.NLCMemberBranch, NLCMembers.NLCMemberType, CONCAT_WS(' ',Contacts.ContactFirstName,Contacts.ContactSurname) AS ContactName,
Contacts.PersonalTel, Contacts.PersonalFax, Contacts.PreferredEmail, NLCClientBody.ClientBodyFax, NLCClientBody.ClientBodyTypeA,
NLCClientBody.ClientBodyTypeB, NLCClientBody.ClientBodyGeographic, Contacts.ContactSurname, NLCClientBody.CBContact1Surname, NLCClientBody.CBContact1FirstName,
NLCClientBody.CBContact1Designation, NLCClientBody.CBContact1Tel
FROM NLCClientBody LEFT JOIN (NLCMembers INNER JOIN Contacts ON (NLCMembers.NLCMemberContactID=Contacts.ContactsID)) ON NLCClientBody.ClientBodyID=NLCMembers.ClientBodyID
WHERE (((NLCClientBody.ClientBodyTypeA)='".$clientbodytypeA."'))";
if (!empty($spriority)) $sql .= " AND CBPriority='".$spriority."'";
if ($ClientBodyName) {
if ($ClientBodyName != '') {
$sql = $sql . " AND UPPER(NLCClientBody.ClientBodyName) LIKE '%" . strtoupper($ClientBodyName) . "%'";
}
}
$sql = $sql . " ORDER BY ClientBodyName, NLCMemberType, ContactSurname";
// echo $sql;
$result=mysql_query($sql);
$bRecordsFoundThis = mysql_num_rows($result);
$bRecordsFound = $bRecordsFound + $bRecordsFoundThis;
// echo "RecordsFound = ".$bRecordsFoundThis;
$prev_client_body_id = -1;
$firsttime = 1;
while ($row=mysql_fetch_array($result)) {
if ($firsttime == 1) {
// First pass through the loop, setup the variables
$client_body_id = $row["ClientBodyID"];
$client_body_name = $row["ClientBodyName"];
$client_body_url = $row["ClientBodyURL"];
$client_body_email = $row["ClientBodyEmail"];
$client_body_tel = $row["ClientBodyTel"];
$client_body_fax = $row["ClientBodyFax"];
$client_body_contact1firstname = $row["CBContact1FirstName"];
$client_body_contact1surname = $row["CBContact1Surname"];
$client_body_contact1designation = $row["CBContact1Designation"];
$client_body_contact1tel = $row["CBContact1Tel"];
$firsttime = 0;
}
// Have we rolled over to a new client body?
if ($client_body_id != $row["ClientBodyID"]) {
$clientarray[] = array('ClientBodyID'=>$client_body_id,
'ClientBodyName'=>$client_body_name,
'ClientBodyURL'=>$client_body_url,
'ClientBodyEmail'=>$client_body_email,
'ClientBodyTel'=>$client_body_tel,
'ClientBodyFax'=>$client_body_fax,
'CBContact1FirstName'=>$client_body_contact1firstname,
'CBContact1Surname'=>$client_body_contact1surname,
'CBContact1Designation'=>$client_body_contact1designation,
'CBContact1Tel'=>$client_body_contact1tel,
'detail'=>$memberarray);
unset($memberarray);
// Set the variables to the new set
$client_body_id = $row["ClientBodyID"];
$client_body_name = $row["ClientBodyName"];
$client_body_url = $row["ClientBodyURL"];
$client_body_email = $row["ClientBodyEmail"];
$client_body_tel = $row["ClientBodyTel"];
$client_body_fax = $row["ClientBodyFax"];
$client_body_contact1firstname = $row["CBContact1FirstName"];
$client_body_contact1surname = $row["CBContact1Surname"];
$client_body_contact1designation = $row["CBContact1Designation"];
$client_body_contact1tel = $row["CBContact1Tel"];
}
// Create the array of contact info
$memberarray[] = array('NLCMemberType'=>$row["NLCMemberType"],
'ContactName'=>$row["ContactName"],
'PersonalTel'=>$row["PersonalTel"],
'PreferredEmail'=>$row["PreferredEmail"]);
}
//Finish off by writing out the last set of info
$clientarray[] = array('ClientBodyID'=>$client_body_id,
'ClientBodyName'=>$client_body_name,
'ClientBodyURL'=>$client_body_url,
'ClientBodyEmail'=>$client_body_email,
'ClientBodyTel'=>$client_body_tel,
'ClientBodyFax'=>$client_body_fax,
'CBContact1FirstName'=>$client_body_contact1firstname,
'CBContact1Surname'=>$client_body_contact1surname,
'CBContact1Designation'=>$client_body_contact1designation,
'CBContact1Tel'=>$client_body_contact1tel,
'detail'=>$memberarray);
return array($bRecordsFoundThis, $clientarray);
}
$bShowNational = 0;
$bShowFunding = 0;
$bShowAssociations = 0;
if ($ClientBodyTypeA) {
if ($ClientBodyTypeA == 'National') {
$bShowNational = 1;
}
if ($ClientBodyTypeA == 'Funding Agencies') {
$bShowFunding = 1;
}
if ($ClientBodyTypeA == 'Associations, Federations and Institutions') {
$bShowAssociations = 1;
}
} else {
$bShowNational = 1;
$bShowFunding = 1;
$bShowAssociations = 1;
}
if ($bShowNational == 1) {
// Get the priority committees first
$SectionReturn=GetSection('National','y');
$bRecordsFoundThis = $SectionReturn[0];
$clientarray = $SectionReturn[1];
$bRecordsFound = $bRecordsFound + $bRecordsFoundThis;
if ($bRecordsFoundThis > 0) {
$mainloop[] = array('ClientBodyType'=>'Priority NLC Committees', 'clientloop'=>$clientarray) ;
}
unset($clientarray);
unset($memberarray);
$SectionReturn=GetSection('National','n');
$bRecordsFoundThis = $SectionReturn[0];
$clientarray = $SectionReturn[1];
$bRecordsFound = $bRecordsFound + $bRecordsFoundThis;
if ($bRecordsFoundThis > 0) {
$mainloop[] = array('ClientBodyType'=>'National Client Bodies', 'clientloop'=>$clientarray) ;
}
unset($clientarray);
unset($memberarray);
}
if ($bShowFunding == 1) {
$SectionReturn=GetSection('Funding Agencies','');
$bRecordsFoundThis = $SectionReturn[0];
$clientarray = $SectionReturn[1];
$bRecordsFound = $bRecordsFound + $bRecordsFoundThis;
if ($bRecordsFoundThis > 0) {
$mainloop[] = array('ClientBodyType'=>'Funding Agencies', 'clientloop'=>$clientarray) ;
}
unset($clientarray);
unset($memberarray);
}
if ($bShowAssociations == 1) {
$SectionReturn=GetSection('Associations, Federations and Institutions','');
$bRecordsFoundThis = $SectionReturn[0];
$clientarray = $SectionReturn[1];
$bRecordsFound = $bRecordsFound + $bRecordsFoundThis;
if ($bRecordsFoundThis > 0) {
$mainloop[] = array('ClientBodyType'=>'Associations, Federations and Institutions', 'clientloop'=>$clientarray) ;
}
unset($clientarray);
unset($memberarray);
}
if (($bShowNational == 1) || ($bShowFunding == 1) || ($bShowAssociations == 1)) {
if ($bRecordsFound > 0) { $template->AddParam('mainloop', $mainloop); }
}
// Now do the provincial / regional section
$bShowProvincial = 0;
if ($ClientBodyTypeA) {
if ($ClientBodyTypeA == 'Provincial / Regional') {
$bShowProvincial = 1;
}
} else {
$bShowProvincial = 1;
}
if ($bShowProvincial == 1) {
$sql = "SELECT NLCClientBody.ClientBodyID, NLCClientBody.ClientBodyName, NLCClientBody.ClientBodyURL, NLCClientBody.ClientBodyEmail, NLCClientBody.ClientBodyTel,
NLCMembers.NLCMemberBranch, NLCMembers.NLCMemberType, CONCAT_WS(' ',Contacts.ContactFirstName,Contacts.ContactSurname) AS ContactName,
Contacts.PersonalTel, Contacts.PersonalFax, Contacts.PreferredEmail, NLCClientBody.ClientBodyFax, NLCClientBody.ClientBodyTypeA,
NLCClientBody.ClientBodyTypeB, NLCClientBody.ClientBodyGeographic, Contacts.ContactSurname, NLCClientBody.CBContact1Surname, NLCClientBody.CBContact1FirstName,
NLCClientBody.CBContact1Designation, NLCClientBody.CBContact1Tel, NLCBranchesFeedback.NLCBranchSuccess, NLCBranchesFeedback.NLCBranchFailure, NLCBranchesFeedback.NLCCompiledBy,
NLCOrdering.OrderNum
FROM NLCOrdering RIGHT JOIN (NLCBranchesFeedback
INNER JOIN (NLCClientBody LEFT JOIN (NLCMembers INNER JOIN Contacts ON (NLCMembers.NLCMemberContactID=Contacts.ContactsID)) ON NLCClientBody.ClientBodyID = NLCMembers.ClientBodyID)
ON NLCBranchesFeedback.NLCBranchName = NLCClientBody.ClientBodyGeographic) ON NLCOrdering.ClientBodyTypeB = NLCClientBody.ClientBodyTypeB
WHERE (((NLCClientBody.ClientBodyTypeA)='Provincial / Regional'))";
if ($ClientBodyGeographic) {
if ($ClientBodyGeographic != '') {
$sql = $sql . " AND NLCClientBody.ClientBodyGeographic = '" . $ClientBodyGeographic . "'";
}
}
if ($ClientBodyName) {
if ($ClientBodyName != '') {
$sql = $sql . " AND UPPER(NLCClientBody.ClientBodyName) LIKE '%" . strtoupper($ClientBodyName) . "%'";
}
}
$sql = $sql . " ORDER BY ClientBodyGeographic, OrderNum, ClientBodyName, NLCMemberType, ContactSurname";
if ($ClientBodyName) { echo('<!--'.$sql.'-->'); }
$result=mysql_query($sql);
$bRecordsFoundThis = mysql_num_rows($result);
$bRecordsFound = $bRecordsFound + $bRecordsFoundThis;
$prev_client_geo = '';
$prev_client_typeb = '';
$prev_client_body_id = -1;
$firsttime = 1;
while ($row=mysql_fetch_array($result)) {
if ($firsttime == 1) {
// First pass through the loop, setup the variables
$client_body_id = $row["ClientBodyID"];
$client_geo = $row["ClientBodyGeographic"];
$nlccompiledby = $row["NLCCompiledBy"];
$nlcbranchsuccess = $row["NLCBranchSuccess"];
$nlcbranchfailure = $row["NLCBranchFailure"];
$client_typeb = $row["ClientBodyTypeB"];
$client_body_id = $row["ClientBodyID"];
$client_body_name = $row["ClientBodyName"];
$client_body_url = $row["ClientBodyURL"];
$client_body_email = $row["ClientBodyEmail"];
$client_body_tel = $row["ClientBodyTel"];
$client_body_fax = $row["ClientBodyFax"];
$client_body_contact1firstname = $row["CBContact1FirstName"];
$client_body_contact1surname = $row["CBContact1Surname"];
$client_body_contact1designation = $row["CBContact1Designation"];
$client_body_contact1tel = $row["CBContact1Tel"];
$firsttime = 0;
}
// Have we rolled over to a new geographic area?
if ($client_geo != $row["ClientBodyGeographic"]) {
// Finish off the client array
$clientarray[] = array('ClientBodyID'=>$client_body_id,
'ClientBodyName'=>$client_body_name,
'ClientBodyURL'=>$client_body_url,
'ClientBodyEmail'=>$client_body_email,
'ClientBodyTel'=>$client_body_tel,
'ClientBodyFax'=>$client_body_fax,
'CBContact1FirstName'=>$client_body_contact1firstname,
'CBContact1Surname'=>$client_body_contact1surname,
'CBContact1Designation'=>$client_body_contact1designation,
'CBContact1Tel'=>$client_body_contact1tel,
'provdetail'=>$memberarray);
// Finish off the type B array
$clienttypebarray[] = array('ClientBodyTypeB'=>$client_typeb,
'provclientloop'=>$clientarray);
$clientgeoarray[] = array('ClientBodyGeographic'=>$client_geo,
'NLCCompiledBy'=>$nlccompiledby,
'NLCBranchSuccess'=>$nlcbranchsuccess,
'NLCBranchFailure'=>$nlcbranchfailure,
'clienttypebloop'=>$clienttypebarray);
unset($clienttypebarray);
unset($clientarray);
unset($memberarray);
// Set the variables to the new set
$client_body_id = $row["ClientBodyID"];
$client_geo = $row["ClientBodyGeographic"];
$nlccompiledby = $row["NLCCompiledBy"];
$nlcbranchsuccess = $row["NLCBranchSuccess"];
$nlcbranchfailure = $row["NLCBranchFailure"];
$client_typeb = $row["ClientBodyTypeB"];
$client_body_id = $row["ClientBodyID"];
$client_body_name = $row["ClientBodyName"];
$client_body_url = $row["ClientBodyURL"];
$client_body_email = $row["ClientBodyEmail"];
$client_body_tel = $row["ClientBodyTel"];
$client_body_fax = $row["ClientBodyFax"];
$client_body_contact1firstname = $row["CBContact1FirstName"];
$client_body_contact1surname = $row["CBContact1Surname"];
$client_body_contact1designation = $row["CBContact1Designation"];
$client_body_contact1tel = $row["CBContact1Tel"];
}
// Have we rolled over to a new type b?
if ($client_typeb != $row["ClientBodyTypeB"]) {
// Finish off the client array
$clientarray[] = array('ClientBodyID'=>$client_body_id,
'ClientBodyName'=>$client_body_name,
'ClientBodyURL'=>$client_body_url,
'ClientBodyEmail'=>$client_body_email,
'ClientBodyTel'=>$client_body_tel,
'ClientBodyFax'=>$client_body_fax,
'CBContact1FirstName'=>$client_body_contact1firstname,
'CBContact1Surname'=>$client_body_contact1surname,
'CBContact1Designation'=>$client_body_contact1designation,
'CBContact1Tel'=>$client_body_contact1tel,
'provdetail'=>$memberarray);
$clienttypebarray[] = array('ClientBodyTypeB'=>$client_typeb,
'provclientloop'=>$clientarray);
unset($clientarray);
unset($memberarray);
// Set the variables to the new set
$client_body_id = $row["ClientBodyID"];
$client_geo = $row["ClientBodyGeographic"];
$nlccompiledby = $row["NLCCompiledBy"];
$nlcbranchsuccess = $row["NLCBranchSuccess"];
$nlcbranchfailure = $row["NLCBranchFailure"];
$client_typeb = $row["ClientBodyTypeB"];
$client_body_id = $row["ClientBodyID"];
$client_body_name = $row["ClientBodyName"];
$client_body_url = $row["ClientBodyURL"];
$client_body_email = $row["ClientBodyEmail"];
$client_body_tel = $row["ClientBodyTel"];
$client_body_fax = $row["ClientBodyFax"];
$client_body_contact1firstname = $row["CBContact1FirstName"];
$client_body_contact1surname = $row["CBContact1Surname"];
$client_body_contact1designation = $row["CBContact1Designation"];
$client_body_contact1tel = $row["CBContact1Tel"];
}
// Have we rolled over to a new client body?
if ($client_body_id != $row["ClientBodyID"]) {
$clientarray[] = array('ClientBodyID'=>$client_body_id,
'ClientBodyName'=>$client_body_name,
'ClientBodyURL'=>$client_body_url,
'ClientBodyEmail'=>$client_body_email,
'ClientBodyTel'=>$client_body_tel,
'ClientBodyFax'=>$client_body_fax,
'CBContact1FirstName'=>$client_body_contact1firstname,
'CBContact1Surname'=>$client_body_contact1surname,
'CBContact1Designation'=>$client_body_contact1designation,
'CBContact1Tel'=>$client_body_contact1tel,
'provdetail'=>$memberarray);
unset($memberarray);
// Set the variables to the new set
$client_body_id = $row["ClientBodyID"];
$client_geo = $row["ClientBodyGeographic"];
$nlccompiledby = $row["NLCCompiledBy"];
$nlcbranchsuccess = $row["NLCBranchSuccess"];
$nlcbranchfailure = $row["NLCBranchFailure"];
$client_typeb = $row["ClientBodyTypeB"];
$client_body_id = $row["ClientBodyID"];
$client_body_name = $row["ClientBodyName"];
$client_body_url = $row["ClientBodyURL"];
$client_body_email = $row["ClientBodyEmail"];
$client_body_tel = $row["ClientBodyTel"];
$client_body_fax = $row["ClientBodyFax"];
$client_body_contact1firstname = $row["CBContact1FirstName"];
$client_body_contact1surname = $row["CBContact1Surname"];
$client_body_contact1designation = $row["CBContact1Designation"];
$client_body_contact1tel = $row["CBContact1Tel"];
}
// Create the array of contact info
$memberarray[] = array('NLCMemberType'=>$row["NLCMemberType"],
'ContactName'=>$row["ContactName"],
'PersonalTel'=>$row["PersonalTel"],
'PreferredEmail'=>$row["PreferredEmail"]);
}
$clientgeoarray[] = array('ClientBodyGeographic'=>$client_geo,
'NLCCompiledBy'=>$nlccompiledby,
'NLCBranchSuccess'=>$nlcbranchsuccess,
'NLCBranchFailure'=>$nlcbranchfailure,
'clienttypebloop'=>$clienttypebarray);
if ($bRecordsFound > 0) { $template->AddParam('clientgeoloop', $clientgeoarray); }
//$template->EchoOutput();
}
?>