<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "summaryid")
    $summary_id = $paramValue;
  else if ($paramName == "index")
    $index = $paramValue;
}    

if ($index == '001') 
  $where = "OC.id = $summary_id AND CO.id = OC.contact_id AND OZ.id = OC.organization_id ";
if ($index == '010')
  $where = "OZ.id = $summary_id AND OC.organization_id = OZ.id AND CO.id = OC.contact_id " ;
if ($index == '100')
  $where = "CO.id = $summary_id AND OC.contact_id = CO.id AND OZ.id = OC.organization_id " ;

$dal = new DAL();
$sql = "SELECT OC.id AS id, " .
       "CONCAT(CO.firstname, ' ', CO.surname) AS 'Contact Name', " .
       "OZ.name AS 'Contact Organization', " .
       "OC.email AS 'Contact Email' " .
       "FROM organizationcontact OC, contact CO, organization OZ " .
       "WHERE $where " .
       "ORDER BY OZ.name ";
$result = $dal->query($sql);

echo json_encode($result);

?>


