<?php

################################
##########   SQL NEWS   ########
################################

function getOneNews($news_id) {
  $news_id = mysql_real_escape_string($news_id);
  $query = "select * from $DB.news_db WHERE news_id = '$news_id'";
  return mysql_query($query);
}

function getLastNews($tendu) {
  $tendu = mysql_real_escape_string($tendu);
  $query = "SELECT * FROM $DB.news_db INNER JOIN $DB.users_db ON news_db.news_user_id = users_db.user_id WHERE news_tendu<='$tendu' ORDER BY news_date desc, news_time desc";
  return mysql_query($query);
}

################################
##########  SQL EDITO   ########
################################

function getOneEdito($edito_id) {
  $edito_id = mysql_real_escape_string($edito_id);
  $query = "select * from $DB.editos_db WHERE edito_id = '$edito_id'";
  return mysql_query($query);
}

function getLastEdito() {
  $query = "select * from $DB.editos_db ORDER BY edito_date DESC";
  return mysql_query($query);
}

function getAllEdito() {
  $query = "select * from $DB.editos_db ORDER BY edito_date DESC";
  return mysql_query($query);
}

################################
##########  SQL VIDEOS  ########
################################

function getOneVideo($vid_id){
  $vid_id = mysql_real_escape_string($vid_id);
  $query = "select * from $DB.videos_db WHERE video_id = '$vid_id'";
  return mysql_query($query);
}

function getAllVideos() {
  $query = "select * from $DB.videos_db ORDER BY video_date desc, video_time desc";
  return mysql_query($query);
}

function getLastVideos() {
  $query = "select * from $DB.videos_db ORDER BY video_id desc";
  return mysql_query($query);
}

function getVideosByType($type) {
  $type = mysql_real_escape_string($type);
  $query = "select * from $DB.videos_db WHERE video_type='$type' ORDER BY video_date desc";
  return mysql_query($query);
}

function getVideosByYearAndTypeAndTendu($year, $type, $tendu) {
  $year = mysql_real_escape_string($year);
  $type = mysql_real_escape_string($type);
  $tendu = mysql_real_escape_string($tendu);
  if ($year == 0)
    $query = "select * from $DB.videos_db
	      WHERE video_type='$type' AND video_tendu<='$tendu' AND YEAR(video_date)<='2000'
	      ORDER BY video_date desc";
  else
    $query = "select * from $DB.videos_db
	      WHERE video_type='$type' AND video_tendu<='$tendu' AND YEAR(video_date)='$year'
	      ORDER BY video_date desc";
  return mysql_query($query);
}

function getLastVideosByTendu($tendu) {
  $tendu = mysql_real_escape_string($tendu);
  $query = "select * from $DB.videos_db WHERE video_tendu<='$tendu' ORDER BY video_id desc";
  return mysql_query($query);
}

##################################
##########  SQL CONTACTS  ########
##################################

function getAssoInfos() {
  $query = "select * from $DB.asso_db";
  return mysql_query($query);
}

function getOneLinkById($id) {
  $id = mysql_real_escape_string($id);
  $query = "select * from $DB.links_db WHERE link_id='$id'";
  return mysql_query($query);
}

function getAllLinks() {
  $query = "select * from $DB.links_db";
  return mysql_query($query);
}

###############################
##########  SQL USERS  ########
###############################


function getOneUserByName($login) {
  $login = mysql_real_escape_string($login);
  $query = "select * from $DB.users_db WHERE user_login='$login'";
  return mysql_query($query);
}

function getOneUserByPseudo($pseudo) {
  $pseudo = mysql_real_escape_string($pseudo);
  $query = "select * from $DB.users_db WHERE user_pseudo='$pseudo'";
  return mysql_query($query);
}

function getOneUserById($id) {
  $id = mysql_real_escape_string($id);
  $query = "select * from $DB.users_db WHERE user_id='$id'";
  return mysql_query($query);
}

function getAllUsers() {
  $query = "select * from $DB.users_db WHERE user_right < 7 ORDER BY user_right desc";
  return mysql_query($query);
}

function getUsersByStatut($statut) {
  $statut = mysql_real_escape_string($statut);
  $query = "SELECT * FROM $DB.users_db WHERE user_statut='$statut' ORDER BY user_right desc";
  return mysql_query($query);
}

################################
##########  SQL MEMBERS  ########
################################

function getAllMembers() {
  $query = "select * from $DB.users_db WHERE user_right >= 7";
  return mysql_query($query);
}

function getAnExistingStatut($statut) {
  $statut = mysql_real_escape_string($statut);
  $query = "select * from $DB.users_db WHERE user_statut = '$statut'";
  return mysql_query($query);
}

####################################
##########   SQL Blacklist  ########
####################################

function getOneBlacklistById($id) {
  $id = mysql_real_escape_string($id);
  $query = "select * from $DB.blacklist_db WHERE blacklist_id='$id'";
  return mysql_query($query);
}

function getOneBlacklistByLogin($login) {
  $login = mysql_real_escape_string($login);
  $query = "select * from $DB.blacklist_db WHERE blacklist_login='$login'";
  return mysql_query($query);
}

function getAllBlacklist() {
  $query = "select * from $DB.blacklist_db";
  return mysql_query($query);
}

function getAllBlacksite() {
  $query = "select * from $DB.blacksites_db";
  return mysql_query($query);
}

function getOneBlacksiteById($id) {
  $id = mysql_real_escape_string($id);
  $query = "select * from $DB.blacksites_db WHERE blacksite_id='$id'";
  return mysql_query($query);
}

?>