<?php //getFontAwesomeIcons.php
include(__DIR__.'/../includes/sysinit.php');

function importDistricts()
{
	global $sableDB;
	// We need to read the font-awesome.css file to get the details on all the icons.	
	$file = SABLE_WORKING_PATH.'lib/districts.txt';
	
	if (!is_file($file)) die($file.' is missing.');
	$fa = fopen($file, "r") or die($file.' cannot be opened.');
	
	// Output one line until end-of-file
	$row = [];
	$inserted = 0;
	$count = 0;
	while(!feof($fa)) 
	{
		$ln = fgets($fa);
		$row = explode('|', trim($ln));
		$dstrct_name = $row[0];
		$dstrct_code = $row[1];
		$ss = 'select province_id from province where province_name = "'.$row[2].'"';
		//echo(PHP_EOL.$ss.PHP_EOL);
		$prvnc_id = $sableDB->getValue($ss);
		$dstrct_seat = $row[3];
		$sql = 'insert into district (district_name, district_code, province_id, district_seat) 
				values 
				("'.$dstrct_name.'", "'.$dstrct_code.'", '.$prvnc_id.', "'.$dstrct_seat.'")';
		$res = $sableDB->updateQuery($sql);
		$count++;
		$inserted += $res;
	}
	fclose($fa);
	
	echo('Added '.$inserted.' of '.$count);
}
importDistricts();
?>