<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.0
 *
 * Copyright (C) 2006-2014  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");

include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_fici.inc.php");
include_once("../classes/phpmailer/class.phpmailer.php");
include_once("../classes/phpmailer/class.smtp.php");
include_once("mail.inc.php");
include_once("../classes/ezSQL/shared/ez_sql_core.php");
include_once("../classes/ezSQL/mysqli/ez_sql_mysqli.php");
include_once("../inc/func_sql.inc.php");
Archivelog(@$_SESSION["code_log"]);
// Variables Formulaire
fix_magic_quotes();
$_POST = clean_str($_POST);

if ((@$_POST['nom'] <> "") AND (@$_POST['desc'] <> "") AND ((@$_POST['td'] == 0) OR (@$_POST['td'] == 1))) {
    $nom_ficdir = @$_POST['nfic'];
    if ((substr($nom_ficdir, 0, 1) <> '.') AND (substr($nom_ficdir, 0, 2) <> '..') AND (trim($nom_ficdir) <> '.htaccess')) // Contrôle de hack
    {
        $chemin_complet = $url_gfc . "/" . $nom_ficdir;

        $td = @$_POST['td'];

        $ren_ok = FALSE;

        if ((est_createur_ficdir($chemin_complet, @$_SESSION["code_log"]) == TRUE) OR (@$_SESSION["niv_log"] == 9)) {
            switch ($td) {
                case 0 :
                    if (is_dir($chemin_complet))
                        $ren_ok = TRUE;
                    break;
                case 1 :
                    if (is_file($chemin_complet))
                        $ren_ok = TRUE;
                    break;
                default :
                    break;
            }
        } else
            $ren_ok = FALSE;

        if ($ren_ok == TRUE) {
            $codeuser = @$_SESSION["code_log"];
            $nouv_desc = @$_POST['desc'];
            $nouv_detail = @$_POST['detail'];
            $prive = 0;
            if ($_POST['prive'] == "y") $prive = 1;
            $min_level = $_SESSION["niv_log"];
            $min_level = intval($_POST['minlevel']);

            $rech = "";
            $rech2 = "";
            $id = donne_id_fic($chemin_complet);

            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            if ($id <> -1) {
                $row = lit_enr_ficid($id, FALSE);
                if (is_array($row)) {
                    extract($row);

                    // On met à jour la fiche
                    $rech = "UPDATE `" . TBFIC . "`";
                    $rech .= " SET `fic_nom`='" . $fic_nom . "', `fic_type`='" . $fic_type . "', `fic_desc`='" . $db->escape($nouv_desc) . "',";
                    $rech .= " `fic_detail`='" . $db->escape($nouv_detail) . "', `fic_prive`='" . $prive . "', `fic_minlevel`='" . $min_level . "',";
                    $rech .= " `fic_datecrea`='" . $datea . "',";
                    $rech .= " `fic_nbtel`='" . $fic_nbtel . "'";
                    $rech .= "  WHERE `fic_id` = '" . $id . "'";

                    // Si le répertoire a été rendu privé, on rend privés tous les fichiers et dossiers qu'il contient
                    // Sinon, on ne touche à rien
                    if ($prive == 1) {
                        $rech2 = "UPDATE `" . TBFIC . "`";
                        $rech2 .= " SET `fic_prive`='1'";
                        $rech2 .= "  WHERE `fic_nom` LIKE '" . $fic_nom . "%'";
                    }
                } else {
                    $msg = _("Impossible de renommer ce fichier/répertoire");
                    $retourliste = FALSE;
                }
            } else {
                $rech = "INSERT INTO `" . TBFIC . "`";
                $rech .= " (fic_nom,fic_type,fic_desc,fic_detail,fic_prive,fic_minlevel,fic_datecrea,fic_codecrea,fic_nbtel) VALUES";
                $rech .= " ('$chemin_complet','$td','" . $db->escape($nouv_desc) . "','" . $db->escape($nouv_detail) . "','$prive','$min_level','$datea','$codeuser','')";
            }
            $db->query($rech);
            if ($rech2 <> "")
                $db->query($rech2);
            $db->disconnect();

            $msg = _("Nom complet et détail modifiés");
            $retourliste = TRUE;
        } else {
            $msg = _("Impossible de renommer ce fichier/répertoire");
            $retourliste = FALSE;
        }
    } else {
        $msg = _("Nom de répertoire incorrect");
        $retourliste = FALSE;
    }
} else {
    $msg = _("Problème dans vos variables URL");
    $retourliste = FALSE;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>SMI - <?PHP echo _("ESPACE PRIVE"); ?> : <?PHP echo _("Renommage fichier/répertoire"); ?></title>

    <?PHP include_once("../inc/header.inc.php"); ?>

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            <?PHP
            if ($retourliste == FALSE)
                echo "warn_txt('" . str_escape($msg) . "');";
            else
                echo "pop_txt('" . str_escape($msg) . "');";
            ?>
            Focus_first();
        }

        $(document).ready(function () {
            init_all();
        });
        //-->
    </script>

</head>
<body>

<p align="center"><span class="titrepage"><?PHP echo _("RENOMMAGE FICHIER/REPERTOIRE"); ?></span></p>

<p align="center">&nbsp;</p>
<?PHP
close_fen_auto('', 'fscomp', 'window.opener.');
?>
</body>
</html>
