<?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");

include_once("../inc/func.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_fici.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"]);
$aff_form = TRUE;
$msg = '';

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

        $chemin_complet = $url_gfc . "/" . $nom_ficdir;

        if ((est_createur_ficdir($chemin_complet, @$_SESSION["code_log"]) == TRUE) OR (@$_SESSION["niv_log"] == 9)) {
            switch ($td) {
                case 0 :
                    if (!is_dir($chemin_complet))
                        $aff_form = FALSE;
                    break;
                case 1 :
                    if (!is_file($chemin_complet))
                        $aff_form = FALSE;
                    break;
                default :
                    break;
            }
        } else {
            $aff_form = FALSE;
            $msg = _("Syntaxe incorrecte");
        }
    }
} else {
    $aff_form = FALSE;
    $msg = _("Syntaxe incorrecte");
}
?>
<!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 language="javascript">
        <!--
        var tab1_champ = ["nom:desc; format:txt ; req:Y ; txt:<?PHP echo _("Nom à affecter"); ?> ; lmx:100 ; stok:frmok ; stbad:frmbad",
            "nom:detail; format:txt ; req:N ; txt:<?PHP echo _("Libellé"); ?> ;  stok:frmok ; stbad:frmbad"];
        //-->
    </script>


    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            init_valid_form('enr','fdren','<?PHP echo $_SESSION['date_fmtshort']; ?>',tab1_champ,'','');
            add_func_click('annul', 'sclose', '');
            Focus_first();
        }

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


</head>

<body>
<?PHP
if ($aff_form == TRUE) {
    $fic_desc = _("(Pas déclaré)");
    $fic_detail = "";
    $row = lit_enr_fic($chemin_complet);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
        if (trim($fic_desc) == "")
            $fic_desc = _("(Pas déclaré)");
    }
    ?>
    <p align="center"><span class="titrepage"><?PHP echo _("RENOMMAGE FICHIER/REPERTOIRE"); ?></span></p>
    <br />
    <br />
    <br />
    <!--- Formulaire de renommage des fichiers ou répertoires -->
    <form action="fdren_enr.php" method="POST" enctype="multipart/form-data" name="fdren" id="fdren">
        <input type="hidden" name="td" id="td" value="<?PHP echo @$_GET['td'] ?>">
        <input type="hidden" name="nfic" id="nfic" value="<?PHP echo @$_GET['name'] ?>">
        <input name="nbutton" type="hidden" id="nbutton" value="">
        <table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">
            <tr>
                <td nowrap class="rubfrm" align="right" class="annot_std_gras" valign="middle" id="f_chemin">
                    <?PHP echo _("Nom :"); ?>
                </td>
                <td nowrap valign="middle">
                    <input style="margin-left:5px;" name="nom" type="text" id="nom" value="<?PHP echo $fic_desc ?>"
                           size="80" readonly>
                    <br />
				<span class="annot_petit_it" style="margin-left:5px;">
				<?PHP
                if ($td == 0)
                    echo _("(Nota : C'est un répertoire)");
                else
                    echo _("(Nota : C'est un fichier)");
                ?>
				</span>
                </td>
            </tr>
            <tr>
                <td nowrap class="rubfrm" align="right" valign="middle" id="f_desc">
                    <?PHP echo _("Nouveau nom :"); ?>
                </td>
                <td nowrap valign="middle">
                    <input style="margin-left:5px;" type="text" name="desc" maxlength="100" size="80" value="">
                </td>
            </tr>
            <tr>
                <td nowrap class="rubfrm" align="right" valign="top" id="f_detail"><?PHP echo _("Descriptif :"); ?></td>
                <td nowrap align="left">
                    <textarea style="margin-left:5px;" name="detail" rows="10"
                              id="detail"><?PHP echo $fic_detail; ?></textarea>
                </td>
            </tr>
            <tr>
                <td nowrap class="rubfrm" align="right" valign="top" id="f_prive"><?PHP echo _("Privé ? :"); ?></td>
                <td nowrap align="left">
                    <?PHP
                    // On ne peut pas modifier un type privé si le dossier contenant est lui-même privé
                    $disable = FALSE;
                    $tab_fic = explode("/", $fic_nom);
                    $nom_fic = $tab_fic[count($tab_fic) - 1];
                    $racine = str_replace("/" . $nom_fic, "", $fic_nom);
                    if (is_prive($racine)) {
                        echo '<input type="checkbox" name="prive2" value="y" style="background : #FFFFFF;" checked="checked" disabled>';
                        echo '<input type="hidden" name="prive" value="y">';

                        echo '<span class="annot_petit_it" style="margin-left:5px;">';
                        echo ' '._("(Impossible de modifier le mode privé car le dossier racine est déjà privé)");
                        echo '</span>';
                    } else
                        echo '<input type="checkbox" name="prive" value="y"';
                    if ($fic_prive == 1)
                        echo ' checked="checked"';
                    echo ' style="background : #FFFFFF;" >';
                    ?>
                </td>
            </tr>
            <tr>
                <td nowrap class="rubfrm" align="right" valign="top" id="f_minlevel"><?PHP echo _("Niveau utilisateur ? :"); ?></td>
                <td nowrap align="left">
                    <?PHP
                    echo '<select name="minlevel" size="1" id="minlevel" style="margin-left:5px;">';
                    foreach ($fictec_minlev as $idx => $value) {
                        echo '<option value="' . $idx . '"';
                        if (intval($fic_minlevel) == intval($idx))
                            echo ' selected';
                        echo '>' . $value . '</option>';
                    }
                    echo '</select>';
                    echo '<div class="annot_petit_it" style="margin-left:5px;">';
                    echo _("Niveau minimum pouvant voir ces fichiers. Aucun = uniquement créateur");
                    echo '<br />'._("Valide uniquement si privé");
                    echo '</div>';
                    ?>
                </td>
            </tr>
        </table>
        <p align="center">
        <?PHP
        echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Valider").'">';
        echo ' <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="'._("Réinitialiser").'">';
        echo '<input name="annul" type="button" class="bton_std" id="annul" value="'._("Quitter").'">';
        ?>
        </p>
    </form>
    <!--- Fin du Formulaire de renommage -->
<?PHP
} else {
    if ($retourliste == FALSE)
        exec_func_js("warn_txt('" . str_escape($msg) . "')");
    else
        exec_func_js("pop_txt('" . str_escape($msg) . "')");
    close_fen_auto(_("Retour à la liste"), '', 'window.opener', 5000);
}
?>
</body>
</html>
