<?php
/*=======================================================================
 *
 * inc_services.inc.php
 *
 * Autor: Marc Vollmann
 *
 =======================================================================*/


// Returns the zone ("serviceplz", "servicezone", "servicezonemapping") from a zipcode
function getServiceZoneByCustomerAndZipcode ($csId, $zipcode) {
  global $db, $PHP_SELF;
  $retVal = "";
  if ($csId != "" && $zipcode != "") :
     $srvpId = getFieldValueFromId("serviceplz", "srvp_plz", $zipcode, "srvp_id");     
     $sqlquery = "SELECT srvz.srvz_no FROM servicezone AS srvz, servicezonemapping AS srvzm"
               . "  WHERE srvz.cs_id = '" . $csId . "' AND srvz.srvz_id = srvzm.srvz_id AND srvzm.srvp_id = '" . $srvpId . "'";
     $result = $db->query($sqlquery);
     if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
     while ($row = $result->fetch_assoc()):
           $retVal = $row["srvz_no"];
     endwhile;
     $result->free();
  endif;
  return $retVal;
}

// Returns all zones from a zipcode (NO DISJUNCT association between zone and zipcode)
function getServiceZonesByCustomerAndZipcode ($csId, $zipcode) {
  global $db, $PHP_SELF;
  $retArray = array();
  if ($csId != "" && $zipcode != "") :
     $srvpId = getFieldValueFromId("serviceplz", "srvp_plz", $zipcode, "srvp_id");     
     $sqlquery = "SELECT srvz.srvz_no FROM servicezone AS srvz, servicezonemapping AS srvzm"
               . "  WHERE srvz.cs_id = '" . $csId . "' AND srvz.srvz_id = srvzm.srvz_id AND srvzm.srvp_id = '" . $srvpId . "'";
     $result = $db->query($sqlquery);
     if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
     while ($row = $result->fetch_assoc()):
           $retArray[] = $row["srvz_no"];
     endwhile;
     $result->free();
  endif;
  return $retArray;
}
?>