<?php
/*
 * Ajout d'un client à l'OPAC 3D
 */

include 'includes/functions.php';
define('INI_SEARCH', 'conf/config.ini');
if (!file_exists(INI_SEARCH)) {
    die('Fichier de config introuvable');
}
$ini = parse_ini_file(INI_SEARCH, true);
$urlBdd = parse_url($ini['Database']['database_ftp']);
$urlBdd['user'] = urldecode($urlBdd['user']);
$urlBdd['pass'] = (isset($urlBdd['pass']))  ? urldecode($urlBdd['pass']) : '';
$urlBdd['host'] = urldecode($urlBdd['host']);
$urlBddCentral = parse_url($ini['Database']['database_institutions']);
$urlBddCentral['user'] = urldecode($urlBddCentral['user']);
$urlBddCentral['pass'] = (isset($urlBddCentral['pass']))  ? urldecode($urlBddCentral['pass']) : '';
$urlBddCentral['host'] = urldecode($urlBddCentral['host']);
echo headerPage('Ajout d\'un client Portail');
?>

<?php if (isset($_GET['ipclient'])) echo '<h2>'.$_GET['ipclient'].'</h2>';else echo '<h2>Hébergé '.($_GET['mode'] == simple ? '<a href="?mode=advanced" title="Passer en mode Avancé">[Simple]</a>' : '<a href="?mode=simple" title="Passer en mode Simple">[Avancé]</a>').'</h2>'; ?>
<div class="blocMenu">
    <form>
      <p><h4>Informations client</h4>
          <table id="tableClient" style="margin:0 auto;">
              <tr>
                  <td>ID Client : </td><td><input id="idclient" type="text" size="40" onblur="javascript:document.getElementById('keyclient').value=this.value.toUpperCase();document.getElementById('userFTP').value=this.value;document.getElementById('passFTP').value=admin.randomString(10);" /></td><td class="help" <?php echo readHelp('idclient') ?>>&nbsp;</td>
              </tr>
              <?php
                  if ($_GET['mode'] != 'simple') echo '
                      <tr>
                          <td>Clé Client : </td><td><input id="keyclient" type="text" size="15" /></td><td class="help" '.readHelp('keyclient').'>&nbsp;</td>
                      </tr>';
                  else echo '<input id="keyclient" type="hidden" value="" />';
              ?>
              <tr>
                  <td>IP agent client : </td><td><input id="ipclient" type="text" size="40" /></td><td class="help" <?php echo readHelp('ipclient') ?>>&nbsp;</td>
              </tr>
              <tr>
                  <td colspan="3">&nbsp;</td>
              </tr>
          </table>
      </p>
      <p><h4><input style="vertical-align:middle;" type="checkbox" name="enableFTP" id="enableFTP" checked="checked" <?php if ($_GET['mode'] != 'simple') echo 'onclick="javascript:if (this.checked == true) document.getElementById(\'tableFTP\').style.display=\'inline\';else document.getElementById(\'tableFTP\').style.display=\'none\';"'; ?>/> Créer un accès FTP au client pour les exports <span class="help" <?php echo readHelp('enableFTP') ?>>&nbsp;</span></h4>
        <?php
        if ($_GET['mode'] != 'simple') echo '
            <table id ="tableFTP" style="margin:0 auto;">
              <tr>
                  <td>Utilisateur FTP : </td><td><input id="userFTP" type="text" size="15" /></td><td class="help" '.readHelp('userFTP').'>&nbsp;</td>
              </tr>
              <tr>
                  <td>Mot de passe FTP : </td><td><input id="passFTP" type="text" size="15" /></td><td class="help" '.readHelp('passFTP').'>&nbsp;</td>
              </tr>
              <tr>
                  <td>Accès à la BDD FTP : </td><td><input id="hostBDD" type="text" size="15" value="'.$urlBdd['host'].'" /><br /><input id="userBDD" type="text" size="15" value="'.$urlBdd['user'].'" /><br /><input id="passBDD" type="text" size="15" value="'.$urlBdd['pass'].'" /></td><td><span class="help" '.readHelp('hostBDD').'>&nbsp;</span><br /><span class="help" '.readHelp('userBDD').'>&nbsp;</span><br /><span class="help" '.readHelp('passBDD').'>&nbsp;</span></td>
              </tr>
              <tr>
                  <td>Accès à la BDD Central : </td><td><input id="hostBDDCentral" type="text" size="15" value="'.$urlBddCentral['host'].'" /><br /><input id="userBDDCentral" type="text" size="15" value="'.$urlBddCentral['user'].'" /><br /><input id="passBDDCentral" type="text" size="15" value="'.$urlBddCentral['pass'].'" /></td><td><span class="help" '.readHelp('hostBDDCentral').'>&nbsp;</span><br /><span class="help" '.readHelp('userBDDCentral').'>&nbsp;</span><br /><span class="help" '.readHelp('passBDDCentral').'>&nbsp;</span></td>
              </tr>
              <tr>
                  <td colspan="3">&nbsp;</td>
              </tr>
            </table>';
        else echo '<input id="userFTP" type="hidden" value="" /><input id="passFTP" type="hidden" value="" /><input id="hostBDD" type="hidden" value="'.$urlBdd['host'].'" /><input id="userBDD" type="hidden" value="'.$urlBdd['user'].'" /><input id="passBDD" type="hidden" value="'.$urlBdd['pass'].'" /><input id="hostBDDCentral" type="hidden" value="'.$urlBddCentral['host'].'" /><input id="userBDDCentral" type="hidden" value="'.$urlBddCentral['user'].'" /><input id="passBDDCentral" type="hidden" value="'.$urlBddCentral['pass'].'" />';
        ?>
        <table style="margin:0 auto;">
          <tr>
            <td colspan="3"><input id="addButton" type="button" value="Créer" onclick="admin.addClientOpac(document.getElementById('idclient').value, document.getElementById('keyclient').value, document.getElementById('ipclient').value, document.getElementById('enableFTP').checked, document.getElementById('userFTP').value, document.getElementById('passFTP').value, document.getElementById('hostBDD').value, document.getElementById('userBDD').value, document.getElementById('passBDD').value, document.getElementById('hostBDDCentral').value, document.getElementById('userBDDCentral').value, document.getElementById('passBDDCentral').value);"/></td>
          </tr>
        </table>
     </p>
    </form>
  <p id="resultAdd"></p>
  <div id="infosAdd"></div>
</div>

<?php
echo footerPage();
?>
