HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/klausurenweb-schueler/lerncode_script.py
from aaw.db_components.component_db_connection import run_query
from aaw.db_auth import generate_lerncode

def add_lerncode(material_id, original_text_id):
    # Prüfen, ob bereits ein Lerncode existiert
    check_sql = "SELECT id FROM material_lerncodes WHERE material_id = %s AND original_text_id = %s"
    existing = run_query(check_sql, (material_id, original_text_id), fetch="one")
    
    if existing:
        # Löschen des vorhandenen Lerncodes
        delete_sql = "DELETE FROM material_lerncodes WHERE material_id = %s AND original_text_id = %s"
        run_query(delete_sql, (material_id, original_text_id), commit=True)
        print("Bestehender Lerncode gelöscht.")
    
    # Neuen Lerncode generieren
    new_lerncode = generate_lerncode()
    print("Neuer Lerncode:", new_lerncode)
    
    # Lerncode in die Datenbank einfügen
    insert_sql = "INSERT INTO material_lerncodes (material_id, original_text_id, lerncode) VALUES (%s, %s, %s)"
    try:
        run_query(insert_sql, (material_id, original_text_id, new_lerncode), commit=True)
        print("Lerncode erfolgreich gespeichert!")
    except Exception as e:
        print("Fehler beim Speichern des Lerncodes:", str(e))

# Material ID 2 und Original Text ID 7
add_lerncode(2, 7)