<?php
/**********************************************************************
	Copyright (C) Evolve Techniologies
	Author : Danushka Widanage
	Email : dwidanage@gmail.com
	Company : Evolve Technologies(pvt)Ltd
***********************************************************************/
function add_courses($course_full_name, $course_short_name, $total_duration, $total_course_fee)
{
	$sql = "INSERT INTO ".TB_PREF."courses (course_full_name, course_short_name, total_duration, total_course_fee)VALUES (
		".db_escape($course_full_name).",
		".db_escape($course_short_name).",
		".db_escape($total_duration).",
		".db_escape($total_course_fee)." )";
	db_query($sql, "could not add course");		
}

function update_courses($id, $course_full_name, $course_short_name, $total_duration,$total_course_fee)
{
	$sql = "UPDATE ".TB_PREF."courses SET 
	course_full_name = ".db_escape($course_full_name).",
	course_short_name =".db_escape($course_short_name).", 
	total_duration=".db_escape($total_duration).",
	total_course_fee=".db_escape($total_course_fee)."
	WHERE id = ".db_escape($id);
	
	db_query($sql, "could not update courses");			
}

function get_all_courses($all=false)
{
	$sql = "SELECT * FROM ".TB_PREF."courses";
	if (!$all)
		$sql .= " WHERE !inactive";
	
	return db_query($sql, "could not get all courses");
} 

function get_course_name($id)
{
	$sql = "SELECT course_full_name FROM ".TB_PREF."courses WHERE id=".db_escape($id);
	
	$result = db_query($sql, "could not get course full name");
	
	$row = db_fetch_row($result);
	return $row[0];
}

function delete_courses($id)
{
	$sql="DELETE FROM ".TB_PREF."courses WHERE id=".db_escape($id);
	db_query($sql,"The Courses record could not be deleted");

}

function get_courses($id)
{
	$sql = "SELECT * FROM ".TB_PREF."courses WHERE id=".db_escape($id);
	
	$result = db_query($sql, "could not get courses");
	
	return db_fetch($result);
}

function get_courses_id($cname)
{
	$sql = "SELECT id FROM ".TB_PREF."courses WHERE course_full_name=".db_escape($cname);
	
	$result = db_query($sql, "could not get course id");
	
	return db_fetch($result);
}


?>