Преглед изворни кода

Delete menu, host, and reporte pages

Alejandro Rosales пре 1 година
родитељ
комит
e4eec1b8cf
5 измењених фајлова са 0 додато и 275 уклоњено
  1. 0 38
      action/new_host.php
  2. 0 66
      pages/host/edit_host.php
  3. 0 78
      pages/host/index.php
  4. 0 21
      pages/menu/index.php
  5. 0 72
      pages/reporte/index.php

+ 0 - 38
action/new_host.php

@@ -1,38 +0,0 @@
-<?php
-require_once "{$_SERVER['DOCUMENT_ROOT']}/dependencies.php";
-
-use Respect\Validation\Validator as v;
-
-// method must be POST
-methods(['POST' => v::keySet(
-    v::key('etiqueta', v::stringType()->notEmpty()),
-    v::key('host', v::stringType()->notEmpty()),
-    v::key('puerto', v::intType()->notEmpty()),
-    v::key('usuario', v::stringType()->notEmpty()),
-    v::key('base_datos', v::stringType()->notEmpty()),
-    v::key('password', v::stringType()->notEmpty()),
-    v::key('periodos', v::arrayType()->notEmpty()->each(v::intType()))
-)]);
-
-try {
-    $db->query('BEGIN');
-    $params = array(
-        'etiqueta' => $_POST['etiqueta'],
-        'host' => $_POST['host'],
-        'puerto' => $_POST['puerto'],
-        'postgres_user' => $_POST['usuario'],
-        'postgres_dbname' => $_POST['base_datos'],
-        'postgres_password' => $_POST['password'],
-        'periodos_gema' => '{' . implode(',', $_POST['periodos']) . '}',
-    );
-    $db->query("INSERT INTO moodle_host (etiqueta, host, puerto, postgres_user, postgres_dbname, postgres_password, periodos_gema) VALUES (:etiqueta, :host, :puerto, :postgres_user, :postgres_dbname, PGP_SYM_ENCRYPT(:postgres_password, '{$_ENV['KEY_ENCRYPT']}'), :periodos_gema)", $params);
-
-    $db->query('COMMIT');
-} catch (\PDOException $th) {
-    $db->query('ROLLBACK');
-    http_response_code(500);
-    echo json_encode(['error' => $th->getMessage()]);
-    exit();
-}
-
-returnResponse(message: "Host {$_POST['etiqueta']} agregado correctamente");

+ 0 - 66
pages/host/edit_host.php

@@ -1,66 +0,0 @@
-<main class="container">
-    <h1>Registrar un nuevo HOST de Moodle</h1>
-    <button class="btn btn-primary" @click="page = 'host'">
-        Regresar
-        <i class="fas fa-arrow-left"></i>
-    </button>
-    <form action="/action/new_host.php" method="post">
-        <div class="grid">
-            <label for="etiqueta">
-                Etiqueta
-                <input type="text" name="etiqueta" placeholder="Etiqueta para identificar el host" required :value="edit_host.etiqueta">
-                <small>Etiqueta para identificar: <code>Moodle2023A</code></small>
-            </label>
-            <label for="base_datos">
-                Base de datos
-                <input type="text" name="base_datos" placeholder="Nombre de la base de datos" required :value="edit_host.postgres_dbname">
-                <small>Ejemplo: <code>moodle42licdb</code></small>
-            </label>
-        </div>
-        <div class="grid">
-            <label for="host">
-                Host de Moodle
-                <input type="text" name="host" placeholder="200.13.89.000" required :value="edit_host.host">
-                <small>localhost, moodleXYZ.lci.ulsa.mx, 200.13.89.000</small>
-            </label>
-
-
-            <label for="puerto">
-                Puerto de la base de datos
-                <!-- validate only numbers -->
-                <input type="text" name="puerto" placeholder="5432" required value="5432" pattern="[0-9]+" :value="edit_host.puerto">
-            </label>
-        </div>
-        <div class="grid">
-            <label for="usuario">
-                Usuario de Postgres
-                <input type="text" name="usuario" placeholder="postgres" required value="postgres" :value="edit_host.postgres_user">
-            </label>
-            <label for="password">
-                Contraseña de Postgres
-                <input type="password" name="password" placeholder="Contraseña del usuario postgres" required>
-            </label>
-        </div>
-        <div class="grid">
-            <label for="periodos[]">Which periodos would you like to order?
-                <select id="periodos[]" name="periodos[]" multiple required>
-                    <?php
-                    foreach ($sgi_db
-                        ->orderBy('Periodo_fecha_inicial', 'DESC')
-                        ->join('Nivel n', 'n."Nivel_id" = p."Nivel_id"')
-                        ->get('Periodo p', 10, ['Periodo_id', 'Periodo_desc', 'Nivel_desc']) as $periodo) : ?>
-                        <option value="<?= $periodo['Periodo_id'] ?>" :selected="edit_host.periodos_gema.includes(<?= $periodo['Periodo_id'] ?>)">
-                            <?= $periodo['Periodo_desc'] ?> de <?= $periodo['Nivel_desc'] ?>
-                        </option>
-                    <?php endforeach ?>
-                </select>
-            </label>
-        </div>
-        <div class="grid">
-            <button type="submit">
-                Registrar
-                <i class="fas fa-database"></i>
-            </button>
-        </div>
-    </form>
-</main>

+ 0 - 78
pages/host/index.php

@@ -1,78 +0,0 @@
-<main class="container" v-if="page === 'host'" v-scope @vue:mounted="mounted">
-    <h1>Conectar un HOST</h1>
-    <form action="action/conectar_moodle.php" method="post" v-scope="{host: null}">
-        <div class="grid">
-            <div v-if="hosts.length > 0">
-                <label for="moodle-host">
-                    Moodle host
-                    <input list="moodle-hosts" name="moodle-host" placeholder="Moodle host" required v-model="host">
-                </label>
-                <datalist id="moodle-hosts" v-for="host in hosts">
-                    <option :value="host.host">
-                        {{ host.etiqueta }}
-                    </option>
-                </datalist>
-            </div>
-            <div v-else>
-                <p>No hay hosts registrados</p>
-            </div>
-            <label for="agregar-host">
-                Agregar host
-                <button id="agregar-host" type="button" @click="page = 'new_host'">
-                    <i class="fas fa-plus"></i>
-                </button>
-            </label>
-        </div>
-        <div class="grid">
-            <button type="button" :disabled="!host" @click="editHost(host)">Editar <i class="fas fa-edit"></i></button>
-            <button type="submit" :disabled="!host">Conectar <i class="fas fa-database"></i></button>
-        </div>
-    </form>
-</main>
-
-<div v-else>
-    <?php require 'edit_host.php' ?>
-</div>
-
-
-
-<script>
-    PetiteVue.createApp({
-        store,
-        // state
-        page: 'host',
-        // data
-        hosts: [],
-        current_host: null,
-
-        async editHost(host) {
-            store.loading = true
-            const hosts = await store.fetch(`http://www.localhost:3000/moodle_host?etiqueta=eq.${host}`, {
-                headers: {
-                    'Prefer': 'plurality=singular'
-                }
-            })
-
-            if (!hosts.ok) {
-                store.loading = false
-                alert('Error al obtener el host: ' + hosts.status)
-                return
-            }
-
-            const data = await hosts.json()
-            this.current_host = data[0]
-            this.loading = false
-
-            this.page = 'edit_host'
-        },
-
-        async mounted() {
-            store.loading = true
-            const hosts = await store.fetch('http://www.localhost:3000/moodle_host')
-            const data = await hosts.json()
-            store.loading = false
-
-            this.hosts = data
-        }
-    }).mount()
-</script>

+ 0 - 21
pages/menu/index.php

@@ -1,21 +0,0 @@
-<?php
-# if method is post
-if ($_SERVER['REQUEST_METHOD'] === 'POST') {
-    $_SESSION['page'] = $_POST['page'];
-    echo $_SESSION['page'];
-    return_index();
-}
-?>
-
-<main class="container">
-    <form action="" method="post">
-        <input type="hidden" name="page" v-model="page">
-        <button @click="page = 'reporte'" type="submit">Reporte de calificaciones <i class="fas fa-file-excel"></i></button>
-        <button @click="page = 'cálculo'" type="submit">Cálculo de calificaciones <i class="fas fa-calculator"></i></button>
-    </form>
-</main>
-<script>
-    PetiteVue.createApp({
-        page: null
-    }).mount();
-</script>

+ 0 - 72
pages/reporte/index.php

@@ -1,72 +0,0 @@
-<?php
-$todas_las_categorías = $moodle_db->get('mdl_course_categories');
-$todos_los_cursos = $moodle_db->query("SELECT courseid, fullname, shortname, COALESCE(MIN(calculation) <> '', false) as formula, MAX(AGGREGATIONCOEF) > 0 as ponderacion FROM  mdl_grade_items mgi JOIN mdl_course mc ON mc.id = mgi.courseid WHERE itemtype IN ('course', 'category') GROUP BY courseid, fullname, shortname");
-
-
-function imprimir_curso($category_id = null)
-{
-    global $todas_las_categorías, $todos_los_cursos, $todos_los_items;
-    # obtener subcategorías
-    $categories = array_filter($todas_las_categorías, fn ($category) => $category['parent'] == $category_id ?? 0 && count(array_filter($todas_las_categorías, fn ($category) => $category['parent'] == $category_id ?? 0)) > 0);
-    # print them as an accordion
-    foreach ($categories as $category) : ?>
-        <details>
-            <summary><?= $category['name'] ?></summary>
-            <?php imprimir_curso($category['id']) ?>
-        </details>
-    <?php endforeach;
-
-    $courses = array_filter($todos_los_cursos, fn ($course) => $course['category'] == $category_id);
-    if (count($courses) == 0) return;
-    ?>
-    <table>
-        <tr>
-            <th>Curso</th>
-            <th>Construcción</th>
-            <th>Ponderación</th>
-        </tr>
-        <tbody>
-            <?php foreach ($courses as $course) : ?>
-                <tr>
-                    <td>
-                        <?= $course['fullname'] ?>
-                        <small><?= $course['shortname'] ?></small>
-                    </td>
-                    <td>
-                        <?php
-
-                        if (boolval($course['formula'])) : ?>
-                            <i class="fas fa-check"></i>
-                        <?php else : ?>
-                            <i class="fas fa-times"></i>
-                        <?php endif ?>
-                    </td>
-                    <td>
-                        <?php
-                        if (boolval($course['ponderacion'])) : ?>
-                            <i class="fas fa-check"></i>
-                        <?php else : ?>
-                            <i class="fas fa-times"></i>
-                        <?php endif ?>
-                    </td>
-                </tr>
-            <?php endforeach ?>
-        </tbody>
-    </table>
-<?php } ?>
-
-
-
-<div class="grid">
-    <label for="sin-construcción">
-        Profesores que no han construido su curso
-        <input type="radio" id="sin-construcción" name="construcción" value="false" checked />
-    </label>
-    <label for="construcción">
-        Profesores que han construido su curso
-        <input type="radio" id="construcción" name="construcción" value="true" checked />
-    </label>
-</div>
-<?php
-imprimir_curso();
-?>