<?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/config.inc.php");
include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_fici.inc.php");
include_once("../inc/fic_txt.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_mail.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/func_txtcm.inc.php");
include_once("../classes/phpmailer/class.phpmailer.php");
include_once("../classes/phpmailer/class.smtp.php");
include_once("../inc/mail.inc.php");
include_once("../classes/ephpu/upload_class.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);

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

// Téléchargement uniquement pour l'administrateur
if (@$_SESSION["niv_log"] == 9) {
    $max_size = $taille_maxi_admin; // Taille maximum autorisée pour téléchargement

    $my_upload = new file_upload;

    // Définition du chemin de stockage
    $my_upload->upload_dir = $root . REP . "/logos/";
    $my_upload->extensions = [".png", ".gif"]; // specify the allowed extensions here
    $my_upload->language = "fr"; // use this to switch the messages into an other language (translate first!!!)
    $my_upload->max_length_filename = 100; // change this value to fit your field length in your database (standard 100)
    $my_upload->rename_file = true;

    if (@$_POST['nbutton'] == "ok") {
        $codeuser = @$_SESSION["code_log"];

        $my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
        $infos_img = @getimagesize($my_upload->the_temp_file);
        $largeurDestination = $infos_img[0];
        $hauteurDestination = $infos_img[1];
        if (($largeurDestination >= 195) AND ($hauteurDestination >= 36)) {
            $my_upload->the_file = $_FILES['upload']['name'];
            $my_upload->http_error = $_FILES['upload']['error'];
            $my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
            $my_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
            switch ($td) {
                case "cge" :
                    $new_name = "logcge";
                    break;
                case "age" :
                case "do" :
                case "st" :
                    $new_name = "log" . strtolower($_POST['code']);
                    break;
                default :
                    break;
            }
            if ($my_upload->upload($new_name)) { // new name is an additional filename information, use this to rename the uploaded file

                $msg = _("Téléchargement réussi");
                $retourliste = TRUE;
            } else {
                $retourliste = FALSE;
                $msg = $my_upload->show_error_string();
            }
        } else {
            $msg = _("Mauvaises dimensions");
            $retourliste = FALSE;
        }
    }
} else {
    $retourliste = FALSE;
    $msg = _("Vous n'avez pas le droit de télécharger des logos");
}
?>
<!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 _("Téléchargement Logo"); ?></title>

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

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            Focus_first();
        }

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

</head>
<body>

<?php include_once("../inc/entete.inc.php"); ?>
<p align="center"><span class="titrepage"><?PHP echo _("TELECHARGEMENT DE LOGO"); ?></span></p>

<p align="center">&nbsp;</p>

<p align="center"><span class="annot_std_gras"><?php echo $msg; ?></span></p>
<?PHP
if ($retourliste == TRUE)
    aff_ret_idx_man($td, '', '', FALSE);
else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "logo_maj.php?td=" . $td);
include_once("pied.php");
?>
</body>
</html>