<?php
include_once("_nemo.list.cls.php");

class Country extends NemoList
{
   private $ID = 0;

   public function __construct($DataKey)
   {
      parent::__construct($DataKey);

   }

   public function getList()
   {
      global $SystemSettings;
      $this->ListSQL("
         SELECT tblCountry.CountryID, tblCountry.strCountry AS Country, COUNT(LearnerID) as 'No Learners', tblCountry.blnActive AS Active, tblCountry.strLastUser AS 'Last User', tblCountry.dtLastEdit AS 'Last Edit'
         FROM tblCountry LEFT JOIN tblLearner ON refCountryID = CountryID
         GROUP BY CountryID, strCountry
         ORDER BY COUNT(LearnerID) DESC, strCountry Asc");

      return $this->renderTable("Country List");
   }

   public static function Save(&$CountryID)
   {
      $db = new NemoDatabase("tblCountry", $CountryID, null, 0);

      $db->SetValues($_POST);

      $db->Fields[strLastUser] = $_SESSION['USER']->USERNAME;
      //$db->Fields[dtLastEdit] = date("YmdHi");
      $result = $db->Save();
      //print_rr($db->Fields);
      if($CountryID == 0) $CountryID = $db->ID[CountryID];

      if($result->Error == 1)
         return $result->Message;
      else
         return "Details Saved. ";
   }

   public static function Delete($chkSelect)
   {
      global $xdb;
      //print_rr($chkSelect);
      if(count($chkSelect) > 0){
         foreach($chkSelect as $key => $value)
         {
            $xdb->doQuery("DELETE FROM tblCountry WHERE CountryID = ". $xdb->qs($key));
         }
         return "Records Deleted.";
      }
   }
}
?>
