<?php
//Add http:// in url
if($_SERVER["SERVER_NAME"]!="localhost")
{
  if(substr($_SERVER['HTTP_HOST'],0,3)!="www")
  {
    $url="http://www.".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    header("Location: $url");
  }
}
/*
  Some Common/Global Variables
*/
global $global_date_time;
$add_vars=array('seconds'=>0, 'minutes'=>0, 'hours'=>-5, 'days'=>0, 'months'=>0, 'years'=>0); //-4 change to -5
$global_date_time=add_month_day_hour_min_with_a_date(date("Y-m-d H:i:s"), $add_vars);
global $global_logged_admin_id;
if(isset($_SESSION['admin_id'])) $global_logged_admin_id=$_SESSION['admin_id'];


/*
  This function will return processing status of a document of a car
  @input:
    $carwise_doc_id: id of car_wise_document_processing table
  @return:
    car_wise_document_processing info if id match
	false if id doesn't match
*/
function get_processing_status_by_carwise_document_id($carwise_doc_id)
{
  //$sql_car_info="SELECT * FROM car_wise_documents WHERE id='$carwise_doc_id'";
  //$doc_info=get_single_row($sql_car_info);
  //$car_id=$doc_info['car_id'];
  $sql_group="SELECT doc_process.*, status.processing_status_name FROM car_wise_document_processing doc_process LEFT JOIN list_status_doc_processing status ON status.id=doc_process.processing_status_id WHERE doc_process.id='$carwise_doc_id'";  
  return get_single_row($sql_group);
}

/*
  This function will return group id by Group Name for an admin user
  @input:
    $group_name: name of group
	$global_logged_admin_id: admin user id
  @return:
    id of contact_group table(group name matched)
	0 if group name doesn't match
*/
function group_id_by_name($group_name, $global_logged_admin_id)
{
  $sql_group="SELECT * FROM contact_group WHERE group_name='$group_name' AND created_by_admin_id='$global_logged_admin_id'";
  $q_group=mysql_query($sql_group);
  if(mysql_num_rows($q_group)>0)
  {
    $group_info=mysql_fetch_array($q_group);
	return $group_info['id'];
	
  }
  else
    return 0;
}

/*
  This function will return invalid contact info by contat_no
  @input:
    $contact_no: any contact no
  @return:
    contact info from invalid_contact_no table
	false (if contact_no doesn't match)	
*/
function invalid_contact_info_by_contact_no($contact_no)
{
  $sql_contact_info="SELECT * FROM invalid_contact_no WHERE invalid_contact_no.invalid_contact_no='$contact_no'";
  return get_single_row($sql_contact_info);
}

/*
  This function will return an array of invalid contacts contat_no
  @input:
    
  @return:
    an array of invalid contacts contat_no
*/
function invalid_contact_list($admin_id)
{
  $sql_contact_info="SELECT * FROM invalid_contact_no WHERE created_by_admin_id='$admin_id'";
  $q_contact_info=mysql_query($sql_contact_info);
  $invalid_contact=array();
  if(mysql_num_rows($q_contact_info)>0)
  while($row=mysql_fetch_array($q_contact_info))
  {
	$invalid_contact[]=$row['invalid_contact_no'];
  }
  return get_single_row($sql_contact_info);
}

/*
  This function will return contact detail info by contact no
  @input:
    $contact_no: contacts table contact_no
	$created_by_admin_id: admin id 
  @return:
    an array of contact info (if contact_no match)
	false (if contact_no doesn't match)	
*/
function get_contact_detail_by_contact_no($contact_no,$created_by_admin_id=1)
{
  $sql_contact_info="SELECT contacts.* FROM contacts WHERE contacts.contact_no='$contact_no' AND created_by_admin_id='$created_by_admin_id'";
  return get_single_row($sql_contact_info);  
}

/*
  This function will return contact detail info by id
  @input:
    $contact_id: contacts table id
  @return:
    an array of contact info (if id match)
	false (if id doesn't match)	
*/
function get_contact_detail_by_id($contact_id)
{
  $sql_contact_info="SELECT contacts.* FROM contacts WHERE contacts.id='$contact_id'";
  return get_single_row($sql_contact_info);  
}


/*
  This function will return member info by email
  @input:
    $member_id: member_basic_info table email
  @return:
    an array of member info (if email match)
	false (if id doesn't match)	
*/
function get_member_info_by_email($member_email)
{
  $sql_member_info="SELECT member.member_email, member.member_username, member.member_password, member.is_featured_member, member.is_active, member.created_at, profile.* FROM member_basic_info member LEFT JOIN member_profile profile ON member.id=profile.member_id WHERE member.member_email='$member_email'";
  return get_single_row($sql_member_info);  
}

?>