From fa27a1c82f87e948fd908eab8fe1cc939371281d Mon Sep 17 00:00:00 2001 From: aschwarz Date: Wed, 5 Apr 2023 10:49:38 +0200 Subject: [PATCH] Edit Zusammenstellung --- controller/admin_notenbuch.php | 252 +++++++++------ js/components/admin_notenbuch.js | 355 ++++++++++++++-------- templates/modern/dashboard/notenbuch.html | 11 + 3 files changed, 400 insertions(+), 218 deletions(-) diff --git a/controller/admin_notenbuch.php b/controller/admin_notenbuch.php index 104580f..6cd0255 100644 --- a/controller/admin_notenbuch.php +++ b/controller/admin_notenbuch.php @@ -3,124 +3,194 @@ require_once("../config.inc.php"); $function = $_POST['function']; if ($function == 'notenbuchsave') { - if (isset($_POST['notenbuch'])) { - $notenbuch = $_POST['notenbuch']; - } + if (isset($_POST['notenbuch'])) { + $notenbuch = $_POST['notenbuch']; + } + if (isset($_POST['var_checkliz'])) { + $var_checkliz = $_POST['var_checkliz']; + } + if (isset($_POST['anz_lizenz'])) { + $anz_lizenz = $_POST['anz_lizenz']; + } - $db = dbconnect(); - $result = $db->query("SELECT count(*) Anz FROM jumi_noten_zusammenstellung WHERE upper(bezeichnung)=upper('$notenbuch')"); - $row = $result->fetch_array(); - - if ($notenbuch == ''){ //verschlüsseltes Passwort überprüfen + if (isset($var_checkliz)) { + if ($var_checkliz == '1') { + $checkliz = '1'; + } else { + $checkliz = '0'; + } + } else { + $checkliz = '0'; + } + + $db = dbconnect(); + $result = $db->query("SELECT count(*) Anz FROM jumi_noten_zusammenstellung WHERE upper(bezeichnung)=upper('$notenbuch')"); + $row = $result->fetch_array(); + + if ($notenbuch == '') { //verschlüsseltes Passwort überprüfen echo '
Der Notenbuchname darf nicht leer sein.
|***|error'; exit; - }else if ($row['Anz'] > 0){ //verschlüsseltes Passwort überprüfen + } else if ($row['Anz'] > 0) { //verschlüsseltes Passwort überprüfen echo '
Der Notenbuchname ist bereits vorhanden.
|***|error'; exit; - }else{ - - $sql1 = $db->query("INSERT INTO jumi_noten_zusammenstellung ( bezeichnung ) VALUES ( '$notenbuch' )"); - if($sql1){ - echo '
Der Notenbuchname wurde gespeichert!
|***|success'; - exit; - }else{ - echo '
Der Notenbuchname wurde nicht gespeichert: Insert Fehler Datenbank.
|***|error'; - exit; + } else { + + $sql1 = $db->query("INSERT INTO jumi_noten_zusammenstellung ( bezeichnung, lizenzpflicht, anzahl_lizenz) VALUES ( '$notenbuch', '$checkliz', $anz_lizenz)"); + if ($sql1) { + echo '
Das Notenbuch wurde angelegt!
|***|success'; + exit; + } else { + echo '
Das Notenbuch wurde nicht angelegt: Insert Fehler Datenbank.
|***|error'; + exit; } - } + } } +if ($function == 'notenbuchupdate') { + if (isset($_POST['notenbuch'])) { + $notenbuch = $_POST['notenbuch']; + } + if (isset($_POST['var_checkliz'])) { + $var_checkliz = $_POST['var_checkliz']; + } + if (isset($_POST['anz_lizenz'])) { + $anz_lizenz = $_POST['anz_lizenz']; + } + if (isset($_POST['zsid'])) { + $zsid = $_POST['zsid']; + } + + if (isset($var_checkliz)) { + if ($var_checkliz == '1') { + $checkliz = '1'; + } else { + $checkliz = '0'; + $anz_lizenz = '0'; + } + } else { + $checkliz = '0'; + $anz_lizenz = '0'; + } + + if ($notenbuch == '') { //verschlüsseltes Passwort überprüfen + echo '
Der Notenbuchname darf nicht leer sein.
|***|error'; + exit; + } else { + $sql1 = $db->query("UPDATE jumi_noten_zusammenstellung + SET bezeichnung ='$notenbuch' + ,lizenzpflicht='$checkliz' + ,anzahl_lizenz=$anz_lizenz + WHERE zsid = $zsid + "); + + if ($sql1) { + echo '
Das Notenbuch wurde geändert!
|***|success'; + exit; + } else { + echo '
Das Notenbuch wurde nicht geändert: Insert Fehler Datenbank.
|***|error'; + exit; + } + } +} + +if ($function == 'editNotenbuch') { + if (isset($_POST['zsid'])) { + $zsid = $_POST['zsid']; + } + $result = $db->query("SELECT bezeichnung, lizenzpflicht, anzahl_lizenz FROM jumi_noten_zusammenstellung WHERE zsid=$zsid"); + $row = $result->fetch_array(); + echo json_encode($row); + +} if ($function == 'erfzuordnung') { - if (isset($_POST['jndid'])) { - $jndid = $_POST['jndid']; - } - if (isset($_POST['zsid'])) { - $zsid = $_POST['zsid']; - } + if (isset($_POST['jndid'])) { + $jndid = $_POST['jndid']; + } + if (isset($_POST['zsid'])) { + $zsid = $_POST['zsid']; + } - $db = dbconnect(); - $sql1 = $db->query("INSERT INTO jumi_noten_zusammenstellung_zuord ( jndid, zsid) VALUES ( $jndid, $zsid )"); - if($sql1){ - echo '
Die Noten wurden zugewiesen!
|***|success|***|'.$jndid; - exit; - }else{ - echo '
Die Noten wurden nicht zugewiesen: Insert Fehler Datenbank.
|***|error'; - exit; - } + $db = dbconnect(); + $sql1 = $db->query("INSERT INTO jumi_noten_zusammenstellung_zuord ( jndid, zsid) VALUES ( $jndid, $zsid )"); + if ($sql1) { + echo '
Die Noten wurden zugewiesen!
|***|success|***|' . $jndid; + exit; + } else { + echo '
Die Noten wurden nicht zugewiesen: Insert Fehler Datenbank.
|***|error'; + exit; + } } if ($function == 'delzuordnung') { - if (isset($_POST['jndid'])) { - $jndid = $_POST['jndid']; - } - if (isset($_POST['zsid'])) { - $zsid = $_POST['zsid']; - } + if (isset($_POST['jndid'])) { + $jndid = $_POST['jndid']; + } + if (isset($_POST['zsid'])) { + $zsid = $_POST['zsid']; + } - $sql1 = $db->query("DELETE FROM jumi_noten_zusammenstellung_zuord WHERE jndid='$jndid' AND zsid='$zsid'"); - if($sql1){ - echo '
Die Noten wurden entfernt!
|***|success|***|'.$jndid; - exit; - }else{ - echo '
Die Noten wurdne nicht entfernt: DELETE Fehler Datenbank.
|***|error'; - exit; - } + $sql1 = $db->query("DELETE FROM jumi_noten_zusammenstellung_zuord WHERE jndid='$jndid' AND zsid='$zsid'"); + if ($sql1) { + echo '
Die Noten wurden entfernt!
|***|success|***|' . $jndid; + exit; + } else { + echo '
Die Noten wurdne nicht entfernt: DELETE Fehler Datenbank.
|***|error'; + exit; + } } - if ($function == 'erfNotenUser') { - if (isset($_POST['zsid'])) { - $zsid = $_POST['zsid']; - } - if (isset($_POST['csid'])) { - $csid = $_POST['csid']; - } + if (isset($_POST['zsid'])) { + $zsid = $_POST['zsid']; + } + if (isset($_POST['csid'])) { + $csid = $_POST['csid']; + } - $db = dbconnect(); - $sql1 = $db->query("INSERT INTO jumi_noten_zus_saenger_zuord ( zsid, csid) VALUES ( $zsid, $csid )"); - if($sql1){ - echo '
Der Benutzer wurde zugewiesen!
|***|success|***|'.$zsid; - exit; - }else{ - echo '
Der Benutzer wurde nicht zugewiesen: Insert Fehler Datenbank.
|***|error'; - exit; - } + $db = dbconnect(); + $sql1 = $db->query("INSERT INTO jumi_noten_zus_saenger_zuord ( zsid, csid) VALUES ( $zsid, $csid )"); + if ($sql1) { + echo '
Der Benutzer wurde zugewiesen!
|***|success|***|' . $zsid; + exit; + } else { + echo '
Der Benutzer wurde nicht zugewiesen: Insert Fehler Datenbank.
|***|error'; + exit; + } } if ($function == 'delNotenUser') { - if (isset($_POST['zsid'])) { - $zsid = $_POST['zsid']; - } - if (isset($_POST['csid'])) { - $csid = $_POST['csid']; - } + if (isset($_POST['zsid'])) { + $zsid = $_POST['zsid']; + } + if (isset($_POST['csid'])) { + $csid = $_POST['csid']; + } - $sql1 = $db->query("DELETE FROM jumi_noten_zus_saenger_zuord WHERE zsid='$zsid' AND csid='$csid'"); - if($sql1){ - echo '
Der Benutzer wurde gelöscht!
|***|success|***|'.$zsid; - exit; - }else{ - echo '
Der Benutzer wurde nicht gelöscht: DELETE Fehler Datenbank.
|***|error'; - exit; - } + $sql1 = $db->query("DELETE FROM jumi_noten_zus_saenger_zuord WHERE zsid='$zsid' AND csid='$csid'"); + if ($sql1) { + echo '
Der Benutzer wurde gelöscht!
|***|success|***|' . $zsid; + exit; + } else { + echo '
Der Benutzer wurde nicht gelöscht: DELETE Fehler Datenbank.
|***|error'; + exit; + } } - if ($function == 'delZusammenstellung') { - if (isset($_POST['zsid'])) { - $zsid = $_POST['zsid']; - } - - $stmt1 = $db->query("DELETE FROM jumi_noten_zusammenstellung_zuord WHERE zsid= $zsid"); - $stmt2 = $db->query("DELETE FROM jumi_noten_zus_saenger_zuord WHERE zsid= $zsid"); - $stmt3 = $db->query("DELETE FROM jumi_noten_zusammenstellung WHERE zsid= $zsid"); - if ($stmt1 AND $stmt2 AND $stmt3) { - echo '
Die Rolle wurde gelöscht!
|***|success'; - exit; + if (isset($_POST['zsid'])) { + $zsid = $_POST['zsid']; + } + + $stmt1 = $db->query("DELETE FROM jumi_noten_zusammenstellung_zuord WHERE zsid=$zsid"); + $stmt2 = $db->query("DELETE FROM jumi_noten_zus_saenger_zuord WHERE zsid= $zsid"); + $stmt3 = $db->query("DELETE FROM jumi_noten_zusammenstellung WHERE zsid= $zsid"); + if ($stmt1 and $stmt2 and $stmt3) { + echo '
Die Rolle wurde gelöscht!
|***|success'; + exit; } else { - echo '
Die Rolle wurde nicht gelöscht: DELETE Fehler Datenbank.
|***|error'; - exit; + echo '
Die Rolle wurde nicht gelöscht: DELETE Fehler Datenbank.
|***|error'; + exit; } } diff --git a/js/components/admin_notenbuch.js b/js/components/admin_notenbuch.js index 1835efe..aebeac8 100644 --- a/js/components/admin_notenbuch.js +++ b/js/components/admin_notenbuch.js @@ -1,165 +1,266 @@ -function notenbuchsave(){ - var notenbuch = document.getElementById("notenbuchname").value; - $.ajax({ - type: 'POST', - url: '../controller/admin_notenbuch.php', - data: { - 'function': 'notenbuchsave', - 'notenbuch': notenbuch - }, - success: function(result) { //we got the response - if(result!=''){ +function notenbuchsave() { + var notenbuch = document.getElementById("notenbuchname").value; + var anz_lizenz = document.getElementById("notenbuchlizenz").value; + var checkliz = document.getElementById("checkliz"); + + if (checkliz.checked == true) { + var var_checkliz = 1; + } else { + var var_checkliz = 0; + } + $.ajax({ + type: 'POST', + url: '../controller/admin_notenbuch.php', + data: { + 'function': 'notenbuchsave', + 'notenbuch': notenbuch, + 'var_checkliz': var_checkliz, + 'anz_lizenz': anz_lizenz + }, + success: function(result) { //we got the response + if (result != '') { var a = result.split('|***|'); - if(a[1]=="success"){ - setTimeout(function() { - document.getElementById("notenbuchname").value =""; - window.location = "?"; - }, 1000); + if (a[1] == "success") { + setTimeout(function() { + document.getElementById("notenbuchname").value = ""; + window.location = "?"; + }, 1000); } $('#msg').show().delay(1000).fadeOut(500); $('#msg').html(a[0]); - } - }, - error: function(xhr, status, exception) { - console.log(xhr); } - }); + }, + error: function(xhr, status, exception) { + console.log(xhr); + } + }); + +} + +function notenbuchupdate(zsid) { + var notenbuch = document.getElementById("notenbuchname").value; + var anz_lizenz = document.getElementById("notenbuchlizenz").value; + var checkliz = document.getElementById("checkliz"); + + if (checkliz.checked == true) { + var var_checkliz = 1; + } else { + var var_checkliz = 0; + } + $.ajax({ + type: 'POST', + url: '../controller/admin_notenbuch.php', + data: { + 'function': 'notenbuchupdate', + 'notenbuch': notenbuch, + 'var_checkliz': var_checkliz, + 'zsid': zsid, + 'anz_lizenz': anz_lizenz + + }, + success: function(result) { //we got the response + if (result != '') { + var a = result.split('|***|'); + if (a[1] == "success") { + setTimeout(function() { + document.getElementById("notenbuchname").value = ""; + window.location = "?"; + }, 1000); + } + $('#msg').show().delay(1000).fadeOut(500); + $('#msg').html(a[0]); + } + }, + error: function(xhr, status, exception) { + console.log(xhr); + } + }); + +} + +function editNotenbuch(zsid) { + + $.ajax({ + type: 'POST', + url: '../controller/admin_notenbuch.php', + data: { + 'function': 'editNotenbuch', + 'zsid': zsid + }, + success: function(result) { //we got the response + const obj = JSON.parse(result); + var bezeichnung = obj.bezeichnung; + var lizenzpflicht = obj.lizenzpflicht; + var anzahl_lizenz = obj.anzahl_lizenz; + + document.getElementById('notenbuchname').value = bezeichnung; + document.getElementById('save').onclick = function() { + notenbuchupdate(zsid) + }; + document.getElementById('save').innerText = 'Update'; + + if (lizenzpflicht == 1) { + document.getElementById("checkliz").checked = true; + document.getElementById('notenbuchlizenz').disabled = false; + document.getElementById('notenbuchlizenz').value = anzahl_lizenz; + } else { + document.getElementById("checkliz").checked = false; + document.getElementById('notenbuchlizenz').disabled = true; + document.getElementById('notenbuchlizenz').value = ''; + } + + // if(result!=''){ + // var a = result.split('|***|'); + // if(a[1]=="success"){ + // setTimeout(function() { + // document.getElementById("notenbuchname").value =""; + // window.location = "?"; + // }, 1000); + // } + // $('#msg').show().delay(1000).fadeOut(500); + // $('#msg').html(a[0]); + // } + }, + error: function(xhr, status, exception) { + console.log(xhr); + } + }); } function erfzuordnung(jndid, zsid) { - $.ajax({ - type: 'POST', - url: '../controller/admin_notenbuch.php', - data: { - 'function': 'erfzuordnung', - 'jndid': jndid, - 'zsid': zsid - }, - success: function(result) { //we got the response - if(result!=''){ + $.ajax({ + type: 'POST', + url: '../controller/admin_notenbuch.php', + data: { + 'function': 'erfzuordnung', + 'jndid': jndid, + 'zsid': zsid + }, + success: function(result) { //we got the response + if (result != '') { var a = result.split('|***|'); - if(a[1]=="success"){ - setTimeout(function() { - // Refresh Modal - var value = a[2]; - // load the url and show modal on success - $("#ZuordnungModal .modal-body").load('notenbuchzuordnung.php?edit='+value, function() { - $("#ZuordnungModal").modal("show"); - }); - }, 1000); + if (a[1] == "success") { + setTimeout(function() { + // Refresh Modal + var value = a[2]; + // load the url and show modal on success + $("#ZuordnungModal .modal-body").load('notenbuchzuordnung.php?edit=' + value, function() { + $("#ZuordnungModal").modal("show"); + }); + }, 1000); } $('#msg').show().delay(1000).fadeOut(500); $('#msg').html(a[0]); - } - }, - error: function(xhr, status, exception) { - console.log(xhr); } - }); + }, + error: function(xhr, status, exception) { + console.log(xhr); + } + }); } function delzuordnung(jndid, zsid) { - $.ajax({ - type: 'POST', - url: '../controller/admin_notenbuch.php', - data: { - 'function': 'delzuordnung', - 'jndid': jndid, - 'zsid': zsid - }, - success: function(result) { //we got the response - if(result!=''){ + $.ajax({ + type: 'POST', + url: '../controller/admin_notenbuch.php', + data: { + 'function': 'delzuordnung', + 'jndid': jndid, + 'zsid': zsid + }, + success: function(result) { //we got the response + if (result != '') { var a = result.split('|***|'); - if(a[1]=="success"){ - setTimeout(function() { - // Refresh Modal - var value = a[2]; - // load the url and show modal on success - $("#ZuordnungModal .modal-body").load('notenbuchzuordnung.php?edit='+value, function() { - $("#ZuordnungModal").modal("show"); - }); - }, 2000); + if (a[1] == "success") { + setTimeout(function() { + // Refresh Modal + var value = a[2]; + // load the url and show modal on success + $("#ZuordnungModal .modal-body").load('notenbuchzuordnung.php?edit=' + value, function() { + $("#ZuordnungModal").modal("show"); + }); + }, 2000); } $('#msg').show().delay(1000).fadeOut(500); $('#msg').html(a[0]); - } - }, - error: function(xhr, status, exception) { - console.log(xhr); } - }); + }, + error: function(xhr, status, exception) { + console.log(xhr); + } + }); } function erfNotenUser(csid, zsid) { - $.ajax({ - type: 'POST', - url: '../controller/admin_notenbuch.php', - data: { - 'function': 'erfNotenUser', - 'csid': csid, - 'zsid': zsid - }, - success: function(result) { //we got the response - if(result!=''){ + $.ajax({ + type: 'POST', + url: '../controller/admin_notenbuch.php', + data: { + 'function': 'erfNotenUser', + 'csid': csid, + 'zsid': zsid + }, + success: function(result) { //we got the response + if (result != '') { var a = result.split('|***|'); - if(a[1]=="success"){ - $(document).ajaxStop(function(){ - // Refresh Modal - var value = a[2]; - // load the url and show modal on success - $("#ZuordnungModal .modal-body").load('notenuserzuordnung.php?edit='+value, function() { - $("#ZuordnungModal").modal("show"); - }); - }); + if (a[1] == "success") { + $(document).ajaxStop(function() { + // Refresh Modal + var value = a[2]; + // load the url and show modal on success + $("#ZuordnungModal .modal-body").load('notenuserzuordnung.php?edit=' + value, function() { + $("#ZuordnungModal").modal("show"); + }); + }); } $('#msg').show().delay(5000).fadeOut(500); $('#msg').html(a[0]); - } - }, - error: function(xhr, status, exception) { - console.log(xhr); } - }); + }, + error: function(xhr, status, exception) { + console.log(xhr); + } + }); } function delNotenUser(csid, zsid) { - $.ajax({ - type: 'POST', - url: '../controller/admin_notenbuch.php', - data: { - 'function': 'delNotenUser', - 'csid': csid, - 'zsid': zsid - }, - success: function(result) { //we got the response - if(result!=''){ + $.ajax({ + type: 'POST', + url: '../controller/admin_notenbuch.php', + data: { + 'function': 'delNotenUser', + 'csid': csid, + 'zsid': zsid + }, + success: function(result) { //we got the response + if (result != '') { var a = result.split('|***|'); - if(a[1]=="success"){ - $(document).ajaxStop(function(){ + if (a[1] == "success") { + $(document).ajaxStop(function() { - // Refresh Modal - var value = a[2]; - // load the url and show modal on success - $("#ZuordnungModal .modal-body").load('notenuserzuordnung.php?edit='+value, function() { - $("#ZuordnungModal").modal("show"); - }); - }); + // Refresh Modal + var value = a[2]; + // load the url and show modal on success + $("#ZuordnungModal .modal-body").load('notenuserzuordnung.php?edit=' + value, function() { + $("#ZuordnungModal").modal("show"); + }); + }); } $('#msg').show().delay(10000).fadeOut(500); $('#msg').html(a[0]); - } - }, - error: function(xhr, status, exception) { - console.log(xhr); } - }); + }, + error: function(xhr, status, exception) { + console.log(xhr); + } + }); } @@ -174,20 +275,20 @@ function delZusammenstellung(zsid) { 'zsid': zsid }, success: function(result) { //we got the response - if(result!=''){ - var a = result.split('|***|'); - if(a[1]=="success"){ - $(document).ajaxStop(function(){ - window.location = "?"; - }); + if (result != '') { + var a = result.split('|***|'); + if (a[1] == "success") { + $(document).ajaxStop(function() { + window.location = "?"; + }); + } + $('#msg').show().delay(10000).fadeOut(500); + $('#msg').html(a[0]); } - $('#msg').show().delay(10000).fadeOut(500); - $('#msg').html(a[0]); - } }, error: function(xhr, status, exception) { console.log(xhr); } }); } -} +} \ No newline at end of file diff --git a/templates/modern/dashboard/notenbuch.html b/templates/modern/dashboard/notenbuch.html index b9c9a67..da9561a 100644 --- a/templates/modern/dashboard/notenbuch.html +++ b/templates/modern/dashboard/notenbuch.html @@ -79,6 +79,16 @@ $(document).ready(function(){
Notenbuchname:
+
+
Lizenz erfoderlich:
+
+
+
+
Anzahl vorhandene Lizenzen:
+
+
+ +
@@ -101,6 +111,7 @@ $(document).ready(function(){
{$table_data[table_data].bezeichnung}
+