<?php

function confirm_query()
{

    if (!$result_set) {
        die("Database query failed " . mysql_query());
    }
}

function mysql_prep($value)
{

    $magic_quotes_active = get_magic_quotes_gpc();
    $new_enough_php = function_exists("mysql_real_escape_string");
    if ($new_enough_php) {

        if ($magic_quotes_active) {
            $value = stripslashes($value);
        }
        $value = mysql_real_escape_string($value);
    } else {
        if (!$magic_quotes_active) {
            $value = addslashes($value);
        }
    }
    return $value;
}

function strip_from_zero($marked_string)
{

    $no_zero = str_replace('*0', '', $marked_string);
    $cleaned_string = str_replace('*', '', $no_zero);
    return $cleaned_string;
}

function redirect_to($location = NULL)
{
    if ($location != NULL) {
        header("Location: {$location}");
        exit;
    }
}

function output_message($message = "")
{
    if (!empty($message)) {
        return "<p style=\"color:#F00; font-weight:bolder; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size:15px\">$message</p>";
    } else {
        return "";
    }
}

function return_reg_table($semid,$level)
{
    
    switch($semid.$level)
    {
        case '1ND I':
            $tablename='ndi_tbl';
            break;
        case '2ND I': 
            $tablename='ndi_tbl';
            break;
            
        case '1HND I':
            $tablename='hndi_tbl';
            break;
        case '2HND I': 
            $tablename='hndi_tbl';
            break;
        
        
        case '3ND II':
            $tablename='ndii_tbl';
            break;
        case '4ND II': 
            $tablename='ndii_tbl';
            break;
            
        case '3HND II':
            $tablename='hndii_tbl';
            break;
        case '4HND II': 
            $tablename='hndii_tbl';
            break;
        
    }
    
    return $tablename;
}



function return_reg_table2($semid, $level)
{
    
    switch($semid.$level)
    {
        case '1ND':
            $tablename='ndi_tbl';
            break;
        case '2ND': 
            $tablename='ndi_tbl';
            break;
            
        case '1HND':
            $tablename='hndi_tbl';
            break;
        case '2HND': 
            $tablename='hndi_tbl';
            break;
        
        
        case '3ND':
            $tablename='ndii_tbl';
            break;
        case '4ND': 
            $tablename='ndii_tbl';
            break;
            
        case '3HND':
            $tablename='hndii_tbl';
            break;
        case '4HND': 
            $tablename='hndii_tbl';
            break;
        
    }
    
    return $tablename;
}


function find_semester($semester)
{
    switch($semester)
    
    {
    case 4: $semester='First';
    break;
    
    case 5: $semester='Second';
    break;
    
    case 7: $semester='First';
    break;
    
    case 8: $semester='Second';
    break;
    
    }
    return $semester;    
}

function find_level($process_id, $level)
{
    $mlevel='';
    if ((($process_id==4) OR ($process_id==5)) &&(($level=='ND') OR ($level=='ND I') OR ($level=='ND II'))){
  $mlevel = 'ND I';
  
}else if ((($process_id==4) OR ($process_id==5)) &&(($level=='HND') OR ($level=='HND I') OR ($level=='HND II'))){
  $mlevel = 'HND I';
  

    
}else if ((($process_id==7) OR ($process_id==8) OR ($process_id==9)) &&($level=='ND I'))  {

$mlevel = "ND II";

    
}else if ((($process_id==7) OR ($process_id==8) OR ($process_id==9))&& ($level=='HND I'))  {
$mlevel = "HND II";
}

return $mlevel;

}




function find_report($process_id, $level)
{
    if (($process_id==5) OR ($process_id==6)  &&(($level=='ND') OR ($level=='ND I'))){
  $mlevel = 'ND I';
  
}else if (($process_id==5) OR ($process_id==6)  &&(($level=='HND') OR ($level=='HND I'))){
  $mlevel = 'HND I';
  

    
}else if (($process_id==9) && (($level=='ND II') OR ($level=='ND I'))) {

$mlevel = "ND II";

    
}else if (($process_id==9) && (($level=='HND II') OR ($level=='HND I'))) {

$mlevel = "HND II";

    
}

return $mlevel;

}


// function __autoload($class_name)
// {
//     $class_name = strtolower($class_name);
//     $path = LIB_PATH . DS . "{$class_name}.php";
//     if (file_exists($path)) {
//         require_once($path);
//     } else {
//         die("The file {$class_name}.php could not be found");
//     }
// }

function include_layout_template($template = "")
{

    include(SITE_ROOT . DS . 'template' . DS . $template);

}

?>