Преглед на файлове

Fixe Menu, Insert User & form user

stany.ferer преди 1 година
родител
ревизия
9e76220c9c
променени са 4 файла, в които са добавени 42 реда и са изтрити 19 реда
  1. 2 2
      core/class/core.class.php
  2. 2 3
      core/class/user.class.php
  3. 20 0
      core/javascript/cms.user.php
  4. 18 14
      core/views/pages/cms.user.php

+ 2 - 2
core/class/core.class.php

@@ -209,7 +209,7 @@ class core
     {
         if (access::ifAccesss($_id)) {
             ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
-            echo '<li class="nav-item"><a class="nav-link' . get::currentPage($_id) . '" aria-current="page"  href="' . $_href . '"' . $_style . '>';
+            echo '<li class="nav-item" style="margin:5px 0;"><a style="display:unset;" class="nav-link' . get::currentPage($_id) . '" aria-current="page"  href="' . $_href . '"' . $_style . '>';
             echo icon::getFont(["type" => $_id, "size" => "18px"]);
             echo ' ' . $_titre . '</a></li>';
         }
@@ -219,7 +219,7 @@ class core
     {
         if (access::ifAccesss($_id)) {
             ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
-            echo '<li class="nav-item"><a class="nav-link" target="' . $_target . '" href="' . $_href . '"' . $_style . '>';
+            echo '<li class="nav-item" style="margin:5px 0;"><a style="display:unset;" class="nav-link" target="' . $_target . '" href="' . $_href . '"' . $_style . '>';
             echo icon::getFont(["type" => $_id, "size" => "18px"]);
             echo ' ' . $_titre . '</a></li>';
         }

+ 2 - 3
core/class/user.class.php

@@ -133,8 +133,8 @@ class user {
     
     public static function add_user(array $_input){
         db::query("INSERT INTO " . DB_T_USER . " "
-                . "(email, password, googleAuthenticator, googleAuthenticatorSecret, prenom, nom, id_type, tags, actif) "
-                . "VALUES (:email, :password, :googleAuthenticator, :googleAuthenticatorSecret, :prenom, :nom, :id_type, :tags, :actif)");
+                . "(email, password, googleAuthenticator, googleAuthenticatorSecret, prenom, nom, id_type, actif) "
+                . "VALUES (:email, :password, :googleAuthenticator, :googleAuthenticatorSecret, :prenom, :nom, :id_type, :actif)");
         db::bind(':email', $_input["email"]);
         db::bind(':password', md5($_input["password"]));
         db::bind(':prenom', $_input["prenom"]);
@@ -149,7 +149,6 @@ class user {
 
             $tags = tags::textToId($_input["tags"], 1); 
             self::addTags(db::lastInsertId(), $tags);
-
             alert::recSuccess("La création a bien été prise en compte");
         } catch (Exception $ex) {
             alert::recError("Erreur lors de la création de l'utilisateur");

+ 20 - 0
core/javascript/cms.user.php

@@ -0,0 +1,20 @@
+<script>
+    function validateAndSubmit() {
+        const form = document.getElementById('form-user');
+        const requiredFields = form.querySelectorAll('[required]');
+        let allFieldsFilled = true;
+
+        requiredFields.forEach(field => {
+            if (!field.value.trim()) {
+                allFieldsFilled = false;
+                field.style.borderColor = 'red';
+            } else {
+                field.style.borderColor = '';
+            }
+        });
+
+        if (allFieldsFilled) {
+            form.submit();
+        }
+    }
+</script>

+ 18 - 14
core/views/pages/cms.user.php

@@ -81,7 +81,7 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
 <br />
 <?php if($protect != 2): ?>
     
-<form method="post" action="/submit.php" oninput='password2.setCustomValidity(password2.value != password.value ? "Les mots de passe ne sont pas identiques" : "")'>
+<form id="form-user" method="post" action="/submit.php" oninput='password2.setCustomValidity(password2.value != password.value ? "Les mots de passe ne sont pas identiques" : "")' onsubmit="return(false);">
 
     <input type="hidden" name="from" value="user">
     
@@ -105,12 +105,12 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
         ?>
         <?php if($protect == 0): ?>
             <?php
-                html::printSelect('name="id_type" class="form-select"', $id_type, $user["id_type"]);
+                html::printSelect('name="id_type" class="form-select"', $id_type, @$user["id_type"]);
             ?>
         <?php endif; ?>
         <?php if($protect == 1 OR $protect == 2): ?>
             <?php 
-                html::printSelect('class="form-control" disabled', $id_type, $user["id_type"]);
+                html::printSelect('class="form-control" disabled', $id_type, @$user["id_type"]);
                 html::printInput('type="hidden" name="id_type"', $user["id_type"]);
             ?>
         <?php endif; ?>
@@ -121,14 +121,14 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
         if(access::ifAccesss("add-user") AND core::ifGet("id")) { ?>
             <div class="form-group">
                 <label>Rôles aditionnels</label>
-                <?= html::printInput('type="text" name="tags" id="tags"', $user["tags"]) ?>
+                <?= html::printInput('type="text" name="tags" id="tags"', @$user["tags"]) ?>
             </div>
             <br />
     <?php 
         } elseif(isset($user["tags"])) { ?>
         <div class="form-group">
             <label>Rôles aditionnels</label>
-            <?= html::printInput('type="text" class="form-control" name="tags" readonly="readonly"', $user["tags"]) ?>
+            <?= html::printInput('type="text" class="form-control" name="tags" readonly="readonly"', @$user["tags"]) ?>
         </div>
         <br />
     <?php 
@@ -142,7 +142,7 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
         <?php
             $confPrenom = 'type="text" name="prenom" class="form-control" ';
             $confPrenom .= $protect == 2 ? 'readonly="readonly"' : 'required';
-            html::printInput($confPrenom, $user["prenom"]);
+            html::printInput($confPrenom, @$user["prenom"]);
         ?>
     </div>
     <br />
@@ -152,7 +152,7 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
         <?php
             $confNom = 'type="text" name="nom" class="form-control" ';
             $confNom .= $protect == 2 ? 'readonly="readonly"' : 'required';
-            html::printInput($confNom, $user["nom"]);
+            html::printInput($confNom, @$user["nom"]);
         ?>
     </div>
     <br />
@@ -162,7 +162,7 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
         <?php
             $confEmail = 'type="text" name="email" class="form-control" ';
             $confEmail .= $protect == 2 ? 'readonly="readonly"' : 'required';
-            html::printInput($confEmail, $user["email"]);
+            html::printInput($confEmail, @$user["email"]);
         ?>
     </div>
     <br />
@@ -172,7 +172,7 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
     <div class="form-group">
         <label>Mot de passe</label>
         <?php
-            $confPassword = 'type="password" class="form-control" minlength="8" maxlength="25" name="password" ';
+            $confPassword = 'type="password" class="form-control" minlength="8" maxlength="25" name="password" required ';
             $confPassword .= core::ifGet("add") ? 'required"' : NULL;
             html::printInput($confPassword);
         ?>
@@ -182,7 +182,7 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
     <div class="form-group">
         <label>Confirmation du mot de passe</label>
         <?php
-            $confPassword2 = 'type="password" class="form-control" minlength="8" maxlength="25" name="password2" ';
+            $confPassword2 = 'type="password" class="form-control" minlength="8" maxlength="25" name="password2" required ';
             $confPassword2 .= core::ifGet("add") ? 'required"' : NULL;
             html::printInput($confPassword2);
         ?>
@@ -196,7 +196,7 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
                     0 => "Désactivé",
                     1 => "Activé",
                 ];
-            html::printSelect('name="googleAuthenticator" class="form-select"', $googleAuthenticator, $user["googleAuthenticator"]);
+            html::printSelect('name="googleAuthenticator" class="form-select"', $googleAuthenticator, @$user["googleAuthenticator"]);
         ?>
     </div>
     <br />
@@ -225,7 +225,7 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
                     0 => "Compte désactivé",
                     1 => "Compte activé",
                 ];
-            html::printSelect('name="actif" class="form-select"', $actif, $user["actif"]);
+            html::printSelect('name="actif" class="form-select"', $actif, @$user["actif"]);
         ?>
     </div>
     <br />
@@ -235,7 +235,7 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
         <?= html::printInput('type="hidden" name="actif"', $user["actif"]); ?>
     <?php endif; ?>
 
-    <input class="btn btn-primary btn-lg" style="width: 100%; margin-bottom:20px;" type="submit" value="<?php echo $submit ?>">
+    <input class="btn btn-primary btn-lg" style="width: 100%; margin-bottom:20px;" type="button" value="<?php echo $submit ?>"  onclick="validateAndSubmit()">
     
 </form>
 
@@ -249,4 +249,8 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
             max: 3
         });
     });
-</script>
+</script>
+
+<?php
+    get::javascript("user");
+?>