Advertisement
Guest User

lib.config.inc.php

a guest
Apr 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.71 KB | None | 0 0
  1. <?php
  2.  
  3. function afficheConfig($filename) {
  4.     $config = parse_ini_file($filename, true);
  5.     #echo '<pre>'. print_r($config, 1) . '</pre>';
  6.  
  7.     $content = [];
  8.     $content[] = '<form id=formConfig name=formConfig method=post action=sendFormConfig.html onsubmit="return newAjaxJSON(this.getAttribute(\'action\'), this)">';
  9.  
  10.     $content[] = '<fieldset><legend>SITE</legend>';
  11.     $content[] = '<label for=SITE_titre>Titre</label>';
  12.     $content[] = '<input required type=text id=SITE_titre name="SITE[titre]" value='.$config['SITE']['titre'].'>';
  13.     $content[] = '<label for=SITE_images>Images</label>';
  14.     $content[] = '<input required type=text id=SITE_images name="SITE[images]" value='.$config['SITE']['images'].'>';
  15.     $content[] = '</fieldset>';
  16.  
  17.     $content[] = '<fieldset><legend>ADMIN</legend>';
  18.     $content[] = '<label for=ADMIN_mail>Mail</label>';
  19.     $content[] = '<input required type=text id=ADMIN_mail name="ADMIN[mail]" value='.$config['ADMIN']['mail'].'>';
  20.     $content[] = '<label for=ADMIN_label>Label</label>';
  21.     $content[] = '<input required type=text id=ADMIN_label name="ADMIN[label]" value='.$config['ADMIN']['label'].'>';
  22.     $content[] = '</fieldset>';
  23.  
  24.     $content[] = '<fieldset><legend>EPHEC</legend>';
  25.     $content[] = '<label for=ADMIN_mail>Mail</label>';
  26.     $content[] = '<input required type=text id=EPHEC_mail name="EPHEC[mail]" value='.$config['EPHEC']['mail'].'>';
  27.     $content[] = '<label for=ADMIN_nom>Nom/prénom</label>';
  28.     $content[] = '<input required type=text id=EPHEC_nom name="EPHEC[nom]" value='.$config['EPHEC']['nom'].'>';
  29.     $content[] = '<label for=ADMIN_matricule>Matricule</label>';
  30.     $content[] = '<input required type=text id=EPHEC_matricule name="EPHEC[matricule]" value='.$config['EPHEC']['matricule'].'>';
  31.     $content[] = '<label for=ADMIN_groupe>Groupe</label>';
  32.     $content[] = '<input required type=text id=EPHEC_groupe name="EPHEC[groupe]" value='.$config['EPHEC']['groupe'].'>';
  33.     $content[] = '<label for=ADMIN_host>Host</label>';
  34.     $content[] = '<input required type=text id=EPHEC_host name="EPHEC[host]" value='.$config['EPHEC']['host'].'>';
  35.     $content[] = '</fieldset>';
  36.  
  37.     $content[] = '<fieldset><legend>LOGO</legend>';
  38.     $content[] = '<label for=LOGO_logo>Logo</label>';
  39.     $content[] = '<input required type=text id=LOGO_logo name="LOGO[logo]" value='.$config['LOGO']['logo'].'>';
  40.     $content[] = '<label for=LOGO_TAILLE>Taille</label>';
  41.     $content[] = '<input required type=number id=LOGO_TAILLE name="LOGO[taille]" value='.$config['LOGO']['taille'].' min='.$config['LOGO']['min'].' max='.$config['LOGO']['max'].' step='.$config['LOGO']['pas'].'>';
  42.     $content[] = '<input hidden name="LOGO[min]" value='.$config['LOGO']['min'].'>';
  43.     $content[] = '<input hidden name="LOGO[max]" value='.$config['LOGO']['max'].'>';
  44.     $content[] = '<input hidden name="LOGO[pas]" value='.$config['LOGO']['pas'].'>';
  45.     $content[] = '</fieldset>';
  46.  
  47.     $content[] = '<fieldset><legend>DB</legend>';
  48.     $content[] = '<label for=DB_host>Host</label>';
  49.     $content[] = '<input required type=text id=DB_host name="DB[host]" value='.$config['DB']['host'].'>';
  50.     $content[] = '<label for=DB_user>User</label>';
  51.     $content[] = '<input required type=text id=DB_user name="DB[user]" value='.$config['DB']['user'].'>';
  52.     $content[] = '<label for=DB_pswd>Password</label>';
  53.     $content[] = '<input required type=text id=DB_pswd name="DB[pswd]" value='.$config['DB']['pswd'].'>';
  54.     $content[] = '<label for=DB_name>Name</label>';
  55.     $content[] = '<input required type=text id=DB_name name="DB[dbname]" value='.$config['DB']['dbname'].'>';
  56.     $content[] = '</fieldset>';
  57.  
  58.     $content[] = '<fieldset><legend>AVATAR</legend>';
  59.     $content[] = '<label for=AVATAR_dossier>Dossier</label>';
  60.     $content[] = '<input required type=text id=AVATAR_dossier name="AVATAR[dossier]" value='.$config['AVATAR']['dossier'].'>';
  61.     $content[] = '<label for=AVATAR_anonyme>Anonyme</label>';
  62.     $content[] = '<input required type=text id=AVATAR_anonyme name="AVATAR[anonyme]" value='.$config['AVATAR']['anonyme'].'>';
  63.     $content[] = '<label for=AVATAR_taille>Taille</label>';
  64.     $content[] = '<input required type=text id=AVATAR_taille name="AVATAR[taille]" value='.$config['AVATAR']['taille'].' min='.$config['AVATAR']['min'].' max='.$config['AVATAR']['max'].'>';
  65.     $content[] = '<input hidden name="AVATAR[min]" value='.$config['AVATAR']['min'].'>';
  66.     $content[] = '<input hidden name="AVATAR[max]" value='.$config['AVATAR']['max'].'>';
  67.     $content[] = '<label for=AVATAR_type>Type</label>';
  68.     $content[] = '<span id=AVATAR_type>';
  69.     foreach($config['AVATAR']['type'] as $type) {
  70.         $checked = in_array($type, $config['AVATAR']['choix']) ? 'checked' : '';
  71.         $content[] = '<input hidden type=checkbox checked name="AVATAR[type]['.$type.']">';
  72.         $content[] = '<label for=AVATAR_type_'.$type.'>'.$type.'</label>';
  73.         $content[] = '<input type=checkbox name="AVATAR[choix]['.$type.']" id=AVATAR_type_'.$type.' '.$checked.'>';
  74.     }
  75.     $content[] = '</span>';
  76.     $content[] = '</label>';
  77.     $content[] = '</fieldset>';
  78.  
  79.     $content[] = '<button type=submit>envoyer</button>';
  80.     $content[] = '<span id=modifCfg></span>';
  81.     $content[] = '</from>';
  82.     return implode("\r\n", $content);
  83. }
  84.  
  85. function updateConfig($filename) {
  86.     $file = fopen($filename, 'w');
  87.     foreach($_POST as $name => $block) {
  88.         fwrite($file, "[$name]\r\n");
  89.         foreach($block as $key => $value) {
  90.             if (gettype($value) != 'array')
  91.                 fwrite($file, "$key = $value\r\n");
  92.             else
  93.                 foreach($value as $subkey => $_)
  94.                     fwrite($file, $key."[] = $subkey\r\n");
  95.         }
  96.     }
  97.     fclose($file);
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement