<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "scopeid")
    $lw_id = $paramValue;
}    
 
$dal = new DAL();
$sql = "SELECT CN.id AS id, " .
       "CONCAT(CN.firstname, ' ', CN.surname) AS 'Contact Name', " .
       "CT.descr AS 'Contact Type', OG.name AS 'Contact Organization', " .
       "EM.address AS 'Contact Email', " .
       "CONCAT(LEFT(TL.value,3), '-', MID(TL.value, 4, 3), '-', RIGHT(TL.value, 4), ' ext. ', TL.exten) AS 'Contact Telephone' " .
       "FROM contact CN, contactype CT, organizationcontact OC, " .
       "organization OG, email EM, organizationcontactelno OCT, telno TL " .
       "WHERE CN.active = 1 AND OC.contact_id = CN.id " .
       "AND OC.organization_id = OG.id AND OC.contactype_id = CT.id " .
       "AND EM.organizationcontact_id = OC.id " .
       "AND OCT.organizationcontact_id = OC.id AND OCT.telno_id = TL.id " .
       "ORDER BY CN.surname ";
$result = $dal->query($sql);

echo json_encode($result);

?>

