<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.2
 *
 * Copyright (C) 2006-2015  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://smi.no-ip.org
 ****************************************************************************************/


// 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 différents fichiers dans SMI */
/*************************************************************/

/**
 * Retourne la liste des icônes non utilisées
 *
 * @param      $url_img
 * @param      $url_lien
 * @param bool $open
 *
 * @return bool
 */
function lst_icon_not_used($url_img, $url_lien,$open = TRUE)
{
    global
    $db;
    if ($open == TRUE)
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
    $used = FALSE;
    $rech = "SELECT COUNT(*) FROM `" . TBSTA . "`, `" . TBLIEU . "`, `" . TBDOSC . "`, `" . TBDOSS . "`, `" . TBTA . "`, `" . TBPSTA . "`, `" . TBINTC . "`";
    $rech .= " WHERE " . TBSTA . ".statut_img = '$url_img' OR " . TBLIEU . ".lieu_img = '$url_img'";
    $rech .= " OR " . TBDOSC . ".dosc_img = '$url_img' OR " . TBDOSS . ".doss_img = '$url_img'";
    $rech .= " OR " . TBTA . ".ta_img = '$url_img' OR " . TBPSTA . ".psta_img = '$url_img'";
    $rech .= " OR " . TBINTC . ".intc_img = '$url_img'";
    $nbused = $db->get_var($rech);
    if ($nbused == 0) {
        echo "<a href=\"" . $url_lien . "\">";
        echo "<img src=\"" . $url_img . "\" border =\"0\">";
        echo " </a>";
    }
    if ($open == TRUE)
        $db->disconnect();
    return $used;
}
