<?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/fic_droits.inc.php");
include_once("../inc/fic_fici.inc.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/lst.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();
$_GET = clean_str($_GET);

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

$pbm_logo = FALSE;
$titre = '';
switch ($td) {
    case "cge" :
        $titre = _("LOGO CENTRE DE GESTION");
        break;
    case "age" :
        $titre = _("LOGO AGENCE");
        break;
    case "do" :
        $titre = _("LOGO DONNEUR D'ORDRES");
        break;
    case "st" :
        $titre = _("LOGO SOUS-TRAITANT");
        break;
    default :
        $pbm_logo = TRUE;
        break;
}
?>
<!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échargements Logo"); ?></title>

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

    <script language="javascript">
    <!--
    <?PHP
    switch ($td)
    {
        case "age" :
        case "do" :
        case "st" :
            echo 'var tab1_champ = new Array(';
            echo '"nom:code ; format:liste ; req:Y ; txt:'._("Nom").' ; vmn:1 ; stok:frmok ; stbad:frmbad");';
            break;
        default :
            break;
    }
    ?>
    //-->
    </script>

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            <?PHP
            switch ($td)
            {
                case "age" :
                case "st" :
                case "do" :
                    echo "init_valid_upll('ok','upll_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    break;
                default :
                    echo "init_valid_upllcge('ok','upll_maj');";
                    break;
            }

            ?>
            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 $titre ?></span></p>

<p align="center" class="annot_gras_it"><?PHP echo _("Veuillez choisir le logo que vous souhaitez télécharger"); ?> </p>
<?PHP
if ($pbm_logo == FALSE) {
    ?>
    <!--- Formulaire d'Upload des Logos -->
    <div id="wait" style="display:block" align="center">
        <p class="annot_gras_it"><?PHP echo _("Téléchargement en cours..."); ?></p>
        <img src="../img/wait30.gif" alt="attn" width="30" height="30" border="0"/>
    </div>
    <div id="no_wait" style="display:block">
    <form action="upll_enr.php" method="POST" enctype="multipart/form-data" name="upll_maj" id="upll_maj">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $taille_maxi_admin; ?>">
    <input name="td" type="hidden" id="td" value="<?PHP echo $td; ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">

    <table width="70%" border="0" cellpadding="0" cellspacing="0" align="center">
        <?PHP
        $txt_code = '';
        switch ($td)
        {
            case "age" :
                $txt_code = _("Pour quelle agence ?");
                $tab_code = [];
                $txt_noresults = _("-- Aucune agence active --");

                // création de la liste des agences ouvertes
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBAGE . "` WHERE `age_ouvert` = '1' ORDER BY age_nom";
                $rows = $db->get_results($rech, ARRAY_A);
                foreach ($rows as $row) {
                    $row = encode_str($row);
                    extract($row);
                    $age_nomcode = $age_nom . " (" . $age_code . ")";
                    if (exist_logo($age_code))
                        $age_nomcode .= " --- " .("Logos OK");
                    else {
                        $existpng = exist_logopng($age_code);
                        $existgif = exist_logogif($age_code);
                        if (($existpng == FALSE) AND ($existgif == FALSE))
                            $age_nomcode .= " --- "._("Les 2 formats manquent");
                        else {
                            if ($existpng == FALSE)
                                $age_nomcode .= " --- "._("Le format PNG manque");
                            if ($existgif == FALSE)
                                $age_nomcode .= " --- "._("Le format GIF manque");
                        }
                    }
                    $tab_code[$age_code] = $age_nomcode;
                }
                $db->disconnect();
                break;
            case "st" :
                $txt_code = _("Pour quel sous-traitant ?");
                $tab_code = [];
                $txt_noresults =  _("-- Aucun sous-traitant actif --");

                // création de la liste des sous-traitants actifs
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBST . "` WHERE `st_ouvert` = '1' ORDER BY st_nom";
                $rows = $db->get_results($rech, ARRAY_A);

                if ($rows) {
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);
                        $st_nomcode = $st_nom . " (" . $st_code . ")";
                        if (exist_logo($st_code))
                            $st_nomcode .= " --- "._("Logos OK");
                        else {
                            $existpng = exist_logopng($st_code);
                            $existgif = exist_logogif($st_code);
                            if (($existpng == FALSE) AND ($existgif == FALSE))
                                $st_nomcode .= " --- "._("Les 2 formats manquent");
                            else {
                                if ($existpng == FALSE)
                                    $st_nomcode .= " --- "._("Le format PNG manque");
                                if ($existgif == FALSE)
                                    $st_nomcode .= " --- "._("Le format GIF manque");
                            }
                        }
                        $tab_code[$st_code] = $st_nomcode;
                    }
                }
                $db->disconnect();
                break;
            case "do" :
                $txt_code = _("Pour quel donneur d'ordres ?");
                $tab_code = [];
                $txt_noresults =  _("-- Aucun donneur d'ordres actif --");

                // Création de la liste des donneurs d'ordres actifs
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBDO . "` WHERE `do_ouvert` = '1' ORDER BY do_nom";
                $rows = $db->get_results($rech, ARRAY_A);

                if ($rows) {
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);
                        $do_nomcode = $do_nom . " (" . $do_code . ")";
                        if (exist_logo($do_code))
                            $do_nomcode .= " --- "._("Logos OK");
                        else {
                            $existpng = exist_logopng($do_code);
                            $existgif = exist_logogif($do_code);
                            if (($existpng == FALSE) AND ($existgif == FALSE))
                                $do_nomcode .= " --- "._("Les 2 formats manquent");
                            else {
                                if ($existpng == FALSE)
                                    $do_nomcode .= " --- "._("Le format PNG manque");
                                if ($existgif == FALSE)
                                    $do_nomcode .= " --- "._("Le format GIF manque");
                            }
                        }
                        $tab_code[$do_code] = $do_nomcode;
                    }
                }
                $db->disconnect();
                break;
            default :
                break;
        }

        if ($txt_code <> '')
        {
            echo '<tr>';
            echo '<td class="rubfrm" nowrap align="right" valign="top" id="f_code">';
            echo $txt_code;
            echo '</td>';
            echo '<td style="padding-left:5px;">';
            cre_select('code', 'code', $tab_code, '', '', _("-- Faites votre choix --"),1,FALSE,'-1',$txt_noresults);
            echo '</td>';
            echo '</tr>';
        }
        ?>
        <tr>
            <td class="rubfrm" nowrap align="right" valign="top" id="f_upload">
                <label for="upload">
                    <?PHP echo _("Logo à télécharger"); ?>
                    <span class="annot_petit_it">(<?PHP echo _("Dans le répertoire des logos"); ?>) :</span>
                </label>
            </td>
            <td nowrap align="left">
                <input style="margin-left:5px;" type="file" name="upload" id="upload" size="100">
		        <div class="annot_petit_it" style="margin-left:5px;">
		        <?PHP echo _("Doit faire au minimum 195x36 dpi"); ?>
		        </div>
            </td>
        </tr>
        <tr>
            <td nowrap align="right" class="annot_std_gras" valign="middle">
                <label for="replace"><?PHP echo _("Remplacer sur le serveur"); ?> : </label>
            </td>
            <td nowrap align="left">
                <input type="checkbox" name="replace" value="y" style="background : #FFFFFF;">
            </td>
        </tr>
        <tr>
            <td nowrap align="right" class="annot_std_gras" valign="middle">
                <label for="check">
                    <?PHP echo _("Vérifier le nom du fichier"); ?> :
                </label>
            </td>
            <td nowrap valign="middle" align="left">
                <?PHP
                if ($niv_util <> 9) {
                    ?>
                    <input name="check" type="checkbox" value="y" style="background : #FFFFFF;" checked
                           disabled="disabled">
                <?PHP
                } else {
                    ?>
                    <input name="check" type="checkbox" value="y" style="background : #FFFFFF;" checked>
                <?PHP
                }
                ?>
            </td>
        </tr>
        </table>
        <p align="center">
        <?PHP
        echo '<input name="ok" type="button" class="bton_std" id="ok" value="' . _("Envoyer") . '">';
        echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="' . _("Réinitialiser") . '">';
        ?>
        </p>
    </form>
    </div>
    <!--- Fin du Formulaire d'upload -->
<?PHP
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");
include_once("pied.php");
?>
</body>
</html>