<?php 

function add_file_system($date_='', $reference='', $name='', $description='')
{
	global $Refs;

	$sql = "INSERT INTO ".TB_PREF."file_system (date_, reference, name, description) VALUES ('".date2sql($date_) . "',
	 ".db_escape($reference) . ", ".db_escape($name) . ", ".db_escape($description) . ")";
   	db_query($sql,"The file_system could not be added");
	$id = get_next_trans_no(ST_FILE_SYSTEM);
	$Refs->save(ST_FILE_SYSTEM, $id, $reference);
	add_audit_trail(ST_FILE_SYSTEM, $id, $date_);
   //	display_error($sql);
}

function update_file_system($selected_id, $date_='', $reference='', $name='', $description='')
{
	$sql = "UPDATE ".TB_PREF."file_system SET date_='".date2sql($date_)."', reference=".db_escape($reference).", name=".db_escape($name).", description=".db_escape($description)."  WHERE id = ".db_escape($selected_id);
   	db_query($sql,"The file_system could not be updated");
}

function delete_file_system($selected_id)
{
	$sql="DELETE FROM ".TB_PREF."file_system WHERE id=".db_escape($selected_id);
	db_query($sql,"could not delete file_system");
}

function get_file_systems($show_inactive)
{
	$sql = "SELECT * FROM ".TB_PREF."file_system";
	if (!$show_inactive) $sql .= " WHERE !inactive";
	// $sql .= " ORDER BY file_system";
	return db_query($sql,"could not file_system");
}

function get_file_system($selected_id)
{
	$sql = "SELECT * FROM ".TB_PREF."file_system WHERE id=".db_escape($selected_id);

	$result = db_query($sql,"could not file_system");
	return db_fetch($result);
}

function get_file_system_name($id)
{
	$sql = "SELECT CONCAT(name,' - ',reference)  FROM ".TB_PREF."file_system WHERE id = ".db_escape($id);
	$result = db_query($sql, "could not file_system");
	$row = db_fetch($result);
	return is_array($row) ? $row[0] : false;
}

// function duplicate_item_brand($brand)
// {
// 	$sql = "SELECT brand FROM ".TB_PREF."brand WHERE brand = ".db_escape(trim($brand));
// 	$result = db_query($sql, "could not duplicate brand");
// 	$data = db_num_rows($result);
// 	return $data;
// }

function get_file_system_inquiry($name='', $from='', $to='') //, $file_system=''
{
	$sql = "SELECT id, reference, date_, name , description FROM ".TB_PREF."file_system WHERE inactive != 1";
	
	$data_after = date2sql($from);
	$date_before = date2sql($to);
	$sql .= " AND date_ >= '$data_after'";
	$sql .= " AND date_ <= '$date_before'";
	if ($name != '') 
		$sql .= " AND name LIKE ".db_escape('%' . $name . '%');
	// if ($file_system != '') 
	// 	$sql .= " AND id LIKE ".db_escape('%' . $file_system . '%');
	$sql .= " GROUP BY id";
	return $sql;
}

//------------------------------------------------------------------------------------


?>