<?php 
global $myUser, $conf;
if(!$myUser->can('setting_global','read')) throw new Exception("Permissions insuffisantes",403);

?>
<div class="row">
	<div class="col-md-12 general-settings" id="general-settings" data-action="general_settings_save">
		<br>
		<?php if($myUser->can('setting_global','configure')): ?>
		<div class="btn btn-success float-right" onclick="general_settings_save();"><i class="fas fa-check"></i> Enregistrer</div>
		<?php endif; ?>
		<h3>Réglages généraux</h3>
		<p>Bienvenue sur l'espace de configuration, cliquez sur le menu de gauche pour acceder aux différents réglages de l'application.</p>
		<hr/>

		<?php if($myUser->can('setting_global','configure')): ?>
		<div>
			<h5>Informations générales :</h5>
			<ul>
				<li>Nom du programme : <strong><?php echo PROGRAM_NAME; ?></strong></li>
				<li>Version : <strong><?php echo SOURCE_VERSION; ?></strong></li>
				<li>Version PHP : <strong><?php echo phpversion(); ?></strong></li>
				<li>Version Apache : <strong><?php echo apache_get_version(); ?></strong></li>
				<li>Version de la base: <strong><?php echo BASE_SGBD.' - '.Database::version(); ?></strong></li>
			
				<li>Adresse de la base : <strong><?php echo BASE_HOST; ?></strong></li>
				<li>Time Zone : <strong><?php echo TIME_ZONE; ?></strong></li>
				<li>OS : <strong><?php echo PHP_OS; ?></strong></li>
				
				<li>Horodatage serveur : <strong><?php echo date('d/m/Y H:i.s'); ?></strong></li>
			</ul>
		</div>
		<hr>
		<!-- Réglages généraux de l'application -->
		<div>
			<h5>Theme :</h5>
			<div class="row">
				<div class="col-md-12 identity-block">
					<div class="row">
						<div class="col-md-6">
							<label> Logo application (clair) <small class="text-muted">(S'appliquera sur les fonds sombre de l'ensemble des établissements)</small> : </label>
							<input type="file" data-type="image" value="action.php?action=general_logo_download" class="form-control-file" id="logo" name="logo" data-delete="general_logo_delete(this)" data-default-src="img/logo/default-logo.png">
							<br>
						</div>
						<div class="col-md-6">
							<label> Logo application (sombre) <small class="text-muted">(S'appliquera sur les fonds clairs de l'ensemble des établissements)</small> : </label>
							<input type="file" data-type="image" value="action.php?action=general_logo_download&variant=dark" class="form-control-file" id="logo_dark"  name="logo_dark" data-delete="general_logo_delete(this)" data-default-src="img/logo/default-logo.dark.png">
							<br>
						</div>
						<div class="col-md-6">
							<label> Favicon de l'application <small class="text-muted">(Cette favicon s'appliquera sur l'ensemble du site)</small> : </label>
							<input type="file" data-type="image" value="action.php?action=general_favicon_download" class="form-control-file" id="favicon" name="favicon" data-delete="general_favicon_delete(this)" data-default-src="img/logo/default-favicon.png">
							<br>
						</div>
						<div class="col-md-6"></div>
						<div class="col-md-6">
							<label class="pointer">
								<input type="checkbox" <?php echo $conf->get('show_application_name')? 'checked="checked"':'' ?> id="show_application_name" name="show_application_name" data-type="checkbox"> Afficher le nom du programme <small class="text-muted">(Partie en-tête uniquement)</small>
							</label>
						</div>
						
					</div>
				</div>



			
			</div>
			<hr>
			<div class="row">
				<div class="col-md-12">
					<h5>Mots de passes :</h5>
					<p>Définissez la politique de format et de changement des mots de passes</p>
					<h6 class="font-weight-bold">FORMATS</h6>
					<div id="password-format-form">
						<?php 

							$selectedFormats = json_decode($conf->get('password_format'),true);
							if(!is_array($selectedFormats )) $selectedFormats  = array();
							foreach(User::passwordFormats() as $format):
						?>
						<label><input type="checkbox" data-type="checkbox" <?php echo in_array($format['pattern'], $selectedFormats)?'checked="checked"':''; ?> data-label="<?php echo $format['label'] ?>" data-pattern="<?php echo $format['pattern'] ?>" onclick="password_settings_format()"> <?php echo $format['label'] ?></label><br/>
						<?php endforeach; ?>
						
					</div>
					<h6 class="font-weight-bold">RENOUVELLEMENT</h6>
					<label>Forcer l'utilisateur a renouveller son mot de passe tous les :</label>
					
					<div class="input-group">
						<input type="text" id="password-delay" value="<?php echo $conf->get('password_delay'); ?>" class="form-control form-control-sm col-sm-1"> 
						<div class="input-group-append">
						    <span class="input-group-text">jours</span>
						</div>
					</div>
					<small class="text-muted">Laisser vide pour désactiver cette fonctionnalité</small>

					<br/><div class="btn btn-success" onclick="general_reset_password_delay()"> Forcer les utilisateurs à changer maintenant</div>


				</div>
			</div>

			<hr/>
			<h5>Logs :</h5>
			<p>Veuillez définir la durée de conservation des logs en Jours poru chaques catégorie<br>
			Laisser vide si vous souhaitez conserver les logs indéfiniment (déconseillé)</p>
				<?php foreach(Log::staticQuery('SELECT DISTINCT category FROM {{table}}',array(),true) as $log): 
					$slug = slugify($log->category);
				?>
					<div class="row mt-2">	
						<div class="col-md-12">
					

							<div class="input-group">
							  <div class="input-group-prepend">
							    <span class="input-group-text"><small class="text-muted mini-title mr-1">catégorie</small> <code><?php echo $log->category ?></code></span>
							  </div>
						

							
							<input type="number" onkeydown="return input_number_control(event);" class="form-inline form-control" id="log_retention_time_<?php echo $slug; ?>"  placeholder="ex. 30" value="<?php echo $conf->get('log_retention_time_'.$slug); ?>">
							</div>		
						</div>
					</div>
				<?php endforeach; ?>
					
			

			<hr/>
			<h5>Divers :</h5>
			<div class="row">
				<div class="col-md-12 general-settings-block">
					<?php echo Configuration::html('configuration-global'); ?>
				</div>
			</div>
			<hr/>
			<div class="row">
				<div class="col-md-12 maintenance-block">
					<span class="float-right">
						<input onchange="toggle_maintenance();" <?php echo file_exists('enabled.maintenance') ? 'checked="checked"' : '' ?> type="checkbox" autocomplete="off" name="maintenance" id="maintenance" data-type="checkbox" data-class="">
						<label for="maintenance" class="pointer">Site en maintenance</label><br>
					</span>
					<h5>Maintenance :</h5>
					<div class="clear"></div>
					<textarea data-type="wysiwyg" name="maintenance-content" id="maintenance-content" cols="30" rows="3" class="form-control">
						<?php echo file_exists('enabled.maintenance') ? file_get_contents('enabled.maintenance') : (file_exists('disabled.maintenance') ? file_get_contents('disabled.maintenance') : ''); ?>
					</textarea>
				</div>
			</div>
		</div>
		<?php endif; ?>
	</div>
</div>
<br>

