<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 0.9.9

Copyright (C) 2006-2009  Sylvain FATOME
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr

Web : http://smitst.homelinux.com
****************************************************************************************/


// Vérification des tentatives de hack
$pos=strpos($_SERVER['PHP_SELF'],"inc.php");
if ($pos===FALSE)
	$ok_inc=TRUE;
else
	$ok_inc=FALSE;
if ($ok_inc==FALSE) header("Location: ../index.php");

/**********************************************************/
/* Fonctions pour les accès aux fichiers marques/éditeurs */
/* et fichiers rattachés                                  */
/**********************************************************/

// Vérification du nombre de marques
function nb_marques($type)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBMQUE;
	if (trim($type)<>"")
		$rexist.=" WHERE mque_type='".intval($type)."'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	$nbexist = mysql_num_rows($rs2);
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $nbexist;
}

// Lecture d'un enregistrement marque
function lit_enr_mque($code,$open)
{
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech2 = "SELECT * FROM " .TBMQUE. " WHERE mque_code = '$code'";
	$rs2 = mysql_query($rech2)or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	if ($open==TRUE)
		mysql_close($conn2);
	
	return $row2;
}

/** Marques - Notes privées**/

// Lecture d'un texte privé marque
function lit_enr_MqueNPriv($code,$codeu)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBMQUEN. "` WHERE `mquen_codemque` = '$code' AND `mquen_codeu` = '$codeu'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $row2;
}

/** Contacts Marques **/

// Vérification du nombre de contacts dans une fiche marque
// On tient compte du niveau utilisateur
function nb_cmque_in_mque($code)
{
	global
		$_SESSION;
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBCMQUE. "` WHERE `cmque_codemque` = '$code'";
	switch ($_SESSION["niv_log"])
	{
		case 3 :
		case 4 :
			$rexist.= " AND (`cmque_prop` = '*' OR `cmque_prop` = '".$_SESSION["code_age"]."')";
			break;
		default :
			break;
	}
	$rs2 = mysql_query($rexist) or die(mysql_error());
	$nbexist = mysql_num_rows($rs2);
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $nbexist;
}

// Lecture d'un contact marque
function lit_enr_cmque_id_in_mque($id,$code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBCMQUE. "` WHERE `cmque_id` = '$id' AND `cmque_codemque` = '$code'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $row2;
}

/** Contacts Marques - Notes privées**/

// Lecture d'un texte privé contact marque
function lit_enr_CMqueNPriv($id,$codeu)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBCMQUEN. "` WHERE `cmquen_idcmque` = '$id' AND `cmquen_codeu` = '$codeu'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $row2;
}


/** Liens Marques **/

// Vérification du nombre de liens dans une fiche marque
function nb_wmque_in_mque($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBWMQUE. "` WHERE `wmque_codemque` = '$code'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	$nbexist = mysql_num_rows($rs2);
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $nbexist;
}

// Lecture d'un lien marque
function lit_enr_wmque_id_in_mque($id,$code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBWMQUE. "` WHERE `wmque_id` = '$id' AND `wmque_codemque` = '$code'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $row2;
}

/** Liens Marques - Notes privées**/

// Lecture d'un texte privé lien marque
function lit_enr_WMqueNPriv($code,$codeu)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBWMQUEN. "` WHERE `wmquen_idwmque` = '$code' AND `wmquen_codeu` = '$codeu'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $row2;
}

?>