Editeur Editez un fichier

Edition d'un fichier

Editez le fichier applications/nuasix/api_authentifications.php
<?php
//_________________________________________________________________________________
//Récupération d'une authentification
$reqAuthentification  	= getQueries("api_authentifications LEFT JOIN api_infos_tables ON api_authentifications.table_uniqid = api_infos_tables.info_table_uniqid", 
									 array("api_authentifications.application_uniqid" => $_SESSION['current_application_uniqid']));

$authentification     	= $reqAuthentification['count'] ? $reqAuthentification['result'][0] : array();
//_________________________________________________________________________________
//_________________________________________________________________________________
//Récupération des tables
$reqTables              = getQueries("api_infos_tables", array("application_uniqid" => $_SESSION['current_application_uniqid']));
$tables                 = $reqTables['result'];
//_________________________________________________________________________________
//_________________________________________________________________________________
//Récupération des colonnes
if($reqAuthentification['count']) {
	$reqColumns      	= getQueries("api_infos_tables_columns", array("table_uniqid" => $authentification['table_uniqid']));
	$columns          	= $reqColumns['result'];
}
//_________________________________________________________________________________
//_________________________________________________________________________________
//Création d'une authentification
if(isset($_POST['add-authentification'])) {
    
    //Données du formulaire
    $form       = array('authentification_uniqid'				=> uniqid(), 
						'authentification_name'     			=> htmlspecialchars($_POST['authentification_name']), 
                        'authentification_description' 			=> htmlspecialchars($_POST['authentification_description']), 
                        'table_uniqid'              			=> htmlspecialchars($_POST['table_uniqid']), 
                        'application_uniqid'           			=> $_SESSION['current_application_uniqid'], 
                        'user_id'                   			=> $user -> getUserId()
                       );

    $flag       = dbRowInsert2("api_authentifications", $form);

    if($flag) {
		
		//_________________________________________________________________________________
		$reqTable				= getQueries('api_infos_tables', array('info_table_uniqid' => htmlspecialchars($_POST['table_uniqid'])));
		$table					= $reqTable['result'][0];
		//_________________________________________________________________________________
		//Création des colonnes nécessaires pour l'authentification
		$columnAccessTokenName	= $table['info_table_name_single'] .'_api_access_token';
		$formAccessToken    	= array("info_table_column_uniqid"      => uniqid(), 
										'info_table_column_name'        => $columnAccessTokenName, 
										"info_table_column_description" => "Access Token", 
										"info_table_column_type"        => "varchar", 
										"info_table_column_length"      => "255", 
										"info_table_column_encrypt"     => 0, 
										"table_uniqid"                  => $table['info_table_uniqid'], 
										'application_uniqid'            => $_SESSION['current_application_uniqid'], 
										'user_id'                       => $user -> getUserId());
		
		//Contrôle si pas déjà existant
		$reqItem			= getQueries('api_infos_tables_columns', array('info_table_column_name' => $columnLastLogin, 
																		   'table_uniqid' 			=> $table['info_table_uniqid']));
		
		if(!$reqItem['count']) {
			$response         	= create_column(array('table_id'    => $table['idInfoTable'], 
													  'columns'     => array( array('column_name' => $columnAccessTokenName, 
																					'column_type' => "varchar", 
																					'column_null' => true) 
																			)));

			if($response['success'])
				$flag2         	= dbRowInsert2('api_infos_tables_columns', $formAccessToken);
			else
				itsLog(array('log_table'        => "api_authentifications",
							 'log_operation'    => "Erreur dans la création de la colonne " . $columnAccessTokenName, 
							 'log_request'      => json_encode($formAccessToken),
							 'log_response'     => json_encode($response),
							 'log_selector'     => json_encode(array()), 
							 'log_color'        => "warning", 
							 'log_display'      => 1,
							 'log_timeout'      => 5000,
							 'user_id'          => $user -> getUserId()
				));
		}
		//_________________________________________________________________________________
		$columnLastLogin	= $table['info_table_name_single'] .'_api_last_login';
		$formLastLogin		= array("info_table_column_uniqid"      => uniqid(), 
										'info_table_column_name'        => $columnLastLogin, 
										"info_table_column_description" => "Dernière connexion", 
										"info_table_column_type"        => "datetime", 
										"info_table_column_length"      => "0", 
										"info_table_column_encrypt"     => 0, 
										"table_uniqid"                  => $table['info_table_uniqid'], 
										'application_uniqid'            => $_SESSION['current_application_uniqid'], 
										'user_id'                       => $user -> getUserId());
		
		
		//Contrôle si pas déjà existant
		$reqItem			= getQueries('api_infos_tables_columns', array('info_table_column_name' => $columnLastLogin, 
																		   'table_uniqid' 			=> $table['info_table_uniqid']));
		
		if(!$reqItem['count']) {
			$response2         	= create_column(array('table_id'    => $table['idInfoTable'], 
													  'columns'     => array( array('column_name' => $columnLastLogin, 
																					'column_type' => "datetime", 
																					'column_null' => true) 
																			)));
			if($response2['success'])
				$flag2         	= dbRowInsert2('api_infos_tables_columns', $formLastLogin);
			else
				itsLog(array('log_table'        => "api_authentifications",
							 'log_operation'    => "Erreur dans la création de la colonne " . $columnLastLogin, 
							 'log_request'      => json_encode($formAccessToken),
							 'log_response'     => json_encode($response2),
							 'log_selector'     => json_encode(array()), 
							 'log_color'        => "warning", 
							 'log_display'      => 1,
							 'log_timeout'      => 5000,
							 'user_id'          => $user -> getUserId()
				));
		}
		//_________________________________________________________________________________
		//_________________________________________________________________________________
        itsLog(array('log_table'        => "api_authentifications",
                     'log_operation'    => "Création d'une authentification", 
                     'log_request'      => json_encode($form),
                     'log_response'     => json_encode($flag),
                     'log_selector'     => json_encode(array()), 
                     'log_color'        => "success", 
                     'log_display'      => 1,
                     'log_timeout'      => 5000,
                     'user_id'          => $user -> getUserId()
        ));
    } else {
        itsLog(array('log_table'        => "api_authentifications",
                     'log_operation'    => "Erreur durant la création d'une authentification", 
                     'log_request'      => json_encode($form),
                     'log_response'     => json_encode($flag),
                     'log_selector'     => json_encode(array()), 
                     'log_color'        => "danger", 
                     'log_display'      => 1,
                     'log_timeout'      => 5000, 
                     'user_id'          => $user -> getUserId()
        ));
    }
    
    
    //Refresh
    redirect($_SERVER['REQUEST_URI']);
}
//_________________________________________________________________________________
//_________________________________________________________________________________
//Mise à jour d'une authentification
if(isset($_POST['update-authentification'])) {
    
    //Données du formulaire
    $form       = array('authentification_name'     			=> htmlspecialchars($_POST['authentification_name']), 
                        'authentification_description' 			=> htmlspecialchars($_POST['authentification_description']), 
						'authentification_email_column_uniqid'	=> htmlspecialchars($_POST['authentification_email_column_uniqid']), 
						'authentification_pwd_column_uniqid'   	=> htmlspecialchars($_POST['authentification_pwd_column_uniqid']), 
                        'application_uniqid'           			=> $_SESSION['current_application_uniqid'], 
                        'user_id'                   			=> $user -> getUserId()
                       );
	$selector	= array('idAuthentification' => $authentification['idAuthentification']);
	
    $flag       = dbRowUpdate2("api_authentifications", $form, $selector);

    if($flag) {
        itsLog(array('log_table'        => "api_authentifications",
                     'log_operation'    => "Modification d'une authentification", 
                     'log_request'      => json_encode($form),
                     'log_response'     => json_encode($flag),
                     'log_selector'     => json_encode($selector), 
                     'log_color'        => "success", 
                     'log_display'      => 1,
                     'log_timeout'      => 5000,
                     'id_log'           => $authentification['idAuthentification'], 
                     'user_id'          => $user -> getUserId()
        ));
    } else {
        itsLog(array('log_table'        => "api_authentifications",
                     'log_operation'    => "Erreur durant la modification d'une authentification", 
                     'log_request'      => json_encode($form),
                     'log_response'     => json_encode($flag),
                     'log_selector'     => json_encode($selector), 
                     'log_color'        => "danger", 
                     'log_display'      => 1,
                     'log_timeout'      => 5000, 
                     'id_log'           => $authentification['idAuthentification'], 
                     'user_id'          => $user -> getUserId()
        ));
    }
    
    
    //Refresh
    redirect($_SERVER['REQUEST_URI']);
}
//_________________________________________________________________________________
//_________________________________________________________________________________
//Suppression d'une authentification
if(isset($_GET['action'])) {
	
	
	$selector	= "idAuthentification" . " = " . $authentification['idAuthentification'];
	//var_dump(dbRowDelete("api_authentifications", $selector));
	
	if( encrypt_decrypt("decrypt", rawurldecode($_GET['action']), $key_user, $iv_user) == 'delete' )
		$flag 	= dbRowDelete("api_authentifications", $selector);
	else
		$flag	= false;
	
   
    if($flag) {
        itsLog(array('log_table'        => "api_authentifications",
                     'log_operation'    => "Suppression d'une authentification", 
                     'log_request'      => json_encode(array()),
                     'log_response'     => json_encode($flag),
                     'log_selector'     => json_encode($selector), 
                     'log_color'        => "success", 
                     'log_display'      => 1,
                     'log_timeout'      => 5000,
                     'id_log'           => $authentification['idAuthentification'], 
                     'user_id'          => $user -> getUserId()
        ));
    } else {
        itsLog(array('log_table'        => "api_authentifications",
                     'log_operation'    => "Erreur durant la suppression d'une authentification", 
                     'log_request'      => json_encode(array()),
                     'log_response'     => json_encode($flag),
                     'log_selector'     => json_encode($selector), 
                     'log_color'        => "danger", 
                     'log_display'      => 1,
                     'log_timeout'      => 5000, 
                     'id_log'           => $authentification['idAuthentification'], 
                     'user_id'          => $user -> getUserId()
        ));
    }
    
    
    //Refresh
    redirect('index.php?page_slug=api_authentifications');
}
//_________________________________________________________________________________
?>
<!--begin::Content-->
<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
	<!--begin::Container-->
	<div class="container-xxl" id="kt_content_container">
		<!--begin::API Overview-->
		<div class="card mb-5 mb-xxl-10">
			<!--begin::Header-->
			<div class="card-header">
				<!--begin::Title-->
				<div class="card-title">
					<h3>API Authentification</h3>
				</div>
				<!--end::Title-->
			</div>
			<!--end::Header-->
			<!--begin::Body-->
			<div class="card-body py-10">
				<!--begin::Row-->
				<div class="row mb-10">
					<!--begin::Col-->
					<div class="col-md-6 pb-10 pb-lg-0">
						<h2>Authentification</h2>
						<p class="fs-6 fw-semibold text-gray-600 py-2">Connectez vos utilisateurs en créant un moyen d'authentification.</p>
						<?php
						if($reqAuthentification['count']) {?>
						<!--begin::Row-->
						<div class="row gx-9 gy-6">
							<!--begin::Col-->
							<div class="col-xl-12" data-kt-billing-element="card">
								<!--begin::Card-->
								<div class="card card-dashed h-xl-100 flex-row flex-stack flex-wrap p-6">
									<!--begin::Info-->
									<div class="d-flex flex-column py-2">
										<!--begin::Owner-->
										<div class="d-flex align-items-center fs-4 fw-bold mb-5"><?= $authentification['authentification_name']?>
										<span class="badge badge-light-success fs-7 ms-2"><?= $authentification['info_table_name']?></span></div>
										<!--end::Owner-->
										<!--begin::Wrapper-->
										<div class="d-flex align-items-center">
											<!--begin::Details-->
											<div>
												<div class="fs-4 fw-bold">Authentification active</div>
												<div class="fs-6 fw-semibold text-gray-400"><?= $authentification['authentification_description']?></div>
											</div>
											<!--end::Details-->
										</div>
										<!--end::Wrapper-->
									</div>
									<!--end::Info-->
									<!--begin::Actions-->
									<div class="d-flex align-items-center py-2">
										<a href="index.php?page_slug=api_authentifications&action=<?= rawurlencode(encrypt_decrypt("encrypt", 'delete', $key_user, $iv_user))?>" class="btn btn-sm btn-light btn-active-light-primary me-3">Supprimer</a>	
										<button class="btn btn-sm btn-light btn-active-light-primary" data-bs-toggle="modal" data-bs-target="#update-item">Modifier</button>
									</div>
									<!--end::Actions-->
								</div>
								<!--end::Card-->
							</div>
							<!--end::Col-->
						</div>
						<!--end::Row-->	
						<?php
						} else {?>
						<a href="#" class="btn btn-light btn-active-light-primary" data-bs-toggle="modal" data-bs-target="#add-item">Créer une authentification</a>	
						<?php
						}
						?>
					</div>
					<!--end::Col-->
					<!--begin::Col-->
					<div class="col-md-6">
						<h2>Clé(s) API</h2>
						<p class="fs-6 fw-semibold text-gray-600 py-2">Générez une clé API attachée à un utilisateur spécifique.</p>
						<a href="index.php?page_slug=api_tokens" class="btn btn-light btn-active-light-primary">Gérez les clés API</a>
					</div>
					<!--end::Col-->
				</div>
				<!--end::Row-->
				<!--begin::Notice-->
				<!--begin::Notice-->
				<div class="notice d-flex bg-light-primary rounded border-primary border border-dashed p-6">
					<!--begin::Icon-->
					<!--begin::Svg Icon | path: icons/duotune/art/art006.svg-->
					<span class="svg-icon svg-icon-2tx svg-icon-primary me-4">
						<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
							<path opacity="0.3" d="M22 19V17C22 16.4 21.6 16 21 16H8V3C8 2.4 7.6 2 7 2H5C4.4 2 4 2.4 4 3V19C4 19.6 4.4 20 5 20H21C21.6 20 22 19.6 22 19Z" fill="currentColor" />
							<path d="M20 5V21C20 21.6 19.6 22 19 22H17C16.4 22 16 21.6 16 21V8H8V4H19C19.6 4 20 4.4 20 5ZM3 8H4V4H3C2.4 4 2 4.4 2 5V7C2 7.6 2.4 8 3 8Z" fill="currentColor" />
						</svg>
					</span>
					<!--end::Svg Icon-->
					<!--end::Icon-->
					<!--begin::Wrapper-->
					<div class="d-flex flex-stack flex-grow-1">
						<!--begin::Content-->
						<div class="fw-semibold">
							<div class="fs-6 text-gray-700">Utilisez l'authentification lorsque vous souhaitez connecter des utilisateurs externes de Nuasix selon une table de données de votre choix.
							<a class="fw-bold" href="#">En savoir plus</a>.</div>
						</div>
						<!--end::Content-->
					</div>
					<!--end::Wrapper-->
				</div>
				<!--end::Notice-->
				<!--end::Notice-->
			</div>
			<!--end::Body-->
		</div>
		<!--end::API overview-->
	</div>
	<!--end::Container-->
	<!--begin::Modal - Ajouter authentification-->
	<div class="modal fade" id="add-item" tabindex="-1" aria-hidden="true">
		<!--begin::Modal dialog-->
		<div class="modal-dialog modal-dialog-centered mw-650px">
			<!--begin::Modal content-->
			<div class="modal-content">
				<!--begin::Modal header-->
				<div class="modal-header">
					<!--begin::Modal title-->
					<h2>Ajouter une authentification</h2>
					<!--end::Modal title-->
					<!--begin::Close-->
					<div class="btn btn-sm btn-icon btn-active-color-primary" data-bs-dismiss="modal">
						<!--begin::Svg Icon | path: icons/duotune/arrows/arr061.svg-->
						<span class="svg-icon svg-icon-1">
							<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
								<rect opacity="0.5" x="6" y="17.3137" width="16" height="2" rx="1" transform="rotate(-45 6 17.3137)" fill="currentColor" />
								<rect x="7.41422" y="6" width="16" height="2" rx="1" transform="rotate(45 7.41422 6)" fill="currentColor" />
							</svg>
						</span>
						<!--end::Svg Icon-->
					</div>
					<!--end::Close-->
				</div>
				<!--end::Modal header-->
				<!--begin::Modal body-->
				<div class="modal-body scroll-y mx-5 mx-xl-15 my-7">
					<!--begin::Form-->
					<form class="form" action="" method="post">
						<!--begin::Input group-->
						<div class="d-flex flex-column mb-7 fv-row">
							<!--begin::Label-->
							<label class="d-flex align-items-center fs-6 fw-semibold form-label mb-2">
								<span class="required">Nom</span>
								<i class="fas fa-exclamation-circle ms-2 fs-7" data-bs-toggle="tooltip" title="Le nom est utilisé à l'interne de Nuasix uniquement."></i>
							</label>
							<!--end::Label-->
							<input type="text" class="form-control form-control-solid" placeholder="" name="authentification_name" required />
						</div>
						<!--end::Input group-->
						<!--begin::Input group-->
						<div class="d-flex flex-column mb-7 fv-row">
							<!--begin::Label-->
							<label class="d-flex align-items-center fs-6 fw-semibold form-label mb-2">
								<span>Description</span>
								<i class="fas fa-exclamation-circle ms-2 fs-7" data-bs-toggle="tooltip" title="La description est utilisée à l'interne de Nuasix uniquement."></i>
							</label>
							<!--end::Label-->
							<input type="text" class="form-control form-control-solid" placeholder="" name="authentification_description" />
						</div>
						<!--end::Input group-->
						<!--begin::Input group-->
						<div class="d-flex flex-column mb-7 fv-row">
							<!--begin::Label-->
							<label class="required fs-6 fw-semibold form-label mb-2">Table API</label>
							<!--end::Label-->
							<!--begin::Input wrapper-->
							<div class="position-relative">
								<select name="table_uniqid" class="form-select form-select-solid" data-control="select2" data-hide-search="true" data-placeholder="Month">
									<?php
									foreach($tables as $table)
										echo '<option value="'.$table['info_table_uniqid'].'">'.$table['info_table_name'].'</option>';
									?>
								</select>
							</div>
							<!--end::Input wrapper-->
						</div>
						<!--end::Input group-->
						<!--begin::Actions-->
						<div class="text-center pt-15">
							<button type="reset" class="btn btn-light me-3" data-bs-dismiss="modal">Annuler</button>
							<button type="submit" class="btn btn-primary" name="add-authentification">
								<span class="indicator-label">Ajouter</span>
								<span class="indicator-progress">Patientez...
								<span class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
							</button>
						</div>
						<!--end::Actions-->
					</form>
					<!--end::Form-->
				</div>
				<!--end::Modal body-->
			</div>
			<!--end::Modal content-->
		</div>
		<!--end::Modal dialog-->
	</div>
	<!--end::Modal - Ajouter authentification-->
	<?php
	if($reqAuthentification['count']) {?>
	<!--begin::Modal - Modifier authentification-->
	<div class="modal fade" id="update-item" tabindex="-1" aria-hidden="true">
		<!--begin::Modal dialog-->
		<div class="modal-dialog modal-dialog-centered mw-650px">
			<!--begin::Modal content-->
			<div class="modal-content">
				<!--begin::Modal header-->
				<div class="modal-header">
					<!--begin::Modal title-->
					<h2>Modifier une authentification</h2>
					<!--end::Modal title-->
					<!--begin::Close-->
					<div class="btn btn-sm btn-icon btn-active-color-primary" data-bs-dismiss="modal">
						<!--begin::Svg Icon | path: icons/duotune/arrows/arr061.svg-->
						<span class="svg-icon svg-icon-1">
							<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
								<rect opacity="0.5" x="6" y="17.3137" width="16" height="2" rx="1" transform="rotate(-45 6 17.3137)" fill="currentColor" />
								<rect x="7.41422" y="6" width="16" height="2" rx="1" transform="rotate(45 7.41422 6)" fill="currentColor" />
							</svg>
						</span>
						<!--end::Svg Icon-->
					</div>
					<!--end::Close-->
				</div>
				<!--end::Modal header-->
				<!--begin::Modal body-->
				<div class="modal-body scroll-y mx-5 mx-xl-15 my-7">
					<!--begin::Form-->
					<form class="form" action="" method="post">
						<!--begin::Input group-->
						<div class="d-flex flex-column mb-7 fv-row">
							<!--begin::Label-->
							<label class="d-flex align-items-center fs-6 fw-semibold form-label mb-2">
								<span class="required">Nom</span>
								<i class="fas fa-exclamation-circle ms-2 fs-7" data-bs-toggle="tooltip" title="Le nom est utilisé à l'interne de Nuasix uniquement."></i>
							</label>
							<!--end::Label-->
							<input type="text" class="form-control form-control-solid" placeholder="" name="authentification_name" value="<?= $authentification['authentification_name']?>" required />
						</div>
						<!--end::Input group-->
						<!--begin::Input group-->
						<div class="d-flex flex-column mb-7 fv-row">
							<!--begin::Label-->
							<label class="d-flex align-items-center fs-6 fw-semibold form-label mb-2">
								<span>Description</span>
								<i class="fas fa-exclamation-circle ms-2 fs-7" data-bs-toggle="tooltip" title="La description est utilisée à l'interne de Nuasix uniquement."></i>
							</label>
							<!--end::Label-->
							<input type="text" class="form-control form-control-solid" placeholder="" name="authentification_description" value="<?= $authentification['authentification_description']?>"/>
						</div>
						<!--end::Input group-->
						<!--begin::Input group-->
						<div class="d-flex flex-column mb-7 fv-row">
							<!--begin::Label-->
							<label class="required fs-6 fw-semibold form-label mb-2">Colonne de l'e-mail</label>
							<!--end::Label-->
							<!--begin::Input wrapper-->
							<div class="position-relative">
								<select name="authentification_email_column_uniqid" class="form-select form-select-solid" data-control="select2" data-hide-search="true" data-placeholder="Colonne e-mail">
									<?php
									foreach($columns as $column)
										echo '<option value="'.$column['info_table_column_uniqid'].'" '.($column['info_table_column_uniqid'] == $authentification['authentification_email_column_uniqid'] ? 'selected' : '').'>'.$column['info_table_column_name'].'</option>';
									?>
								</select>
							</div>
							<!--end::Input wrapper-->
						</div>
						<!--end::Input group-->
						<!--begin::Input group-->
						<div class="d-flex flex-column mb-7 fv-row">
							<!--begin::Label-->
							<label class="required fs-6 fw-semibold form-label mb-2">Colonne du mot de passe</label>
							<!--end::Label-->
							<!--begin::Input wrapper-->
							<div class="position-relative">
								<select name="authentification_pwd_column_uniqid" class="form-select form-select-solid" data-control="select2" data-hide-search="true" data-placeholder="Colonne mot de passe">
									<?php
									foreach($columns as $column)
										echo '<option value="'.$column['info_table_column_uniqid'].'" '.($column['info_table_column_uniqid'] == $authentification['authentification_pwd_column_uniqid'] ? 'selected' : '').'>'.$column['info_table_column_name'].'</option>';
									?>
								</select>
							</div>
							<!--end::Input wrapper-->
						</div>
						<!--end::Input group-->
						<!--begin::Actions-->
						<div class="text-center pt-15">
							<button type="reset" class="btn btn-light me-3" data-bs-dismiss="modal">Annuler</button>
							<button type="submit" class="btn btn-primary" name="update-authentification">
								<span class="indicator-label">Ajouter</span>
								<span class="indicator-progress">Patientez...
								<span class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
							</button>
						</div>
						<!--end::Actions-->
					</form>
					<!--end::Form-->
				</div>
				<!--end::Modal body-->
			</div>
			<!--end::Modal content-->
		</div>
		<!--end::Modal dialog-->
	</div>
	<!--end::Modal - Modifier authentification-->	
	<?php
	}
	?>
</div>
<!--end::Content-->

Conseils et liens

Liens vers des ressources utiles pour l'édition de fichier