chore: version inicial del codigo fuente del LMS Estafeta
This commit is contained in:
+85
@@ -0,0 +1,85 @@
|
|||||||
|
# =====================================================================
|
||||||
|
# .gitignore — Plataforma LMS Estafeta
|
||||||
|
# Sube SOLO código fuente y configuración de ejemplo.
|
||||||
|
# Excluye dependencias, datos de usuarios, secretos, logs y temporales.
|
||||||
|
# =====================================================================
|
||||||
|
|
||||||
|
# --- Credenciales / configuración local (NUNCA versionar) ---
|
||||||
|
/config.php
|
||||||
|
/config.local.php
|
||||||
|
/env.php
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
*.pem
|
||||||
|
*.key
|
||||||
|
|
||||||
|
# --- Dependencias (se regeneran con `composer install`) ---
|
||||||
|
/vendor/
|
||||||
|
composer.phar
|
||||||
|
# NOTA: composer.json y composer.lock SÍ se versionan.
|
||||||
|
|
||||||
|
# --- Datos de usuarios / paquetes SCORM / subidas (pesados + privados) ---
|
||||||
|
/data/recursos/
|
||||||
|
/data/scormpkg/
|
||||||
|
/data/tmpusers.xlsx
|
||||||
|
/data/*.xlsx
|
||||||
|
/data/imgcat/
|
||||||
|
/data/files/
|
||||||
|
# Se permite el .htaccess de protección de data/
|
||||||
|
!/data/.htaccess
|
||||||
|
|
||||||
|
# --- Multimedia generada / pesada ---
|
||||||
|
/Multimedia/
|
||||||
|
multimedia/
|
||||||
|
|
||||||
|
# --- Logs / auditoría ---
|
||||||
|
/logs/*
|
||||||
|
!/logs/.htaccess
|
||||||
|
|
||||||
|
# --- Base de datos: carpeta completa fuera del repositorio ---
|
||||||
|
# Contiene dumps con datos personales y herramientas locales.
|
||||||
|
/bd/
|
||||||
|
|
||||||
|
# --- Respaldos / archivos temporales del proyecto ---
|
||||||
|
*.back
|
||||||
|
*.bak
|
||||||
|
*.orig
|
||||||
|
*.rej
|
||||||
|
*~
|
||||||
|
*.tmp
|
||||||
|
*.temp
|
||||||
|
*.log
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
desktop.ini
|
||||||
|
/purge/
|
||||||
|
/certificado/tmp/
|
||||||
|
/tmp/
|
||||||
|
/temp/
|
||||||
|
|
||||||
|
# --- Configuración de máquina local (php.ini/user.ini) ---
|
||||||
|
/config/php.ini
|
||||||
|
/config/.user.ini
|
||||||
|
!/config/.htaccess
|
||||||
|
|
||||||
|
# --- IDE / editores ---
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.sublime-project
|
||||||
|
*.sublime-workspace
|
||||||
|
*.code-workspace
|
||||||
|
nbproject/
|
||||||
|
.project
|
||||||
|
.buildpath
|
||||||
|
.settings/
|
||||||
|
|
||||||
|
# --- OS ---
|
||||||
|
ehthumbs.db
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# --- Node (si en el futuro se agrega build de front) ---
|
||||||
|
node_modules/
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
+228
@@ -0,0 +1,228 @@
|
|||||||
|
# CHANGELOG / Registro de cambios — Plataforma LMS Estafeta
|
||||||
|
|
||||||
|
> Documento de seguimiento para agentes. Describe **todos los cambios de esta iteración**, el estado actual verificado del repositorio, archivos a subir a producción y pendientes.
|
||||||
|
>
|
||||||
|
> **Ruta local trabajada:** `C:\backup\htdocs\gitlab\Estafeta`
|
||||||
|
> **Ruta de ejecución del usuario (dev):** `C:\xampp\htdocs\git\Estafeta-plataform`
|
||||||
|
> **Producción:** `https://induccion-estafeta.com.mx/`
|
||||||
|
> **Rama/base:** sin control de versiones (copia de htdocs).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 0. Contexto y decisiones
|
||||||
|
|
||||||
|
1. **Login:** por decisión del negocio se ingresa **solo con número de empleado**. No se implementó verificación de contraseña (omitido a propósito). Aun así se endureció la sesión y se agregó rate-limit.
|
||||||
|
2. **RTE:** se decide usar **únicamente `runtime/`** y **eliminar `runtimev2/`**.
|
||||||
|
3. **SCORM:** el RTE central `runtime/sco.php` sirve un contenedor con barra superior + botón "Regresar" e **iframe** que carga el paquete, con el API SCORM en la página padre (así Storyline/Rise lo encuentran subiendo por los frames).
|
||||||
|
4. Los endpoints de `admin/` (y los del front que devuelven JSON) **siempre responden JSON**; nunca deben emitir HTML de avisos/errores.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Resumen por fases
|
||||||
|
|
||||||
|
### Fase 1 — Seguridad base
|
||||||
|
- **`admin/auth_guard.php` (nuevo):** valida sesión + rol admin; responde `{"code":"403","msg":"No autorizado"}` si no. Fuerza `display_errors=0` y descarta salida previa (buffering) para no contaminar el JSON.
|
||||||
|
- **Guard añadido** a **113** endpoints `admin/*.php` con `require_once __DIR__.'/auth_guard.php';` (se excluyen `admin/index.php` y `admin/audit.php`, que son apoyo, no endpoints).
|
||||||
|
- **`data/.htaccess` (nuevo):** `Options -Indexes` + bloqueo de ejecución de scripts (los SCORM son estáticos → evita RCE/XSS por archivos subidos).
|
||||||
|
- **`runtime/sco.php`:** `display_errors`/`display_startup_errors` en `0`; se quitó `allow_url_include`.
|
||||||
|
- **Backups eliminados:** `admin/index.php.back`, `admin/usuarios.php.back`, `admin/usuarios.bak.php`, `admin/usuarios.bak.html`, `admin/usuarios_manager.bak.php`, `runtime/getUserDashBoard.php.back`, `runtime/runtime.js.back`, carpeta `admin/backup100322/`.
|
||||||
|
|
||||||
|
### Fase 2 — Endurecimiento
|
||||||
|
- **`config.php`:** endurecimiento de sesión (`session.use_strict_mode`, `use_only_cookies`, `cookie_httponly`, `cookie_samesite=Lax`, `cookie_secure` si HTTPS). Solo aplica si no hay sesión activa.
|
||||||
|
- **`runtime/newlogin.php`:** reescrito con **consultas preparadas**, `session_regenerate_id(true)` (anti-fijación) y **rate-limit por IP** (60/10 min). Mantiene login por número de empleado.
|
||||||
|
- **`admin/usuarios_add.php` / `admin/usuarios_upadate.php`:** convertidos a **sentencias preparadas**.
|
||||||
|
- **CSRF:** token en `admin/index.php` (`<meta name="csrf-token">`), envío global en `js/admin.js` (`X-CSRF-Token` + `window.CSRF_TOKEN`), verificación en `auth_guard.php` para POST/PUT/DELETE, y cabecera `X-CSRF-Token` añadida a todos los uploads Uppy.
|
||||||
|
- **`runtimev2/api.php`:** corregido bug `=` → `==` en `LMSInitialize` (comparación de `lesson_status`/`score.raw`).
|
||||||
|
|
||||||
|
### Fase 3 — Mantenibilidad y calidad
|
||||||
|
- **N+1 eliminado** en `runtime/getUserDashBoard.php`: los hijos se traen con una sola consulta `WHERE padre IN (...)`.
|
||||||
|
- **Auditoría:** `admin/audit.php` (nuevo) + `logs/.htaccess` (nuevo). Registra en `logs/admin.log`: fecha, IP, userid, numempl, archivo, acción, detalle.
|
||||||
|
- **Sentencias preparadas + auditoría** en: `admin/categorias_add.php`, `categorias_upadate.php`, `categorias_delete.php`, `recursos_add.php`, `recursos_update.php`, `recursos_delete.php`, `gamification_add.php`, `gamification_delete.php`. Los `*_delete` sanitizan ids con `intval`.
|
||||||
|
- **`runtimev2/` eliminada** (sin referencias en el proyecto).
|
||||||
|
|
||||||
|
### Correcciones posteriores (vistas admin + dashboard)
|
||||||
|
- **polyfill.io eliminado** de `footer.php` y `runtime/rte.php` (dominio comprometido en 2024; causaba 404/CORS y rompía DataTables).
|
||||||
|
- **`JSON.parse` inseguro:** se añadió helper `parseJSON(resp)` (try/catch) y se reemplazaron todos los `JSON.parse(response)` en: `admin/usuarios.html`, `categorias.html`, `asignaciones.html`, `constancias.html`, `encuestas.html`, `evaluaciones.html`, `gamification.html`, `licencia.html`, `recursos.html`.
|
||||||
|
- **`admin/usuarios.php` y `admin/usuarios_manager.php`:** reescritos como DataTables server-side limpio y **con sentencias preparadas**; se eliminó el cifrado roto de la consulta y la propiedad `"query"` que rompía el `drawCallback` (`Cannot read properties of null (reading 'query')`).
|
||||||
|
- **`admin/usuarios.html`:** quitadas asignaciones `query = json.query`; reload con `ajax.reload(null, false)`.
|
||||||
|
- **`admin/usuarios_*_list.php` (8):** `mysqli_fetch_array` → `mysqli_fetch_assoc` (evita claves numéricas duplicadas en el JSON).
|
||||||
|
- **`admin/exportUsers.php`:** exporta según rol (`roladmin`), sin depender del `query` cifrado; `exportar()` envía `?roladmin=`.
|
||||||
|
- **`runtime/getUserDashBoard.php`:** blindado como endpoint JSON (`display_errors=0`, `Content-Type: application/json`, valida sesión y responde `{"code":"0","msg":"Sesión no válida"}` en lugar de HTML).
|
||||||
|
- **`dashboard.php`:** parseo tolerante de la respuesta (try/catch) con mensaje amigable.
|
||||||
|
- **`config.php`:** `ini_set` de sesión solo si no hay sesión activa (evita warnings).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Archivos NUEVOS
|
||||||
|
|
||||||
|
| Archivo | Propósito |
|
||||||
|
|---|---|
|
||||||
|
| `admin/auth_guard.php` | Guard de autenticación admin + verificación CSRF |
|
||||||
|
| `admin/audit.php` | Función `audit_log()` → escribe `logs/admin.log` |
|
||||||
|
| `admin/recursos_scorm_upload.php` | Subida de `.zip` SCORM: valida, descomprime en `data/scormpkg/<categoria>/` y devuelve la URL de inicio |
|
||||||
|
| `data/.htaccess` | `Options -Indexes` + bloqueo de ejecución de scripts en `data/` |
|
||||||
|
| `logs/.htaccess` | Protección de la carpeta de auditoría |
|
||||||
|
| `README.md` | Documentación general del proyecto (stack, funcionalidades, instalación, seguridad) |
|
||||||
|
| `CHANGELOG.md` | Este documento |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Archivos MODIFICADOS (por área)
|
||||||
|
|
||||||
|
### Configuración
|
||||||
|
- `config.php` — hardening de sesión (condicional).
|
||||||
|
|
||||||
|
### Runtime / RTE
|
||||||
|
- `runtime/gotorte.php` — lanzador central; carga `runtime/sco.php` con `require` (sin redirect) y respaldo al `sco.php` del paquete.
|
||||||
|
- `runtime/sco.php` — contenedor con barra + botón Regresar, API en el padre, iframe con cache-busting, cierre de BD, `display_errors=0`.
|
||||||
|
- `runtime/commit.php` — `mysqli_close($link)`.
|
||||||
|
- `runtime/finish.php` — `mysqli_close($link)`.
|
||||||
|
- `runtime/runtime.js` — `pagehide` en lugar de `window.onunload`.
|
||||||
|
- `runtime/getUserDashBoard.php` — N+1 resuelto + endpoint JSON blindado.
|
||||||
|
- `runtime/newlogin.php` — consultas preparadas + anti-fijación + rate-limit.
|
||||||
|
- `runtime/rte.php` — removido polyfill.io.
|
||||||
|
|
||||||
|
### Front (alumno)
|
||||||
|
- `dashboard.php` — scroll/resaltado de categoría al volver (`?idcat=`), parseo tolerante del dashboard.
|
||||||
|
- `recursos.php` — botón "Regresa al menú anterior" → `dashboard.php?idcat=<cat>`.
|
||||||
|
- `footer.php` — removido polyfill.io.
|
||||||
|
|
||||||
|
### Admin — endpoints
|
||||||
|
- `admin/usuarios.php`, `admin/usuarios_manager.php` — server-side limpio + preparadas.
|
||||||
|
- `admin/usuarios_add.php`, `admin/usuarios_upadate.php` — preparadas + auditoría.
|
||||||
|
- `admin/categorias_add.php`, `admin/categorias_upadate.php`, `admin/categorias_delete.php` — preparadas + auditoría.
|
||||||
|
- `admin/recursos_add.php`, `admin/recursos_update.php`, `admin/recursos_delete.php` — preparadas + auditoría.
|
||||||
|
- `admin/gamification_add.php`, `admin/gamification_delete.php` — preparadas + auditoría.
|
||||||
|
- `admin/exportUsers.php` — export por rol sin query cifrado.
|
||||||
|
- `admin/usuarios_{centros,distritos,posiciones,sociedades,divisiones,unidades,ceco,supervisores}_list.php` — `fetch_assoc`.
|
||||||
|
- `admin/categorias.php` — normalización de imagen (`assetUrl` inline) + `'Raíz'`.
|
||||||
|
- `admin/usuarios.php`/`recursos.php` (endpoints de tabla) — columnas/normalizaciones.
|
||||||
|
- **113** `admin/*.php` — línea del guard añadida.
|
||||||
|
|
||||||
|
### Admin — vistas (HTML)
|
||||||
|
- `admin/usuarios.html`, `categorias.html`, `asignaciones.html`, `constancias.html`, `encuestas.html`, `evaluaciones.html`, `gamification.html`, `licencia.html`, `recursos.html` — helper `parseJSON`, CSRF en Uppy, preselección por id en selects.
|
||||||
|
- `admin/index.php` — meta CSRF.
|
||||||
|
|
||||||
|
### JS
|
||||||
|
- `js/admin.js` — `window.CSRF_TOKEN` + `$.ajaxSetup({ headers: { 'X-CSRF-Token': csrf } })`.
|
||||||
|
|
||||||
|
### Data (paquete de ejemplo)
|
||||||
|
- `data/scormpkg/Premio_Nacional/index.html` — busca API subiendo al padre y redirige a Genially.
|
||||||
|
- `data/scormpkg/Premio_Nacional/sco.php`, `imsmanifest.xml`, XSDs — paquete creado.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Archivos ELIMINADOS
|
||||||
|
|
||||||
|
- Carpeta `runtimev2/` (completa).
|
||||||
|
- `admin/index.php.back`, `admin/usuarios.php.back`, `admin/usuarios.bak.php`, `admin/usuarios.bak.html`, `admin/usuarios_manager.bak.php`.
|
||||||
|
- `runtime/getUserDashBoard.php.back`, `runtime/runtime.js.back`.
|
||||||
|
- Carpeta `admin/backup100322/`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Estado verificado del repositorio
|
||||||
|
|
||||||
|
- `runtimev2/` → **no existe**. Sin referencias en el proyecto.
|
||||||
|
- `admin/auth_guard.php`, `admin/audit.php`, `data/.htaccess`, `logs/.htaccess`, `README.md` → **existen**.
|
||||||
|
- Endpoints `admin/*.php` con guard: **113**. Sin guard: solo `audit.php` (helper) e `index.php` (layout).
|
||||||
|
- No quedan archivos `*.back`/`*.bak` (fuera de `vendor/` y `data/`).
|
||||||
|
- `php -l` sin errores en los archivos tocados.
|
||||||
|
- Pruebas con BD temporal (`estafeta_lms2`) realizadas y **eliminadas** al terminar: login, dashboard (con/sin sesión), usuarios server-side, listas, CRUD categorías/recursos con auditoría.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Instrucciones para subir a producción (resumen)
|
||||||
|
|
||||||
|
**Obligatorio subir:**
|
||||||
|
1. `config.php`, `footer.php`, `dashboard.php`, `recursos.php`
|
||||||
|
2. `runtime/` completo (gotorte, sco, commit, finish, runtime.js, getUserDashBoard, newlogin, rte)
|
||||||
|
3. `admin/` completo (incluye `auth_guard.php`, `audit.php`, `recursos_scorm_upload.php`, todos los `.php` con guard y todos los `.html`)
|
||||||
|
4. `js/admin.js`
|
||||||
|
5. `data/.htaccess`
|
||||||
|
6. `logs/` (carpeta con `.htaccess`)
|
||||||
|
7. `data/scormpkg/Premio_Nacional/`
|
||||||
|
|
||||||
|
**Requisitos del servidor:**
|
||||||
|
- Permisos de escritura en `data/`, `data/scormpkg/`, `logs/`.
|
||||||
|
- `ZipArchive` habilitado en PHP.
|
||||||
|
- `upload_max_filesize` / `post_max_size` acordes al tamaño de los SCORM.
|
||||||
|
|
||||||
|
**NO subir / ya no aplica:**
|
||||||
|
- `runtimev2/` (eliminada).
|
||||||
|
- `config.php` ya no contiene `assetUrl()` (se quitó).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. Pendientes / recomendaciones (no bloqueantes)
|
||||||
|
|
||||||
|
1. **Credenciales:** mover `config.php` a variables de entorno y **rotar** la clave `wwserv_estafeta` (aparece comentada en el archivo). Hoy sigue en texto plano.
|
||||||
|
2. **SQL restante:** migrar a sentencias preparadas los endpoints de `constancias`, `encuestas`, `evaluaciones`, `licencia` y otros CRUD que aún interpolan SQL.
|
||||||
|
3. **Contraseñas:** la columna `password` usa `getEncrypt()` (no-op). Solo hashear si algún día se habilita login con contraseña.
|
||||||
|
4. **`session.save_path`** del `.htaccess` apunta a `ea-php73`; revisar con el PHP real en producción.
|
||||||
|
5. **polyfill.io dentro de `data/scormpkg/**`:** los paquetes antiguos aún lo referencian, pero no se usan (los sirve el RTE central). Limpiar opcionalmente.
|
||||||
|
6. **Tests automatizados** de flujos críticos (login, SCORM, alta de recursos).
|
||||||
|
7. **Consolidación de RTE** ya resuelta con la eliminación de `runtimev2/`; validar en producción el lanzamiento de Storyline/Rise/NOM-035.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. Notas de troubleshooting
|
||||||
|
|
||||||
|
- **`Fatal error: Unknown database 'estafeta_lms2'`** (local): es solo del entorno local (falta la BD). En producción existe `wwserv_estafeta`. Opciones: crear/importar la BD local o hacer `dbConnect()` tolerante.
|
||||||
|
- **`Unexpected token '<' ... is not valid JSON`:** indica que un endpoint devolvió HTML (error PHP). Con los cambios, los endpoints JSON ya no deben emitir HTML; si reaparece, revisar en DevTools → Network la respuesta del endpoint y confirmar que el archivo subido es el nuevo.
|
||||||
|
- **`polyfill.io` CORS/404:** dominio comprometido; ya removido del proyecto.
|
||||||
|
- **Rutas RTE:** `runtime/sco.php` usa rutas raíz (`$_SERVER['DOCUMENT_ROOT']."/sessionManager.php"`). Si el LMS se sirve en subcarpeta, ajustar a `/gitlab/estafeta/...`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. Corrección: vista de Usuarios (500 por columnas faltantes)
|
||||||
|
|
||||||
|
**Síntoma:** `POST admin/usuarios.php`, `usuarios_{centros,distritos,posiciones,sociedades,divisiones,unidades,ceco,supervisores}_list.php` → `500 (Internal Server Error)`.
|
||||||
|
|
||||||
|
**Causa raíz:** la BD local `estafeta_lms2` conserva el esquema **antiguo** de `user`
|
||||||
|
(solo `centrotrabajoid` / `distritoid` con FK a `centrotrabajo` / `distrito`).
|
||||||
|
El código actual lee/escribe columnas **denormalizadas** en `user`
|
||||||
|
(`centrotrabajonom`, `distritonom`, `posicion`, `sociedad`, `division`,
|
||||||
|
`unidad_organizativa`, `ceco`, `supervisor`). En PHP 8.1+ `mysqli` lanza
|
||||||
|
`mysqli_sql_exception` ante `Unknown column`, que antes terminaba en un fatal
|
||||||
|
sin control (HTTP 500). En PHP 7.4 solo devolvía resultados vacíos.
|
||||||
|
|
||||||
|
**Cambios:**
|
||||||
|
1. `bd/migration_usuarios_org_fields.sql` (nuevo): agrega las columnas faltantes
|
||||||
|
a `user` (idempotente) y rellena `centrotrabajonom` / `distritonom` desde las
|
||||||
|
FK `centrotrabajo` / `distrito`. **Aplicar en cada entorno.**
|
||||||
|
2. `admin/auth_guard.php`: `set_exception_handler` que descarta la salida previa
|
||||||
|
y responde JSON (`{"code":"500",...}`) en cualquier excepción no controlada,
|
||||||
|
en lugar de HTML; registra el detalle en `error_log`.
|
||||||
|
|
||||||
|
**Verificación local:** los 10 endpoints de usuarios + `usuarios.php` /
|
||||||
|
`usuarios_manager.php` responden JSON con datos; centros y distritos se
|
||||||
|
rellenan desde las FK.
|
||||||
|
|
||||||
|
**Pendiente del entorno:** completar la BD local (faltan tablas `licencia`,
|
||||||
|
`evaluaciones`, `encuestas`, `constancias`, etc.); `usuarios_statistical.php`
|
||||||
|
falla por `Table 'estafeta_lms2.licencia' doesn't exist` (ahora responde JSON 500
|
||||||
|
en vez de fatal).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. Corrección: traducción de DataTables (español)
|
||||||
|
|
||||||
|
**Síntoma:** las tablas de `recursos`, `categorias`, `gamification` (y otras del
|
||||||
|
panel) mostraban la interfaz de DataTables en **inglés** (Search, Show entries,
|
||||||
|
Previous/Next, "No data available", etc.).
|
||||||
|
|
||||||
|
**Causa raíz:** las vistas cargaban el idioma desde un CDN externo
|
||||||
|
(`https://cdn.datatables.net/plug-ins/.../i18n/Spanish.json`). Cuando el CDN no
|
||||||
|
está disponible (sin internet, bloqueado o CORS), DataTables cae a los textos por
|
||||||
|
defecto en inglés. `usuarios.html` ya usaba la copia local y sí se traducía.
|
||||||
|
|
||||||
|
**Cambios:** se reemplazó la URL del CDN por la copia local `../json/Spanish.json`
|
||||||
|
(compatible con DataTables 1.10.20 incluida en `js/datatables.min.js`) en:
|
||||||
|
- `admin/categorias.html`, `gamification.html`, `recursos.html`, `constancias.html`,
|
||||||
|
`encuestas.html`, `evaluaciones.html`, `reporte_categoria.html`, `reporte_curso.html`
|
||||||
|
- `admin/reporte_categoria.php`, `reporte_curso.php`, `reporte_distrito.php`,
|
||||||
|
`reporte_categoria_completadav2.php`, `reporte_categoria_visitadosv2.php`
|
||||||
|
|
||||||
|
**Verificación:** `http://localhost/git/LMS-Estafeta/json/Spanish.json` responde
|
||||||
|
HTTP 200; ya no quedan referencias a `cdn.datatables.net/plug-ins` en `admin/`.
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
# Plataforma LMS — Estafeta
|
||||||
|
|
||||||
|
Plataforma de aprendizaje (LMS) desarrollada a la medida para **Grupo Estafeta**. Administra cursos/categorías, recursos SCORM, evaluaciones, encuestas, gamificación (insignias/sellos), constancias y reportes de avance de los colaboradores.
|
||||||
|
|
||||||
|
> Sitio de producción: https://induccion-estafeta.com.mx/
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Tabla de contenido
|
||||||
|
|
||||||
|
- [Stack utilizado](#stack-utilizado)
|
||||||
|
- [Arquitectura y estructura](#arquitectura-y-estructura)
|
||||||
|
- [Funcionalidades principales](#funcionalidades-principales)
|
||||||
|
- [Alumno / Colaborador](#alumno--colaborador)
|
||||||
|
- [Administración](#administración)
|
||||||
|
- [SCORM / RTE](#scorm--rte)
|
||||||
|
- [Reportes](#reportes)
|
||||||
|
- [Modelo de datos](#modelo-de-datos)
|
||||||
|
- [Requisitos](#requisitos)
|
||||||
|
- [Instalación](#instalación)
|
||||||
|
- [Configuración](#configuración)
|
||||||
|
- [Seguridad](#seguridad)
|
||||||
|
- [Convenciones](#convenciones)
|
||||||
|
- [Roadmap / pendientes](#roadmap--pendientes)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Stack utilizado
|
||||||
|
|
||||||
|
**Backend**
|
||||||
|
- **PHP 7.4** (Apache + `mod_php`, ea-php74)
|
||||||
|
- **MySQL / MariaDB** (extensión `mysqli`)
|
||||||
|
- **Composer** con:
|
||||||
|
- `phpoffice/phpspreadsheet` — generación/lectura de Excel
|
||||||
|
- `mpdf/mpdf` — generación de PDF (constancias, reportes)
|
||||||
|
- `swiftmailer/swiftmailer` — envío de correo
|
||||||
|
|
||||||
|
**Frontend**
|
||||||
|
- **HTML5, CSS3, JavaScript (jQuery 3.4.1)**
|
||||||
|
- **Bootstrap 4** + **bootstrap-select**
|
||||||
|
- **DataTables** (+ checkboxes, searchpanes, select) — tablas de administración
|
||||||
|
- **SweetAlert2** — modales/alertas
|
||||||
|
- **Uppy** — carga de archivos (imágenes, paquetes SCORM)
|
||||||
|
- **Trumbowyg** — editor WYSIWYG
|
||||||
|
- **Highcharts** — gráficas de reportes
|
||||||
|
- **Select2, Daterangepicker, Moment, Lodash, Owl Carousel, signature_pad** — apoyo de UI
|
||||||
|
- Librerías de exportación: **excelexportjs, js-xlsx, FileSaver**
|
||||||
|
|
||||||
|
**SCORM**
|
||||||
|
- RTE propio en `runtime/` que implementa **SCORM 1.2** (API `LMSInitialize`, `LMSGetValue`, `LMSSetValue`, `LMSCommit`, `LMSFinish`) y lanza los paquetes en un `<iframe>`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Arquitectura y estructura
|
||||||
|
|
||||||
|
Aplicación **PHP monolítica** de múltiples páginas (sin framework), con endpoints AJAX que devuelven JSON y vistas HTML que se cargan dinámicamente en el panel de administración.
|
||||||
|
|
||||||
|
```
|
||||||
|
Estafeta/
|
||||||
|
├── index.php # Login (solo número de empleado)
|
||||||
|
├── dashboard.php # Panel del alumno (categorías asignadas)
|
||||||
|
├── recursos.php # Recursos de una categoría (?idcat=)
|
||||||
|
├── pasaporte.php # Pasaporte de sellos del alumno
|
||||||
|
├── evaluaciones.php # Evaluaciones
|
||||||
|
├── encuestas.php # Encuestas
|
||||||
|
├── certificate.php # Constancias
|
||||||
|
├── config.php # Configuración + conexión a BD + helpers
|
||||||
|
├── sessionManager.php # Bootstrap de sesión (redirige a logout si no hay sesión)
|
||||||
|
├── header.php / footer.php # Layout común
|
||||||
|
├── runtime/ # RTE SCORM (api, sco, commit, finish, gotorte, newlogin...)
|
||||||
|
├── controller/ # Endpoints JSON del front del alumno
|
||||||
|
├── admin/ # Panel de administración (endpoints + vistas .html)
|
||||||
|
│ ├── index.php # Layout admin (carga secciones en .mainseccion)
|
||||||
|
│ ├── auth_guard.php # Guard de autenticación + CSRF
|
||||||
|
│ ├── audit.php # Registro de auditoría (logs/admin.log)
|
||||||
|
│ └── *.php / *.html # Módulos (usuarios, categorías, recursos, etc.)
|
||||||
|
├── cron_report/ # Tareas programadas (avance/sellos)
|
||||||
|
├── evaluaciones/ # Lógica de evaluaciones
|
||||||
|
├── data/ # Datos subidos: scormpkg/, recursos/, imgcat/, ...
|
||||||
|
│ └── .htaccess # Bloquea ejecución de scripts en data/
|
||||||
|
├── logs/ # Bitácora de auditoría (.htaccess de protección)
|
||||||
|
├── vendor/ # Dependencias Composer
|
||||||
|
└── js/ css/ img/ webfonts/ # Recursos frontend
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Funcionalidades principales
|
||||||
|
|
||||||
|
### Alumno / Colaborador
|
||||||
|
- **Ingreso** con número de empleado.
|
||||||
|
- **Dashboard** con las categorías/cursos asignados, agrupados por categoría padre e hijos.
|
||||||
|
- **Cursos SCORM**: apertura de paquetes SCORM 1.2 en un contenedor con barra superior, botón **"Regresar al menú anterior"** (con scroll y resaltado de la categoría al volver) y registro de avance.
|
||||||
|
- **Progreso y sellos**: marca de `completed`/`passed` por recurso; **pasaporte de sellos** por categoría.
|
||||||
|
- **Evaluaciones** y **encuestas**.
|
||||||
|
- **Constancias** en PDF al completar objetivos.
|
||||||
|
|
||||||
|
### Administración
|
||||||
|
Panel en `admin/` (carga secciones vía AJAX en un layout):
|
||||||
|
- **Usuarios**: alta/edición/baja, carga masiva, roles, centros/distritos/posiciones/sociedades/divisiones.
|
||||||
|
- **Categorías**: jerarquía (padre/hijo), clave, imagen, orden, habilitado.
|
||||||
|
- **Recursos (SCORM)**: alta/edición, URL del paquete, imagen; **carga de `.zip` SCORM** que se descomprime en `data/scormpkg/<categoría>/` y genera la URL automáticamente (soporta Storyline, Rise y HTML).
|
||||||
|
- **Asignaciones**: asignación de categorías a usuarios (individual y masiva).
|
||||||
|
- **Evaluaciones / Encuestas**: preguntas, opciones, respuestas y estado.
|
||||||
|
- **Gamificación**: insignias por objetivo (categoría o recurso).
|
||||||
|
- **Constancias**: plantillas (logo/fondo) por categoría.
|
||||||
|
- **Permisos / Licencia**.
|
||||||
|
- **Auditoría**: registro de acciones de escritura en `logs/admin.log`.
|
||||||
|
|
||||||
|
### SCORM / RTE
|
||||||
|
- Punto de entrada: `runtime/gotorte.php?recursoid=<id>` → carga central `runtime/sco.php`.
|
||||||
|
- `runtime/sco.php` sirve un contenedor con el **API SCORM** en la página padre y el paquete en un `<iframe>` (así los SCO localizan el API subiendo por los frames).
|
||||||
|
- Persistencia de progreso en la tabla **`scormvars`** vía `runtime/commit.php` y `runtime/finish.php` (tiempo total, estado, calificación).
|
||||||
|
- Detección robusta del archivo de inicio (por `imsmanifest.xml` o nombres comunes: `index.html`, `index_lms.html`, `story.html`, etc.).
|
||||||
|
|
||||||
|
### Reportes
|
||||||
|
Módulos en `admin/reporte_*` con filtros por categoría, distrito, fechas y estado:
|
||||||
|
- Avance general, por categoría, completados y visitados.
|
||||||
|
- Exportación a **Excel** y vistas con **Highcharts**.
|
||||||
|
- Vistas SQL (`viewReporte*`) para consultas agregadas.
|
||||||
|
- Tareas programadas (`cron_report/`) para consolidar avance/sellos.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Modelo de datos
|
||||||
|
|
||||||
|
Principales tablas y vistas (MySQL):
|
||||||
|
|
||||||
|
| Tabla / Vista | Descripción |
|
||||||
|
|---|---|
|
||||||
|
| `user` | Colaboradores (numempl, nombre, área, rol, habilitado, etc.) |
|
||||||
|
| `categoria` | Categorías jerárquicas (padre, clave, nombre, imagen, orden) |
|
||||||
|
| `scormpkg` | Recursos/cursos (url, idcategoria, imagen, clave, habilitado) |
|
||||||
|
| `scormvars` | Datos de avance SCORM por usuario y recurso (estado, score, tiempo) |
|
||||||
|
| `asignacion` | Categorías asignadas a usuarios |
|
||||||
|
| `insignias` | Gamificación (insignia por objetivo) |
|
||||||
|
| `evaluaciones`, `evaluaciones_preguntas`, `evaluaciones_opciones`, `evaluaciones_respuestas`, `evaluaciones_estado` | Evaluaciones |
|
||||||
|
| `encuestas`, `encuestas_preguntas`, `encuestas_respuestas`, `encuesta_estado` | Encuestas |
|
||||||
|
| `constancias` | Plantillas de constancias por categoría |
|
||||||
|
| `licencia`, `config` | Configuración/permisos |
|
||||||
|
| `viewReporte*` | Vistas para reportes agregados |
|
||||||
|
|
||||||
|
> El estado de un recurso se considera **completado** cuando existe una fila en `scormvars` con `VarName = 'cmi.core.lesson_status'` y `VarValue` `completed` o `passed` para el usuario y el `SCOInstanceID` (id de `scormpkg`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Requisitos
|
||||||
|
|
||||||
|
- PHP **7.4** con extensiones: `mysqli`, `zip`, `openssl`, `gd`/`mbstring` (según uso), `dom`/`libxml`.
|
||||||
|
- MySQL 5.7+ / MariaDB.
|
||||||
|
- Apache con `mod_rewrite`.
|
||||||
|
- Composer.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Instalación
|
||||||
|
|
||||||
|
1. Clonar/copiar el proyecto en el webroot (`htdocs/git/Estafeta-plataform` o similar).
|
||||||
|
2. Instalar dependencias:
|
||||||
|
```bash
|
||||||
|
composer install
|
||||||
|
```
|
||||||
|
3. Crear la base de datos e importar el respaldo:
|
||||||
|
```sql
|
||||||
|
CREATE DATABASE estafeta_lms2 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
|
||||||
|
```
|
||||||
|
Luego importar el dump `.sql` correspondiente.
|
||||||
|
4. Ajustar credenciales en `config.php` (host, usuario, contraseña, nombre de BD).
|
||||||
|
5. Dar permisos de escritura a: `data/`, `data/scormpkg/`, `data/recursos/`, `data/imgcat/`, `logs/`.
|
||||||
|
6. Verificar límites de PHP para SCORM (`upload_max_filesize`, `post_max_size`) en `php.ini`/`.htaccess`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Configuración
|
||||||
|
|
||||||
|
En `config.php`:
|
||||||
|
```php
|
||||||
|
$CFG->wwwroot = 'https://tu-dominio/'; // debe terminar en "/"
|
||||||
|
$CFG->sessionname = 'estafetalms360';
|
||||||
|
$dbhost = 'localhost';
|
||||||
|
$dbuser = '...';
|
||||||
|
$dbpass = '...';
|
||||||
|
$dbname = 'estafeta_lms2';
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Seguridad
|
||||||
|
|
||||||
|
Medidas ya implementadas:
|
||||||
|
- `admin/auth_guard.php`: valida sesión + rol admin en los endpoints de `admin/` y **token CSRF** en métodos de escritura.
|
||||||
|
- Sesión endurecida (`use_strict_mode`, `use_only_cookies`, `HttpOnly`, `SameSite=Lax`, `Secure` en HTTPS).
|
||||||
|
- Login con **consultas preparadas**, `session_regenerate_id(true)` y **límite de intentos** por IP.
|
||||||
|
- Consultas preparadas en los CRUD principales (usuarios, categorías, recursos, insignias).
|
||||||
|
- `data/.htaccess` y `logs/.htaccess`: `Options -Indexes` y bloqueo de ejecución de scripts en carpetas de datos.
|
||||||
|
- Auditoría de acciones de administración (`logs/admin.log`).
|
||||||
|
|
||||||
|
Recomendaciones pendientes:
|
||||||
|
- Mover credenciales de `config.php` a variables de entorno y rotar claves.
|
||||||
|
- Extender sentencias preparadas al resto de endpoints (encuestas, evaluaciones, constancias, licencia).
|
||||||
|
- Revisar `session.save_path` en `.htaccess`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Convenciones
|
||||||
|
|
||||||
|
- Vistas de administración: `admin/<modulo>.html` (front) + `admin/<modulo>.php` (endpoint JSON) + `admin/<modulo>_add.php` / `_upadate.php` / `_delete.php`.
|
||||||
|
- Los endpoints validan sesión/rol y **responden JSON**.
|
||||||
|
- Nombres de tablas/columnas en `snake_case`; jerarquía de categorías con `padre` (0 = raíz).
|
||||||
|
- `$CFG->wwwroot` siempre con `/` final.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Roadmap / pendientes
|
||||||
|
|
||||||
|
- Migrar todo el SQL restante a **sentencias preparadas**.
|
||||||
|
- **Hashear** contraseñas (si en el futuro se habilita login con contraseña).
|
||||||
|
- Test automatizados de flujos críticos (login, SCORM, alta de recursos).
|
||||||
|
- Optimización: cache de assets, minificación, revisión de consultas.
|
||||||
|
- Accesibilidad e internacionalización.
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
//ini_set('display_errors', 1);
|
||||||
|
//ini_set('display_startup_errors', 1);
|
||||||
|
//error_reporting(E_ALL);
|
||||||
|
ini_set('memory_limit', '1024M');
|
||||||
|
//header('Content-Type: application/json');
|
||||||
|
//header('Access-Control-Allow-Origin: *');
|
||||||
|
//header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
|
||||||
|
//header('Access-Control-Allow-Headers: *');
|
||||||
|
|
||||||
|
require_once("../config.php");
|
||||||
|
dbConnect();
|
||||||
|
global $link;
|
||||||
|
$return = new stdClass();
|
||||||
|
if(isset($fechainicio)) {$fechainicio = $_POST['fechaini'];} else { $fechainicio = strtotime('-4 month'); }
|
||||||
|
if(isset($fechafin)) {$fechafin = $_POST['fechafin']; $fechafin = date('Y-m-d', strtotime($fechafin."+ 1 days") ); } else { $fechafin = strtotime('yesterday'); }
|
||||||
|
if(isset($estado)) {$estado = $_POST['estado']; if($estado==1) { $estado = 'ACTIVO'; } else { $estado = 'BAJA'; } } else { $estado = 'ACTIVO'; };
|
||||||
|
$sqlusers = "SELECT * FROM viewReporteCategorias";
|
||||||
|
$resultusers = mysqli_query($link, $sqlusers);
|
||||||
|
$data = [];
|
||||||
|
if( $resultusers ){
|
||||||
|
while ($row = mysqli_fetch_assoc ($resultusers)){
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$sqlcolumns = "SELECT categoria.id, categoria.clave, categoria.nombre FROM categoria WHERE padre = 0 AND habilitado = 1 ORDER BY categoria.id";
|
||||||
|
$resultcolumn= mysqli_query($link, $sqlcolumns);
|
||||||
|
if( $resultcolumn ){
|
||||||
|
while ($row = mysqli_fetch_assoc ($resultcolumn)){
|
||||||
|
$categorias[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$columnasvisibles= array(
|
||||||
|
'Estado del empleado',
|
||||||
|
'Número de empleado',
|
||||||
|
'Nombres(s)',
|
||||||
|
'Apellidos',
|
||||||
|
'Posición',
|
||||||
|
'Sociedad',
|
||||||
|
'División',
|
||||||
|
'Unidad organizativa',
|
||||||
|
'CeCo',
|
||||||
|
'Centro de trabajo',
|
||||||
|
'Distrito',
|
||||||
|
'Supervisor',
|
||||||
|
'fecha'
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($categorias as $key2 => $cat) {
|
||||||
|
array_push($columnasvisibles, $cat['nombre']);
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i=0; $i < sizeof($columnasvisibles) ; $i++) {
|
||||||
|
$columnasvisibles[$i] = array('title' => $columnasvisibles[$i]);
|
||||||
|
}
|
||||||
|
$return->columnasvisibles = $columnasvisibles;
|
||||||
|
|
||||||
|
if (!empty($data)) {
|
||||||
|
$anterior = '';
|
||||||
|
$users = 0;
|
||||||
|
$fecha_max = null;
|
||||||
|
foreach ($data as $key1 => $col) {
|
||||||
|
//print_r($col);die;
|
||||||
|
//echo $col[2]."<br>";
|
||||||
|
if ($col['numempl'] == $anterior) {
|
||||||
|
//echo $col['numempl']." igual - ".$col['nomcat']."- ".$users." <br>";
|
||||||
|
|
||||||
|
if($fecha_max == null){
|
||||||
|
//$datos[($users-1)][$col['fecha']] = $col['fecha'];
|
||||||
|
$fecha_max = strtotime($col['fecha']);
|
||||||
|
}else if( strtotime($col['fecha']) >= $fecha_max){
|
||||||
|
$fecha_max = strtotime($col['fecha']);
|
||||||
|
//$datos[($users-1)][$col['fecha']] = $col['fecha'];
|
||||||
|
}
|
||||||
|
$datos[($users-1)][$col['nomcat']] = $col['estado1'];
|
||||||
|
}else{
|
||||||
|
//echo $col['numempl']." nuevo - ".$col['nomcat']." - ".$users." <br>";
|
||||||
|
if($fecha_max!=null){
|
||||||
|
$datos[($users-1)]["fecha"] = date("d-m-Y",$fecha_max);
|
||||||
|
}
|
||||||
|
$fecha_max = null;
|
||||||
|
$datos[$users] =
|
||||||
|
['estado_empleado' => $col['estado_empleado'],
|
||||||
|
'numempl' => $col['numempl'],
|
||||||
|
'nombre' => $col['nombre'],
|
||||||
|
'apellidos' =>$col['apellidos'],
|
||||||
|
'posicion'=>$col['posicion'],
|
||||||
|
'sociedad'=> $col['sociedad'],
|
||||||
|
'division'=> $col['division'],
|
||||||
|
'unidad_organizativa' => $col['unidad_organizativa'],
|
||||||
|
'ceco'=>$col['ceco'],
|
||||||
|
'nomdistrito'=>$col['nomdistrito'],
|
||||||
|
'nomcentro' => $col['nomcentro'],
|
||||||
|
'supervisor'=>$col['supervisor'],
|
||||||
|
'fecha'=>$col['fecha']
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($categorias as $key2 => $cat) {
|
||||||
|
if ($cat['nombre'] == $col['nomcat']) {
|
||||||
|
|
||||||
|
if($fecha_max == null){
|
||||||
|
//$datos[$users][$col['fecha']] = $col['fecha'];
|
||||||
|
$fecha_max = strtotime($col['fecha']);
|
||||||
|
}else if( strtotime($col['fecha']) >= $fecha_max){
|
||||||
|
$fecha_max = strtotime($col['fecha']);
|
||||||
|
//$datos[$users][$col['fecha']] = $col['fecha'];
|
||||||
|
}
|
||||||
|
$datos[$users][$cat['nombre']] = $col['estado1'];
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$datos[$users][$cat['nombre']] = 'No completado';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$users++;
|
||||||
|
}
|
||||||
|
$anterior = $col['numempl'];
|
||||||
|
}
|
||||||
|
//print_r($datos[0]);
|
||||||
|
foreach ($datos as $col => $columnas) {
|
||||||
|
$fill = [];
|
||||||
|
foreach ($columnas as $key => $value) {
|
||||||
|
array_push($fill, $value);
|
||||||
|
|
||||||
|
}
|
||||||
|
$datos[$col] = $fill;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$datos = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
//echo json_encode($datos, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); die;
|
||||||
|
|
||||||
|
$filtered_resultusers = array_filter($datos, function($var) use ($fechainicio, $fechafin, $estado) {
|
||||||
|
$evtime = strtotime($var[12]);
|
||||||
|
return $evtime <= $fechafin && $evtime >= $fechainicio && $var[0] == $estado;
|
||||||
|
});
|
||||||
|
$finaldata = [];
|
||||||
|
foreach ($filtered_resultusers as $cols) {
|
||||||
|
$finaldata[] = $cols;
|
||||||
|
}
|
||||||
|
//echo $sqlusers;
|
||||||
|
//echo "<pre>".print_r($finaldata,true)."</pre>";
|
||||||
|
$return->data = $finaldata;
|
||||||
|
mysqli_close($link);
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
include '../config.php';
|
||||||
|
session_name($CFG->sessionname);
|
||||||
|
session_start();
|
||||||
|
if(!isset($_SESSION['usersession'])){
|
||||||
|
header("Location: ".$CFG->wwwroot);
|
||||||
|
}
|
||||||
|
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
$datatotal = [];
|
||||||
|
|
||||||
|
$sqlcat = "SELECT nombre FROM categoria WHERE padre = 0 ";
|
||||||
|
|
||||||
|
$resultcat = mysqli_query($link, $sqlcat);
|
||||||
|
|
||||||
|
$encabezadosrow = ['numempl'];
|
||||||
|
|
||||||
|
while ($row = mysqli_fetch_assoc ($resultcat)){
|
||||||
|
array_push($encabezadosrow, $row['nombre']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
user.numempl,
|
||||||
|
categoria.nombre
|
||||||
|
FROM
|
||||||
|
asignacion
|
||||||
|
INNER JOIN user ON user.userid = asignacion.uid
|
||||||
|
INNER JOIN categoria ON categoria.id = asignacion.catid
|
||||||
|
WHERE categoria.habilitado = 1
|
||||||
|
ORDER BY categoria.order_desc";
|
||||||
|
|
||||||
|
$resultados = mysqli_query($link, $sqlusers);
|
||||||
|
while ($row = mysqli_fetch_assoc ($resultados)){
|
||||||
|
$data [] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
$numempl = 0;
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
foreach ($value as $key2 => $value1) {
|
||||||
|
if($key2 == 'numempl'){
|
||||||
|
if ($value1 != $numempl) {
|
||||||
|
$numempl = $value1;
|
||||||
|
$dataind[0] = $value1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
foreach ($encabezadosrow as $keyenc => $encabezado) {
|
||||||
|
if ($keyenc > 0) {
|
||||||
|
if ($value1 == $encabezado) {
|
||||||
|
$dataind[$keyenc] = "1";
|
||||||
|
}else{
|
||||||
|
$dataind[$keyenc] = "0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array_push($datatotal, $dataind);
|
||||||
|
|
||||||
|
//print_r($datatotal);
|
||||||
|
|
||||||
|
|
||||||
|
function cleanData(&$str)
|
||||||
|
{
|
||||||
|
$str = mb_convert_encoding($str , 'UTF-16LE' ,'UTF-8');
|
||||||
|
$str = preg_replace("/\t/", "\\t", $str);
|
||||||
|
$str = preg_replace("/\r?\n/", "\\n", $str);
|
||||||
|
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// filename for download
|
||||||
|
$filename = "Listado_Asignaciones" . date('Ymd') . ".csv";
|
||||||
|
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||||
|
header("Content-Type: text/csv");
|
||||||
|
$out = fopen("php://output", 'w');
|
||||||
|
$flag = false;
|
||||||
|
|
||||||
|
$encabezados = $encabezadosrow;
|
||||||
|
array_walk($encabezados, __NAMESPACE__ . '\cleanData');
|
||||||
|
|
||||||
|
|
||||||
|
fputcsv($out, array_values($encabezados), ',', '"');
|
||||||
|
|
||||||
|
foreach ($datatotal as $key => $val) {
|
||||||
|
array_walk($val, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($val), ',', '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($out);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
require_once "../config.php";
|
||||||
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
$return = new stdClass();
|
||||||
|
//print_r($_FILES); die;
|
||||||
|
$files = $_FILES['customFile'];
|
||||||
|
$file_path = $files['tmp_name'][0]; // temporary upload path of the first file
|
||||||
|
$fileName = 'tmpusers.xlsx';
|
||||||
|
$dir_subida = '../data/tmpusers.xlsx';
|
||||||
|
move_uploaded_file($file_path, $dir_subida);
|
||||||
|
/** Identify the type of $inputFileName **/
|
||||||
|
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($dir_subida);
|
||||||
|
/** Create a new Reader of the type that has been identified **/
|
||||||
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
|
$spreadsheet = $reader->load($dir_subida);
|
||||||
|
/** Convert Spreadsheet Object to an Array for ease of use **/
|
||||||
|
$schdeules = $spreadsheet->getActiveSheet()->toArray();
|
||||||
|
unlink($dir_subida);
|
||||||
|
$return = new stdClass();
|
||||||
|
//paso 1 verifcar headers
|
||||||
|
$headers = $schdeules[0];
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
if(!in_array ( "numempl", $headers )){
|
||||||
|
$return->error = "1";
|
||||||
|
$return->msg = "No existe la columna número de empleado (numempl)";
|
||||||
|
}else{
|
||||||
|
|
||||||
|
$values = array_splice ($schdeules, 1, sizeof($schdeules)-1);
|
||||||
|
$return->procesados = sizeof($values);
|
||||||
|
$return->correctos = 0;
|
||||||
|
$return->results = [];
|
||||||
|
foreach ($values as $value) {
|
||||||
|
if( $value[0] == "" ){
|
||||||
|
array_push ($return->results, '<span class="text-danger font-weight-bold">Usuario sin numempl: '.implode(', ', $value) .'<span>');
|
||||||
|
}else if(userExist($value[0])){
|
||||||
|
|
||||||
|
for ($i=1; $i < sizeof($headers) ; $i++) {
|
||||||
|
//echo $headers[$i]." - ";
|
||||||
|
$categoria = buscarCategoria($headers[$i]);
|
||||||
|
$userid = buscarID($value[0]);
|
||||||
|
//echo $userid." - ";
|
||||||
|
//echo $categoria." - ";
|
||||||
|
|
||||||
|
if ($value[$i] == 0) {
|
||||||
|
//echo "ELIMINAR -";
|
||||||
|
|
||||||
|
if (buscarUser($categoria,$userid)) {
|
||||||
|
|
||||||
|
$sql = "DELETE FROM asignacion WHERE catid = '$categoria' AND uid = '$userid'";
|
||||||
|
|
||||||
|
if(mysqli_query($link, $sql)){
|
||||||
|
$return->correctos++;
|
||||||
|
array_push ($return->results, 'El usuario: <b>' . $value[0] . '</b> ya no esta asignado a la categoría <b>'.$headers[$i].'</b>.');
|
||||||
|
}else{
|
||||||
|
array_push ($return->results, 'El usuario: ' . $value[0] . ' error: '. mysqli_error($link));
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
//echo "No se encontró asignado el usuario ".$value[0]."<br>";
|
||||||
|
array_push($return->results,'No se encontró asignado el usuario <b>'.$value[0].'</b> a la categoría <b>'.$headers[$i].'</b>.');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
//echo "ASIGNAR - ";
|
||||||
|
|
||||||
|
if (!buscarUser($categoria,$userid)) {
|
||||||
|
|
||||||
|
$sql = "INSERT INTO asignacion(uid, catid) VALUES ($userid,$categoria)";
|
||||||
|
|
||||||
|
if(mysqli_query($link, $sql)){
|
||||||
|
$return->correctos++;
|
||||||
|
array_push ($return->results, 'El usuario: <b>' . $value[0] . '</b> se asignó correctamentea la categoría <b>'.$headers[$i].'</b>.');
|
||||||
|
}else{
|
||||||
|
array_push ($return->results, 'El usuario: ' . $value[0] . ' error: '. mysqli_error($link));
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
//echo "Ya se encuentra asignado el usuario ".$value[0]." <br>";
|
||||||
|
array_push($return->results,'Ya se encuentra asignado el usuario <b>'.$value[0].'</b> a la categoría <b>'.$headers[$i].'</b>.');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
array_push ($return->results, 'El usuario: ' . $value[0] . ' no se encuentra registrado aún.');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function userExist($numempl){
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$sql ="select * from user where numempl = '$numempl'";
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buscarID($numempl){
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$sql ="select userid from user where numempl = '$numempl'";
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
//return false;
|
||||||
|
}else{
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$userid = $row['userid'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $userid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function BuscarCategoria($categorianombre){
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
$sql ="SELECT id,clave,nombre FROM categoria WHERE nombre LIKE '$categorianombre'";
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
|
||||||
|
}else{
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$idcat = $row['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $idcat;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function buscarUser($categoria,$user){
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$sql ="SELECT * FROM `asignacion` WHERE catid = '$categoria' AND uid = '$user'";
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
|
||||||
|
include '../config.php';
|
||||||
|
require_once '../vendor/Classes/PHPExcel.php';
|
||||||
|
session_name($CFG->sessionname);
|
||||||
|
session_start();
|
||||||
|
if(!isset($_SESSION['usersession'])){
|
||||||
|
header("Location: ".$CFG->wwwroot);
|
||||||
|
}
|
||||||
|
|
||||||
|
dbConnect();
|
||||||
|
global $link;
|
||||||
|
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
categoria.nombre
|
||||||
|
FROM
|
||||||
|
categoria
|
||||||
|
WHERE
|
||||||
|
habilitado = 1 AND padre = 0";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$resultados = mysqli_query($link, $sqlusers);
|
||||||
|
$columnasname = ['numempl'];
|
||||||
|
while ($row = mysqli_fetch_array ($resultados)){
|
||||||
|
array_push($columnasname,$row['nombre']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$objPHPExcel = new PHPExcel();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$objPHPExcel->
|
||||||
|
getProperties()
|
||||||
|
->setCreator("Estafeta")
|
||||||
|
->setLastModifiedBy("Estafeta")
|
||||||
|
->setTitle("Template asignación")
|
||||||
|
->setSubject("Template")
|
||||||
|
->setDescription("Template para asignación de usuarios a categorías")
|
||||||
|
->setKeywords("Template")
|
||||||
|
->setCategory("Template");
|
||||||
|
|
||||||
|
|
||||||
|
$columnas = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
|
||||||
|
|
||||||
|
for ($i=0; $i < sizeof($columnasname) ; $i++) {
|
||||||
|
$objPHPExcel->setActiveSheetIndex(0)
|
||||||
|
->setCellValue($columnas[$i].'1', $columnasname[$i]);
|
||||||
|
$objPHPExcel->getActiveSheet()
|
||||||
|
->getColumnDimension($columnas[$i])
|
||||||
|
->setAutoSize(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$objPHPExcel->getActiveSheet()->setTitle('Asignaciones');
|
||||||
|
$objPHPExcel->setActiveSheetIndex(0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
header('Content-Type: application/vnd.ms-excel');
|
||||||
|
header('Content-Disposition: attachment;filename="template_asignacion_'.date('Ymd').'.xlsx"');
|
||||||
|
header('Cache-Control: max-age=0');
|
||||||
|
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
|
||||||
|
$objWriter->save('php://output');
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
include '../config.php';
|
||||||
|
session_name($CFG->sessionname);
|
||||||
|
session_start();
|
||||||
|
if(!isset($_SESSION['usersession'])){
|
||||||
|
header("Location: ".$CFG->wwwroot);
|
||||||
|
}
|
||||||
|
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
categoria.nombre
|
||||||
|
FROM
|
||||||
|
categoria
|
||||||
|
WHERE
|
||||||
|
habilitado = 1 AND padre = 0";
|
||||||
|
|
||||||
|
$resultados = mysqli_query($link, $sqlusers);
|
||||||
|
function cleanData(&$str)
|
||||||
|
{
|
||||||
|
$str = mb_convert_encoding($str , 'UTF-16LE' ,'UTF-8');
|
||||||
|
$str = preg_replace("/\t/", "\\t", $str);
|
||||||
|
$str = preg_replace("/\r?\n/", "\\n", $str);
|
||||||
|
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// filename for download
|
||||||
|
$filename = "template_asignacion_" . date('Ymd') . ".csv";
|
||||||
|
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||||
|
header("Content-Type: text/csv");
|
||||||
|
$out = fopen("php://output", 'w');
|
||||||
|
$flag = false;
|
||||||
|
|
||||||
|
$columnas = ['numempl'];
|
||||||
|
while ($row = mysqli_fetch_array ($resultados)){
|
||||||
|
array_push($columnas,$row['nombre']);
|
||||||
|
}
|
||||||
|
//$encabezados = ["numempl","Bievennido a bordo","Ciclos Operativos en Estafeta","Punto de Venta","Tu paquete mi paquete"];
|
||||||
|
$encabezados = $columnas;
|
||||||
|
array_walk($encabezados, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($encabezados), ',', '"');
|
||||||
|
//while ($row = mysqli_fetch_array ($resultados, MYSQLI_NUM)) {
|
||||||
|
//array_walk($row, __NAMESPACE__ . '\cleanData');
|
||||||
|
//fputcsv($out, array_values($row), ',', '"');
|
||||||
|
//}
|
||||||
|
|
||||||
|
fclose($out);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,443 @@
|
|||||||
|
<section class="py-md-4 py-2">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h1 class="text-secondary font-weight-bolder">Asignaciones</h1>
|
||||||
|
<p>Sistema de asignación de usuarios a categorías principales, al momento de crear la asignación, el usuario tendrá acceso a todos los recursos de dicha categoría, sino se le asigna ninguna categoría el usuario no podrá acceder a ningún recurso.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 controller">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12 text-left py-2 py-md-0 cat_disponibles">
|
||||||
|
<p>Selecciona la categoría<p>
|
||||||
|
<select id="catsuperior" class="col-12 col-md-6 selectpicker" data-live-search="true">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row my-3">
|
||||||
|
<div class="col-12 text-left">
|
||||||
|
<h3 class="catname">Bienvenido a bordo de Estafeta</h3>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||||||
|
<div class="card h-100 bg-transparent freecardasignaciones">
|
||||||
|
<div class="card-header bg-transparent">
|
||||||
|
<h5 class="text-primary font-weight-bold">Asignados</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<select class="custom-select" multiple id="lista_asignaciones">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer bg-transparent">
|
||||||
|
<input class="form-control w-100" id="busqueda_asignados" type="text" placeholder="Buscar..">
|
||||||
|
<div class="row align-items-center text-center my-3">
|
||||||
|
<div class="col-6 text-center">
|
||||||
|
<div class="btn btn-primary btn_quitar">Quitar seleccionados</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-6 text-center">
|
||||||
|
<div class="btn btn-primary btn_quitar_des">Limpiar selección</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||||||
|
<div class="card h-100 bg-transparent freecardasignaciones">
|
||||||
|
<div class="card-header bg-transparent">
|
||||||
|
<h5 class="text-primary font-weight-bold">Disponibles</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<select class="custom-select" multiple id="lista_disponibles">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer bg-transparent">
|
||||||
|
<input class="form-control w-100" id="busqueda_disponibles" type="text" placeholder="Buscar..">
|
||||||
|
<div class="row align-items-center text-center my-3">
|
||||||
|
<div class="col-6 text-center">
|
||||||
|
<div class="btn btn-primary btn_agregar">Agregar seleccionados</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-6 text-center">
|
||||||
|
<div class="btn btn-primary btn_agregar_des">Limpiar selección</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2">
|
||||||
|
<hr>
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center align-self-center">
|
||||||
|
<div class="col-12">
|
||||||
|
<h2>Asignación masiva de usuarios</h2>
|
||||||
|
</div>
|
||||||
|
<div class="col-12">Para asignar un usuario a una categoría coloca el número <b>1</b> para quitar la asignación a dicha categoría coloca el número <b>0</b>.
|
||||||
|
</div>
|
||||||
|
<div class="col-12 my-3"><a class="btn btn-secondary" href="asignacion_template.php" download target="_blank">Descargar template asignación de usuarios</a></div>
|
||||||
|
</div>
|
||||||
|
<div class="row align-items-center align-self-center">
|
||||||
|
<div class="col-12 col-md-6 colform">
|
||||||
|
<form name="masiveusers_asignacion" method="post" enctype="multipart/form-data" id="masiveusers_asignacion">
|
||||||
|
<div class="custom-file">
|
||||||
|
<input type="file" class="custom-file-input" id="customFile" name="customFile" required accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
|
||||||
|
<label class="custom-file-label" for="customFile">Subir archivo</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row justify-content-end my-3">
|
||||||
|
<div class="col-12 col-md-6 text-right">
|
||||||
|
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Enviar</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row align-items-center align-self-center">
|
||||||
|
<div class="col-12 col-md-6 ">
|
||||||
|
<div class="card h-100 bg-transparent rounded-0 border-0 ">
|
||||||
|
<div class="card-body resultadosmasivos_asignacion"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<script type="text/javascript">
|
||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
function parseJSON(resp) {
|
||||||
|
if (resp == null) return null;
|
||||||
|
if (typeof resp === 'object') return resp;
|
||||||
|
try { return JSON.parse(resp); }
|
||||||
|
catch (e) { console.error('Respuesta no-JSON del servidor:', String(resp).substring(0, 300)); return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/***************** masiveusers ****************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
$("#masiveusers_asignacion").validate({
|
||||||
|
rules: {
|
||||||
|
customFile: {
|
||||||
|
required: true,
|
||||||
|
extension: "xlsx"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
invalidHandler: function (event, validator) {
|
||||||
|
$(".custom-file-label").removeClass('selected').html('Subir archivo');
|
||||||
|
},
|
||||||
|
submitHandler: function () {
|
||||||
|
var data = new FormData();
|
||||||
|
|
||||||
|
url = 'asignacion_masive_upload.php';
|
||||||
|
|
||||||
|
console.log(url);
|
||||||
|
|
||||||
|
//File data
|
||||||
|
var file_data = $('input[name="customFile"]')[0].files;
|
||||||
|
for (var i = 0; i < file_data.length; i++) {
|
||||||
|
data.append("customFile[]", file_data[i]);
|
||||||
|
}
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
method: "post",
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
data: data,
|
||||||
|
success: function (response) {
|
||||||
|
//success
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
console.log(_data);
|
||||||
|
if (_data.error > 0) {
|
||||||
|
Swal.fire({
|
||||||
|
html: _data.msg,
|
||||||
|
icon: "error",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$('#masiveusers_asignacion').trigger("reset");
|
||||||
|
$(".custom-file-label").removeClass('selected').html('Subir archivo');
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$(".resultadosmasivos_asignacion").html("");
|
||||||
|
$(".resultadosmasivos_asignacion").html('<h3>Resultado</h3><ul class="list-group listresult_asignacion"></ul>')
|
||||||
|
$.each(_data.results, function (index, val) {
|
||||||
|
$(".listresult_asignacion").append('<li class="list-group-item">' + val + '</li>');
|
||||||
|
});
|
||||||
|
//$(".resultadosmasivos_asignacion").append('<p class="my-2 pl-2">Procesados: ' + _data.procesados + ' Correctos: ' + _data.correctos + '</p>');
|
||||||
|
$('#masiveusers_asignacion').trigger("reset");
|
||||||
|
$(".custom-file-label").removeClass('selected').html('Subir archivo');
|
||||||
|
verAsiganaciones($('#catsuperior').val());
|
||||||
|
$(".layer-load").show();
|
||||||
|
}
|
||||||
|
$(".layer-load").hide();
|
||||||
|
},
|
||||||
|
error: function (e) {
|
||||||
|
//error
|
||||||
|
$(".layer-load").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add the following code if you want the name of the file appear on select
|
||||||
|
$(".custom-file-input").on("change", function () {
|
||||||
|
var fileName = $(this).val().split("\\").pop();
|
||||||
|
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function listadoDeCategorias() {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias_list.php',
|
||||||
|
type: 'POST'
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
if (_data.code == "1") {
|
||||||
|
$("#catsuperior").html("");
|
||||||
|
var _padres = _.filter(_data.datos, function (n) {
|
||||||
|
return n.padre == 0;
|
||||||
|
});
|
||||||
|
/*
|
||||||
|
var _datos = _.groupBy(_data.datos, function (n) {
|
||||||
|
return n.padre;
|
||||||
|
});
|
||||||
|
$.each(_padres, function (index, val1) {
|
||||||
|
$("#catsuperior").append('<optgroup label="' + val1.nombre + '"></optgroup>');
|
||||||
|
$.each(_datos, function (index, cats) {
|
||||||
|
$.each(cats, function (index, val) {
|
||||||
|
if (val.padre == val1.id || val.nombre == val1.nombre) {
|
||||||
|
if (val.nombre == val1.nombre) {
|
||||||
|
$("[label='" + val1.nombre + "']").append('<option class="font-weight-bold" value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
} else {
|
||||||
|
$("[label='" + val1.nombre + "']").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});*/
|
||||||
|
$.each(_padres, function (index, val) {
|
||||||
|
$("#catsuperior").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
});
|
||||||
|
$('#catsuperior').selectpicker('render');
|
||||||
|
$('#catsuperior').change(function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
/* Act on the event */
|
||||||
|
verAsiganaciones($(this).val());
|
||||||
|
});
|
||||||
|
$('#catsuperior').trigger('change');
|
||||||
|
} else {
|
||||||
|
$(".controller").html('<h1>No existen categorias</h1>');
|
||||||
|
}
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function verAsiganaciones(indexofcat) {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'asignaciones.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { indexofcat: indexofcat },
|
||||||
|
})
|
||||||
|
.done(function (reponse) {
|
||||||
|
var _data = JSON.parse(reponse);
|
||||||
|
if (_data.code == 0) {
|
||||||
|
Swal.fire({
|
||||||
|
html: _data.msg,
|
||||||
|
icon: 'error',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$("#lista_asignaciones").html("");
|
||||||
|
$("#lista_disponibles").html("");
|
||||||
|
|
||||||
|
$(".catname").html("Asignaciones en la categoría: <span class='text-secondary'>" + _data.catdata[0].nombre + "</span>");
|
||||||
|
$.each(_data.asignados, function (index, val) {
|
||||||
|
$("#lista_asignaciones").append('<option class="user_listado" value="' + val.userid + '">' + val.numempl + '</option>');
|
||||||
|
});
|
||||||
|
|
||||||
|
$.each(_data.disponibles, function (index, val) {
|
||||||
|
$("#lista_disponibles").append('<option class="user_listado" value="' + val.userid + '">' + val.numempl + '</option>');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#busqueda_disponibles").on("keyup", function () {
|
||||||
|
var value = $(this).val().toLowerCase();
|
||||||
|
$("#lista_disponibles option").filter(function () {
|
||||||
|
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$("#busqueda_asignados").on("keyup", function () {
|
||||||
|
var value = $(this).val().toLowerCase();
|
||||||
|
$("#lista_asignaciones option").filter(function () {
|
||||||
|
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".btn_quitar").click(function (event) {
|
||||||
|
var asignados = $('#lista_asignaciones').val();
|
||||||
|
if (asignados.length == 0) {
|
||||||
|
Swal.fire({
|
||||||
|
html: "No hay usuarios seleccionados",
|
||||||
|
icon: 'error',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'asignaciones_remove.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { id: asignados, idcat: $('#catsuperior').val() }
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
if (_data.code == 0) {
|
||||||
|
Swal.fire({
|
||||||
|
html: _data.msg,
|
||||||
|
icon: 'error',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
verAsiganaciones($('#catsuperior').val());
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
html: _data.msg,
|
||||||
|
icon: 'success',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
verAsiganaciones($('#catsuperior').val());
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$(".btn_agregar").click(function (event) {
|
||||||
|
var disponibles = $('#lista_disponibles').val();
|
||||||
|
if (disponibles.length == 0) {
|
||||||
|
Swal.fire({
|
||||||
|
html: "No hay usuarios seleccionados",
|
||||||
|
icon: 'error',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'asignaciones_add.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { id: disponibles, idcat: $('#catsuperior').val() }
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
if (_data.code == 0) {
|
||||||
|
Swal.fire({
|
||||||
|
html: _data.msg,
|
||||||
|
icon: 'error',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
verAsiganaciones($('#catsuperior').val());
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
html: _data.msg,
|
||||||
|
icon: 'success',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
verAsiganaciones($('#catsuperior').val());
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$(".btn_quitar_des, .btn_agregar_des").click(function (event) {
|
||||||
|
$(this).closest('.freecardasignaciones').find('option').prop("selected", false);
|
||||||
|
});
|
||||||
|
listadoDeCategorias();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$indexofcat = $_POST['indexofcat'];
|
||||||
|
|
||||||
|
$sqlusuarioencategoria = "SELECT
|
||||||
|
`user`.userid,
|
||||||
|
`user`.numempl
|
||||||
|
FROM
|
||||||
|
asignacion
|
||||||
|
INNER JOIN `user` ON `user`.userid = asignacion.uid
|
||||||
|
WHERE asignacion.catid = $indexofcat AND `user`.habilitado = 1";
|
||||||
|
|
||||||
|
$sqldisponibles ="SELECT
|
||||||
|
`user`.userid,
|
||||||
|
`user`.numempl
|
||||||
|
FROM
|
||||||
|
`user`
|
||||||
|
WHERE
|
||||||
|
`user`.userid NOT IN ( SELECT `user`.userid FROM asignacion INNER JOIN `user` ON `user`.userid = asignacion.uid WHERE asignacion.catid = $indexofcat )
|
||||||
|
AND
|
||||||
|
`user`.habilitado = 1";
|
||||||
|
|
||||||
|
$sqlcatdata = "SELECT * FROM categoria WHERE id = $indexofcat";
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sqlusuarioencategoria);
|
||||||
|
$return = new stdClass();
|
||||||
|
$return->asignados = [];
|
||||||
|
$return->disponibles = [];
|
||||||
|
$return->catdata = [];
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin usuarios asignados";
|
||||||
|
} else {
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="usuarios asignados";
|
||||||
|
|
||||||
|
while ($row = mysqli_fetch_array ($result)){
|
||||||
|
$return->asignados[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = mysqli_query($link, $sqldisponibles);
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg .="<br>Sin usuarios disponibles";
|
||||||
|
} else {
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg ="usuarios disponibles";
|
||||||
|
while ($row = mysqli_fetch_array ($result)){
|
||||||
|
$return->disponibles[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = mysqli_query($link, $sqlcatdata);
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg .="<br>Sin categorias";
|
||||||
|
} else {
|
||||||
|
while ($row = mysqli_fetch_array ($result)){
|
||||||
|
$return->code = "1";
|
||||||
|
$return->catdata[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$ids = $_POST['id'];
|
||||||
|
$idcat = $_POST['idcat'];
|
||||||
|
$sql = "";
|
||||||
|
foreach ($ids as $key => $value) {
|
||||||
|
$sql .= "INSERT INTO asignacion ( uid, catid ) VALUES ($value, $idcat); ";
|
||||||
|
}
|
||||||
|
$return = new stdClass();
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
if (mysqli_multi_query($link, $sql)) {
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg = "Actualización correcta";
|
||||||
|
} else {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg .= "Error: " . $sql . "<br>" . mysqli_error($link);
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$ids = $_POST['id'];
|
||||||
|
$idcat = $_POST['idcat'];
|
||||||
|
$sql = "";
|
||||||
|
foreach ($ids as $key => $value) {
|
||||||
|
$sql .= "DELETE FROM asignacion WHERE uid = $value AND catid = $idcat; ";
|
||||||
|
}
|
||||||
|
$return = new stdClass();
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
if (mysqli_multi_query($link, $sql)) {
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg = "Actualización correcta";
|
||||||
|
} else {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg .= "Error: " . $sql . "<br>" . mysqli_error($link);
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
// Auditoría de acciones de administración.
|
||||||
|
// Uso: require_once __DIR__.'/audit.php'; luego audit_log('categoria_update', 'detalle');
|
||||||
|
require_once dirname(__DIR__) . '/config.php';
|
||||||
|
|
||||||
|
function audit_log($accion, $detalle = '') {
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
if (session_status() !== PHP_SESSION_NONE && !empty($_SESSION['usersession'])) {
|
||||||
|
$u = json_decode($_SESSION['usersession'], true);
|
||||||
|
$numempl = isset($u['numempl']) ? $u['numempl'] : '';
|
||||||
|
$userid = isset($u['userid']) ? (int)$u['userid'] : 0;
|
||||||
|
} else {
|
||||||
|
$numempl = '';
|
||||||
|
$userid = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'UNKNOWN';
|
||||||
|
$archivo = isset($_SERVER['SCRIPT_NAME']) ? basename($_SERVER['SCRIPT_NAME']) : '';
|
||||||
|
if (strlen($detalle) > 2000) { $detalle = substr($detalle, 0, 2000); }
|
||||||
|
|
||||||
|
$logDir = dirname(__DIR__) . '/logs';
|
||||||
|
if (!is_dir($logDir)) { @mkdir($logDir, 0775, true); }
|
||||||
|
$linea = sprintf(
|
||||||
|
"%s\t%s\t%d\t%s\t%s\t%s\t%s\n",
|
||||||
|
date('Y-m-d H:i:s'),
|
||||||
|
$ip,
|
||||||
|
$userid,
|
||||||
|
$numempl,
|
||||||
|
$archivo,
|
||||||
|
$accion,
|
||||||
|
str_replace(array("\t", "\r", "\n"), ' ', $detalle)
|
||||||
|
);
|
||||||
|
@file_put_contents($logDir . '/admin.log', $linea, FILE_APPEND | LOCK_EX);
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
// Guard de autenticación + CSRF para endpoints de admin.
|
||||||
|
// Include al inicio de cada endpoint (require_once __DIR__.'/auth_guard.php';)
|
||||||
|
|
||||||
|
// Los endpoints de admin SIEMPRE responden JSON: nunca emitir HTML de avisos/errores.
|
||||||
|
@ini_set('display_errors', '0');
|
||||||
|
@ini_set('display_startup_errors', '0');
|
||||||
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
|
||||||
|
|
||||||
|
// Descartar cualquier salida previa (BOM, espacios, avisos) antes del JSON.
|
||||||
|
if (ob_get_level() === 0) { @ob_start(); }
|
||||||
|
|
||||||
|
require_once dirname(__DIR__) . '/config.php';
|
||||||
|
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_name($CFG->sessionname);
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($_SESSION['usersession']) || empty($_SESSION['isadmin'])) {
|
||||||
|
while (ob_get_level() > 0) { @ob_end_clean(); }
|
||||||
|
http_response_code(403);
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
echo json_encode(array('code' => '403', 'msg' => 'No autorizado'), JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cualquier salida accidental (avisos/notices) antes del JSON se descarta aquí.
|
||||||
|
while (ob_get_level() > 0) { @ob_end_clean(); }
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
// Excepciones no controladas (p. ej. mysqli_sql_exception en PHP 8+) deben
|
||||||
|
// responder JSON, nunca HTML con stack trace (evita el "Unexpected token '<'").
|
||||||
|
set_exception_handler(function ($e) {
|
||||||
|
while (ob_get_level() > 0) { @ob_end_clean(); }
|
||||||
|
error_log('admin endpoint: ' . $e->getMessage());
|
||||||
|
http_response_code(500);
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
echo json_encode(array('code' => '500', 'msg' => 'Error interno del servidor', 'error' => $e->getMessage()), JSON_UNESCAPED_UNICODE);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (empty($_SESSION['csrf'])) {
|
||||||
|
$_SESSION['csrf'] = bin2hex(random_bytes(32));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verificación CSRF en métodos que cambian estado
|
||||||
|
$metodo = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET';
|
||||||
|
if ($metodo === 'POST' || $metodo === 'PUT' || $metodo === 'DELETE') {
|
||||||
|
$token = isset($_SERVER['HTTP_X_CSRF_TOKEN']) ? $_SERVER['HTTP_X_CSRF_TOKEN'] : '';
|
||||||
|
if ($token === '' && isset($_POST['csrf'])) { $token = $_POST['csrf']; }
|
||||||
|
if (!is_string($token) || !hash_equals($_SESSION['csrf'], $token)) {
|
||||||
|
http_response_code(403);
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
echo json_encode(array('code' => '403', 'msg' => 'Token CSRF inválido'), JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,588 @@
|
|||||||
|
<section class="py-md-4 py-2 border-bottom border-secondary">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h1 class="text-secondary font-weight-bolder">Categorias</h1>
|
||||||
|
<p>Sistema de gestión de categorias, se pueden agregar categorias, desactivar categorias y modificar categorias.</p>
|
||||||
|
<p>Una categoría puede contener cero o mas recursos.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 controller">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center align-self-center">
|
||||||
|
<div class="col-12">
|
||||||
|
<table id="datatable" class="display table table-striped table-bordered" cellspacing="0" width="100%">
|
||||||
|
<thead>
|
||||||
|
<tr></tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 editor" style="display: none;">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center justify-content-start">
|
||||||
|
<div class="col-12 text-left my-4">
|
||||||
|
<h3 class="title-cat edit" style="display: none;">Editar Categoría</h3>
|
||||||
|
<h3 class="title-cat crear" style="display: none;">Crear Categoría</h3>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-10">
|
||||||
|
<form class="formcontroller">
|
||||||
|
<input type="hidden" name="idcat" id="idcat" value="">
|
||||||
|
<input type="hidden" name="urlimgcat" id="urlimgcat" value="">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="catsuperior" class="col-md-2 col-12 col-form-label">Categoría superior</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="catsuperior" name="catsuperior" class="col-12 selectpicker" data-live-search="true" required="required">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-2 col-12 col-form-label" for="nombre">Nombre</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<textarea id="nombre" name="nombre" cols="40" rows="5" class="form-control" required="required"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="desc" class="col-md-2 col-12 col-form-label">Descripción</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<textarea id="desc" name="desc" cols="40" rows="5" class="form-control"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="clave" class="col-md-2 col-12 col-form-label">Clave</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<input id="clave" name="clave" placeholder="clave" type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="habilitado" class="col-md-2 col-12 col-form-label">Habilitado</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="habilitado" name="habilitado" class="custom-select" required="required">
|
||||||
|
<option value="1">SI</option>
|
||||||
|
<option value="0">No</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="order" class="col-md-2 col-12 col-form-label">Orden del módulo</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<input id="order" name="order" placeholder="Orden módulo" type="number" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-2 col-12 col-form-label">Imagen</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||||||
|
<div class="UppyDragDrop"></div>
|
||||||
|
<div class="w-100 my-3">
|
||||||
|
<div class="for-ProgressBar"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0 preview" style="display: none;">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="ThumbnailGenerator"></div>
|
||||||
|
<div class="uploaded-files text-secondary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row justify-content-center">
|
||||||
|
<div class="col-12 col-md-6 text-right">
|
||||||
|
<div class="btn btn-warning btn_cancelar">Cancelar</div>
|
||||||
|
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Enviar</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(".layer-load").show();
|
||||||
|
var table;
|
||||||
|
var categoriasList = [];
|
||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
function parseJSON(resp) {
|
||||||
|
if (resp == null) return null;
|
||||||
|
if (typeof resp === 'object') return resp;
|
||||||
|
try { return JSON.parse(resp); }
|
||||||
|
catch (e) { console.error('Respuesta no-JSON del servidor:', String(resp).substring(0, 300)); return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** UPLOAD ********************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
var uppy = Uppy.Core({
|
||||||
|
debug: false,
|
||||||
|
autoProceed: true,
|
||||||
|
allowMultipleUploads: true,
|
||||||
|
locale: Uppy.locales.Spanish,
|
||||||
|
restrictions: {
|
||||||
|
allowedFileTypes: ['image/*']
|
||||||
|
}
|
||||||
|
});
|
||||||
|
uppy.use(Uppy.DragDrop, {
|
||||||
|
target: '.UppyDragDrop',
|
||||||
|
locale: {
|
||||||
|
strings: {
|
||||||
|
browse: 'Buscar',
|
||||||
|
dropHereOr: "Arrastra el archivo aqu\xed o %{browse}",
|
||||||
|
dropHint: "Arrastra el archivo aqu\xed",
|
||||||
|
dropPaste: "Arrastra el archivo aqu\xed, pegar o %{browse}",
|
||||||
|
dropPasteImport: "Arrastra el archivo aqu\xed, pegar, %{browse} o importar desde",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).use(Uppy.XHRUpload, {
|
||||||
|
headers: { 'X-CSRF-Token': window.CSRF_TOKEN },
|
||||||
|
endpoint: "categorias_upload.php",
|
||||||
|
formData: true,
|
||||||
|
method: 'post',
|
||||||
|
fieldName: 'files[]'
|
||||||
|
}).use(Uppy.ProgressBar, { target: '.for-ProgressBar', hideAfterFinish: false }).on('upload-success', function (file, response) { onUploadSuccess(file, response) });
|
||||||
|
|
||||||
|
function onUploadSuccess(file, response) {
|
||||||
|
if (response.uploadURL) {
|
||||||
|
var url = response.uploadURL;
|
||||||
|
$("#urlimgcat").val(url);
|
||||||
|
var fileName = file.name;
|
||||||
|
$(".preview").show();
|
||||||
|
$(".uploaded-files").show().addClass('newimg');
|
||||||
|
$(".uploaded-files").html("");
|
||||||
|
$(".uploaded-files").html('<a class="btn-link" href="' + response.uploadURL + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + response.uploadURL + '"><br>' + fileName + '</a>');
|
||||||
|
} else {
|
||||||
|
Swal.fire(
|
||||||
|
'',
|
||||||
|
response.body.txt,
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
uppy.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** DATATABLE *****************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
function getData() {
|
||||||
|
listadoDeCategorias();
|
||||||
|
$("#datatable").html('<thead><tr></tr></thead>');
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias.php',
|
||||||
|
cache: false
|
||||||
|
}).done(function (data) {
|
||||||
|
var _data = JSON.parse(data);
|
||||||
|
var tableName = "#datatable";
|
||||||
|
var str;
|
||||||
|
$.each(_data.columns, function (k, colObj) {
|
||||||
|
str = '<th>' + colObj + '</th>';
|
||||||
|
$(str).appendTo(tableName + '>thead>tr');
|
||||||
|
});
|
||||||
|
|
||||||
|
table = $('#datatable').DataTable({
|
||||||
|
dom: "Bfrtip",
|
||||||
|
responsive: true,
|
||||||
|
"drawCallback": function (settings) {
|
||||||
|
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||||||
|
addEventsCheck();
|
||||||
|
|
||||||
|
|
||||||
|
$("#datatable td").each(function(index, el) {
|
||||||
|
var txt = $.trim($(this).text());
|
||||||
|
if (txt === "" || txt.indexOf("http") < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (/\.(jpe?g|png|gif|webp|bmp|svg)(\?.*)?$/i.test(txt)) {
|
||||||
|
$(this).html("<div class='text-center'><a href='" + txt + "' target='_blank'>" +
|
||||||
|
"<img style='width:150px; max-width:100%; display:block; margin:0 auto;' src='" + txt + "' class='listimg p-3'></a></div>");
|
||||||
|
} else if (txt.indexOf(".mp4") >= 0) {
|
||||||
|
$(this).html("<div class='openanimacion text-center' style='cursor:pointer;' onclick='window.open(\"" + txt + "\");'>" +
|
||||||
|
"<img style='width:150px; max-width:100%; display:block; margin:0 auto;' src='../img/icons/008-film.png' class='listimg p-3'></div>");
|
||||||
|
} else {
|
||||||
|
$(this).html("<div class='openanimacion text-center' style='cursor:pointer;' onclick='window.open(\"" + txt + "\");'>" +
|
||||||
|
"<img style='width:150px; max-width:100%; display:block; margin:0 auto;' src='../img/icons/214-worldwide.png' class='listimg p-3'></div>");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
buttons: [{
|
||||||
|
extend: 'excel',
|
||||||
|
text: 'Exportar a Excel'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Editar',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
editar(e, dt, node, config);
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_edit'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Alternar habilitar',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
deshabilitar(e, dt, node, config)
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_habilitar'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Crear',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
crear();
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_crear'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
'columnDefs': [{
|
||||||
|
'targets': 0,
|
||||||
|
'checkboxes': { 'selectRow': true }
|
||||||
|
}],
|
||||||
|
|
||||||
|
'order': [
|
||||||
|
[1, 'asc']
|
||||||
|
],
|
||||||
|
data: _data.datos,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
table.columns.adjust().draw();
|
||||||
|
$(window).resize(function (event) {
|
||||||
|
/* Act on the event */
|
||||||
|
table.columns.adjust().draw();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reloadData() {
|
||||||
|
listadoDeCategorias();
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias.php',
|
||||||
|
cache: false
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
var NewlyCreatedData = JSON.parse(data);
|
||||||
|
table.clear();
|
||||||
|
table.rows.add(NewlyCreatedData.datos); // Add new data
|
||||||
|
table.columns.adjust().draw(); // Redraw the DataTable
|
||||||
|
table.column(0).checkboxes.deselectAll();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addEventsCheck() {
|
||||||
|
$("#datatable_wrapper input[type='checkbox']").on('change', function (e) {
|
||||||
|
setTimeout(function (){
|
||||||
|
console.log($("#datatable_wrapper input[type='checkbox']:checked").length);
|
||||||
|
if (table.column(0).checkboxes.selected().length == 0) {
|
||||||
|
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||||||
|
} else if (table.column(0).checkboxes.selected().length == 1) {
|
||||||
|
$("#btn_edit, #btn_habilitar").removeClass('disabled');
|
||||||
|
} else if (table.column(0).checkboxes.selected().length > 1) {
|
||||||
|
$("#btn_edit").addClass('disabled');
|
||||||
|
$("#btn_habilitar").removeClass('disabled');
|
||||||
|
}
|
||||||
|
}, 150);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** Editar, Deshabilitar, Crear ***********************/
|
||||||
|
/**********************************************************************/
|
||||||
|
|
||||||
|
function listadoDeCategorias() {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias_list.php',
|
||||||
|
type: 'POST'
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
if (_data.code == "1") {
|
||||||
|
categoriasList = _data.datos;
|
||||||
|
$("#catsuperior").html("");
|
||||||
|
$("#catsuperior").append('<option value="0">Raíz</option>');
|
||||||
|
var _padres = _.filter(_data.datos, function (n) {
|
||||||
|
return n.padre == 0;
|
||||||
|
});
|
||||||
|
$.each(_padres, function (index, val) {
|
||||||
|
$("#catsuperior").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
categoriasList = [];
|
||||||
|
$("#catsuperior").html('<option value="0">Raíz</option>');
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#catsuperior').selectpicker('render');
|
||||||
|
$("#catsuperior").selectpicker('refresh');
|
||||||
|
$(".layer-load").hide();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function editar(e, dt, node, config) {
|
||||||
|
var $table = table.table().node();
|
||||||
|
var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
|
||||||
|
$($chkbox_checked).closest('tr')
|
||||||
|
var data = table.row($($chkbox_checked).closest('tr')).data();
|
||||||
|
$("#idcat").val(data[0]);
|
||||||
|
|
||||||
|
var catId = parseInt(data[0], 10);
|
||||||
|
var padreId = null;
|
||||||
|
$.each(categoriasList, function (i, c) {
|
||||||
|
if (parseInt(c.id, 10) === catId) {
|
||||||
|
padreId = parseInt(c.padre, 10) || 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (padreId === null) {
|
||||||
|
var nombrePadre = $.trim(data[1]);
|
||||||
|
if (nombrePadre === 'Raiz' || nombrePadre === 'Raíz') {
|
||||||
|
padreId = 0;
|
||||||
|
} else {
|
||||||
|
$('#catsuperior option').each(function () {
|
||||||
|
if ($.trim($(this).text()) === nombrePadre) {
|
||||||
|
padreId = $(this).val();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (padreId !== null) {
|
||||||
|
$('#catsuperior').selectpicker('val', String(padreId));
|
||||||
|
$('#catsuperior').selectpicker('refresh');
|
||||||
|
}
|
||||||
|
$("#clave").val(data[2]);
|
||||||
|
//$("#nombre").val(data[3]);
|
||||||
|
//$("#desc").val(data[5]);
|
||||||
|
$("#nombre").val(data[3]);
|
||||||
|
$("#nombre").trumbowyg('html',data[3]);
|
||||||
|
$("#desc").val(data[5]);
|
||||||
|
$("#desc").trumbowyg('html',data[5]);
|
||||||
|
|
||||||
|
$("#habilitado").val(data[6]);
|
||||||
|
if (data[4] != null && data[4] !== "") {
|
||||||
|
var name = String(data[4]).split('/');
|
||||||
|
$(".preview").show();
|
||||||
|
$(".uploaded-files").show().html('<a class="btn-link" href="' + data[4] + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + data[4] + '"><br>' + name[name.length - 1] + '</a>');
|
||||||
|
$("#urlimgcat").val(data[4]);
|
||||||
|
} else {
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".uploaded-files").html("");
|
||||||
|
$("#urlimgcat").val("");
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#order").val(data[7]);
|
||||||
|
|
||||||
|
$(".newimg").removeClass('newimg');
|
||||||
|
$(".controller").hide();
|
||||||
|
$(".editor").show();
|
||||||
|
$(".edit").show();
|
||||||
|
$(".crear").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deshabilitar(e, dt, node, config) {
|
||||||
|
var rows_selected = table.column(0).checkboxes.selected();
|
||||||
|
|
||||||
|
var ids = new Array();
|
||||||
|
$.each(rows_selected, function (index, rowId) {
|
||||||
|
ids.push(rowId);
|
||||||
|
});
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias_delete.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { ids: ids },
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
Swal.fire({
|
||||||
|
html: response,
|
||||||
|
icon: "success",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
reloadData();
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function crear() {
|
||||||
|
listadoDeCategorias();
|
||||||
|
|
||||||
|
$("#idcat").val("");
|
||||||
|
$("#nombre").val("");
|
||||||
|
$("#desc").val("");
|
||||||
|
$('#nombre').trumbowyg('empty');
|
||||||
|
$('#desc').trumbowyg('empty');
|
||||||
|
$("#urlimgcat").val("");
|
||||||
|
$("#clave").val("");
|
||||||
|
$("#habilitado").val(1);
|
||||||
|
$("#catsuperior").val('0');
|
||||||
|
$('#catsuperior').selectpicker('val','0');
|
||||||
|
$(".newimg").removeClass('newimg');
|
||||||
|
$(".controller").hide();
|
||||||
|
$(".editor").show();
|
||||||
|
$(".edit").hide();
|
||||||
|
$(".crear").show();
|
||||||
|
}
|
||||||
|
$(".btn_cancelar").click(function (event) {
|
||||||
|
//TODO Mejorar si un usuario subio, pero al fin se arrepiente
|
||||||
|
$(".newimg").removeClass('newimg');
|
||||||
|
if ($(".uploaded-files").hasClass('newimg')) {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias_deletefile.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { file: $(".uploaded-files a").attr('href') },
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function (error) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
$(".uploaded-files").removeClass('newimg');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$(".formcontroller").validate({
|
||||||
|
submitHandler: function (form) {
|
||||||
|
|
||||||
|
var controller = 'categorias_upadate.php';
|
||||||
|
if ($(".crear").css("display") == "block") {
|
||||||
|
controller = 'categorias_add.php';
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: controller,
|
||||||
|
type: 'POST',
|
||||||
|
data: $(".formcontroller").serializeArray(),
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
//console.log("success");
|
||||||
|
Swal.fire({
|
||||||
|
html: response,
|
||||||
|
icon: 'success',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
reloadData();
|
||||||
|
$(".mainseccion").load("categorias.html", function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
nombre: {
|
||||||
|
required: true,
|
||||||
|
maxlength: 254,
|
||||||
|
minlength: 7
|
||||||
|
}
|
||||||
|
},
|
||||||
|
messages: {
|
||||||
|
nombre: {
|
||||||
|
required: "El nombre de categoría es obligatorio",
|
||||||
|
minlength: jQuery.validator.format("El nombre de categoría es de al menos {0} caracteres"),
|
||||||
|
maxlength: jQuery.validator.format("El nombre de categoría es de máximo {0} digitos"),
|
||||||
|
number: "Solo se aceptan números"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
getData();
|
||||||
|
|
||||||
|
$("#desc, #nombre").trumbowyg({
|
||||||
|
lang: 'es',
|
||||||
|
btns: [
|
||||||
|
['viewHTML'],
|
||||||
|
['formatting'],
|
||||||
|
['strong', 'em', 'del'],
|
||||||
|
['superscript', 'subscript'],
|
||||||
|
['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
|
||||||
|
['unorderedList', 'orderedList'],
|
||||||
|
['removeformat']
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$sql="SELECT
|
||||||
|
cat1.id as id,
|
||||||
|
CASE
|
||||||
|
WHEN cat1.padre = 0 THEN
|
||||||
|
'Raíz'
|
||||||
|
ELSE
|
||||||
|
(SELECT cat2.nombre FROM categoria as cat2 WHERE cat2.id = cat1.padre)
|
||||||
|
END AS 'Categoría superior',
|
||||||
|
cat1.clave as 'Clave',
|
||||||
|
cat1.nombre as Nombre,
|
||||||
|
cat1.imagen as 'Imagen',
|
||||||
|
cat1.descripcion as 'Descripción',
|
||||||
|
cat1.habilitado as Habilitado,
|
||||||
|
cat1.order_desc as 'Orden de módulo',
|
||||||
|
cat1.creado as 'Fecha de creación',
|
||||||
|
cat1.Actualizacion as 'Última modificación'
|
||||||
|
FROM
|
||||||
|
categoria as cat1
|
||||||
|
ORDER BY cat1.padre ASC";
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
$return = new stdClass();
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin categorías";
|
||||||
|
$return->columns = ["id","Categoría superior","Clave","Nombre","Imagen","Descripción","Habilitado","Orden de módulo","Fecha de creación","Última modificación"];
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="categorías";
|
||||||
|
$return->datos = [];
|
||||||
|
$return->columns = [];
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$return->columns = array_keys($row);
|
||||||
|
}
|
||||||
|
mysqli_data_seek($result, 0);
|
||||||
|
$wwwroot = rtrim($CFG->wwwroot, '/');
|
||||||
|
while ($row = mysqli_fetch_row ($result)){
|
||||||
|
if (isset($row[4])) {
|
||||||
|
$img = trim((string)$row[4]);
|
||||||
|
if ($img !== '' && !preg_match('~^(https?:)?//~i', $img)) {
|
||||||
|
$img = $wwwroot . '/' . ltrim($img, '/');
|
||||||
|
}
|
||||||
|
$row[4] = $img;
|
||||||
|
}
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once __DIR__.'/audit.php';
|
||||||
|
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$urlimgcat = isset($_POST['urlimgcat']) ? $_POST['urlimgcat'] : '';
|
||||||
|
$nombre = isset($_POST['nombre']) ? $_POST['nombre'] : '';
|
||||||
|
$desc = isset($_POST['desc']) ? $_POST['desc'] : '';
|
||||||
|
$habilitado = isset($_POST['habilitado']) ? (int)$_POST['habilitado'] : 0;
|
||||||
|
$order = isset($_POST['order']) ? (int)$_POST['order'] : 0;
|
||||||
|
$clave = isset($_POST['clave']) ? $_POST['clave'] : '';
|
||||||
|
$catsuperior = isset($_POST['catsuperior']) ? (int)$_POST['catsuperior'] : 0;
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
$sql = "INSERT INTO categoria (padre,imagen,nombre,descripcion,habilitado,order_desc,clave) VALUES (?,?,?,?,?,?,?)";
|
||||||
|
$stmt = mysqli_prepare($link, $sql);
|
||||||
|
if ($stmt) {
|
||||||
|
mysqli_stmt_bind_param($stmt, 'issssis', $catsuperior, $urlimgcat, $nombre, $desc, $habilitado, $order, $clave);
|
||||||
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
|
audit_log('categoria_create', 'nombre=' . $nombre . ' padre=' . $catsuperior);
|
||||||
|
echo "Categoría creada";
|
||||||
|
} else {
|
||||||
|
http_response_code(500);
|
||||||
|
echo "Error al crear categoría";
|
||||||
|
}
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
} else {
|
||||||
|
http_response_code(500);
|
||||||
|
echo "Error al preparar la consulta";
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once __DIR__.'/audit.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$ids = isset($_POST['ids']) ? (array)$_POST['ids'] : array();
|
||||||
|
$ids = array_values(array_filter(array_map('intval', $ids), function ($v) { return $v > 0; }));
|
||||||
|
if (!count($ids)) { echo "Sin identificadores"; exit; }
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$lista = implode(', ', $ids);
|
||||||
|
$sql = "UPDATE categoria SET habilitado = IF(habilitado=1, 0, 1) WHERE id IN ($lista)";
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
audit_log('categoria_toggle', 'ids=' . $lista);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
?>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once("../config.php");
|
||||||
|
//$filelink = "http://localhost/git/estafeta-lms360/site/data/imgcat/tablero051594833914.png";
|
||||||
|
$filelink = $_POST["file"];
|
||||||
|
$filepath = getCurrentOrParentDirectory(parse_url ($filelink,PHP_URL_PATH) );
|
||||||
|
unlink($filepath);
|
||||||
|
function getCurrentOrParentDirectory( $filename )
|
||||||
|
{
|
||||||
|
echo '<p>'.$filename.'</p>';
|
||||||
|
$patharray = explode('/',$filename);
|
||||||
|
$path = $patharray[sizeof($patharray)-3].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-2].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-1];
|
||||||
|
return ROOTPATH.$path;
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$sql = "SELECT
|
||||||
|
categoria.id,
|
||||||
|
categoria.padre,
|
||||||
|
categoria.nombre
|
||||||
|
FROM
|
||||||
|
categoria
|
||||||
|
WHERE categoria.nombre <> ''";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
$return = new stdClass();
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin categorías";
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="categorías";
|
||||||
|
$return->datos = [];
|
||||||
|
while ($row = mysqli_fetch_array ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once __DIR__.'/audit.php';
|
||||||
|
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$idcat = isset($_POST['idcat']) ? (int)$_POST['idcat'] : 0;
|
||||||
|
$urlimgcat = isset($_POST['urlimgcat']) ? $_POST['urlimgcat'] : '';
|
||||||
|
$nombre = isset($_POST['nombre']) ? $_POST['nombre'] : '';
|
||||||
|
$desc = isset($_POST['desc']) ? $_POST['desc'] : '';
|
||||||
|
$habilitado = isset($_POST['habilitado']) ? (int)$_POST['habilitado'] : 0;
|
||||||
|
$order = isset($_POST['order']) ? (int)$_POST['order'] : 0;
|
||||||
|
$clave = isset($_POST['clave']) ? $_POST['clave'] : '';
|
||||||
|
$catsuperior = isset($_POST['catsuperior']) ? (int)$_POST['catsuperior'] : 0;
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
$sql = "UPDATE categoria SET padre=?, imagen=?, nombre=?, clave=?, descripcion=?, habilitado=?, order_desc=? WHERE id=?";
|
||||||
|
$stmt = mysqli_prepare($link, $sql);
|
||||||
|
if ($stmt) {
|
||||||
|
mysqli_stmt_bind_param($stmt, 'issssiii', $catsuperior, $urlimgcat, $nombre, $clave, $desc, $habilitado, $order, $idcat);
|
||||||
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
|
audit_log('categoria_update', 'id=' . $idcat . ' nombre=' . $nombre . ' padre=' . $catsuperior);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
} else {
|
||||||
|
http_response_code(500);
|
||||||
|
echo "Error al actualizar categoría";
|
||||||
|
}
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
} else {
|
||||||
|
http_response_code(500);
|
||||||
|
echo "Error al preparar la consulta";
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
// upload.php
|
||||||
|
require_once "../config.php";
|
||||||
|
$return = new stdClass();
|
||||||
|
$files = $_FILES['files'];
|
||||||
|
$file_path = $files['tmp_name'][0]; // temporary upload path of the first file
|
||||||
|
$file_name = $_POST['name']; // desired name of the file
|
||||||
|
|
||||||
|
$file_basename = substr($file_name, 0, strripos($file_name, '.')); // This returns file name
|
||||||
|
$file_ext = substr($file_name, strripos($file_name, '.')); // This returns file ext
|
||||||
|
$file_name = $file_basename .round(microtime(true)) . $file_ext ;
|
||||||
|
|
||||||
|
$file_type = $files['type'][0]; //returns the mimetype
|
||||||
|
$allowed = array("image/jpeg", "image/gif", "image/png", "image/jpg");
|
||||||
|
if(!in_array($file_type, $allowed)) {
|
||||||
|
$return->txt = 'Solo se aceptan jpg, gif, y png.';
|
||||||
|
$return->error = '1';
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filex = '../data/imgcat/' . basename($file_name) ;
|
||||||
|
move_uploaded_file($file_path, $filex); //
|
||||||
|
$return->error = '0';
|
||||||
|
$return->url= $CFG->wwwroot.'data/imgcat/' . basename($file_name);
|
||||||
|
//$return->url= $file_path . basename($file_name);
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,881 @@
|
|||||||
|
<section class="py-md-4 py-2">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h1 class="text-secondary font-weight-bolder">Constancias</h1>
|
||||||
|
<p>Sistema de gestión constancias por categoria, se pueden agregar contancias, desactivar y modificar contancias.</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-12 col-md-12 col-12"><a href="../certificate.php" target="_blank" type="button" class="btn btn-default border border-default">Ver Constancia Activa</a></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 controller">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center align-self-center">
|
||||||
|
<div class="col-12">
|
||||||
|
<table id="datatable" class="display table table-striped table-bordered" cellspacing="0" width="100%">
|
||||||
|
<thead>
|
||||||
|
<tr></tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 editor" style="display: none;">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center justify-content-start">
|
||||||
|
<div class="col-12 text-left my-4">
|
||||||
|
<h3 class="title-cat edit" style="display: none;">Editar constancia</h3>
|
||||||
|
<h3 class="title-cat crear" style="display: none;">Crear constancia</h3>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-10">
|
||||||
|
<form class="formcontroller">
|
||||||
|
<input type="hidden" name="idconstancia" id="idconstancia" value="">
|
||||||
|
<input type="hidden" name="imgfirma" id="imgfirma" value="" required="required">
|
||||||
|
<input type="hidden" name="urlimglogo" id="urlimglogo" value="" required="required">
|
||||||
|
<input type="hidden" name="urlimgfondo" id="urlimgfondo" value="" required="required">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="catsuperior" class="col-lg-2 col-md-2 col-12 col-form-label">Categoría</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<select id="catsuperior" name="catsuperior" required="required" class="form-control col-12" data-live-search="true">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-lg-2 col-md-2 col-12 col-form-label" for="representante">Nombre del representante</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<input id="representante" name="representante" placeholder="Nombre del representante" type="text" class="form-control" required="required">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-lg-2 col-md-2 col-12 col-form-label" for="cargo">Cargo del representante</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<input id="cargo" name="cargo" placeholder="Cargo del representante" type="text" class="form-control" required="required">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="habilitado" class="col-lg-2 col-md-2 col-12 col-form-label">Habilitado constancia</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<select id="habilitado" name="habilitado" class="custom-select" required="required">
|
||||||
|
<option value="1">HABILITADO</option>
|
||||||
|
<option value="0">DESHABILITADO</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="offset-lg-2 col-lg-10 col-md-12 col-12">
|
||||||
|
<h6>Estilos de logo</h6>
|
||||||
|
</div>
|
||||||
|
<div class="offset-lg-2 col-lg-8 col-md-12 col-12">
|
||||||
|
<hr class="border border-primary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="habilitado_logo" class="col-lg-2 col-md-2 col-12 col-form-label">Habilitado logo</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<select id="habilitado_logo" name="habilitado_logo" class="custom-select" required="required">
|
||||||
|
<option value="1">HABILITADO</option>
|
||||||
|
<option value="0">DESHABILITADO</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="config_logo">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-lg-2 col-md-2 col-12 col-form-label">Logo</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<p class="text-dark font-weight-bold">Se recomienda usar png y un tamaño de 512px x 512px</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||||||
|
<div class="UppyDragDrop"></div>
|
||||||
|
<div class="w-100 my-3">
|
||||||
|
<div class="for-ProgressBar"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0 preview" style="display: none;">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="ThumbnailGenerator"></div>
|
||||||
|
<div class="uploaded-files text-secondary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="alineacion_logo" class="col-lg-2 col-md-2 col-12 col-form-label">Alineación del logo</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<select id="alineacion_logo" name="alineacion_logo" class="custom-select" required="required">
|
||||||
|
<option value="center">Centrado</option>
|
||||||
|
<option value="left">Izquierda</option>
|
||||||
|
<option value="right">Derecha</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="offset-lg-2 col-lg-8 col-md-10 col-12">
|
||||||
|
<h6>Estilos de fondo</h6>
|
||||||
|
</div>
|
||||||
|
<div class="offset-lg-2 col-lg-8 col-md-10 col-12">
|
||||||
|
<hr class="border border-primary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="habilitado_fondo" class="col-lg-2 col-md-2 col-12 col-form-label">Habilitado fondo</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<select id="habilitado_fondo" name="habilitado_fondo" class="custom-select" required="required">
|
||||||
|
<option value="1">HABILITADO</option>
|
||||||
|
<option value="0">DESHABILITADO</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="config_fondo">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-lg-2 col-md-2 col-12 col-form-label">Fondo</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12 col-md-12 col-12">
|
||||||
|
<p class="text-dark font-weight-bold">Se recomienda usar png y un tamaño de 1500px x 1060px</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||||||
|
<div class="UppyDragDropFondo"></div>
|
||||||
|
<div class="w-100 my-3">
|
||||||
|
<div class="for-ProgressBarFondo"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0 previewFondo" style="display: none;">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="ThumbnailGeneratorFondo"></div>
|
||||||
|
<div class="uploaded-filesFondo text-secondary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="offset-lg-2 col-lg-10 col-md-10 col-12">
|
||||||
|
<h6>Estilos del contenido</h6>
|
||||||
|
</div>
|
||||||
|
<div class="offset-lg-2 col-lg-8 col-md-10 col-12">
|
||||||
|
<hr class="border border-primary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="alineacion_content" class="col-lg-2 col-md-2 col-12 col-form-label">Alineación del contenido</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<select id="alineacion_content" name="alineacion_content" class="custom-select" required="required">
|
||||||
|
<option value="center">Centrado</option>
|
||||||
|
<option value="left">Izquierda</option>
|
||||||
|
<option value="right">Derecha</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-lg-2 col-md-2 col-12 col-form-label">Firma</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
|
||||||
|
<canvas id="signature" width="100%" class="col-lg-12 col-md-12 col-12 border border-primary mb-3"></canvas>
|
||||||
|
<img id="preview" class="img-fluid border border-primary mb-3" style="display: none;" />
|
||||||
|
<br>
|
||||||
|
<div style="text-align:center;">
|
||||||
|
<input type="button" id="export" class="btn btn-success btn-sm" value="Guardar firma"/>
|
||||||
|
<input type="button" id="reset" class="btn btn-danger btn-sm" value="Limpiar firma" style="display: none;" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group row justify-content-center">
|
||||||
|
<div class="col-12 col-md-6 text-right">
|
||||||
|
<div class="btn btn-warning btn_cancelar">Cancelar</div>
|
||||||
|
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Enviar</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(".layer-load").show();
|
||||||
|
var table;
|
||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
function parseJSON(resp) {
|
||||||
|
if (resp == null) return null;
|
||||||
|
if (typeof resp === 'object') return resp;
|
||||||
|
try { return JSON.parse(resp); }
|
||||||
|
catch (e) { console.error('Respuesta no-JSON del servidor:', String(resp).substring(0, 300)); return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/*********************** FIRMA ****************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
var canvas = document.getElementById("signature");
|
||||||
|
var w = window.innerWidth;
|
||||||
|
var h = window.innerHeight;
|
||||||
|
var body = $('body').width();
|
||||||
|
var m = $('.mainseccion').width();
|
||||||
|
console.log('tamaño de body: '+body);
|
||||||
|
// Como el lienzo no tiene ningún tamaño, lo especificaremos con JS
|
||||||
|
// El ancho del canvas será el ancho del dispositivo.
|
||||||
|
if (body <= 330) {
|
||||||
|
canvas.width = w-65;
|
||||||
|
canvas.height = h/1.5;
|
||||||
|
}else if(body >= 331 && body <= 660){
|
||||||
|
canvas.width = w-65;
|
||||||
|
canvas.height = h/2;
|
||||||
|
}else if (body >= 661 && body <= 850) {
|
||||||
|
canvas.width = m-65;
|
||||||
|
canvas.height = h/1.5;
|
||||||
|
}else{
|
||||||
|
canvas.width = body/2.5;
|
||||||
|
canvas.height = h/3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var signaturePad = new SignaturePad(canvas,{
|
||||||
|
dotSize: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("export").addEventListener("click",function(e){
|
||||||
|
// Siéntete libre de hacer lo que quieras con la imagen
|
||||||
|
// como exportar a un servidor o incluso guardarlo en el dispositivo.
|
||||||
|
var imageURI = signaturePad.toDataURL();
|
||||||
|
$('#imgfirma').val(imageURI);
|
||||||
|
$('#preview').show();
|
||||||
|
$('#export').hide();
|
||||||
|
$('#reset').show();
|
||||||
|
document.getElementById("preview").src = imageURI;
|
||||||
|
$('#signature').hide();
|
||||||
|
},false);
|
||||||
|
|
||||||
|
document.getElementById("reset").addEventListener("click",function(e){
|
||||||
|
// Limpia el lienzo
|
||||||
|
signaturePad.clear();
|
||||||
|
$('#signature').show();
|
||||||
|
$('#export').show();
|
||||||
|
//$('#reset').hide();
|
||||||
|
$('#preview').hide();
|
||||||
|
$('#imgfirma').val('');
|
||||||
|
},false);
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** UPLOAD LOGO ****************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
var uppy = Uppy.Core({
|
||||||
|
debug: false,
|
||||||
|
autoProceed: true,
|
||||||
|
allowMultipleUploads: true,
|
||||||
|
locale: Uppy.locales.Spanish,
|
||||||
|
restrictions: {
|
||||||
|
allowedFileTypes: ['image/*']
|
||||||
|
}
|
||||||
|
});
|
||||||
|
uppy.use(Uppy.DragDrop, {
|
||||||
|
target: '.UppyDragDrop',
|
||||||
|
locale: {
|
||||||
|
strings: {
|
||||||
|
browse: 'Buscar',
|
||||||
|
dropHereOr: "Arrastra el archivo aqu\xed o %{browse}",
|
||||||
|
dropHint: "Arrastra el archivo aqu\xed",
|
||||||
|
dropPaste: "Arrastra el archivo aqu\xed, pegar o %{browse}",
|
||||||
|
dropPasteImport: "Arrastra el archivo aqu\xed, pegar, %{browse} o importar desde",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).use(Uppy.XHRUpload, {
|
||||||
|
headers: { 'X-CSRF-Token': window.CSRF_TOKEN },
|
||||||
|
endpoint: "constancias_upload_logo.php",
|
||||||
|
formData: true,
|
||||||
|
method: 'post',
|
||||||
|
fieldName: 'files[]'
|
||||||
|
}).use(Uppy.ProgressBar, { target: '.for-ProgressBar', hideAfterFinish: false }).on('upload-success', function (file, response) { onUploadSuccess(file, response) });
|
||||||
|
|
||||||
|
function onUploadSuccess(file, response) {
|
||||||
|
if (response.uploadURL) {
|
||||||
|
var url = response.uploadURL;
|
||||||
|
$("#urlimglogo").val(url);
|
||||||
|
var fileName = file.name;
|
||||||
|
$(".preview").show();
|
||||||
|
$(".uploaded-files").show().addClass('newimg');
|
||||||
|
$(".uploaded-files").html("");
|
||||||
|
$(".uploaded-files").html('<a class="btn-link" href="' + response.uploadURL + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + response.uploadURL + '"><br>' + fileName + '</a>');
|
||||||
|
} else {
|
||||||
|
Swal.fire(
|
||||||
|
'',
|
||||||
|
response.body.txt,
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
uppy.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** UPLOAD FONDO ****************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
var uppyFondo = Uppy.Core({
|
||||||
|
debug: false,
|
||||||
|
autoProceed: true,
|
||||||
|
allowMultipleUploads: true,
|
||||||
|
locale: Uppy.locales.Spanish,
|
||||||
|
restrictions: {
|
||||||
|
allowedFileTypes: ['image/*']
|
||||||
|
}
|
||||||
|
});
|
||||||
|
uppyFondo.use(Uppy.DragDrop, {
|
||||||
|
target: '.UppyDragDropFondo',
|
||||||
|
locale: {
|
||||||
|
strings: {
|
||||||
|
browse: 'Buscar',
|
||||||
|
dropHereOr: "Arrastra el archivo aqu\xed o %{browse}",
|
||||||
|
dropHint: "Arrastra el archivo aqu\xed",
|
||||||
|
dropPaste: "Arrastra el archivo aqu\xed, pegar o %{browse}",
|
||||||
|
dropPasteImport: "Arrastra el archivo aqu\xed, pegar, %{browse} o importar desde",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).use(Uppy.XHRUpload, {
|
||||||
|
headers: { 'X-CSRF-Token': window.CSRF_TOKEN },
|
||||||
|
endpoint: "constancias_upload_fondo.php",
|
||||||
|
formData: true,
|
||||||
|
method: 'post',
|
||||||
|
fieldName: 'files[]'
|
||||||
|
}).use(Uppy.ProgressBar, { target: '.for-ProgressBarFondo', hideAfterFinish: false }).on('upload-success', function (file, response) { onUploadSuccessFondo(file, response) });
|
||||||
|
|
||||||
|
function onUploadSuccessFondo(file, response) {
|
||||||
|
if (response.uploadURL) {
|
||||||
|
var url = response.uploadURL;
|
||||||
|
$("#urlimgfondo").val(url);
|
||||||
|
var fileName = file.name;
|
||||||
|
$(".previewFondo").show();
|
||||||
|
$(".uploaded-filesFondo").show().addClass('newimgFondo');
|
||||||
|
$(".uploaded-filesFondo").html("");
|
||||||
|
$(".uploaded-filesFondo").html('<a class="btn-link" href="' + response.uploadURL + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + response.uploadURL + '"><br>' + fileName + '</a>');
|
||||||
|
} else {
|
||||||
|
Swal.fire(
|
||||||
|
'',
|
||||||
|
response.body.txt,
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
uppyFondo.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** DATATABLE *****************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
function getData() {
|
||||||
|
listadoDeCategorias();
|
||||||
|
$("#datatable").html('<thead><tr></tr></thead>');
|
||||||
|
$.ajax({
|
||||||
|
url: 'constancias.php'
|
||||||
|
}).done(function (data) {
|
||||||
|
var _data = JSON.parse(data);
|
||||||
|
var tableName = "#datatable";
|
||||||
|
var str;
|
||||||
|
$.each(_data.columns, function (k, colObj) {
|
||||||
|
str = '<th>' + colObj + '</th>';
|
||||||
|
$(str).appendTo(tableName + '>thead>tr');
|
||||||
|
});
|
||||||
|
|
||||||
|
table = $('#datatable').DataTable({
|
||||||
|
dom: "Bfrtip",
|
||||||
|
responsive: true,
|
||||||
|
"drawCallback": function (settings) {
|
||||||
|
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||||||
|
addEventsCheck();
|
||||||
|
},
|
||||||
|
buttons: [{
|
||||||
|
extend: 'excel',
|
||||||
|
text: 'Exportar a Excel'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Editar',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
editar(e, dt, node, config);
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_edit'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Alternar habilitar',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
deshabilitar(e, dt, node, config)
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_habilitar'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Crear',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
crear();
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_crear'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
'columnDefs': [{
|
||||||
|
'targets': 0,
|
||||||
|
'checkboxes': { 'selectRow': true }
|
||||||
|
}],
|
||||||
|
|
||||||
|
'order': [
|
||||||
|
[1, 'asc']
|
||||||
|
],
|
||||||
|
data: _data.datos,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
table.columns.adjust().draw();
|
||||||
|
$(window).resize(function (event) {
|
||||||
|
/* Act on the event */
|
||||||
|
table.columns.adjust().draw();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reloadData() {
|
||||||
|
listadoDeCategorias();
|
||||||
|
$.ajax({
|
||||||
|
url: 'constancias.php'
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
var NewlyCreatedData = JSON.parse(data);
|
||||||
|
table.clear();
|
||||||
|
table.rows.add(NewlyCreatedData.datos); // Add new data
|
||||||
|
table.columns.adjust().draw(); // Redraw the DataTable
|
||||||
|
table.column(0).checkboxes.deselectAll();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addEventsCheck() {
|
||||||
|
$("#datatable_wrapper input[type='checkbox']").on('change', function (e) {
|
||||||
|
setTimeout(function (){
|
||||||
|
console.log($("#datatable_wrapper input[type='checkbox']:checked").length);
|
||||||
|
if (table.column(0).checkboxes.selected().length == 0) {
|
||||||
|
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||||||
|
} else if (table.column(0).checkboxes.selected().length == 1) {
|
||||||
|
$("#btn_edit, #btn_habilitar").removeClass('disabled');
|
||||||
|
} else if (table.column(0).checkboxes.selected().length > 1) {
|
||||||
|
$("#btn_edit").addClass('disabled');
|
||||||
|
$("#btn_habilitar").removeClass('disabled');
|
||||||
|
}
|
||||||
|
}, 150);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** Editar, Deshabilitar, Crear ***********************/
|
||||||
|
/**********************************************************************/
|
||||||
|
|
||||||
|
function listadoDeCategorias() {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias_list.php',
|
||||||
|
type: 'POST'
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
if (_data.code == "1") {
|
||||||
|
$("#catsuperior").html("");
|
||||||
|
var _padres = _.filter(_data.datos, function (n) {
|
||||||
|
return n.padre == 0;
|
||||||
|
});
|
||||||
|
var _datos = _.groupBy(_data.datos, function (n) {
|
||||||
|
return n.padre;
|
||||||
|
});
|
||||||
|
|
||||||
|
$.each(_padres, function (index, val1) {
|
||||||
|
$("#catsuperior").append('<option disabled style="background-color: #959595; color: white;">' + val1.nombre + '</option>');
|
||||||
|
$.each(_datos, function (index, cats) {
|
||||||
|
$.each(cats, function (index, val) {
|
||||||
|
if (val.padre == val1.id || val.nombre == val1.nombre) {
|
||||||
|
if (val.nombre == val1.nombre) {
|
||||||
|
//$("[label='" + val1.nombre + "']").append('<option class="font-weight-bold" value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
} else {
|
||||||
|
$("#catsuperior").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
html: "Sin categorias",
|
||||||
|
icon: "error",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$(".btn_cancelar").click();
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$(".layer-load").hide();
|
||||||
|
//$('#catsuperior').selectpicker();
|
||||||
|
//if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
|
||||||
|
//$('#catsuperior').selectpicker('mobile');
|
||||||
|
//}
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function editar(e, dt, node, config) {
|
||||||
|
var $table = table.table().node();
|
||||||
|
var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
|
||||||
|
$($chkbox_checked).closest('tr')
|
||||||
|
var data = table.row($($chkbox_checked).closest('tr')).data();
|
||||||
|
$("#idconstancia").val(data[0]);
|
||||||
|
$("#catsuperior").find('option').each(function (index, el) {
|
||||||
|
if ($(this).text() == data[2]) {
|
||||||
|
$("#catsuperior").val($(this).attr('value'));
|
||||||
|
//$('#catsuperior').selectpicker('render');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$("#representante").val(data[3]);
|
||||||
|
$("#cargo").val(data[4]);
|
||||||
|
$("#habilitado").find('option').each(function (index, el) {
|
||||||
|
if ($(this).text() == data[5]) {
|
||||||
|
$("#habilitado").val($(this).attr('value'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#habilitado_logo").find('option').each(function (index, el) {
|
||||||
|
if ($(this).text() == data[6]) {
|
||||||
|
$("#habilitado_logo").val($(this).attr('value'));
|
||||||
|
if ($("#habilitado_logo").val() == '1') {
|
||||||
|
$('.config_logo').show();
|
||||||
|
}else{
|
||||||
|
$('.config_logo').hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#alineacion_logo').val(data[10]);
|
||||||
|
$('#alineacion_content').val(data[12]);
|
||||||
|
|
||||||
|
$("#habilitado_fondo").find('option').each(function (index, el) {
|
||||||
|
if ($(this).text() == data[7]) {
|
||||||
|
$("#habilitado_fondo").val($(this).attr('value'));
|
||||||
|
if ($("#habilitado_fondo").val() == '1') {
|
||||||
|
$('.config_fondo').show();
|
||||||
|
}else{
|
||||||
|
$('.config_fondo').hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data[8] != null) {
|
||||||
|
var name = String(data[8]).split('/');
|
||||||
|
$("#preview").show();
|
||||||
|
$("#signature").hide();
|
||||||
|
$("#export").hide();
|
||||||
|
$("#preview").attr('src',data[8]);
|
||||||
|
$("#imgfirma").val(data[8]);
|
||||||
|
}
|
||||||
|
$('#reset').show();
|
||||||
|
|
||||||
|
if (data[9] != null) {
|
||||||
|
var name = String(data[9]).split('/');
|
||||||
|
$(".previewFondo").show();
|
||||||
|
$(".uploaded-filesFondo").html('<a class="btn-link" href="' + data[9] + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + data[9] + '"><br>' + name[name.length - 1] + '</a>');
|
||||||
|
$("#urlimgfondo").val(data[9]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data[10] != null) {
|
||||||
|
var name = String(data[11]).split('/');
|
||||||
|
$(".preview").show();
|
||||||
|
$(".uploaded-files").html('<a class="btn-link" href="' + data[11] + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + data[11] + '"><br>' + name[name.length - 1] + '</a>');
|
||||||
|
$("#urlimglogo").val(data[11]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$(".newimg").removeClass('newimg');
|
||||||
|
$(".newimg").removeClass('newimgFondo');
|
||||||
|
$(".controller").hide();
|
||||||
|
$(".editor").show();
|
||||||
|
$(".edit").show();
|
||||||
|
$(".crear").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deshabilitar(e, dt, node, config) {
|
||||||
|
var rows_selected = table.column(0).checkboxes.selected();
|
||||||
|
|
||||||
|
var ids = new Array();
|
||||||
|
$.each(rows_selected, function (index, rowId) {
|
||||||
|
ids.push(rowId);
|
||||||
|
});
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'constancias_delete.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { ids: ids },
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
Swal.fire({
|
||||||
|
html: response,
|
||||||
|
icon: "success",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
reloadData();
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function crear() {
|
||||||
|
|
||||||
|
$("#idconstancia").val("");
|
||||||
|
$("#imgfirma").val("");
|
||||||
|
$("#urlimglogo").val("");
|
||||||
|
$("#urlimgfondo").val("");
|
||||||
|
$('#catsuperior').prop('selectedIndex',1);
|
||||||
|
$("#representante").val("");
|
||||||
|
$("#cargo").val("");
|
||||||
|
$("#reset").show();
|
||||||
|
|
||||||
|
$("#habilitado").val(1);
|
||||||
|
$(".newimg").removeClass('newimg');
|
||||||
|
$(".newimgFondo").removeClass('newimgFondo');
|
||||||
|
$(".controller").hide();
|
||||||
|
$(".editor").show();
|
||||||
|
$(".edit").hide();
|
||||||
|
$(".crear").show();
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#habilitado_logo").change(function(){
|
||||||
|
if ($(this).val() == '1') {
|
||||||
|
$('.config_logo').show();
|
||||||
|
}else{
|
||||||
|
$('.config_logo').hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#habilitado_fondo").change(function(){
|
||||||
|
if ($(this).val() == '1') {
|
||||||
|
$('.config_fondo').show();
|
||||||
|
}else{
|
||||||
|
$('.config_fondo').hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#alineacion_logo').prop('selectedIndex',0);
|
||||||
|
$('#alineacion_content').prop('selectedIndex',0);
|
||||||
|
|
||||||
|
|
||||||
|
$(".btn_cancelar").click(function (event) {
|
||||||
|
//$(".newimg").removeClass('newimg');
|
||||||
|
//$(".newimgFondo").removeClass('newimgFondo');
|
||||||
|
if ($(".uploaded-files").hasClass('newimg') || $(".uploaded-filesFondo").hasClass('newimgFondo')) {
|
||||||
|
$(".layer-load").show();
|
||||||
|
|
||||||
|
if ($(".uploaded-files").hasClass('newimg')){
|
||||||
|
$.ajax({
|
||||||
|
url: 'constancias_deletefile_logo.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { file: $(".uploaded-files a").attr('href') },
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function (error) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
signaturePad.clear();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
$(".uploaded-files").removeClass('newimg');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if ($(".uploaded-filesFondo").hasClass('newimgFondo')) {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'constancias_deletefile_fondo.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { file: $(".uploaded-filesFondo a").attr('href') },
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function (error) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
$(".previewFondo").hide();
|
||||||
|
$(".ThumbnailGeneratorFondo, .uploaded-filesFondo").html("");
|
||||||
|
uppyFondo.reset();
|
||||||
|
signaturePad.clear();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
$(".uploaded-filesFondo").removeClass('newimgFondo');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".previewFondo").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
$(".ThumbnailGeneratorFondo, .uploaded-filesFondo").html("");
|
||||||
|
uppy.reset();
|
||||||
|
uppyFondo.reset();
|
||||||
|
|
||||||
|
signaturePad.clear();
|
||||||
|
|
||||||
|
$('#preview').hide();
|
||||||
|
$('#signature').show();
|
||||||
|
$('#export').show();
|
||||||
|
$('#reset').hide();
|
||||||
|
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".previewFondo").hide();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$.validator.addMethod('validUrl', function(value, element) {
|
||||||
|
var url = $.validator.methods.url.bind(this);
|
||||||
|
var pattern = new RegExp("^(?:https?://|s?ftps?://)?(?!www | www\.)[A-Za-z0-9_-]+\.+[A-Za-z0-9.\/%&=\?_:;-]+$");
|
||||||
|
return pattern.test("http://localhost/git/estafeta-lms360/site/pkg/scorm_check/index.html");
|
||||||
|
}, 'Por favorsss, escribe una URL válida.');
|
||||||
|
|
||||||
|
$(".formcontroller").validate({
|
||||||
|
submitHandler: function (form) {
|
||||||
|
|
||||||
|
var controller = 'constancias_update.php';
|
||||||
|
if ($(".crear").css("display") == "block") {
|
||||||
|
controller = 'constancias_add.php';
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: controller,
|
||||||
|
type: 'POST',
|
||||||
|
data: $(".formcontroller").serializeArray(),
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
//console.log("success");
|
||||||
|
Swal.fire({
|
||||||
|
html: response,
|
||||||
|
icon:'success',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".previewFondo").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
$(".ThumbnailGenerator, .uploaded-filesFondo").html("");
|
||||||
|
uppy.reset();
|
||||||
|
uppyFondo.reset();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".previewFondo").hide();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
reloadData();
|
||||||
|
$(".mainseccion").load("constancias.html", function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
representante: {
|
||||||
|
required: true,
|
||||||
|
maxlength: 254,
|
||||||
|
minlength: 2,
|
||||||
|
normalizer: function( value ) {
|
||||||
|
return $.trim( value );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cargo: {
|
||||||
|
required: true,
|
||||||
|
maxlength: 254,
|
||||||
|
minlength: 2,
|
||||||
|
normalizer: function( value ) {
|
||||||
|
return $.trim( value );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
imgfirma:{
|
||||||
|
required:true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
getData();
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$sql="SELECT
|
||||||
|
c.idconstancia,
|
||||||
|
c.idcategoria as 'No. categoría',
|
||||||
|
cat.nombre as 'Nombre categoría',
|
||||||
|
c.representante as 'Representante',
|
||||||
|
c.cargo_rep as 'Cargo representante',
|
||||||
|
IF(c.habilitado = 1, 'HABILITADO','DESHABILITADO') as 'Habilitado constancia',
|
||||||
|
IF(c.habilitado_logo = 1, 'HABILITADO','DESHABILITADO') as 'Habilitado logo',
|
||||||
|
IF(c.habilitado_fondo = 1, 'HABILITADO','DESHABILITADO') as 'Habilitado fondo',
|
||||||
|
c.firma as 'Firma',
|
||||||
|
c.fondo as 'Fondo',
|
||||||
|
c.align_logo as 'Alineación logo',
|
||||||
|
c.logo as 'Logo',
|
||||||
|
c.align_content as 'Alineación contenido',
|
||||||
|
c.creacion as 'Creación',
|
||||||
|
c.actualizacion as 'Actualización'
|
||||||
|
FROM
|
||||||
|
constancias as c
|
||||||
|
INNER JOIN categoria as cat ON cat.id = c.idcategoria";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
$return = new stdClass();
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin constancias";
|
||||||
|
$return->columns = ["idconstancia","No. categoría","Nombre categoría","Representante","Cargo representante","Firma","Fondo","Alineación fondo","Logo","Alineación logo","Habilitado","Habilitado logo","Habilitado fondo","Creación","Actualización"];
|
||||||
|
$return->datos = [];
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="Constancias";
|
||||||
|
$return->datos = [];
|
||||||
|
$return->columns = [];
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$return->columns = array_keys($row);
|
||||||
|
}
|
||||||
|
mysqli_data_seek($result, 0);
|
||||||
|
while ($row = mysqli_fetch_row ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$catsuperior = $_POST['catsuperior'];
|
||||||
|
$nombre = $_POST['representante'];
|
||||||
|
$cargo = $_POST['cargo'];
|
||||||
|
$firma = $_POST['imgfirma'];
|
||||||
|
|
||||||
|
$a_logo = $_POST['alineacion_logo'];
|
||||||
|
$a_cont = $_POST['alineacion_content'];
|
||||||
|
|
||||||
|
if( $_POST['urlimglogo'] == "" ){
|
||||||
|
$urlimglogo = NULL;
|
||||||
|
}else{
|
||||||
|
$urlimglogo =$_POST['urlimglogo'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $_POST['urlimgfondo'] == "" ){
|
||||||
|
$urlimgfondo = NULL;
|
||||||
|
}else{
|
||||||
|
$urlimgfondo =$_POST['urlimgfondo'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$habilitado= $_POST['habilitado'];
|
||||||
|
$habilitado_logo= $_POST['habilitado_logo'];
|
||||||
|
$habilitado_fondo= $_POST['habilitado_fondo'];
|
||||||
|
|
||||||
|
$sql = "INSERT INTO constancias(idcategoria, firma, representante, cargo_rep, fondo, align_logo, logo, align_content, habilitado, habilitado_logo,habilitado_fondo) VALUES ($catsuperior,'$firma','$nombre','$cargo','$urlimgfondo','$a_logo','$urlimglogo','$a_cont',$habilitado,$habilitado_logo,$habilitado_fondo)";
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
echo "Constancia creado";
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$ids = $_POST['ids'];
|
||||||
|
$sql = "UPDATE constancias SET habilitado = IF(habilitado=1, 0, 1) WHERE idconstancia IN (".implode(', ', $ids).")";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
?>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once("../config.php");
|
||||||
|
//$filelink = "http://localhost/git/estafeta-lms360/site/data/imgcat/tablero051594833914.png";
|
||||||
|
$filelink = $_POST["file"];
|
||||||
|
$filepath = getCurrentOrParentDirectory(parse_url ($filelink,PHP_URL_PATH) );
|
||||||
|
unlink($filepath);
|
||||||
|
function getCurrentOrParentDirectory( $filename )
|
||||||
|
{
|
||||||
|
echo '<p>'.$filename.'</p>';
|
||||||
|
$patharray = explode('/',$filename);
|
||||||
|
$path = $patharray[sizeof($patharray)-3].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-2].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-1];
|
||||||
|
return ROOTPATH.$path;
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once("../config.php");
|
||||||
|
//$filelink = "http://localhost/git/estafeta-lms360/site/data/imgcat/tablero051594833914.png";
|
||||||
|
$filelink = $_POST["file"];
|
||||||
|
$filepath = getCurrentOrParentDirectory(parse_url ($filelink,PHP_URL_PATH) );
|
||||||
|
unlink($filepath);
|
||||||
|
function getCurrentOrParentDirectory( $filename )
|
||||||
|
{
|
||||||
|
echo '<p>'.$filename.'</p>';
|
||||||
|
$patharray = explode('/',$filename);
|
||||||
|
$path = $patharray[sizeof($patharray)-3].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-2].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-1];
|
||||||
|
return ROOTPATH.$path;
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$idconstancia = $_POST['idconstancia'];
|
||||||
|
$catsuperior = $_POST['catsuperior'];
|
||||||
|
$nombre = $_POST['representante'];
|
||||||
|
$cargo = $_POST['cargo'];
|
||||||
|
$firma = $_POST['imgfirma'];
|
||||||
|
|
||||||
|
$a_logo = $_POST['alineacion_logo'];
|
||||||
|
$a_cont = $_POST['alineacion_content'];
|
||||||
|
|
||||||
|
if( $_POST['urlimglogo'] == "" ){
|
||||||
|
$urlimglogo = NULL;
|
||||||
|
}else{
|
||||||
|
$urlimglogo =$_POST['urlimglogo'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $_POST['urlimgfondo'] == "" ){
|
||||||
|
$urlimgfondo = NULL;
|
||||||
|
}else{
|
||||||
|
$urlimgfondo =$_POST['urlimgfondo'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$habilitado= $_POST['habilitado'];
|
||||||
|
$habilitado_logo= $_POST['habilitado_logo'];
|
||||||
|
$habilitado_fondo= $_POST['habilitado_fondo'];
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "UPDATE constancias SET idcategoria=$catsuperior,firma='$firma',representante='$nombre',cargo_rep='$cargo',fondo='$urlimgfondo',logo='$urlimglogo',habilitado=$habilitado, habilitado_logo = $habilitado_logo, habilitado_fondo= $habilitado_fondo, align_logo= '$a_logo', align_content= '$a_cont' WHERE idconstancia = $idconstancia";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
// upload.php
|
||||||
|
require_once "../config.php";
|
||||||
|
$return = new stdClass();
|
||||||
|
$files = $_FILES['files'];
|
||||||
|
$file_path = $files['tmp_name'][0]; // temporary upload path of the first file
|
||||||
|
$file_name = $_POST['name']; // desired name of the file
|
||||||
|
|
||||||
|
$file_basename = substr($file_name, 0, strripos($file_name, '.')); // This returns file name
|
||||||
|
$file_ext = substr($file_name, strripos($file_name, '.')); // This returns file ext
|
||||||
|
$file_name = $file_basename .round(microtime(true)) . $file_ext ;
|
||||||
|
|
||||||
|
$file_type = $files['type'][0]; //returns the mimetype
|
||||||
|
$allowed = array("image/jpeg", "image/gif", "image/png", "image/jpg");
|
||||||
|
if(!in_array($file_type, $allowed)) {
|
||||||
|
$return->txt = 'Solo se aceptan jpg, gif, y png.';
|
||||||
|
$return->error = '1';
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filex = '../data/constancias/' . basename($file_name) ;
|
||||||
|
move_uploaded_file($file_path, $filex); //
|
||||||
|
$return->error = '0';
|
||||||
|
$return->url= $CFG->wwwroot.'data/constancias/' . basename($file_name);
|
||||||
|
//$return->url= $file_path . basename($file_name);
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
// upload.php
|
||||||
|
require_once "../config.php";
|
||||||
|
$return = new stdClass();
|
||||||
|
$files = $_FILES['files'];
|
||||||
|
$file_path = $files['tmp_name'][0]; // temporary upload path of the first file
|
||||||
|
$file_name = $_POST['name']; // desired name of the file
|
||||||
|
|
||||||
|
$file_basename = substr($file_name, 0, strripos($file_name, '.')); // This returns file name
|
||||||
|
$file_ext = substr($file_name, strripos($file_name, '.')); // This returns file ext
|
||||||
|
$file_name = $file_basename .round(microtime(true)) . $file_ext ;
|
||||||
|
|
||||||
|
$file_type = $files['type'][0]; //returns the mimetype
|
||||||
|
$allowed = array("image/jpeg", "image/gif", "image/png", "image/jpg");
|
||||||
|
if(!in_array($file_type, $allowed)) {
|
||||||
|
$return->txt = 'Solo se aceptan jpg, gif, y png.';
|
||||||
|
$return->error = '1';
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filex = '../data/constancias/' . basename($file_name) ;
|
||||||
|
move_uploaded_file($file_path, $filex); //
|
||||||
|
$return->error = '0';
|
||||||
|
$return->url= $CFG->wwwroot.'data/constancias/' . basename($file_name);
|
||||||
|
//$return->url= $file_path . basename($file_name);
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,992 @@
|
|||||||
|
<section class="py-md-4 py-2">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h1 class="text-secondary font-weight-bolder">Encuestas</h1>
|
||||||
|
<p>Sistema de gestión de encuestas, se pueden agregar encuesta, desactivar encuesta y modificar encuesta.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 controller">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center align-self-center">
|
||||||
|
<div class="col-12">
|
||||||
|
<table id="datatable" class="display table table-striped table-bordered" cellspacing="0" width="100%">
|
||||||
|
<thead>
|
||||||
|
<tr></tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 editor" style="display: none;">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center justify-content-start">
|
||||||
|
<div class="col-12 text-left my-4">
|
||||||
|
<h3 class="title-cat edit" style="display: none;">Editar encuesta</h3>
|
||||||
|
<h3 class="title-cat crear" style="display: none;">Crear encuesta</h3>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-10">
|
||||||
|
<form class="formcontroller">
|
||||||
|
<input type="hidden" name="idencuesta" id="idencuesta" value="">
|
||||||
|
<input type="hidden" name="urlimgencuesta" id="urlimgencuesta" value="">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="catsuperior" class="col-lg-2 col-lg-2 col-md-2 col-12 col-form-label">Categoría</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<select id="catsuperior" name="catsuperior" required="required" class="form-control col-12" data-live-search="true">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-lg-2 col-md-2 col-12 col-form-label" for="titulo">Titulo</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<input id="titulo" name="titulo" placeholder="Titulo" type="text" class="form-control" required="required">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="desc" class="col-lg-2 col-md-2 col-12 col-form-label">Descripción</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<textarea id="desc" name="desc" cols="40" rows="5" class="form-control"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-lg-2 col-md-2 col-12 col-form-label" for="orden">Orden</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<input id="orden" name="orden" placeholder="Orden" type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="estilo" class="col-lg-2 col-md-2 col-12 col-form-label">Estilo</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<select id="estilo" name="estilo" class="custom-select" required="required">
|
||||||
|
<option value="libre">Libre</option>
|
||||||
|
<option value="bloqueado">Bloqueado</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="habilitado" class="col-lg-2 col-md-2 col-12 col-form-label">Habilitado</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<select id="habilitado" name="habilitado" class="custom-select" required="required">
|
||||||
|
<option value="1">HABILITADO</option>
|
||||||
|
<option value="0">DESHABILITADO</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-lg-2 col-md-2 col-12 col-form-label">Imagen</label>
|
||||||
|
<div class="col-lg-8 col-md-10 col-12">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12 col-md-12 col-12">
|
||||||
|
<p class="text-dark font-weight-bold">Se recomienda usar png y un tamaño de 512 x 512 px</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||||||
|
<div class="UppyDragDrop"></div>
|
||||||
|
<div class="w-100 my-3">
|
||||||
|
<div class="for-ProgressBar"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0 preview" style="display: none;">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="ThumbnailGenerator"></div>
|
||||||
|
<div class="uploaded-files text-secondary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row justify-content-center">
|
||||||
|
<div class="col-12 col-md-6 text-right">
|
||||||
|
<div class="btn btn-warning btn_cancelar">Cancelar</div>
|
||||||
|
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Enviar</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 editor-options" style="display: none;">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center justify-content-start">
|
||||||
|
<div class="col-12 text-left my-4">
|
||||||
|
<h3 class="title-cat edit-options" style="display: none;">Editar preguntas</h3>
|
||||||
|
<h3 class="title-cat crear-options" style="display: none;">Crear preguntas</h3>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-10">
|
||||||
|
<form class="formcontroller-options">
|
||||||
|
<input type="hidden" name="idencuesta-options" id="idencuesta-options" value="">
|
||||||
|
<input type="hidden" name="idoptions" id="idoptions" value="">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="desc" class="col-md-2 col-12 col-form-label">Pregunta</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<textarea id="pregunta" name="pregunta" cols="40" rows="5" class="form-control" placeholder="Pregunta" required="required"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="desc" class="col-md-2 col-12 col-form-label">Descripción de la pregunta</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<textarea id="desc_pregunta" name="desc_pregunta" cols="40" rows="5" class="form-control" placeholder="Descripción de la pregunta"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="answers" class="col-md-2 col-12 col-form-label">Respuestas (una por linea)</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<textarea id="answers" name="answers" cols="40" rows="5" class="form-control" placeholder="Coloca una opción por cada linea" required="required"></textarea>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="py-2 check_answers text-danger" style="display: none;"><input type="checkbox" id="editanswers" name="editanswers" value="desactivado"><b> Habilitar edición de respuestas</b></div>
|
||||||
|
<input type="hidden" name="status-answers" id="status-answers" value="desactivado">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-2 col-12 col-form-label" for="orden-option">Orden de la pregunta</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<input id="orden-options" name="orden-options" placeholder="Orden de la pregunta" type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="habilitado-option" class="col-md-2 col-12 col-form-label">Habilitado</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="habilitado-options" name="habilitado-options" class="custom-select" required="required">
|
||||||
|
<option value="1">HABILITADO</option>
|
||||||
|
<option value="0">DESHABILITADO</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group row justify-content-center">
|
||||||
|
<div class="col-12 col-md-6 text-right">
|
||||||
|
<div class="btn btn-warning btn_cancelar_options">Cancelar</div>
|
||||||
|
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Agregar</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 controller-options" style="display: none;">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center align-self-center">
|
||||||
|
<div class="col-12">
|
||||||
|
<table id="datatable-options" class="display table table-striped table-bordered" cellspacing="0" width="100%">
|
||||||
|
<thead>
|
||||||
|
<tr></tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="col-10 col-md-10 text-right">
|
||||||
|
<div class="btn btn-warning btn_cancelar">Cancelar</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(".layer-load").show();
|
||||||
|
var table;
|
||||||
|
var tableOptions;
|
||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
function parseJSON(resp) {
|
||||||
|
if (resp == null) return null;
|
||||||
|
if (typeof resp === 'object') return resp;
|
||||||
|
try { return JSON.parse(resp); }
|
||||||
|
catch (e) { console.error('Respuesta no-JSON del servidor:', String(resp).substring(0, 300)); return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** UPLOAD ********************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
var uppy = Uppy.Core({
|
||||||
|
debug: false,
|
||||||
|
autoProceed: true,
|
||||||
|
allowMultipleUploads: true,
|
||||||
|
locale: Uppy.locales.Spanish,
|
||||||
|
restrictions: {
|
||||||
|
allowedFileTypes: ['image/*']
|
||||||
|
}
|
||||||
|
});
|
||||||
|
uppy.use(Uppy.DragDrop, {
|
||||||
|
target: '.UppyDragDrop',
|
||||||
|
locale: {
|
||||||
|
strings: {
|
||||||
|
browse: 'Buscar',
|
||||||
|
dropHereOr: "Arrastra el archivo aqu\xed o %{browse}",
|
||||||
|
dropHint: "Arrastra el archivo aqu\xed",
|
||||||
|
dropPaste: "Arrastra el archivo aqu\xed, pegar o %{browse}",
|
||||||
|
dropPasteImport: "Arrastra el archivo aqu\xed, pegar, %{browse} o importar desde",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).use(Uppy.XHRUpload, {
|
||||||
|
headers: { 'X-CSRF-Token': window.CSRF_TOKEN },
|
||||||
|
endpoint: "encuestas_upload.php",
|
||||||
|
formData: true,
|
||||||
|
method: 'post',
|
||||||
|
fieldName: 'files[]'
|
||||||
|
}).use(Uppy.ProgressBar, { target: '.for-ProgressBar', hideAfterFinish: false }).on('upload-success', function (file, response) { onUploadSuccess(file, response) });
|
||||||
|
|
||||||
|
function onUploadSuccess(file, response) {
|
||||||
|
if (response.uploadURL) {
|
||||||
|
var url = response.uploadURL;
|
||||||
|
$("#urlimgencuesta").val(url);
|
||||||
|
var fileName = file.name;
|
||||||
|
$(".preview").show();
|
||||||
|
$(".uploaded-files").show().addClass('newimg');
|
||||||
|
$(".uploaded-files").html("");
|
||||||
|
$(".uploaded-files").html('<a class="btn-link" href="' + response.uploadURL + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + response.uploadURL + '"><br>' + fileName + '</a>');
|
||||||
|
} else {
|
||||||
|
Swal.fire(
|
||||||
|
'',
|
||||||
|
response.body.txt,
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
uppy.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** DATATABLE *****************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
function getData() {
|
||||||
|
listadoDeCategorias();
|
||||||
|
$("#datatable").html('<thead><tr></tr></thead>');
|
||||||
|
$.ajax({
|
||||||
|
url: 'encuestas.php'
|
||||||
|
}).done(function (data) {
|
||||||
|
var _data = JSON.parse(data);
|
||||||
|
var tableName = "#datatable";
|
||||||
|
var str;
|
||||||
|
$.each(_data.columns, function (k, colObj) {
|
||||||
|
str = '<th>' + colObj + '</th>';
|
||||||
|
$(str).appendTo(tableName + '>thead>tr');
|
||||||
|
});
|
||||||
|
|
||||||
|
table = $('#datatable').DataTable({
|
||||||
|
dom: "Bfrtip",
|
||||||
|
responsive: true,
|
||||||
|
"drawCallback": function (settings) {
|
||||||
|
$("#btn_edit, #btn_habilitar, #btn_edit_options").addClass('disabled');
|
||||||
|
addEventsCheck();
|
||||||
|
},
|
||||||
|
buttons: [{
|
||||||
|
extend: 'excel',
|
||||||
|
text: 'Exportar a Excel'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Editar',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
editar(e, dt, node, config);
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_edit'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Editar opciones',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
editar_options(e, dt, node, config);
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
class:'btn btn-info',
|
||||||
|
id: 'btn_edit_options'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Alternar habilitar',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
deshabilitar(e, dt, node, config)
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_habilitar'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Crear',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
crear();
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_crear'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
'columnDefs': [{
|
||||||
|
'targets': 0,
|
||||||
|
'checkboxes': { 'selectRow': true }
|
||||||
|
}],
|
||||||
|
|
||||||
|
'order': [
|
||||||
|
[1, 'asc']
|
||||||
|
],
|
||||||
|
data: _data.datos,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
table.columns.adjust().draw();
|
||||||
|
$(window).resize(function (event) {
|
||||||
|
/* Act on the event */
|
||||||
|
table.columns.adjust().draw();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reloadData() {
|
||||||
|
listadoDeCategorias();
|
||||||
|
$.ajax({
|
||||||
|
url: 'encuestas.php'
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
var NewlyCreatedData = JSON.parse(data);
|
||||||
|
table.clear();
|
||||||
|
table.rows.add(NewlyCreatedData.datos); // Add new data
|
||||||
|
table.columns.adjust().draw(); // Redraw the DataTable
|
||||||
|
table.column(0).checkboxes.deselectAll();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function addEventsCheck() {
|
||||||
|
$("#datatable_wrapper input[type='checkbox']").on('change', function (e) {
|
||||||
|
setTimeout(function (){
|
||||||
|
console.log($("#datatable_wrapper input[type='checkbox']:checked").length);
|
||||||
|
if (table.column(0).checkboxes.selected().length == 0) {
|
||||||
|
$("#btn_edit, #btn_habilitar, #btn_edit_options").addClass('disabled');
|
||||||
|
} else if (table.column(0).checkboxes.selected().length == 1) {
|
||||||
|
$("#btn_edit, #btn_habilitar, #btn_edit_options").removeClass('disabled');
|
||||||
|
} else if (table.column(0).checkboxes.selected().length > 1) {
|
||||||
|
$("#btn_edit, #btn_edit_options").addClass('disabled');
|
||||||
|
$("#btn_habilitar").removeClass('disabled');
|
||||||
|
}
|
||||||
|
}, 150);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** Editar, Deshabilitar, Crear ***********************/
|
||||||
|
/**********************************************************************/
|
||||||
|
|
||||||
|
function listadoDeCategorias() {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias_list.php',
|
||||||
|
type: 'POST'
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
if (_data.code == "1") {
|
||||||
|
$("#catsuperior").html("");
|
||||||
|
var _padres = _.filter(_data.datos, function (n) {
|
||||||
|
return n.padre == 0;
|
||||||
|
});
|
||||||
|
var _datos = _.groupBy(_data.datos, function (n) {
|
||||||
|
return n.padre;
|
||||||
|
});
|
||||||
|
|
||||||
|
$.each(_padres, function (index, val1) {
|
||||||
|
$("#catsuperior").append('<option disabled style="background-color: #959595; color: white;">' + val1.nombre + '</option>');
|
||||||
|
$.each(_datos, function (index, cats) {
|
||||||
|
$.each(cats, function (index, val) {
|
||||||
|
if (val.padre == val1.id || val.nombre == val1.nombre) {
|
||||||
|
if (val.nombre == val1.nombre) {
|
||||||
|
//$("[label='" + val1.nombre + "']").append('<option class="font-weight-bold" value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
} else {
|
||||||
|
$("#catsuperior").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
html: "Sin categorias",
|
||||||
|
icon: "error",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$(".btn_cancelar").click();
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$(".layer-load").hide();
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function editar(e, dt, node, config) {
|
||||||
|
var $table = table.table().node();
|
||||||
|
var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
|
||||||
|
$($chkbox_checked).closest('tr')
|
||||||
|
var data = table.row($($chkbox_checked).closest('tr')).data();
|
||||||
|
|
||||||
|
$("#idencuesta").val(data[0]);
|
||||||
|
$("#catsuperior").val(data[1]);
|
||||||
|
$("#titulo").val(data[3]);
|
||||||
|
$("#desc").val(data[4]);
|
||||||
|
$("#desc").trumbowyg('html',data[4]);
|
||||||
|
$("#orden").val(data[5]);
|
||||||
|
|
||||||
|
|
||||||
|
if (data[6] != null) {
|
||||||
|
var name = String(data[6]).split('/');
|
||||||
|
$(".preview").show();
|
||||||
|
$(".uploaded-files").html('<a class="btn-link" href="' + data[6] + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + data[6] + '"><br>' + name[name.length - 1] + '</a>');
|
||||||
|
$("#urlimgencuesta").val(data[6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#estilo").val(data[7]);
|
||||||
|
|
||||||
|
$("#habilitado").find('option').each(function (index, el) {
|
||||||
|
if ($(this).text() == data[8]) {
|
||||||
|
$("#habilitado").val($(this).attr('value'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$(".newimg").removeClass('newimg');
|
||||||
|
$(".controller").hide();
|
||||||
|
$(".editor").show();
|
||||||
|
$(".edit").show();
|
||||||
|
$(".crear").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
function editar_options(e, dt, node, config) {
|
||||||
|
$('.edit-options').show();
|
||||||
|
var $table = table.table().node();
|
||||||
|
var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
|
||||||
|
$($chkbox_checked).closest('tr')
|
||||||
|
var data = table.row($($chkbox_checked).closest('tr')).data();
|
||||||
|
|
||||||
|
loadOptions(data[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deshabilitar(e, dt, node, config) {
|
||||||
|
var rows_selected = table.column(0).checkboxes.selected();
|
||||||
|
|
||||||
|
var ids = new Array();
|
||||||
|
$.each(rows_selected, function (index, rowId) {
|
||||||
|
ids.push(rowId);
|
||||||
|
});
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'encuestas_delete.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { ids: ids },
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
Swal.fire({
|
||||||
|
html: response,
|
||||||
|
icon: "success",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
reloadData();
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function crear() {
|
||||||
|
$("#idencuesta").val("");
|
||||||
|
$("#nombre").val("");
|
||||||
|
$("#desc").val("");
|
||||||
|
$("#urlimgencuesta").val("");
|
||||||
|
$("#habilitado").val(1);
|
||||||
|
$(".newimg").removeClass('newimg');
|
||||||
|
$(".controller").hide();
|
||||||
|
$(".editor").show();
|
||||||
|
$(".edit").hide();
|
||||||
|
$(".crear").show();
|
||||||
|
}
|
||||||
|
$(".btn_cancelar").click(function (event) {
|
||||||
|
//$(".newimg").removeClass('newimg');
|
||||||
|
if ($(".uploaded-files").hasClass('newimg')) {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'encuestas_deletefile.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { file: $(".uploaded-files a").attr('href') },
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function (error) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
$(".editor-options").hide();
|
||||||
|
$(".uploaded-files").removeClass('newimg');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
$(".editor-options").hide();
|
||||||
|
$(".controller-options").hide();
|
||||||
|
}
|
||||||
|
reloadData();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$.validator.addMethod('validUrl', function(value, element) {
|
||||||
|
var url = $.validator.methods.url.bind(this);
|
||||||
|
var pattern = new RegExp("^(?:https?://|s?ftps?://)?(?!www | www\.)[A-Za-z0-9_-]+\.+[A-Za-z0-9.\/%&=\?_:;-]+$");
|
||||||
|
return pattern.test("http://localhost/git/estafeta-lms360/site/pkg/scorm_check/index.html");
|
||||||
|
}, 'Por favorsss, escribe una URL válida.');
|
||||||
|
|
||||||
|
$(".formcontroller").validate({
|
||||||
|
submitHandler: function (form) {
|
||||||
|
$('.layer-load').show();
|
||||||
|
|
||||||
|
var controller = 'encuestas_update.php';
|
||||||
|
if ($(".crear").css("display") == "block") {
|
||||||
|
controller = 'encuestas_add.php';
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: controller,
|
||||||
|
type: 'POST',
|
||||||
|
data: $(".formcontroller").serializeArray(),
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
if (_data.code == '200') {
|
||||||
|
loadOptions(_data.data['id']);
|
||||||
|
}else{
|
||||||
|
Swal.fire({
|
||||||
|
html: _data.msg,
|
||||||
|
icon: 'error',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
titulo: {
|
||||||
|
required: true,
|
||||||
|
maxlength: 254,
|
||||||
|
minlength: 2,
|
||||||
|
normalizer: function( value ) {
|
||||||
|
return $.trim( value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/**************** DATATABLE OPTIONS ***********************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
function getDataOptions(encuesta) {
|
||||||
|
listadoDeCategorias();
|
||||||
|
$("#datatable-options").html('<thead><tr></tr></thead>');
|
||||||
|
$.ajax({
|
||||||
|
url: 'encuestas_options.php',
|
||||||
|
type:'POST',
|
||||||
|
data:{idencuesta:encuesta}
|
||||||
|
}).done(function (data) {
|
||||||
|
var _data = JSON.parse(data);
|
||||||
|
|
||||||
|
var tableNameOptions = "#datatable-options";
|
||||||
|
var strOptions;
|
||||||
|
$.each(_data.columns, function (k, colObj) {
|
||||||
|
strOptions = '<th>' + colObj + '</th>';
|
||||||
|
$(strOptions).appendTo(tableNameOptions + '>thead>tr');
|
||||||
|
});
|
||||||
|
|
||||||
|
tableOptions = $('#datatable-options').DataTable({
|
||||||
|
dom: "Bfrtip",
|
||||||
|
responsive: false,
|
||||||
|
"drawCallback": function (settings) {
|
||||||
|
$("#btn_edit_options_select, #btn_habilitar_options").addClass('disabled');
|
||||||
|
addEventsCheckOptions();
|
||||||
|
},
|
||||||
|
buttons: [{
|
||||||
|
extend: 'excel',
|
||||||
|
text: 'Exportar a Excel'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Editar pregunta',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
editar_options_select(e, dt, node, config);
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_edit_options_select'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Alternar habilitar',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
deshabilitar(e, dt, node, config)
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_habilitar_options'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Agregar pregunta',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
crear_options();
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_crear_options'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
'columnDefs': [{
|
||||||
|
'targets': 0,
|
||||||
|
'checkboxes': { 'selectRow': true }
|
||||||
|
}],
|
||||||
|
|
||||||
|
'order': [
|
||||||
|
[4, 'asc']
|
||||||
|
],
|
||||||
|
data: _data.datos,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
tableOptions.columns.adjust().draw();
|
||||||
|
$(window).resize(function (event) {
|
||||||
|
/* Act on the event */
|
||||||
|
tableOptions.columns.adjust().draw();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function reloadDataOptions(encuesta) {
|
||||||
|
$.ajax({
|
||||||
|
url: 'encuestas_options.php',
|
||||||
|
type:'POST',
|
||||||
|
data:{idencuesta:encuesta}
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
$('.editor-options').hide(300);
|
||||||
|
$('.controller-options').show(300);
|
||||||
|
var NewlyCreatedData = JSON.parse(data);
|
||||||
|
tableOptions.clear();
|
||||||
|
tableOptions.rows.add(NewlyCreatedData.datos); // Add new data
|
||||||
|
tableOptions.columns.adjust().draw(); // Redraw the DataTable
|
||||||
|
tableOptions.column(0).checkboxes.deselectAll();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function addEventsCheckOptions() {
|
||||||
|
$("#datatable-options input[type='checkbox']").on('change', function (e) {
|
||||||
|
setTimeout(function (){
|
||||||
|
console.log($("#datatable-options input[type='checkbox']:checked").length);
|
||||||
|
if (tableOptions.column(0).checkboxes.selected().length == 0) {
|
||||||
|
$("#btn_edit_options_select, #btn_habilitar_options, #btn_edit_options").addClass('disabled');
|
||||||
|
} else if (tableOptions.column(0).checkboxes.selected().length == 1) {
|
||||||
|
$("#btn_edit_options_select, #btn_habilitar_options, #btn_edit_options").removeClass('disabled');
|
||||||
|
} else if (tableOptions.column(0).checkboxes.selected().length > 1) {
|
||||||
|
$("#btn_edit_options_select").addClass('disabled');
|
||||||
|
$("#btn_habilitar_options").removeClass('disabled');
|
||||||
|
}
|
||||||
|
}, 150);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loadOptions(encuesta){
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: $(".navbar").offset().top
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
if ($('#datatable-options').hasClass('Initialize')) {
|
||||||
|
reloadDataOptions(encuesta);
|
||||||
|
}else{
|
||||||
|
getDataOptions(encuesta);
|
||||||
|
$('#datatable-options').addClass('Initialize');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$('#idencuesta-options').val(encuesta);
|
||||||
|
$('.controller').hide(300);
|
||||||
|
$('.editor').hide(300);
|
||||||
|
$('.controller-options').show(300);
|
||||||
|
$('.layer-load').hide();
|
||||||
|
}
|
||||||
|
/**********************************************************************/
|
||||||
|
/************* Editar, Deshabilitar, Crear Opciones *******************/
|
||||||
|
/**********************************************************************/
|
||||||
|
function crear_options() {
|
||||||
|
$('.check_answers').hide();
|
||||||
|
$('#answers').attr('disabled',false);
|
||||||
|
$("#idpregunta").val("");
|
||||||
|
$('#pregunta').val();
|
||||||
|
$('#pregunta').trumbowyg('empty');
|
||||||
|
$("#answers").val("");
|
||||||
|
$("#habilitado").val(1);
|
||||||
|
|
||||||
|
|
||||||
|
$(".controller-options").hide();
|
||||||
|
$(".editor-options").show();
|
||||||
|
$(".edit-options").hide();
|
||||||
|
$(".crear-options").show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function editar_options_select(e, dt, node, config) {
|
||||||
|
var $tableOptions = tableOptions.table().node();
|
||||||
|
var $chkbox_checkedOptions = $('tbody input[type="checkbox"]:checked', $tableOptions);
|
||||||
|
$($chkbox_checkedOptions).closest('tr')
|
||||||
|
var dataOptions = tableOptions.row($($chkbox_checkedOptions).closest('tr')).data();
|
||||||
|
|
||||||
|
$("#idoptions").val(dataOptions[0]);
|
||||||
|
$("#pregunta").val(dataOptions[1]);
|
||||||
|
$("#pregunta").trumbowyg('html',dataOptions[1]);
|
||||||
|
$("#desc_pregunta").val(dataOptions[2]);
|
||||||
|
$("#desc_pregunta").trumbowyg('html',dataOptions[2]);
|
||||||
|
|
||||||
|
var str = dataOptions[3];
|
||||||
|
var opciones = str.split(",");
|
||||||
|
|
||||||
|
console.log(opciones);
|
||||||
|
$('#answers').html('');
|
||||||
|
$.each(opciones, function (k, colObj) {
|
||||||
|
$('#answers').append(colObj+' ');
|
||||||
|
});
|
||||||
|
$('#answers').attr('disabled',true);
|
||||||
|
$('#status-answers').val('desactivado');
|
||||||
|
$("#editanswers").prop('checked',false);
|
||||||
|
$('.check_answers').show();
|
||||||
|
|
||||||
|
$("#orden-options").val(dataOptions[4]);
|
||||||
|
$("#habilitado").find('option').each(function (index, el) {
|
||||||
|
if ($(this).text() == dataOptions[5]) {
|
||||||
|
$("#habilitado").val($(this).attr('value'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".newimg").removeClass('newimg');
|
||||||
|
$(".controller-options").hide();
|
||||||
|
$(".editor-options").show();
|
||||||
|
$(".edit-options").show();
|
||||||
|
$(".crear-options").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#editanswers").on('change', function() {
|
||||||
|
if( $(this).is(':checked') ) {
|
||||||
|
const swalWithBootstrapButtons = Swal.mixin({
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-success',
|
||||||
|
cancelButton: 'btn btn-danger'
|
||||||
|
},
|
||||||
|
buttonsStyling: false
|
||||||
|
})
|
||||||
|
|
||||||
|
swalWithBootstrapButtons.fire({
|
||||||
|
title: 'Edición de respuestas?',
|
||||||
|
text: "Estas seguro de editar las respuestas al hacerlo se reiniciar el voteo de la pregunta",
|
||||||
|
icon: 'warning',
|
||||||
|
allowOutsideClick: false,
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: 'Si, continuar',
|
||||||
|
cancelButtonText: 'No, cancelar',
|
||||||
|
reverseButtons: true
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
$('#answers').attr('disabled',false);
|
||||||
|
$('#status-answers').val('activado');
|
||||||
|
swalWithBootstrapButtons.fire(
|
||||||
|
'Activado',
|
||||||
|
'Se ha activado la edición de respuestas',
|
||||||
|
'success'
|
||||||
|
)
|
||||||
|
} else if (
|
||||||
|
/* Read more about handling dismissals below */
|
||||||
|
result.dismiss === Swal.DismissReason.cancel
|
||||||
|
) {
|
||||||
|
$("#editanswers").prop('checked',false);
|
||||||
|
swalWithBootstrapButtons.fire(
|
||||||
|
'Cancelado',
|
||||||
|
'No se ha activado la edición de respuestas',
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
html: 'Se ha deshabilitado la edición de las respuestas',
|
||||||
|
icon: 'success',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$('#answers').attr('disabled',true);
|
||||||
|
$('#status-answers').val('desactivado');
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$(".btn_cancelar_options").click(function (event) {
|
||||||
|
$('.editor-options').hide(300);
|
||||||
|
$('.controller-options').show(300);
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".formcontroller-options").validate({
|
||||||
|
submitHandler: function (form) {
|
||||||
|
$('.layer-load').show();
|
||||||
|
|
||||||
|
var controller = 'encuestas_preguntas_update.php';
|
||||||
|
if ($(".crear-options").css("display") == "block") {
|
||||||
|
controller = 'encuestas_preguntas_add.php';
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: controller,
|
||||||
|
type: 'POST',
|
||||||
|
data: $(".formcontroller-options").serializeArray(),
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
Swal.fire({
|
||||||
|
html: _data.msg,
|
||||||
|
icon: _data.icon,
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {
|
||||||
|
$('.layer-load').hide();
|
||||||
|
},
|
||||||
|
onClose: function () {
|
||||||
|
reloadDataOptions($('#idencuesta-options').val());
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
pregunta: {
|
||||||
|
required: true,
|
||||||
|
maxlength: 254,
|
||||||
|
minlength: 2,
|
||||||
|
normalizer: function( value ) {
|
||||||
|
return $.trim( value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/*************************** Configuraciones **************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
|
||||||
|
$("#desc, #desc_pregunta, #pregunta").trumbowyg({
|
||||||
|
lang: 'es',
|
||||||
|
btns: [
|
||||||
|
['viewHTML'],
|
||||||
|
['formatting'],
|
||||||
|
['strong', 'em', 'del'],
|
||||||
|
['superscript', 'subscript'],
|
||||||
|
['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
|
||||||
|
['unorderedList', 'orderedList'],
|
||||||
|
['removeformat']
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
getData();
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$sql="SELECT
|
||||||
|
encuestas.idencuesta,
|
||||||
|
encuestas.idcategoria 'No. de categoría',
|
||||||
|
categoria.nombre as 'Nombre categoría',
|
||||||
|
encuestas.titulo as 'Titulo',
|
||||||
|
encuestas.descripcion as 'Descripción',
|
||||||
|
encuestas.order_desc as 'Orden',
|
||||||
|
encuestas.imagen as 'Imagen',
|
||||||
|
encuestas.estilo as 'Estilo',
|
||||||
|
IF(encuestas.habilitado = 1, 'HABILITADO','DESHABILITADO') as Habilitado,
|
||||||
|
encuestas.creacion as 'Creación',
|
||||||
|
encuestas.actualizacion as 'Actualización'
|
||||||
|
FROM
|
||||||
|
encuestas
|
||||||
|
INNER JOIN categoria ON categoria.id = encuestas.idcategoria";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
$return = new stdClass();
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin encuestas";
|
||||||
|
$return->columns = ["idencuesta","No. de categoría","Nombre categoría","Titulo","Descripción","Orden","Imagen","Estilo","Habilitado","Creación","Actualización"];
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="Encuestas";
|
||||||
|
$return->datos = [];
|
||||||
|
$return->columns = [];
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$return->columns = array_keys($row);
|
||||||
|
}
|
||||||
|
mysqli_data_seek($result, 0);
|
||||||
|
while ($row = mysqli_fetch_row ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$catsuperior = $_POST['catsuperior'];
|
||||||
|
$titulo= $_POST['titulo'];
|
||||||
|
$desc= $_POST['desc'];
|
||||||
|
$orden= $_POST['orden'];
|
||||||
|
$estilo= $_POST['estilo'];
|
||||||
|
$habilitado= $_POST['habilitado'];
|
||||||
|
if( $_POST['urlimgencuesta'] == "" ){
|
||||||
|
$urlimgencuesta = $CFG->wwwroot.'img/icons/211-gift.png';
|
||||||
|
}else{
|
||||||
|
$urlimgencuesta =$_POST['urlimgencuesta'];
|
||||||
|
}
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
$sql = "INSERT INTO encuestas (idcategoria, titulo, descripcion, order_desc, estilo, habilitado, imagen) VALUES ($catsuperior,'$titulo', '$desc', $orden, '$estilo', $habilitado,'$urlimgencuesta');";
|
||||||
|
$sql .= " SELECT LAST_INSERT_ID() as id;";
|
||||||
|
|
||||||
|
if($result = mysqli_multi_query($link, $sql)){
|
||||||
|
$return->code = "200";
|
||||||
|
do {
|
||||||
|
/* almacenar resultado de la primera consulta */
|
||||||
|
if ($result = mysqli_store_result($link)) {
|
||||||
|
while ($row = mysqli_fetch_assoc($result)) {
|
||||||
|
$return->data = $row;
|
||||||
|
|
||||||
|
}
|
||||||
|
mysqli_free_result($result);
|
||||||
|
}
|
||||||
|
/* mostrar divisor */
|
||||||
|
if (mysqli_more_results($link)) {
|
||||||
|
//printf("-----------------\n");
|
||||||
|
}
|
||||||
|
} while (mysqli_next_result($link));
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$ids = $_POST['ids'];
|
||||||
|
$sql = "UPDATE encuestas SET habilitado = IF(habilitado=1, 0, 1) WHERE idencuesta IN (".implode(', ', $ids).")";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
?>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once("../config.php");
|
||||||
|
//$filelink = "http://localhost/git/estafeta-lms360/site/data/imgcat/tablero051594833914.png";
|
||||||
|
$filelink = $_POST["file"];
|
||||||
|
$filepath = getCurrentOrParentDirectory(parse_url ($filelink,PHP_URL_PATH) );
|
||||||
|
unlink($filepath);
|
||||||
|
function getCurrentOrParentDirectory( $filename )
|
||||||
|
{
|
||||||
|
echo '<p>'.$filename.'</p>';
|
||||||
|
$patharray = explode('/',$filename);
|
||||||
|
$path = $patharray[sizeof($patharray)-3].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-2].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-1];
|
||||||
|
return ROOTPATH.$path;
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
$return->datos = [];
|
||||||
|
$idencuesta = $_POST['idencuesta'];
|
||||||
|
|
||||||
|
$sql="SELECT
|
||||||
|
encuestas_preguntas.idpregunta,
|
||||||
|
encuestas_preguntas.titulo as 'Pregunta',
|
||||||
|
encuestas_preguntas.descripcion_p as 'Descripción',
|
||||||
|
GROUP_CONCAT(encuestas_respuestas.titulo ORDER BY encuestas_respuestas.idrespuesta) as 'Respuestas',
|
||||||
|
encuestas_preguntas.orden_p as 'Orden de preguntas',
|
||||||
|
IF(encuestas_preguntas.habilitado = 1, 'Habilitado','Deshabilitado') as 'Habilitado',
|
||||||
|
encuestas_preguntas.creacion as 'Creación',
|
||||||
|
encuestas_preguntas.actualizacion as 'Actualización'
|
||||||
|
FROM
|
||||||
|
encuestas_preguntas
|
||||||
|
INNER JOIN encuestas_respuestas ON encuestas_respuestas.idpregunta = encuestas_preguntas.idpregunta
|
||||||
|
WHERE
|
||||||
|
encuestas_preguntas.idencuesta = $idencuesta
|
||||||
|
GROUP BY encuestas_respuestas.idpregunta
|
||||||
|
ORDER BY encuestas_preguntas.orden_p ASC";
|
||||||
|
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin opciones";
|
||||||
|
$return->columns = ["idpregunta","Pregunta","Descripción","Respuestas","Orden de preguntas","Habilitado","Creación","Actualización"];
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="Opciones encuesta #".$idencuesta;
|
||||||
|
$return->datos = [];
|
||||||
|
$return->columns = [];
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$return->columns = array_keys($row);
|
||||||
|
}
|
||||||
|
mysqli_data_seek($result, 0);
|
||||||
|
while ($row = mysqli_fetch_row ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sizeof($return->datos) == 1 && $return->datos[0][0] == null ) {
|
||||||
|
$return->columns = ["idpregunta","Pregunta","Descripción","Respuestas","Orden de preguntas","Habilitado","Creación","Actualización"];
|
||||||
|
$return->datos = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$idencuesta = $_POST['idencuesta-options'];
|
||||||
|
$titulo = $_POST['pregunta'];
|
||||||
|
$desc = $_POST['desc_pregunta'];
|
||||||
|
$orden = $_POST['orden-options'];
|
||||||
|
$habilitado = $_POST['habilitado-options'];
|
||||||
|
$idpregunta;
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
$sql = "INSERT INTO encuestas_preguntas (idencuesta,titulo,descripcion_p,orden_p,habilitado) VALUES ($idencuesta,'$titulo','$desc', $orden,$habilitado)";
|
||||||
|
|
||||||
|
if($result = mysqli_query($link, $sql)){
|
||||||
|
$idpregunta = mysqli_insert_id($link);
|
||||||
|
|
||||||
|
if(!is_null($idpregunta)){
|
||||||
|
|
||||||
|
$answers = isset($_POST['answers']) ? explode(PHP_EOL, $_POST['answers']) : '';
|
||||||
|
$totalOpciones = sizeof($answers);
|
||||||
|
$totalInsert = 0;
|
||||||
|
$alerts = [];
|
||||||
|
foreach ($answers as $answer) {
|
||||||
|
if (empty($answer)) continue;
|
||||||
|
|
||||||
|
$sqlAnswer = "INSERT INTO encuestas_respuestas (idpregunta, titulo) VALUES ($idpregunta,'$answer')";
|
||||||
|
if($result = mysqli_query($link, $sqlAnswer)){
|
||||||
|
$totalInsert++;
|
||||||
|
array_push($alerts, "Registro exitoso<br>");
|
||||||
|
}else{
|
||||||
|
array_push($alerts, "Consulta fallo! SQL: ".$sqlAnswer."<br><br> Error: ".mysqli_error($link));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($totalOpciones == $totalInsert) {
|
||||||
|
$return->code = "200";
|
||||||
|
$return->icon = "success";
|
||||||
|
$return->msg = "Registrado exitosamente!";
|
||||||
|
}else{
|
||||||
|
$return->code = "300";
|
||||||
|
$return->icon = "warning";
|
||||||
|
$return->msg = $alerts;
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "error";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "error";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$ids = $_POST['ids'];
|
||||||
|
$sql = "UPDATE encuestas_preguntas SET habilitado = IF(habilitado=1, 0, 1) WHERE idpregunta IN (".implode(', ', $ids).")";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
?>
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
$idpregunta = $_POST['idoptions'];
|
||||||
|
$pregunta = $_POST['pregunta'];
|
||||||
|
$titulo = $_POST['pregunta'];
|
||||||
|
$desc = $_POST['desc_pregunta'];
|
||||||
|
$orden = $_POST['orden-options'];
|
||||||
|
$status = $_POST['status-answers'];
|
||||||
|
$habilitado = $_POST['habilitado-options'];
|
||||||
|
$idpregunta;
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
$sql = "UPDATE encuestas_preguntas SET titulo='$pregunta',descripcion_p='$desc',orden_p = $orden, habilitado = $habilitado WHERE idpregunta = $idpregunta";
|
||||||
|
|
||||||
|
if($result = mysqli_query($link, $sql)){
|
||||||
|
|
||||||
|
if ($status == 'activado') {
|
||||||
|
$sqlDelete = "DELETE FROM encuestas_respuestas WHERE idpregunta = $idpregunta";
|
||||||
|
|
||||||
|
if($result = mysqli_query($link, $sqlDelete)){
|
||||||
|
$answers = isset($_POST['answers']) ? explode(PHP_EOL, $_POST['answers']) : '';
|
||||||
|
$totalOpciones = sizeof($answers);
|
||||||
|
$totalInsert = 0;
|
||||||
|
$alerts = [];
|
||||||
|
foreach ($answers as $answer) {
|
||||||
|
if (empty($answer)) continue;
|
||||||
|
|
||||||
|
$sqlAnswer = "INSERT INTO encuestas_respuestas (idpregunta, titulo) VALUES ($idpregunta,'$answer')";
|
||||||
|
if($result = mysqli_query($link, $sqlAnswer)){
|
||||||
|
$totalInsert++;
|
||||||
|
array_push($alerts, "Registro exitoso<br>");
|
||||||
|
}else{
|
||||||
|
array_push($alerts, "Consulta fallo! SQL: ".$sqlAnswer."<br><br> Error: ".mysqli_error($link));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($totalOpciones == $totalInsert) {
|
||||||
|
$return->code = "200";
|
||||||
|
$return->icon = "success";
|
||||||
|
$return->msg = "Registrado exitosamente!";
|
||||||
|
}else{
|
||||||
|
$return->code = "300";
|
||||||
|
$return->icon = "warning";
|
||||||
|
$return->msg = $alerts;
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "error";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sqlDelete."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$return->code = "200";
|
||||||
|
$return->icon = "success";
|
||||||
|
$return->msg = "Registrado exitosamente!";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "error";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$idencuesta = $_POST['idencuesta'];
|
||||||
|
$catsuperior = $_POST['catsuperior'];
|
||||||
|
$titulo = $_POST['titulo'];
|
||||||
|
$desc = $_POST['desc'];
|
||||||
|
$orden = $_POST['orden'];
|
||||||
|
$estilo= $_POST['estilo'];
|
||||||
|
$habilitado = $_POST['habilitado'];
|
||||||
|
if( $_POST['urlimgencuesta'] == "" ){
|
||||||
|
$urlimgencuesta = $CFG->wwwroot.'img/icons/211-gift.png';
|
||||||
|
}else{
|
||||||
|
$urlimgencuesta =$_POST['urlimgencuesta'];
|
||||||
|
}
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "UPDATE encuestas SET titulo='$titulo',descripcion='$desc',idcategoria='$catsuperior',order_desc= $orden, estilo = '$estilo',imagen='$urlimgencuesta',habilitado= '$habilitado' WHERE idencuesta = $idencuesta";
|
||||||
|
|
||||||
|
|
||||||
|
if($result = mysqli_multi_query($link, $sql)){
|
||||||
|
$return->code = "200";
|
||||||
|
$return->data = array('id' => $idencuesta);
|
||||||
|
$return->msg = "Exito!";
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
// upload.php
|
||||||
|
require_once "../config.php";
|
||||||
|
$return = new stdClass();
|
||||||
|
$files = $_FILES['files'];
|
||||||
|
$file_path = $files['tmp_name'][0]; // temporary upload path of the first file
|
||||||
|
$file_name = $_POST['name']; // desired name of the file
|
||||||
|
|
||||||
|
$file_basename = substr($file_name, 0, strripos($file_name, '.')); // This returns file name
|
||||||
|
$file_ext = substr($file_name, strripos($file_name, '.')); // This returns file ext
|
||||||
|
$file_name = $file_basename .round(microtime(true)) . $file_ext ;
|
||||||
|
|
||||||
|
$file_type = $files['type'][0]; //returns the mimetype
|
||||||
|
$allowed = array("image/jpeg", "image/gif", "image/png", "image/jpg");
|
||||||
|
if(!in_array($file_type, $allowed)) {
|
||||||
|
$return->txt = 'Solo se aceptan jpg, gif, y png.';
|
||||||
|
$return->error = '1';
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filex = '../data/evaluaciones/' . basename($file_name) ;
|
||||||
|
move_uploaded_file($file_path, $filex); //
|
||||||
|
$return->error = '0';
|
||||||
|
$return->url= $CFG->wwwroot.'data/evaluaciones/' . basename($file_name);
|
||||||
|
//$return->url= $file_path . basename($file_name);
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
?>
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$sql="SELECT
|
||||||
|
eva.idevaluacion,
|
||||||
|
eva.categoria as 'No. de categoría',
|
||||||
|
cat.nombre as 'Nombre categoría',
|
||||||
|
eva.titulo as 'Titulo',
|
||||||
|
eva.descripcion as 'Descripción',
|
||||||
|
eva.instrucciones as 'Instrucciones',
|
||||||
|
eva.orden as 'Orden',
|
||||||
|
eva.tipointentos as 'Intentos',
|
||||||
|
eva.intentos as 'Número de intentos',
|
||||||
|
eva.tipotiempo as 'Tiempo',
|
||||||
|
eva.tiempo as 'Límite de tiempo',
|
||||||
|
eva.calificacion as 'Calificación aprobatoria (porcentaje)',
|
||||||
|
eva.tipopreguntas as 'Modo de preguntas',
|
||||||
|
COUNT(ep.idpregunta) as 'Preguntas',
|
||||||
|
eva.retroalimentacion as 'Retroalimentación',
|
||||||
|
IF(eva.habilitado = 1, 'HABILITADO','DESHABILITADO') as Habilitado,
|
||||||
|
eva.imagen as 'Imagen',
|
||||||
|
eva.creacion as 'Creación',
|
||||||
|
eva.actualizacion as 'Actualización'
|
||||||
|
FROM
|
||||||
|
evaluaciones as eva
|
||||||
|
INNER JOIN categoria as cat ON cat.id = eva.categoria
|
||||||
|
LEFT JOIN evaluaciones_preguntas as ep ON ep.idevaluacion = eva.idevaluacion";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
$return = new stdClass();
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin evaluaciones";
|
||||||
|
$return->columns = ["idevaluacion","No. de categoría","Nombre categoría","Titulo","Descripción","Orden","Intentos","Número de intentos","Calificación","Modo de preguntas","Retroalimentación","Habilitado","Imagen","Creación","Actualización"];
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="Evaluaciones";
|
||||||
|
$return->datos = [];
|
||||||
|
$return->columns = [];
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$return->columns = array_keys($row);
|
||||||
|
}
|
||||||
|
mysqli_data_seek($result, 0);
|
||||||
|
while ($row = mysqli_fetch_row ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sizeof($return->datos) == 1 && $return->datos[0][0] == null ) {
|
||||||
|
$return->columns = ["idevaluacion","No. de categoría","Nombre categoría","Titulo","Descripción","Orden","Intentos","Número de intentos","Calificación","Modo de preguntas","Retroalimentación","Habilitado","Imagen","Creación","Actualización"];
|
||||||
|
$return->datos = [];
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$catsuperior = $_POST['catsuperior'];
|
||||||
|
$titulo= $_POST['titulo'];
|
||||||
|
$desc= $_POST['desc'];
|
||||||
|
$instrucciones= $_POST['inst'];
|
||||||
|
$orden= $_POST['orden'];
|
||||||
|
$tipointentos = $_POST['tipointentos'];
|
||||||
|
if ($tipointentos == 'Limitado') {
|
||||||
|
$intentos = $_POST['intentos'];
|
||||||
|
}else{
|
||||||
|
$intentos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tipotiempo = $_POST['tipotiempo'];
|
||||||
|
if ($tipotiempo == 'Limitado') {
|
||||||
|
$tiempo = $_POST['tiempo'];
|
||||||
|
}else{
|
||||||
|
$tiempo = 0;
|
||||||
|
}
|
||||||
|
$tipopreguntas = $_POST['tipopreguntas'];
|
||||||
|
$calificacion = $_POST['calificacion'];
|
||||||
|
$retro = $_POST['retro'];
|
||||||
|
$habilitado= $_POST['habilitado'];
|
||||||
|
if( $_POST['urlimgevaluacion'] == "" ){
|
||||||
|
$urlimgevaluacion = $CFG->wwwroot.'img/icons/211-gift.png';
|
||||||
|
}else{
|
||||||
|
$urlimgevaluacion =$_POST['urlimgevaluacion'];
|
||||||
|
}
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
$sql = "INSERT INTO evaluaciones (categoria, titulo, descripcion, instrucciones, orden, tipointentos, intentos,tipotiempo, tiempo, calificacion, tipopreguntas, retroalimentacion, habilitado, imagen) VALUES ($catsuperior, '$titulo', '$desc', '$instrucciones',$orden, '$tipointentos', $intentos, '$tipotiempo', $tiempo, $calificacion, '$tipopreguntas', '$retro', $habilitado, '$urlimgevaluacion')";
|
||||||
|
|
||||||
|
if($result = mysqli_multi_query($link, $sql)){
|
||||||
|
$idevaluacion = mysqli_insert_id($link);
|
||||||
|
$return->idevaluacion = $idevaluacion;
|
||||||
|
$return->code = "200";
|
||||||
|
$return->msg = 'Evaluación creada exitosamente';
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$ids = $_POST['ids'];
|
||||||
|
$sql = "UPDATE evaluaciones SET habilitado = IF(habilitado=1, 0, 1) WHERE idevaluacion IN (".implode(', ', $ids).")";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
?>
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
$idevaluacion = $_POST['idevaluacion'];
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
SELECT
|
||||||
|
ep.idpregunta,
|
||||||
|
ep.titulo,
|
||||||
|
ep.orden,
|
||||||
|
ep.puntos
|
||||||
|
FROM
|
||||||
|
evaluaciones_preguntas as ep
|
||||||
|
WHERE
|
||||||
|
ep.idevaluacion = $idevaluacion
|
||||||
|
AND ep.habilitado = 1
|
||||||
|
ORDER BY ep.orden ASC";
|
||||||
|
|
||||||
|
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "warning";
|
||||||
|
$return->msg="Sin preguntas";
|
||||||
|
}else{
|
||||||
|
$return->code = "200";
|
||||||
|
$return->icon = "success";
|
||||||
|
$return->msg="Preguntas";
|
||||||
|
$return->datos = [];
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
$return->datos = [];
|
||||||
|
$idevaluacion = $_POST['idevaluacion'];
|
||||||
|
|
||||||
|
$sql="SELECT
|
||||||
|
eva_p.idpregunta,
|
||||||
|
eva_p.titulo as 'Pregunta',
|
||||||
|
eva_p.descripcion as 'Descripción',
|
||||||
|
eva_p.puntos as 'Puntos de la pregunta',
|
||||||
|
eva_p.orden as 'Número de preguntas',
|
||||||
|
eva_p.tipo as 'Tipo de respuesta',
|
||||||
|
IF(eva_p.habilitado = 1, 'Habilitado','Deshabilitado') as 'Habilitado',
|
||||||
|
eva_p.creacion as 'Creación',
|
||||||
|
eva_p.actualizacion as 'Actualización'
|
||||||
|
FROM
|
||||||
|
evaluaciones_preguntas as eva_p
|
||||||
|
WHERE
|
||||||
|
eva_p.idevaluacion = $idevaluacion
|
||||||
|
ORDER BY eva_p.orden ASC";
|
||||||
|
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin preguntas";
|
||||||
|
$return->columns = ["idpregunta","Pregunta","Descripción","Puntos de la pregunta","Número de preguntas","Tipo de respuesta","Habilitado","Creación","Actualización"];
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="Pregunta evaluacion #".$idevaluacion;
|
||||||
|
$return->datos = [];
|
||||||
|
$return->columns = [];
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$return->columns = array_keys($row);
|
||||||
|
}
|
||||||
|
mysqli_data_seek($result, 0);
|
||||||
|
while ($row = mysqli_fetch_row ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sizeof($return->datos) == 1 && $return->datos[0][0] == null ) {
|
||||||
|
$return->columns = ["idpregunta","Pregunta","Descripción","Respuestas","Orden de preguntas","Habilitado","Creación","Actualización"];
|
||||||
|
$return->datos = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$idevaluacion = $_POST['idevaluacion-options'];
|
||||||
|
$titulo = $_POST['pregunta'];
|
||||||
|
$desc = $_POST['desc_pregunta'];
|
||||||
|
$puntos = $_POST['puntos'];
|
||||||
|
$tipo = $_POST['tipo_p'];
|
||||||
|
$habilitado = $_POST['habilitado-options'];
|
||||||
|
$idpregunta;
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
|
||||||
|
$sqlCount = "SELECT
|
||||||
|
COUNT(*) as num
|
||||||
|
FROM
|
||||||
|
evaluaciones_preguntas
|
||||||
|
WHERE
|
||||||
|
habilitado = 1";
|
||||||
|
|
||||||
|
$resultCount = mysqli_query($link, $sqlCount);
|
||||||
|
|
||||||
|
while ($row = mysqli_fetch_assoc ($resultCount)){
|
||||||
|
$orden = $row['num'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$orden = ($orden+1);
|
||||||
|
|
||||||
|
$sql = "INSERT INTO evaluaciones_preguntas (idevaluacion,titulo,descripcion,puntos,orden,tipo,habilitado) VALUES ($idevaluacion,'$titulo','$desc',$puntos, $orden,'$tipo',$habilitado)";
|
||||||
|
|
||||||
|
if($result = mysqli_query($link, $sql)){
|
||||||
|
$idpregunta = mysqli_insert_id($link);
|
||||||
|
$return->pregunta = $idpregunta;
|
||||||
|
$return->code = "200";
|
||||||
|
$return->icon = "success";
|
||||||
|
$return->msg = "Pregunta registrada exitosamente";
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "error";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$ids = $_POST['ids'];
|
||||||
|
$sql = "UPDATE evaluaciones_preguntas SET habilitado = IF(habilitado=1, 0, 1) WHERE idpregunta IN (".implode(', ', $ids).")";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
?>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$ids = $_POST['ids'];
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
$alerts = [];
|
||||||
|
|
||||||
|
$sql = "";
|
||||||
|
foreach ($ids as $num => $val) {
|
||||||
|
$sql .= "UPDATE evaluaciones_preguntas SET orden = ".($num+1)." WHERE idpregunta = $val;";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if($result = mysqli_multi_query($link, $sql)){
|
||||||
|
$return->code = "200";
|
||||||
|
$return->icon = "success";
|
||||||
|
$return->msg = 'Preguntas reordenadas exitosamente';
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "error";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
$idpregunta = $_POST['idpregunta'];
|
||||||
|
$pregunta = $_POST['pregunta'];
|
||||||
|
$titulo = $_POST['pregunta'];
|
||||||
|
$desc = $_POST['desc_pregunta'];
|
||||||
|
$puntos = $_POST['puntos'];
|
||||||
|
$orden = $_POST['orden_p'];
|
||||||
|
$tipo = $_POST['tipo_p'];
|
||||||
|
$habilitado = $_POST['habilitado-options'];
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
$sql = "UPDATE evaluaciones_preguntas SET titulo='$pregunta',descripcion='$desc', puntos = $puntos,orden = $orden, tipo = '$tipo', habilitado = $habilitado WHERE idpregunta = $idpregunta";
|
||||||
|
|
||||||
|
if($result = mysqli_query($link, $sql)){
|
||||||
|
$return->pregunta = $idpregunta;
|
||||||
|
$return->code = "200";
|
||||||
|
$return->icon = "success";
|
||||||
|
$return->msg = "Pregunta actualizada exitosamente";
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "error";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
$return->datos = [];
|
||||||
|
$idpregunta = $_POST['idpregunta'];
|
||||||
|
|
||||||
|
$sql="SELECT
|
||||||
|
eo.idopcion,
|
||||||
|
eo.texto as 'Respuesta',
|
||||||
|
IF(eo.respuesta = 1, 'Correcto','Incorrecto') as 'Correcta/iIncorrecta',
|
||||||
|
IF(eo.habilitado = 1, 'HABILITADO','DESHABILITADO') as 'Habilitado',
|
||||||
|
eo.creacion as 'Creación',
|
||||||
|
eo.actualizacion as 'Actualización'
|
||||||
|
FROM
|
||||||
|
evaluaciones_opciones as eo
|
||||||
|
WHERE
|
||||||
|
eo.idpregunta = $idpregunta AND eo.habilitado = 1";
|
||||||
|
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin respuestas";
|
||||||
|
$return->columns = ["idopcion","Respuesta","Correcto/Incorrecto","Habilitado","Creación","Actualización"];
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="Respuestas pregunta #".$idpregunta;
|
||||||
|
$return->datos = [];
|
||||||
|
$return->columns = [];
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$return->columns = array_keys($row);
|
||||||
|
}
|
||||||
|
mysqli_data_seek($result, 0);
|
||||||
|
while ($row = mysqli_fetch_row ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$pregunta = $_POST['idpreguntarespuesta'];
|
||||||
|
$texto = $_POST['respuesta'];
|
||||||
|
$valor = $_POST['valor'];
|
||||||
|
$habilitado = $_POST['habilitado-respuesta'];
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
$sql = "INSERT INTO evaluaciones_opciones(idpregunta, texto, respuesta, habilitado) VALUES ($pregunta,'$texto',$valor,$habilitado)";
|
||||||
|
|
||||||
|
if($result = mysqli_query($link, $sql)){
|
||||||
|
$return->code = "200";
|
||||||
|
$return->icon = "success";
|
||||||
|
$return->msg = "Respuesta registrada exitosamente";
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "error";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$ids = $_POST['ids'];
|
||||||
|
$sql = "UPDATE evaluaciones_opciones SET habilitado = IF(habilitado=1, 0, 1) WHERE idopcion IN (".implode(', ', $ids).")";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
?>
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
$idrespuesta = $_POST['idrespuesta'];
|
||||||
|
$texto = $_POST['respuesta'];
|
||||||
|
$valor = $_POST['valor'];
|
||||||
|
$habilitado = $_POST['habilitado-respuesta'];
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
$sql = "UPDATE evaluaciones_opciones SET texto='$texto',respuesta=$valor,habilitado=$habilitado WHERE idopcion = $idrespuesta";
|
||||||
|
|
||||||
|
if($result = mysqli_query($link, $sql)){
|
||||||
|
$return->code = "200";
|
||||||
|
$return->icon = "success";
|
||||||
|
$return->msg = "Respuesta actualizada exitosamente";
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "error";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
error_reporting(0);
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$idevaluacion = $_POST['idevaluacion'];
|
||||||
|
$catsuperior = $_POST['catsuperior'];
|
||||||
|
$titulo = $_POST['titulo'];
|
||||||
|
$desc = $_POST['desc'];
|
||||||
|
$instrucciones = $_POST['inst'];
|
||||||
|
$orden = $_POST['orden'];
|
||||||
|
$tipointentos = $_POST['tipointentos'];
|
||||||
|
if ($tipointentos == 'Limitado') {
|
||||||
|
$intentos = $_POST['intentos'];
|
||||||
|
}else{
|
||||||
|
$intentos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tipotiempo = $_POST['tipotiempo'];
|
||||||
|
if ($tipotiempo == 'Limitado') {
|
||||||
|
$tiempo = $_POST['tiempo'];
|
||||||
|
}else{
|
||||||
|
$tiempo = 0;
|
||||||
|
}
|
||||||
|
$tipopreguntas = $_POST['tipopreguntas'];
|
||||||
|
$calificacion = $_POST['calificacion'];
|
||||||
|
$retro = $_POST['retro'];
|
||||||
|
$habilitado = $_POST['habilitado'];
|
||||||
|
if( $_POST['urlimgevaluacion'] == "" ){
|
||||||
|
$urlimgevaluacion = $CFG->wwwroot.'img/icons/211-gift.png';
|
||||||
|
}else{
|
||||||
|
$urlimgevaluacion = $_POST['urlimgevaluacion'];
|
||||||
|
}
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "UPDATE evaluaciones SET categoria=$catsuperior ,titulo='$titulo', descripcion='$desc', instrucciones = '$instrucciones', orden=$orden, tipointentos='$tipointentos', intentos=$intentos, tipotiempo='$tipotiempo', tiempo=$tiempo, calificacion=$calificacion, tipopreguntas='$tipopreguntas', retroalimentacion='$retro', habilitado=$habilitado,imagen='$urlimgevaluacion' WHERE idevaluacion=$idevaluacion";
|
||||||
|
|
||||||
|
|
||||||
|
if($result = mysqli_multi_query($link, $sql)){
|
||||||
|
$return->code = "200";
|
||||||
|
$return->idevaluacion = $idevaluacion;
|
||||||
|
$return->msg = "Exito!";
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->msg = "Consulta fallo! SQL: ".$sql."<br><br> Error: ".mysqli_error($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
// upload.php
|
||||||
|
require_once "../config.php";
|
||||||
|
$return = new stdClass();
|
||||||
|
$files = $_FILES['files'];
|
||||||
|
$file_path = $files['tmp_name'][0]; // temporary upload path of the first file
|
||||||
|
$file_name = $_POST['name']; // desired name of the file
|
||||||
|
|
||||||
|
$file_basename = substr($file_name, 0, strripos($file_name, '.')); // This returns file name
|
||||||
|
$file_ext = substr($file_name, strripos($file_name, '.')); // This returns file ext
|
||||||
|
$file_name = $file_basename .round(microtime(true)) . $file_ext ;
|
||||||
|
|
||||||
|
$file_type = $files['type'][0]; //returns the mimetype
|
||||||
|
$allowed = array("image/jpeg", "image/gif", "image/png", "image/jpg");
|
||||||
|
if(!in_array($file_type, $allowed)) {
|
||||||
|
$return->txt = 'Solo se aceptan jpg, gif, y png.';
|
||||||
|
$return->error = '1';
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filex = '../data/evaluaciones/' . basename($file_name) ;
|
||||||
|
move_uploaded_file($file_path, $filex); //
|
||||||
|
$return->error = '0';
|
||||||
|
$return->url= $CFG->wwwroot.'data/evaluaciones/' . basename($file_name);
|
||||||
|
//$return->url= $file_path . basename($file_name);
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once("../config.php");
|
||||||
|
|
||||||
|
dbConnect();
|
||||||
|
global $link;
|
||||||
|
|
||||||
|
$rol = isset($_REQUEST['roladmin']) ? (int)$_REQUEST['roladmin'] : 2;
|
||||||
|
|
||||||
|
$sqluserstotal = "SELECT
|
||||||
|
user.userid,
|
||||||
|
user.numempl,
|
||||||
|
user.email,
|
||||||
|
user.nombre,
|
||||||
|
user.apellido,
|
||||||
|
rol.nombre as rol,
|
||||||
|
user.centrotrabajonom,
|
||||||
|
user.distritonom,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as habilitado,
|
||||||
|
user.lastlogin,
|
||||||
|
user.creado,
|
||||||
|
user.actualizacion
|
||||||
|
FROM
|
||||||
|
user
|
||||||
|
INNER JOIN rol ON user.idrol = rol.id";
|
||||||
|
if ($rol != 2) {
|
||||||
|
$sqluserstotal .= " WHERE user.idrol != 2";
|
||||||
|
}
|
||||||
|
|
||||||
|
$resultados = array();
|
||||||
|
$headers = array("Número de empleado","Nombres (s)","Apellidos","Perfil","Centro de trabajo","Distrito","Posición","Sociedad","División","Unidad organizativa","CeCo","Supervisor","Habilitado","Ultimo acceso","Creado","Actualización");
|
||||||
|
array_push($resultados, $headers);
|
||||||
|
|
||||||
|
$resultusers = mysqli_query($link, $sqluserstotal);
|
||||||
|
if ($resultusers && mysqli_num_rows($resultusers) > 0) {
|
||||||
|
while ($usuario = mysqli_fetch_assoc($resultusers)) {
|
||||||
|
$resultados[] = array(
|
||||||
|
$usuario['numempl'],
|
||||||
|
$usuario['nombre'],
|
||||||
|
$usuario['apellido'],
|
||||||
|
$usuario['rol'],
|
||||||
|
$usuario['centrotrabajonom'],
|
||||||
|
$usuario['distritonom'],
|
||||||
|
$usuario['posicion'],
|
||||||
|
$usuario['sociedad'],
|
||||||
|
$usuario['division'],
|
||||||
|
$usuario['unidad_organizativa'],
|
||||||
|
$usuario['ceco'],
|
||||||
|
$usuario['supervisor'],
|
||||||
|
$usuario['habilitado'],
|
||||||
|
$usuario['lastlogin'],
|
||||||
|
$usuario['creado'],
|
||||||
|
$usuario['actualizacion'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanData(&$str)
|
||||||
|
{
|
||||||
|
$str = mb_convert_encoding($str, 'UTF-16LE', 'UTF-8');
|
||||||
|
$str = preg_replace("/\t/", " ", $str);
|
||||||
|
$str = preg_replace("/\r?\n/", " ", $str);
|
||||||
|
if (strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = "reporte - Listado de Usuarios" . date('Ymd') . ".csv";
|
||||||
|
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||||
|
header("Content-Type: text/csv");
|
||||||
|
$out = fopen("php://output", 'w');
|
||||||
|
foreach ($resultados as $row) {
|
||||||
|
array_walk($row, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($row), ',', '"');
|
||||||
|
}
|
||||||
|
fclose($out);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,643 @@
|
|||||||
|
<section class="py-md-4 py-2">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h1 class="text-secondary font-weight-bolder">Gamification</h1>
|
||||||
|
<p>Sistema de gamification, se pueden crear insignias por logros en los recursos o por categorias.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 controller">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center align-self-center">
|
||||||
|
<div class="col-12">
|
||||||
|
<table id="datatable" class="display table table-striped table-bordered" cellspacing="0" width="100%">
|
||||||
|
<thead>
|
||||||
|
<tr></tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 editor" style="display: none;">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center justify-content-start">
|
||||||
|
<div class="col-12 text-left my-4">
|
||||||
|
<h3 class="title-cat edit" style="display: none;">Editar Insignia</h3>
|
||||||
|
<h3 class="title-cat crear" style="display: none;">Crear Insignia</h3>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-10">
|
||||||
|
<form class="formcontroller">
|
||||||
|
<input type="hidden" name="idobjetivo" id="idobjetivo" value="">
|
||||||
|
<input type="hidden" name="rowid" id="rowid" value="">
|
||||||
|
<input type="hidden" name="urlimginsignia" id="urlimginsignia" value="">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="tipo" class="col-md-2 col-12 col-form-label">Tipo</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="tipo" name="tipo" class="col-12 selectpicker" data-live-search="true" required="required">
|
||||||
|
<option value="categoria" selected>Categoría</option>
|
||||||
|
<option value="scormpkg">Recurso</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="catsuperior" class="col-md-2 col-12 col-form-label">Objetivo</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="wcats"><select id="catsuperior" name="catsuperior" class="col-12 selectpicker" data-live-search="true" required="required"></select></div>
|
||||||
|
<div class="wrecurso"><select id="recurso" name="recurso" class="col-12 selectpicker" data-live-search="true" required="required"></select></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-2 col-12 col-form-label" for="nombre">Nombre</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<input id="nombre" name="nombre" placeholder="Nombre" type="text" class="form-control" required="required">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="desc" class="col-md-2 col-12 col-form-label">Descripción</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<textarea id="desc" name="desc" cols="40" rows="5" class="form-control"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="habilitado" class="col-md-2 col-12 col-form-label">Habilitado</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="habilitado" name="habilitado" class="custom-select" required="required">
|
||||||
|
<option value="1" selected>SI</option>
|
||||||
|
<option value="0">No</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-2 col-12 col-form-label">Imagen</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||||||
|
<div class="UppyDragDrop"></div>
|
||||||
|
<div class="w-100 my-3">
|
||||||
|
<div class="for-ProgressBar"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0 preview" style="display: none;">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="ThumbnailGenerator"></div>
|
||||||
|
<div class="uploaded-files text-secondary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row justify-content-center">
|
||||||
|
<div class="col-12 col-md-6 text-right">
|
||||||
|
<div class="btn btn-warning btn_cancelar">Cancelar</div>
|
||||||
|
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Enviar</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(".layer-load").show();
|
||||||
|
var table;
|
||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
function parseJSON(resp) {
|
||||||
|
if (resp == null) return null;
|
||||||
|
if (typeof resp === 'object') return resp;
|
||||||
|
try { return JSON.parse(resp); }
|
||||||
|
catch (e) { console.error('Respuesta no-JSON del servidor:', String(resp).substring(0, 300)); return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** UPLOAD ********************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
var uppy = Uppy.Core({
|
||||||
|
debug: false,
|
||||||
|
autoProceed: true,
|
||||||
|
allowMultipleUploads: true,
|
||||||
|
locale: Uppy.locales.Spanish,
|
||||||
|
restrictions: {
|
||||||
|
allowedFileTypes: ['image/*']
|
||||||
|
}
|
||||||
|
});
|
||||||
|
uppy.use(Uppy.DragDrop, {
|
||||||
|
target: '.UppyDragDrop',
|
||||||
|
locale: {
|
||||||
|
strings: {
|
||||||
|
browse: 'Buscar',
|
||||||
|
dropHereOr: "Arrastra el archivo aqu\xed o %{browse}",
|
||||||
|
dropHint: "Arrastra el archivo aqu\xed",
|
||||||
|
dropPaste: "Arrastra el archivo aqu\xed, pegar o %{browse}",
|
||||||
|
dropPasteImport: "Arrastra el archivo aqu\xed, pegar, %{browse} o importar desde",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).use(Uppy.XHRUpload, {
|
||||||
|
headers: { 'X-CSRF-Token': window.CSRF_TOKEN },
|
||||||
|
endpoint: "gamification_upload.php",
|
||||||
|
formData: true,
|
||||||
|
method: 'post',
|
||||||
|
fieldName: 'files[]'
|
||||||
|
}).use(Uppy.ProgressBar, { target: '.for-ProgressBar', hideAfterFinish: false }).on('upload-success', function (file, response) { onUploadSuccess(file, response) });
|
||||||
|
|
||||||
|
function onUploadSuccess(file, response) {
|
||||||
|
if (response.uploadURL) {
|
||||||
|
var url = response.uploadURL;
|
||||||
|
$("#urlimginsignia").val(url);
|
||||||
|
var fileName = file.name;
|
||||||
|
$(".preview").show();
|
||||||
|
$(".uploaded-files").show().addClass('newimg');
|
||||||
|
$(".uploaded-files").html("");
|
||||||
|
$(".uploaded-files").html('<a class="btn-link" href="' + response.uploadURL + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + response.uploadURL + '"><br>' + fileName + '</a>');
|
||||||
|
} else {
|
||||||
|
Swal.fire(
|
||||||
|
'',
|
||||||
|
response.body.txt,
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
uppy.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** DATATABLE *****************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
function getData() {
|
||||||
|
listadoDeCategorias();
|
||||||
|
|
||||||
|
$("#datatable").html('<thead><tr></tr></thead>');
|
||||||
|
$.ajax({
|
||||||
|
url: 'gamification.php'
|
||||||
|
}).done(function (data) {
|
||||||
|
var _data = JSON.parse(data);
|
||||||
|
var tableName = "#datatable";
|
||||||
|
var str;
|
||||||
|
$.each(_data.columns, function (k, colObj) {
|
||||||
|
str = '<th>' + colObj + '</th>';
|
||||||
|
$(str).appendTo(tableName + '>thead>tr');
|
||||||
|
});
|
||||||
|
|
||||||
|
table = $('#datatable').DataTable({
|
||||||
|
dom: "Bfrtip",
|
||||||
|
responsive: true,
|
||||||
|
"drawCallback": function (settings) {
|
||||||
|
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||||||
|
addEventsCheck();
|
||||||
|
},
|
||||||
|
buttons: [{
|
||||||
|
extend: 'excel',
|
||||||
|
text: 'Exportar a Excel'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Editar',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
editar(e, dt, node, config);
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_edit'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Alternar habilitar',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
deshabilitar(e, dt, node, config)
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_habilitar'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Crear',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
crear();
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_crear'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
'columnDefs': [{
|
||||||
|
'targets': 0,
|
||||||
|
'checkboxes': { 'selectRow': true }
|
||||||
|
}],
|
||||||
|
|
||||||
|
'order': [
|
||||||
|
[1, 'asc']
|
||||||
|
],
|
||||||
|
data: _data.datos,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
table.columns.adjust().draw();
|
||||||
|
$(window).resize(function (event) {
|
||||||
|
table.columns.adjust().draw();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reloadData() {
|
||||||
|
//listadoDeCategorias();
|
||||||
|
$.ajax({
|
||||||
|
url: 'gamification.php'
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
var NewlyCreatedData = JSON.parse(data);
|
||||||
|
table.clear();
|
||||||
|
table.rows.add(NewlyCreatedData.datos); // Add new data
|
||||||
|
table.columns.adjust().draw(); // Redraw the DataTable
|
||||||
|
table.column(0).checkboxes.deselectAll();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addEventsCheck() {
|
||||||
|
$("#datatable_wrapper input[type='checkbox']").on('change', function (e) {
|
||||||
|
setTimeout(function (){
|
||||||
|
console.log($("#datatable_wrapper input[type='checkbox']:checked").length);
|
||||||
|
if (table.column(0).checkboxes.selected().length == 0) {
|
||||||
|
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||||||
|
} else if (table.column(0).checkboxes.selected().length == 1) {
|
||||||
|
$("#btn_edit, #btn_habilitar").removeClass('disabled');
|
||||||
|
} else if (table.column(0).checkboxes.selected().length > 1) {
|
||||||
|
$("#btn_edit").addClass('disabled');
|
||||||
|
$("#btn_habilitar").removeClass('disabled');
|
||||||
|
}
|
||||||
|
}, 150);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** Editar, Deshabilitar, Crear ***********************/
|
||||||
|
/**********************************************************************/
|
||||||
|
function initTipo() {
|
||||||
|
|
||||||
|
$("#tipo").selectpicker('render');
|
||||||
|
$("#tipo").change(function (event) {
|
||||||
|
if ($("#catsuperior").find('option').length == 0 && $("#recurso").find('option').length == 0) {
|
||||||
|
Swal.fire({
|
||||||
|
html: "Sin categorias y sin recursos",
|
||||||
|
icon: "error",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$(".btn_cancelar").click();
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if ($(this).val() == "categoria") {
|
||||||
|
$(".wrecurso").hide();
|
||||||
|
$(".wcats").show();
|
||||||
|
if ($("#catsuperior").find('option').length == 0) {
|
||||||
|
Swal.fire({
|
||||||
|
html: "Sin categorias",
|
||||||
|
icon: "error",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$("#tipo").val('categoria');
|
||||||
|
$("#tipo").selectpicker('render');
|
||||||
|
$("#tipo").trigger('change');
|
||||||
|
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$(".wrecurso").show();
|
||||||
|
$(".wcats").hide();
|
||||||
|
if ($("#recurso").find('option').length == 0) {
|
||||||
|
Swal.fire({
|
||||||
|
html: "Sin recursos",
|
||||||
|
icon: "error",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$("#tipo").val('categoria');
|
||||||
|
$("#tipo").selectpicker('render');
|
||||||
|
$("#tipo").trigger('change');
|
||||||
|
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function listadoDeRecursos() {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'recursos_list.php',
|
||||||
|
type: 'POST'
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
if (_data.code == "1") {
|
||||||
|
$("#recurso").html("");
|
||||||
|
var _padres = _.groupBy(_data.datos, function (n) {
|
||||||
|
return n.catname;
|
||||||
|
});
|
||||||
|
$.each(_padres, function (index, val) {
|
||||||
|
$("#recurso").append('<optgroup label="' + index + '"></optgroup>');
|
||||||
|
$.each(val, function (indexs, val2) {
|
||||||
|
$("[label='" + index + "']").append('<option value="' + val2.id + '">' + val2.nombre + '</option>');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$('#recurso').selectpicker('render');
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
initTipo();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function listadoDeCategorias() {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias_list.php',
|
||||||
|
type: 'POST'
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
if (_data.code == "1") {
|
||||||
|
$("#catsuperior").html("");
|
||||||
|
var _padres = _.filter(_data.datos, function (n) {
|
||||||
|
return n.padre == 0;
|
||||||
|
});
|
||||||
|
var _datos = _.groupBy(_data.datos, function (n) {
|
||||||
|
return n.padre;
|
||||||
|
});
|
||||||
|
$.each(_padres, function (index, val1) {
|
||||||
|
$("#catsuperior").append('<optgroup label="' + val1.nombre + '"></optgroup>');
|
||||||
|
$.each(_datos, function (index, cats) {
|
||||||
|
$.each(cats, function (index, val) {
|
||||||
|
if (val.padre == val1.id || val.nombre == val1.nombre) {
|
||||||
|
if (val.nombre == val1.nombre) {
|
||||||
|
//$("[label='" + val1.nombre + "']").append('<option class="font-weight-bold" value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
} else {
|
||||||
|
$("[label='" + val1.nombre + "']").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$('#catsuperior').selectpicker('render');
|
||||||
|
} else {
|
||||||
|
$(".controller").html('<h1>No existen categorias</h1>');
|
||||||
|
}
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
listadoDeRecursos();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function editar(e, dt, node, config) {
|
||||||
|
$(".uploaded-files").removeClass("newimg");
|
||||||
|
var $table = table.table().node();
|
||||||
|
var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
|
||||||
|
$($chkbox_checked).closest('tr')
|
||||||
|
var data = table.row($($chkbox_checked).closest('tr')).data();
|
||||||
|
$("#rowid").val(data[0]);
|
||||||
|
$("#idobjetivo").val(data[1]);
|
||||||
|
if (data[3] == "Categoría") {
|
||||||
|
$(".wcats").show();
|
||||||
|
$(".wrecurso").hide();
|
||||||
|
$("#tipo").val('categoria');
|
||||||
|
$("#catsuperior").find('option').each(function (index, el) {
|
||||||
|
if ($(this).text() == data[2]) {
|
||||||
|
$("#catsuperior").val($(this).attr('value'));
|
||||||
|
$('#catsuperior').selectpicker('render');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$(".wcats").show();
|
||||||
|
$(".wrecurso").hide();
|
||||||
|
$("#tipo").val('scormpkg');
|
||||||
|
$("#recurso").find('option').each(function (index, el) {
|
||||||
|
if ($(this).text() == data[2]) {
|
||||||
|
$("#recurso").val($(this).attr('value'));
|
||||||
|
$('#recurso').selectpicker('render');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$('#tipo').selectpicker('render');
|
||||||
|
$("#nombre").val(data[4]);
|
||||||
|
$("#desc").val(data[5]);
|
||||||
|
if (data[6] != null) {
|
||||||
|
var name = String(data[6]).split('/');
|
||||||
|
$(".preview").show();
|
||||||
|
$(".uploaded-files").html('<a class="btn-link" href="' + data[6] + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + data[6] + '"><br>' + name[name.length - 1] + '</a>');
|
||||||
|
$("#urlimginsignia").val(data[6]);
|
||||||
|
$(".uploaded-files").addClass('updimg');
|
||||||
|
}
|
||||||
|
$("#habilitado").val(data[7]);
|
||||||
|
$(".controller").hide();
|
||||||
|
$(".editor").show();
|
||||||
|
$(".edit").show();
|
||||||
|
$(".crear").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deshabilitar(e, dt, node, config) {
|
||||||
|
var rows_selected = table.column(0).checkboxes.selected();
|
||||||
|
var ids = new Array();
|
||||||
|
$.each(rows_selected, function (index, rowId) {
|
||||||
|
ids.push(rowId);
|
||||||
|
});
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'gamification_delete.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { ids: ids },
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
Swal.fire({
|
||||||
|
html: response,
|
||||||
|
icon: "success",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
reloadData();
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function crear() {
|
||||||
|
$("#idobjetivo").val("");
|
||||||
|
$("#nombre").val("");
|
||||||
|
$("#desc").val("");
|
||||||
|
$("#urlimginsignia").val("");
|
||||||
|
$(".wrecurso").hide();
|
||||||
|
$(".wcats").show();
|
||||||
|
$("#clave").val("");
|
||||||
|
$("#habilitado").val(1);
|
||||||
|
$(".controller").hide();
|
||||||
|
$(".editor").show();
|
||||||
|
$(".edit").hide();
|
||||||
|
$(".crear").show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$(".btn_cancelar").click(function (event) {
|
||||||
|
if ($(".uploaded-files").hasClass('newimg')) {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'gamification_deletefile.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { file: $(".uploaded-files a").attr('href') },
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function (error) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
$(".uploaded-files").removeClass('newimg');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$(".formcontroller").validate({
|
||||||
|
submitHandler: function (form) {
|
||||||
|
if ($(".uploaded-files").hasClass('newimg')) {
|
||||||
|
var controller = 'gamification_upadate.php';
|
||||||
|
if ($(".crear").css("display") == "block") {
|
||||||
|
controller = 'gamification_add.php';
|
||||||
|
}
|
||||||
|
if ($("#tipo").val() == "categoria") {
|
||||||
|
$("#idobjetivo").val($("#catsuperior").val());
|
||||||
|
} else {
|
||||||
|
$("#idobjetivo").val($("#recurso").val());
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: controller,
|
||||||
|
type: 'POST',
|
||||||
|
data: $(".formcontroller").serializeArray(),
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
Swal.fire({
|
||||||
|
html: response,
|
||||||
|
icon: 'success',
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
reloadData();
|
||||||
|
|
||||||
|
$(".mainseccion").load("gamification.html", function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
}).fail(function () {}).always(function () {});
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
html: "La imagen de la insignia es obligatoria",
|
||||||
|
icon: "error",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
nombre: {
|
||||||
|
required: true,
|
||||||
|
maxlength: 254,
|
||||||
|
minlength: 2,
|
||||||
|
normalizer: function (value) {
|
||||||
|
return $.trim(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
messages: {
|
||||||
|
nombre: {
|
||||||
|
required: "El nombre de la Insignia es obligatorio",
|
||||||
|
minlength: jQuery.validator.format("El nombre de la Insignia es de al menos {0} caracteres"),
|
||||||
|
maxlength: jQuery.validator.format("El nombre de la Insignia es de máximo {0} caracteres")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
getData();
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$sql="
|
||||||
|
SELECT
|
||||||
|
insignias.id,
|
||||||
|
insignias.idobjetivo as 'Id objetivo',
|
||||||
|
CASE
|
||||||
|
WHEN insignias.objetivo = 'categoria' THEN
|
||||||
|
(SELECT nombre FROM categoria WHERE categoria.id = insignias.idobjetivo)
|
||||||
|
ELSE
|
||||||
|
(SELECT nombre FROM scormpkg WHERE scormpkg.id = insignias.idobjetivo)
|
||||||
|
END AS 'Recurso',
|
||||||
|
insignias.objetivo as 'Tipo',
|
||||||
|
insignias.nombre as 'Nombre',
|
||||||
|
insignias.descripcion as 'Descripción',
|
||||||
|
insignias.imagen as 'Imagen',
|
||||||
|
insignias.habilitado as 'Habilitado',
|
||||||
|
insignias.creado as 'Creado',
|
||||||
|
insignias.actualizacion as 'Actualización'
|
||||||
|
FROM
|
||||||
|
insignias";
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
$return = new stdClass();
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin categorías";
|
||||||
|
$return->columns = ["id","Id objetivo","Recurso","Tipo","Nombre","Descripción","Imagen","Habilitado","Creado","Actualización"];
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="categorías";
|
||||||
|
$return->datos = [];
|
||||||
|
$return->columns = [];
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$return->columns = array_keys($row);
|
||||||
|
}
|
||||||
|
mysqli_data_seek($result, 0);
|
||||||
|
while ($row = mysqli_fetch_row ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once __DIR__.'/audit.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$idobjetivo = isset($_POST['idobjetivo']) ? (int)$_POST['idobjetivo'] : 0;
|
||||||
|
$urlimginsignia = isset($_POST['urlimginsignia']) ? $_POST['urlimginsignia'] : '';
|
||||||
|
$tipo = (isset($_POST['tipo']) && $_POST['tipo'] == 'categoria') ? 'Categoría' : 'Recurso';
|
||||||
|
$nombre = isset($_POST['nombre']) ? $_POST['nombre'] : '';
|
||||||
|
$desc = isset($_POST['desc']) ? $_POST['desc'] : '';
|
||||||
|
$habilitado = isset($_POST['habilitado']) ? (int)$_POST['habilitado'] : 0;
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
$sql = "INSERT INTO insignias (idobjetivo,objetivo,nombre,descripcion,imagen,habilitado) VALUES (?,?,?,?,?,?)";
|
||||||
|
$stmt = mysqli_prepare($link, $sql);
|
||||||
|
if ($stmt) {
|
||||||
|
mysqli_stmt_bind_param($stmt, 'issssi', $idobjetivo, $tipo, $nombre, $desc, $urlimginsignia, $habilitado);
|
||||||
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
|
audit_log('insignia_create', 'nombre=' . $nombre . ' objetivo=' . $idobjetivo . ' tipo=' . $tipo);
|
||||||
|
echo "Insignia creada";
|
||||||
|
} else {
|
||||||
|
http_response_code(500);
|
||||||
|
echo "Error al crear insignia";
|
||||||
|
}
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
} else {
|
||||||
|
http_response_code(500);
|
||||||
|
echo "Error al preparar la consulta";
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once __DIR__.'/audit.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$ids = isset($_POST['ids']) ? (array)$_POST['ids'] : array();
|
||||||
|
$ids = array_values(array_filter(array_map('intval', $ids), function ($v) { return $v > 0; }));
|
||||||
|
if (!count($ids)) { echo "Sin identificadores"; exit; }
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$lista = implode(', ', $ids);
|
||||||
|
$sql = "UPDATE insignias SET habilitado = IF(habilitado=1, 0, 1) WHERE id IN ($lista)";
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
audit_log('insignia_toggle', 'ids=' . $lista);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
?>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once("../config.php");
|
||||||
|
//$filelink = "http://localhost/git/estafeta-lms360/site/data/imgcat/tablero051594833914.png";
|
||||||
|
$filelink = $_POST["file"];
|
||||||
|
$filepath = getCurrentOrParentDirectory(parse_url ($filelink,PHP_URL_PATH) );
|
||||||
|
unlink($filepath);
|
||||||
|
function getCurrentOrParentDirectory( $filename )
|
||||||
|
{
|
||||||
|
echo '<p>'.$filename.'</p>';
|
||||||
|
$patharray = explode('/',$filename);
|
||||||
|
$path = $patharray[sizeof($patharray)-3].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-2].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-1];
|
||||||
|
return ROOTPATH.$path;
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
/*
|
||||||
|
[idobjetivo] =>
|
||||||
|
[urlimginsignia] => http://localhost/git/estafeta-lms360/site/data/insignia/001-unlocked1595810921.png
|
||||||
|
[tipo] => categoria
|
||||||
|
[catsuperior] => 1
|
||||||
|
[nombre] => uno
|
||||||
|
[desc] =>
|
||||||
|
[habilitado] => 1
|
||||||
|
[Enviar] => Enviar
|
||||||
|
*/
|
||||||
|
require_once "../config.php";
|
||||||
|
$rowid = $_POST['rowid'];
|
||||||
|
$idobjetivo = $_POST['idobjetivo'];
|
||||||
|
$urlimginsignia = $_POST['urlimginsignia'];
|
||||||
|
$tipo = $_POST['tipo'] == 'categoria' ? 'Categoría' : 'Recurso';
|
||||||
|
$nombre = $_POST['nombre'];
|
||||||
|
$desc = $_POST['desc'];
|
||||||
|
$habilitado = $_POST['habilitado'];
|
||||||
|
|
||||||
|
$sql = "UPDATE insignias SET
|
||||||
|
idobjetivo = $idobjetivo ,
|
||||||
|
objetivo = '$tipo' ,
|
||||||
|
nombre = '$nombre' ,
|
||||||
|
descripcion = '$desc' ,
|
||||||
|
imagen = '$urlimginsignia' ,
|
||||||
|
habilitado = '$habilitado'
|
||||||
|
WHERE id = $rowid";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
echo "Insignia actualizada";
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
// upload.php
|
||||||
|
require_once "../config.php";
|
||||||
|
$return = new stdClass();
|
||||||
|
$files = $_FILES['files'];
|
||||||
|
$file_path = $files['tmp_name'][0]; // temporary upload path of the first file
|
||||||
|
$file_name = $_POST['name']; // desired name of the file
|
||||||
|
|
||||||
|
$file_basename = substr($file_name, 0, strripos($file_name, '.')); // This returns file name
|
||||||
|
$file_ext = substr($file_name, strripos($file_name, '.')); // This returns file ext
|
||||||
|
$file_name = $file_basename .round(microtime(true)) . $file_ext ;
|
||||||
|
|
||||||
|
$file_type = $files['type'][0]; //returns the mimetype
|
||||||
|
$allowed = array("image/jpeg", "image/gif", "image/png", "image/jpg");
|
||||||
|
if(!in_array($file_type, $allowed)) {
|
||||||
|
$return->txt = 'Solo se aceptan jpg, gif, y png.';
|
||||||
|
$return->error = '1';
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filex = '../data/insignia/' . basename($file_name) ;
|
||||||
|
move_uploaded_file($file_path, $filex); //
|
||||||
|
$return->error = '0';
|
||||||
|
$return->url= $CFG->wwwroot.'data/insignia/' . basename($file_name);
|
||||||
|
//$return->url= $file_path . basename($file_name);
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
?>
|
||||||
+227
@@ -0,0 +1,227 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
||||||
|
|
||||||
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||||
|
|
||||||
|
header("Pragma: no-cache");
|
||||||
|
|
||||||
|
require_once "../sessionManager.php";
|
||||||
|
|
||||||
|
//require_once "../config.php";
|
||||||
|
|
||||||
|
if(!$_SESSION['isadmin']){ echo "No tienes permisos para ingresar"; die;}else{$user = json_decode($_SESSION['usersession']);}
|
||||||
|
|
||||||
|
if (empty($_SESSION['csrf'])) { $_SESSION['csrf'] = bin2hex(random_bytes(32)); }
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<title>::ADMIN::</title>
|
||||||
|
|
||||||
|
<meta name="csrf-token" content="<?php echo htmlspecialchars($_SESSION['csrf'], ENT_QUOTES); ?>">
|
||||||
|
|
||||||
|
<?php require_once "../header.php"; ?>
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>webfonts/HelveticaNeue/stylesheet.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>css/datatables.min.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>css/dataTables.checkboxes.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/searchpanes/1.2.1/css/searchPanes.dataTables.min.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>css/theme-bulma/borderless.min.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>css/bootstrap-select.min.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>css/admin.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>trumbowyg/ui/trumbowyg.min.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>/highcharts/css/highcharts.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>/highcharts/css/themes/sand-signika.css">
|
||||||
|
|
||||||
|
<link href="<?php echo $CFG->wwwroot ?>css/uppy.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>css/select2.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>css/daterangepicker.css" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script src="<?php echo $CFG->wwwroot ?>/highcharts/highcharts.js"></script>
|
||||||
|
|
||||||
|
<script src="<?php echo $CFG->wwwroot ?>/highcharts/modules/series-label.js"></script>
|
||||||
|
|
||||||
|
<script src="<?php echo $CFG->wwwroot ?>/highcharts/modules/exporting.js"></script>
|
||||||
|
|
||||||
|
<script src="<?php echo $CFG->wwwroot ?>/highcharts/modules/export-data.js"></script>
|
||||||
|
|
||||||
|
<script src="<?php echo $CFG->wwwroot ?>/highcharts/modules/accessibility.js"></script>
|
||||||
|
|
||||||
|
<script src="<?php echo $CFG->wwwroot ?>/highcharts/themes/sand-signika.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="layer-load">
|
||||||
|
|
||||||
|
<div class="lds-ring">
|
||||||
|
|
||||||
|
<div></div>
|
||||||
|
|
||||||
|
<div></div>
|
||||||
|
|
||||||
|
<div></div>
|
||||||
|
|
||||||
|
<div></div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex" id="wrapper">
|
||||||
|
|
||||||
|
<!-- Sidebar -->
|
||||||
|
|
||||||
|
<div class="bg-color-1 border-right text-azul" id="sidebar-wrapper">
|
||||||
|
|
||||||
|
<div class="sidebar-heading text-center">
|
||||||
|
|
||||||
|
<img src="<?php echo $CFG->wwwroot ?>img/logo-ue.svg" width="200" class="img-fluid">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="list-group list-group-flush">
|
||||||
|
|
||||||
|
<div data-uri="usuarios.html" class="list-group-item btn-seccion list-group-item-action bg-color-1 active">Usuarios</div>
|
||||||
|
|
||||||
|
<div data-uri="categorias.html" class="list-group-item btn-seccion list-group-item-action bg-color-1 admin">Categorias</div>
|
||||||
|
|
||||||
|
<div data-uri="recursos.html" class="list-group-item btn-seccion list-group-item-action bg-color-1 admin">Recursos</div>
|
||||||
|
|
||||||
|
<div data-uri="asignaciones.html" class="list-group-item btn-seccion list-group-item-action bg-color-1 ">Asignaciones</div>
|
||||||
|
|
||||||
|
<div data-uri="gamification.html" class="list-group-item btn-seccion list-group-item-action bg-color-1 admin">Gamification</div>
|
||||||
|
|
||||||
|
<div data-uri="reportes.html" class="list-group-item btn-seccion list-group-item-action bg-color-1">Reportes</div>
|
||||||
|
|
||||||
|
<div data-uri="licencia.html" class="list-group-item btn-seccion list-group-item-action bg-color-1 admin">Permisos</div>
|
||||||
|
|
||||||
|
<div data-uri="notificaciones.html" style="display: none;" class="list-group-item btn-seccion list-group-item-action bg-color-1 ">Notificaciones</div>
|
||||||
|
|
||||||
|
<div class="d-inline-block w-100 text-center py-4">
|
||||||
|
|
||||||
|
<a href="<?php echo $CFG->wwwuserhome; ?>" target="_blank" class="btn btn-outline-primary">Ver sitio</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- /#sidebar-wrapper -->
|
||||||
|
|
||||||
|
<!-- Page Content -->
|
||||||
|
|
||||||
|
<div id="page-content-wrapper">
|
||||||
|
|
||||||
|
<nav class="navbar bg-color-1 border-bottom">
|
||||||
|
|
||||||
|
<button class="btn btn-primary" id="menu-toggle"><i class="fal fa-bars"></i></button>
|
||||||
|
|
||||||
|
<ul class="nav navbar-nav navbar-right">
|
||||||
|
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<input type="hidden" name="roladmin" id="roladmin" value="<?php echo $user->idrol; ?>">
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<a href="<?php echo $CFG->wwwroot ?>runtime/logout.php" class="btn btn-primary">
|
||||||
|
|
||||||
|
<i class="fas fa-power-off"></i>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container-fluid mainseccion">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- /#page-content-wrapper -->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php require_once "../footer.php"; ?>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>js/datatables.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>js/lodash.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>js/dataTables.checkboxes.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>js/bootstrap-select.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>js/bootstrap-select.defaults-es_ES.min.js"></script>
|
||||||
|
|
||||||
|
<script src="<?php echo $CFG->wwwroot ?>js/uppy.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>trumbowyg/trumbowyg.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>js/admin.js?no-cache=<?php echo random_int(0 , 100000) ?>"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="https://cdn.datatables.net/searchpanes/1.2.1/js/dataTables.searchPanes.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>js/select2.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>js/moment.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>js/daterangepicker.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* jQuery Dynatable plugin 0.3.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Steve Schwartz (JangoSteve)
|
||||||
|
*
|
||||||
|
* Dual licensed under the AGPL and Proprietary licenses:
|
||||||
|
* http://www.dynatable.com/license/
|
||||||
|
*
|
||||||
|
* Date: Tue Jan 02 2014
|
||||||
|
*/
|
||||||
|
th {
|
||||||
|
background: #006a72;
|
||||||
|
}
|
||||||
|
th a {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
th a:hover {
|
||||||
|
color: #fff;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynatable-search {
|
||||||
|
float: right;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynatable-pagination-links {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynatable-record-count {
|
||||||
|
display: block;
|
||||||
|
padding: 5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynatable-pagination-links span,
|
||||||
|
.dynatable-pagination-links li {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynatable-page-link,
|
||||||
|
.dynatable-page-break {
|
||||||
|
display: block;
|
||||||
|
padding: 5px 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynatable-page-link {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynatable-active-page,
|
||||||
|
.dynatable-disabled-page {
|
||||||
|
cursor: text;
|
||||||
|
}
|
||||||
|
.dynatable-active-page:hover,
|
||||||
|
.dynatable-disabled-page:hover {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynatable-active-page {
|
||||||
|
background: #006a72;
|
||||||
|
border-radius: 5px;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.dynatable-active-page:hover {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.dynatable-disabled-page,
|
||||||
|
.dynatable-disabled-page:hover {
|
||||||
|
background: none;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,134 @@
|
|||||||
|
<section class="py-md-4 py-2">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h1 class="text-secondary font-weight-bolder">Licencia</h1>
|
||||||
|
<p>Apartado solo para el Aministrador para modificar el límite de usuarios que se pueden registrar en la plataforma en perfil de Manager.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 controller">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row align-items-center align-self-center">
|
||||||
|
<div class="col-12 text-left my-4">
|
||||||
|
<h3 class="title-cat edit" style="display: none;">Editar límite</h3>
|
||||||
|
<h3 class="title-cat crear" style="display: none;">Crear límite</h3>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-12 col-md-12 col-12">
|
||||||
|
<form class="formlimite" autocomplete="off">
|
||||||
|
<input type="hidden" name="idlicencia" id="idlicencia">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-2 col-12 col-form-label" for="cantidad">Límite de usuarios</label>
|
||||||
|
<div class="col-lg-8 col-md-8 col-12">
|
||||||
|
<input id="cantidad" name="cantidad" value="10" placeholder="Límite de usuarios" type="number" class="form-control" required="required">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row justify-content-center">
|
||||||
|
<div class="col-12 col-md-6 text-right">
|
||||||
|
<!--<div class="btn btn-warning btn_cancelar">Cancelar</div> -->
|
||||||
|
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Enviar</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(".layer-load").show();
|
||||||
|
|
||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
function parseJSON(resp) {
|
||||||
|
if (resp == null) return null;
|
||||||
|
if (typeof resp === 'object') return resp;
|
||||||
|
try { return JSON.parse(resp); }
|
||||||
|
catch (e) { console.error('Respuesta no-JSON del servidor:', String(resp).substring(0, 300)); return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Limite();
|
||||||
|
/**********************************************************************/
|
||||||
|
/***************************** OBTENER LÍMITE *************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
function Limite(){
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: 'usuarios_statistical.php'
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
if (_data.code == "200") {
|
||||||
|
$('#cantidad').val(_data.limite.limite);
|
||||||
|
$('#idlicencia').val(_data.limite.idlicencia);
|
||||||
|
$('.edit').show();
|
||||||
|
$('.crear').hide();
|
||||||
|
}else{
|
||||||
|
$('.crear').show();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**********************************************************************/
|
||||||
|
/***************************** ACTUALIAR LÍMITE ***********************/
|
||||||
|
/**********************************************************************/
|
||||||
|
$(".formlimite").validate({
|
||||||
|
submitHandler: function (form) {
|
||||||
|
var licencia = 'licencia_update.php';
|
||||||
|
if ($(".crear").css("display") == "block") {
|
||||||
|
licencia = 'licencia_add.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: licencia,
|
||||||
|
type: 'POST',
|
||||||
|
data: $(".formlimite").serializeArray(),
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
html: _data.msg,
|
||||||
|
icon: _data.icon,
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
Limite();
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
cantidad: {
|
||||||
|
required: true,
|
||||||
|
maxlength: 254,
|
||||||
|
minlength: 2,
|
||||||
|
number: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
messages: {
|
||||||
|
cantidad: {
|
||||||
|
required: "Límite de usuarios requerido"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
extract($_POST);
|
||||||
|
$sql = "INSERT INTO licencia(
|
||||||
|
limiteusers
|
||||||
|
)
|
||||||
|
VALUES(
|
||||||
|
$cantidad
|
||||||
|
)";
|
||||||
|
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
if ( $result = mysqli_query($link, $sql) ) {
|
||||||
|
$return->code = "200";
|
||||||
|
$return->icon = "success";
|
||||||
|
$return->msg="Límite de usuarios registrada exitosamente.";
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "error";
|
||||||
|
$return->msg="Hubo un problema al registrar la cantidad.";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
extract($_POST);
|
||||||
|
|
||||||
|
$sql = "UPDATE `licencia` SET limiteusers = $cantidad WHERE idlicencia = $idlicencia";
|
||||||
|
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
if ( $result = mysqli_query($link, $sql) ) {
|
||||||
|
$return->code = "200";
|
||||||
|
$return->icon = "success";
|
||||||
|
$return->msg="Límte de usuarios actualizada correctamente. ";
|
||||||
|
}else{
|
||||||
|
$return->code = "400";
|
||||||
|
$return->icon = "error";
|
||||||
|
$return->msg="Hubo un problema al registrar la cantidad.";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$sql = "SELECT
|
||||||
|
categoria.id,
|
||||||
|
categoria.clave,
|
||||||
|
categoria.padre,
|
||||||
|
categoria.nombre
|
||||||
|
FROM
|
||||||
|
categoria
|
||||||
|
WHERE
|
||||||
|
categoria.habilitado = 1";
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
$return = new stdClass();
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin categorias";
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="Categorias";
|
||||||
|
$return->datos = [];
|
||||||
|
while ($row = mysqli_fetch_array ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$sql = "SELECT
|
||||||
|
scormpkg.id,
|
||||||
|
scormpkg.idcategoria,
|
||||||
|
scormpkg.clave,
|
||||||
|
scormpkg.nombre
|
||||||
|
FROM
|
||||||
|
scormpkg
|
||||||
|
WHERE
|
||||||
|
scormpkg.habilitado = 1
|
||||||
|
ORDER BY scormpkg.id ASC";
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
$return = new stdClass();
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin subtemas";
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="Subtemas";
|
||||||
|
$return->datos = [];
|
||||||
|
while ($row = mysqli_fetch_array ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$subtema = $_POST['subtema'];
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
scormpkg.id as idsubtema,
|
||||||
|
scormpkg.nombre as nombresubtema,
|
||||||
|
scormpkg.idcategoria as tema,
|
||||||
|
categoria.padre as categoria
|
||||||
|
FROM
|
||||||
|
scormpkg
|
||||||
|
INNER JOIN categoria ON categoria.id = scormpkg.idcategoria
|
||||||
|
WHERE
|
||||||
|
scormpkg.id = ".$subtema;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
$return = new stdClass();
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin tema";
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="Temas";
|
||||||
|
$return->datos = [];
|
||||||
|
while ($row = mysqli_fetch_array ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
// database information
|
||||||
|
require_once("../config.php");
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$sqlusers = "SELECT * from user limit 10";
|
||||||
|
$filtrados = mysqli_query($link, $sqlusers);
|
||||||
|
$return = new stdClass();
|
||||||
|
$return->records = [];
|
||||||
|
$return->header = [];
|
||||||
|
$return->flag = true;
|
||||||
|
$return->queryRecordCount = $filtrados->num_rows;
|
||||||
|
$return->totalRecordCount = 10000;
|
||||||
|
|
||||||
|
while ($row = mysqli_fetch_assoc ($filtrados))
|
||||||
|
{
|
||||||
|
if($return->flag){
|
||||||
|
foreach ($row as $key => $value) {
|
||||||
|
$return->header[] = $key;
|
||||||
|
}
|
||||||
|
$return->flag = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$return->records[] = $row;
|
||||||
|
}
|
||||||
|
//print("<pre>".print_r($return,true)."</pre>");
|
||||||
|
$lista = json_encode($return->records, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT);
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title></title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="jquery.dynatable.css">
|
||||||
|
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>js/jquery-3.4.1.min.js"></script>
|
||||||
|
<script type="text/javascript" src="jquery.dynatable.js"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
|
||||||
|
<table id="my-final-table">
|
||||||
|
<thead>
|
||||||
|
<?php
|
||||||
|
foreach ($return->header as $key => $value) {
|
||||||
|
echo '<th>'. $value .'</th>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var data = <?php echo $lista; ?>;
|
||||||
|
|
||||||
|
$('#my-final-table').dynatable({
|
||||||
|
dataset: {
|
||||||
|
records: data
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<section class="py-md-4 py-2">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h1 class="text-secondary font-weight-bolder">Notificaciones</h1>
|
||||||
|
<p>Sistema de notificaciones masivas o por usuario, para funcionar el usuario o grupo de usuarios deben contar con un correo eléctronico.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 controller">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row align-items-center align-self-center">
|
||||||
|
<div class="col-12"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,686 @@
|
|||||||
|
<section class="py-md-4 py-2">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h1 class="text-secondary font-weight-bolder">Recursos</h1>
|
||||||
|
<p>Sistema de gestión recursos por categoria, se pueden agregar recursos, desactivar recursos y modificar recursos.</p>
|
||||||
|
<p>Los recursos deben estar empaquetados en scorm 1.2, es muy importante que si es un recurso no calificable se marque como 100% y "completed" al ser visitado dicho recurso.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 controller">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center align-self-center">
|
||||||
|
<div class="col-12">
|
||||||
|
<table id="datatable" class="display table table-striped table-bordered" cellspacing="0" width="100%">
|
||||||
|
<thead>
|
||||||
|
<tr></tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="py-md-4 py-2 editor" style="display: none;">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row align-items-center justify-content-start">
|
||||||
|
<div class="col-12 text-left my-4">
|
||||||
|
<h3 class="title-cat edit" style="display: none;">Editar recurso</h3>
|
||||||
|
<h3 class="title-cat crear" style="display: none;">Crear recurso</h3>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-10">
|
||||||
|
<form class="formcontroller">
|
||||||
|
<input type="hidden" name="idrecurso" id="idrecurso" value="">
|
||||||
|
<input type="hidden" name="urlimgrecurso" id="urlimgrecurso" value="">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="catsuperior" class="col-md-2 col-12 col-form-label">Categoría</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="catsuperior" name="catsuperior" required="required" class="form-control col-12" data-live-search="true">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-2 col-12 col-form-label" for="nombre">Nombre</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<input id="nombre" name="nombre" placeholder="Nombre" type="text" class="form-control" required="required">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-2 col-12 col-form-label" for="nombre">URL</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<input id="url" name="url" placeholder="URL" type="text" class="form-control" required="required">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-2 col-12 col-form-label">Archivo SCORM (.zip)</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<p class="text-dark font-weight-bold">Sube el paquete SCORM (.zip). Se descomprimirá en el servidor y la URL de inicio se colocará automáticamente en el campo URL.</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||||||
|
<div class="UppyDragDropScorm"></div>
|
||||||
|
<div class="w-100 my-3">
|
||||||
|
<div class="for-ProgressBarScorm"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0 previewscorm" style="display: none;">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="uploaded-scorm text-secondary"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="desc" class="col-md-2 col-12 col-form-label">Descripción</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<textarea id="desc" name="desc" cols="40" rows="5" class="form-control"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="clave" class="col-md-2 col-12 col-form-label">Clave</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<input id="clave" name="clave" placeholder="clave" type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="habilitado" class="col-md-2 col-12 col-form-label">Habilitado</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="habilitado" name="habilitado" class="custom-select" required="required">
|
||||||
|
<option value="1">SI</option>
|
||||||
|
<option value="0">No</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-2 col-12 col-form-label">Imagen</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<p class="text-dark font-weight-bold">Se recomienda usar png y un tamaño de 512 x 512 px</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||||||
|
<div class="UppyDragDrop"></div>
|
||||||
|
<div class="w-100 my-3">
|
||||||
|
<div class="for-ProgressBar"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 py-2 py-md-0 preview" style="display: none;">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="ThumbnailGenerator"></div>
|
||||||
|
<div class="uploaded-files text-secondary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row justify-content-center">
|
||||||
|
<div class="col-12 col-md-6 text-right">
|
||||||
|
<div class="btn btn-warning btn_cancelar">Cancelar</div>
|
||||||
|
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Enviar</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(".layer-load").show();
|
||||||
|
var table;
|
||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
function parseJSON(resp) {
|
||||||
|
if (resp == null) return null;
|
||||||
|
if (typeof resp === 'object') return resp;
|
||||||
|
try { return JSON.parse(resp); }
|
||||||
|
catch (e) { console.error('Respuesta no-JSON del servidor:', String(resp).substring(0, 300)); return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** UPLOAD ********************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
var uppy = Uppy.Core({
|
||||||
|
debug: false,
|
||||||
|
autoProceed: true,
|
||||||
|
allowMultipleUploads: true,
|
||||||
|
locale: Uppy.locales.Spanish,
|
||||||
|
restrictions: {
|
||||||
|
allowedFileTypes: ['image/*']
|
||||||
|
}
|
||||||
|
});
|
||||||
|
uppy.use(Uppy.DragDrop, {
|
||||||
|
target: '.UppyDragDrop',
|
||||||
|
locale: {
|
||||||
|
strings: {
|
||||||
|
browse: 'Buscar',
|
||||||
|
dropHereOr: "Arrastra el archivo aqu\xed o %{browse}",
|
||||||
|
dropHint: "Arrastra el archivo aqu\xed",
|
||||||
|
dropPaste: "Arrastra el archivo aqu\xed, pegar o %{browse}",
|
||||||
|
dropPasteImport: "Arrastra el archivo aqu\xed, pegar, %{browse} o importar desde",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).use(Uppy.XHRUpload, {
|
||||||
|
headers: { 'X-CSRF-Token': window.CSRF_TOKEN },
|
||||||
|
endpoint: "recursos_upload.php",
|
||||||
|
formData: true,
|
||||||
|
method: 'post',
|
||||||
|
fieldName: 'files[]'
|
||||||
|
}).use(Uppy.ProgressBar, { target: '.for-ProgressBar', hideAfterFinish: false }).on('upload-success', function (file, response) { onUploadSuccess(file, response) });
|
||||||
|
|
||||||
|
function onUploadSuccess(file, response) {
|
||||||
|
if (response.uploadURL) {
|
||||||
|
var url = response.uploadURL;
|
||||||
|
$("#urlimgrecurso").val(url);
|
||||||
|
var fileName = file.name;
|
||||||
|
$(".preview").show();
|
||||||
|
$(".uploaded-files").show().addClass('newimg');
|
||||||
|
$(".uploaded-files").html("");
|
||||||
|
$(".uploaded-files").html('<a class="btn-link" href="' + response.uploadURL + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + response.uploadURL + '"><br>' + fileName + '</a>');
|
||||||
|
} else {
|
||||||
|
Swal.fire(
|
||||||
|
'',
|
||||||
|
response.body.txt,
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
uppy.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** UPLOAD SCORM (.zip) *******************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
var uppyScorm = Uppy.Core({
|
||||||
|
debug: false,
|
||||||
|
autoProceed: true,
|
||||||
|
allowMultipleUploads: false,
|
||||||
|
locale: Uppy.locales.Spanish,
|
||||||
|
restrictions: {
|
||||||
|
allowedFileTypes: ['.zip', 'application/zip', 'application/x-zip-compressed', 'application/octet-stream'],
|
||||||
|
maxNumberOfFiles: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
uppyScorm.use(Uppy.DragDrop, {
|
||||||
|
target: '.UppyDragDropScorm',
|
||||||
|
locale: {
|
||||||
|
strings: {
|
||||||
|
browse: 'Buscar',
|
||||||
|
dropHereOr: "Arrastra el .zip aqu\xed o %{browse}",
|
||||||
|
dropHint: "Arrastra el .zip aqu\xed",
|
||||||
|
dropPaste: "Arrastra el .zip aqu\xed, pegar o %{browse}",
|
||||||
|
dropPasteImport: "Arrastra el .zip aqu\xed, pegar, %{browse} o importar desde",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).use(Uppy.XHRUpload, {
|
||||||
|
headers: { 'X-CSRF-Token': window.CSRF_TOKEN },
|
||||||
|
endpoint: "recursos_scorm_upload.php",
|
||||||
|
formData: true,
|
||||||
|
method: 'post',
|
||||||
|
fieldName: 'files[]'
|
||||||
|
}).use(Uppy.ProgressBar, { target: '.for-ProgressBarScorm', hideAfterFinish: false })
|
||||||
|
.on('upload-success', function (file, response) { onScormSuccess(file, response); })
|
||||||
|
.on('upload-error', function (file, error, response) {
|
||||||
|
Swal.fire('', (response && response.body && response.body.txt) ? response.body.txt : 'Error al subir el SCORM', 'error');
|
||||||
|
uppyScorm.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
uppyScorm.on('file-added', function (file) {
|
||||||
|
uppyScorm.setFileMeta(file.id, { catid: $("#catsuperior").val() });
|
||||||
|
});
|
||||||
|
|
||||||
|
function onScormSuccess(file, response) {
|
||||||
|
if (response.uploadURL) {
|
||||||
|
$("#url").val(response.uploadURL);
|
||||||
|
$(".previewscorm").show();
|
||||||
|
$(".uploaded-scorm").html('<a class="btn-link" href="' + response.uploadURL + '" target="_blank">' + file.name + '</a><br><small>' + response.uploadURL + '</small>');
|
||||||
|
Swal.fire('', 'Paquete SCORM cargado. La URL se actualizó.', 'success');
|
||||||
|
} else {
|
||||||
|
Swal.fire('', (response.body && response.body.txt) ? response.body.txt : 'Error al subir el SCORM', 'error');
|
||||||
|
uppyScorm.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** DATATABLE *****************************************/
|
||||||
|
/**********************************************************************/
|
||||||
|
function getData() {
|
||||||
|
listadoDeCategorias();
|
||||||
|
$("#datatable").html('<thead><tr></tr></thead>');
|
||||||
|
$.ajax({
|
||||||
|
url: 'recursos.php',
|
||||||
|
cache: false
|
||||||
|
}).done(function (data) {
|
||||||
|
var _data = JSON.parse(data);
|
||||||
|
var tableName = "#datatable";
|
||||||
|
var str;
|
||||||
|
$.each(_data.columns, function (k, colObj) {
|
||||||
|
str = '<th>' + colObj + '</th>';
|
||||||
|
$(str).appendTo(tableName + '>thead>tr');
|
||||||
|
});
|
||||||
|
|
||||||
|
table = $('#datatable').DataTable({
|
||||||
|
dom: "Bfrtip",
|
||||||
|
responsive: true,
|
||||||
|
"drawCallback": function (settings) {
|
||||||
|
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||||||
|
addEventsCheck();
|
||||||
|
|
||||||
|
$("#datatable td").each(function(index, el) {
|
||||||
|
if( $(this).text().indexOf("recursos") >= 0 ){
|
||||||
|
var dummiimg = '<img src="'+ $(this).text() + '" style="width:250px; max-width: 100%;display: block;margin: 0 auto;" class="listimg" >';
|
||||||
|
$(this).html(dummiimg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#datatable td").each(function(index, el) {
|
||||||
|
if( $(this).text().indexOf("http") >= 0 && $(this).text().indexOf(".mp4") <= 0){
|
||||||
|
var link = decodeURI($(el).html());
|
||||||
|
var dummiimg = "<div class='openanimacion text-center' style='cursor:pointer;' onclick='window.open(`"+ link +"`);' >"+
|
||||||
|
"<img style='width:150px; max-width: 100%;display: block;margin: 0 auto;' src='../img/icons/214-worldwide.png' class='listimg p-3'></div>";
|
||||||
|
$(this).html(dummiimg);
|
||||||
|
}else if($(this).text().indexOf(".mp4") >= 0) {
|
||||||
|
var link = decodeURI($(el).html());
|
||||||
|
var dummiimg = "<div class='openanimacion text-center' style='cursor:pointer;' onclick='window.open(`"+ link +"`);' >"+
|
||||||
|
"<img style='width:150px; max-width: 100%;display: block;margin: 0 auto;' src='../img/icons/008-film.png' class='listimg p-3'></div>";
|
||||||
|
$(this).html(dummiimg);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
var link = decodeURI($(el).html());
|
||||||
|
var dummiimg = "<div class='openanimacion text-center' style='cursor: pointer;' onclick='window.open(`"+ link +"`);' >"+
|
||||||
|
"<video autoplay muted loop style='width:130px; display: block;margin: 0 auto;' src='"+ $(this).text() + "' class='listimg p-3'></video></div>";
|
||||||
|
$(this).html(dummiimg);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
buttons: [{
|
||||||
|
extend: 'excel',
|
||||||
|
text: 'Exportar a Excel'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Editar',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
editar(e, dt, node, config);
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_edit'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Alternar habilitar',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
deshabilitar(e, dt, node, config)
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_habilitar'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Crear',
|
||||||
|
action: function (e, dt, node, config) {
|
||||||
|
crear();
|
||||||
|
},
|
||||||
|
attr: {
|
||||||
|
id: 'btn_crear'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
'columnDefs': [{
|
||||||
|
'targets': 0,
|
||||||
|
'checkboxes': { 'selectRow': true }
|
||||||
|
}, {
|
||||||
|
'targets': 10,
|
||||||
|
'visible': false
|
||||||
|
}],
|
||||||
|
|
||||||
|
'order': [
|
||||||
|
[1, 'asc']
|
||||||
|
],
|
||||||
|
data: _data.datos,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
table.columns.adjust().draw();
|
||||||
|
$(window).resize(function (event) {
|
||||||
|
/* Act on the event */
|
||||||
|
table.columns.adjust().draw();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reloadData() {
|
||||||
|
listadoDeCategorias();
|
||||||
|
$.ajax({
|
||||||
|
url: 'recursos.php',
|
||||||
|
cache: false
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
var NewlyCreatedData = JSON.parse(data);
|
||||||
|
table.clear();
|
||||||
|
table.rows.add(NewlyCreatedData.datos); // Add new data
|
||||||
|
table.columns.adjust().draw(); // Redraw the DataTable
|
||||||
|
table.column(0).checkboxes.deselectAll();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addEventsCheck() {
|
||||||
|
$("#datatable input[type='checkbox']").on('change', function (e) {
|
||||||
|
setTimeout(function (){
|
||||||
|
console.log($("#datatable_wrapper input[type='checkbox']:checked").length);
|
||||||
|
if (table.column(0).checkboxes.selected().length == 0) {
|
||||||
|
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||||||
|
} else if (table.column(0).checkboxes.selected().length == 1) {
|
||||||
|
$("#btn_edit, #btn_habilitar").removeClass('disabled');
|
||||||
|
} else if (table.column(0).checkboxes.selected().length > 1) {
|
||||||
|
$("#btn_edit").addClass('disabled');
|
||||||
|
$("#btn_habilitar").removeClass('disabled');
|
||||||
|
}
|
||||||
|
}, 150);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
/****************** Editar, Deshabilitar, Crear ***********************/
|
||||||
|
/**********************************************************************/
|
||||||
|
|
||||||
|
function listadoDeCategorias() {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias_list.php',
|
||||||
|
type: 'POST',
|
||||||
|
cache: false
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = parseJSON(response);
|
||||||
|
if (_data.code == "1") {
|
||||||
|
$("#catsuperior").html("");
|
||||||
|
var _padres = _.filter(_data.datos, function (n) {
|
||||||
|
return n.padre == 0;
|
||||||
|
});
|
||||||
|
var _datos = _.groupBy(_data.datos, function (n) {
|
||||||
|
return n.padre;
|
||||||
|
});
|
||||||
|
|
||||||
|
$.each(_padres, function (index, val1) {
|
||||||
|
$("#catsuperior").append('<option disabled style="background-color: #959595; color: white;">' + val1.nombre + '</option>');
|
||||||
|
$.each(_datos, function (index, cats) {
|
||||||
|
$.each(cats, function (index, val) {
|
||||||
|
if (val.padre == val1.id || val.nombre == val1.nombre) {
|
||||||
|
if (val.nombre == val1.nombre) {
|
||||||
|
//$("[label='" + val1.nombre + "']").append('<option class="font-weight-bold" value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
} else {
|
||||||
|
$("#catsuperior").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
html: "Sin categorias",
|
||||||
|
icon: "error",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$(".btn_cancelar").click();
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$(".layer-load").hide();
|
||||||
|
//$('#catsuperior').selectpicker();
|
||||||
|
//if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
|
||||||
|
//$('#catsuperior').selectpicker('mobile');
|
||||||
|
//}
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function editar(e, dt, node, config) {
|
||||||
|
var $table = table.table().node();
|
||||||
|
var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
|
||||||
|
$($chkbox_checked).closest('tr')
|
||||||
|
var data = table.row($($chkbox_checked).closest('tr')).data();
|
||||||
|
$("#idrecurso").val(data[0]);
|
||||||
|
$("#clave").val(data[1]);
|
||||||
|
$("#nombre").val(data[2]);
|
||||||
|
$("#url").val(data[3]);
|
||||||
|
$("#habilitado").val(data[4]);
|
||||||
|
$("#desc").val(data[5]);
|
||||||
|
if (data[6] != null) {
|
||||||
|
var name = String(data[6]).split('/');
|
||||||
|
$(".preview").show();
|
||||||
|
$(".uploaded-files").html('<a class="btn-link" href="' + data[6] + '" target="_blank">' +
|
||||||
|
'<img class="img-fluid" src="' + data[6] + '"><br>' + name[name.length - 1] + '</a>');
|
||||||
|
$("#urlimgrecurso").val(data[6]);
|
||||||
|
}
|
||||||
|
console.log("catsup: "+data[9]);
|
||||||
|
var sel = $("#catsuperior");
|
||||||
|
var catid = (data[10] != null && data[10] !== "") ? String(data[10]) : "";
|
||||||
|
var nombreCat = (data[9] != null) ? $.trim(String(data[9])) : "";
|
||||||
|
sel.val("");
|
||||||
|
if (catid !== "" && sel.find("option[value='" + catid + "']").length) {
|
||||||
|
sel.val(catid);
|
||||||
|
} else {
|
||||||
|
var encontrado = false;
|
||||||
|
sel.find('option').each(function (index, el) {
|
||||||
|
if ($.trim($(this).text()) === nombreCat) {
|
||||||
|
sel.val($(this).attr('value'));
|
||||||
|
encontrado = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!encontrado && catid !== "") {
|
||||||
|
sel.append("<option value='" + catid + "'>" + nombreCat + "</option>");
|
||||||
|
sel.val(catid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$(".newimg").removeClass('newimg');
|
||||||
|
$(".controller").hide();
|
||||||
|
$(".editor").show();
|
||||||
|
$(".edit").show();
|
||||||
|
$(".crear").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deshabilitar(e, dt, node, config) {
|
||||||
|
var rows_selected = table.column(0).checkboxes.selected();
|
||||||
|
|
||||||
|
var ids = new Array();
|
||||||
|
$.each(rows_selected, function (index, rowId) {
|
||||||
|
ids.push(rowId);
|
||||||
|
});
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'recursos_delete.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { ids: ids },
|
||||||
|
cache: false
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
Swal.fire({
|
||||||
|
html: response,
|
||||||
|
icon: "success",
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
reloadData();
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function crear() {
|
||||||
|
|
||||||
|
$("#idrecurso").val("");
|
||||||
|
$("#nombre").val("");
|
||||||
|
$("#desc").val("");
|
||||||
|
$("#urlimgrecurso").val("");
|
||||||
|
$("#clave").val("");
|
||||||
|
$("#habilitado").val(1);
|
||||||
|
$("#url").val('');
|
||||||
|
$(".newimg").removeClass('newimg');
|
||||||
|
$(".controller").hide();
|
||||||
|
$(".editor").show();
|
||||||
|
$(".edit").hide();
|
||||||
|
$(".crear").show();
|
||||||
|
}
|
||||||
|
$(".btn_cancelar").click(function (event) {
|
||||||
|
$(".newimg").removeClass('newimg');
|
||||||
|
$(".previewscorm").hide();
|
||||||
|
$(".uploaded-scorm").html("");
|
||||||
|
uppyScorm.reset();
|
||||||
|
if ($(".uploaded-files").hasClass('newimg')) {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'recursos_deletefile.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: { file: $(".uploaded-files a").attr('href') },
|
||||||
|
cache: false
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function (error) {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
$(".uploaded-files").removeClass('newimg');
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$.validator.addMethod('validUrl', function(value, element) {
|
||||||
|
var url = $.validator.methods.url.bind(this);
|
||||||
|
var pattern = new RegExp("^(?:https?://|s?ftps?://)?(?!www | www\.)[A-Za-z0-9_-]+\.+[A-Za-z0-9.\/%&=\?_:;-]+$");
|
||||||
|
return pattern.test("http://localhost/git/estafeta-lms360/site/pkg/scorm_check/index.html");
|
||||||
|
}, 'Por favorsss, escribe una URL válida.');
|
||||||
|
|
||||||
|
$(".formcontroller").validate({
|
||||||
|
submitHandler: function (form) {
|
||||||
|
|
||||||
|
var controller = 'recursos_update.php';
|
||||||
|
if ($(".crear").css("display") == "block") {
|
||||||
|
controller = 'recursos_add.php';
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: controller,
|
||||||
|
type: 'POST',
|
||||||
|
data: $(".formcontroller").serializeArray(),
|
||||||
|
cache: false
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
//console.log("success");
|
||||||
|
Swal.fire({
|
||||||
|
html: response,
|
||||||
|
onBeforeOpen: function () {},
|
||||||
|
onOpen: function () {},
|
||||||
|
onRender: function () {},
|
||||||
|
onClose: function () {
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".ThumbnailGenerator, .uploaded-files").html("");
|
||||||
|
uppy.reset();
|
||||||
|
$(".preview").hide();
|
||||||
|
$(".controller").show();
|
||||||
|
$(".editor").hide();
|
||||||
|
reloadData();
|
||||||
|
$(".mainseccion").load("recursos.html", function () {
|
||||||
|
$(".layer-load").hide();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onAfterClose: function () {}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
//console.log("error");
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
//console.log("complete");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
nombre: {
|
||||||
|
required: true,
|
||||||
|
maxlength: 254,
|
||||||
|
minlength: 2,
|
||||||
|
normalizer: function( value ) {
|
||||||
|
return $.trim( value );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
required: true,
|
||||||
|
validUrl: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
getData();
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$sql="SELECT
|
||||||
|
scormpkg.id as id,
|
||||||
|
scormpkg.clave as Clave,
|
||||||
|
scormpkg.nombre as Nombre,
|
||||||
|
scormpkg.url as URL,
|
||||||
|
scormpkg.habilitado as Habilitado,
|
||||||
|
scormpkg.descripcion as 'Descripción',
|
||||||
|
scormpkg.imagen as 'Imagen',
|
||||||
|
scormpkg.creacion as 'Creación',
|
||||||
|
scormpkg.Actualizacion as 'Actualizacion',
|
||||||
|
categoria.nombre as 'Categoría',
|
||||||
|
scormpkg.idcategoria as 'idcategoria'
|
||||||
|
FROM
|
||||||
|
scormpkg
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
ORDER BY categoria.id ASC";
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
$return = new stdClass();
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin recursos";
|
||||||
|
$return->columns = ["id","Clave","Nombre","URL","Habilitado","Descripción","Imagen","Creación","Actualización","Categoría","idcategoria"];
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="recursos";
|
||||||
|
$return->datos = [];
|
||||||
|
$return->columns = [];
|
||||||
|
while ($row = mysqli_fetch_assoc ($result)){
|
||||||
|
$return->columns = array_keys($row);
|
||||||
|
}
|
||||||
|
mysqli_data_seek($result, 0);
|
||||||
|
while ($row = mysqli_fetch_row ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once __DIR__.'/audit.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$catsuperior = isset($_POST['catsuperior']) ? (int)$_POST['catsuperior'] : 0;
|
||||||
|
$nombre = isset($_POST['nombre']) ? $_POST['nombre'] : '';
|
||||||
|
$url = isset($_POST['url']) ? $_POST['url'] : '';
|
||||||
|
$desc = isset($_POST['desc']) ? $_POST['desc'] : '';
|
||||||
|
$clave = isset($_POST['clave']) ? $_POST['clave'] : '';
|
||||||
|
$habilitado = isset($_POST['habilitado']) ? (int)$_POST['habilitado'] : 0;
|
||||||
|
if (isset($_POST['urlimgrecurso']) && $_POST['urlimgrecurso'] !== "") {
|
||||||
|
$urlimgrecurso = $_POST['urlimgrecurso'];
|
||||||
|
} else {
|
||||||
|
$urlimgrecurso = $CFG->wwwroot.'img/icons/211-gift.png';
|
||||||
|
}
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
$sql = "INSERT INTO scormpkg (idcategoria, clave, nombre, url, habilitado, descripcion, imagen) VALUES (?,?,?,?,?,?,?)";
|
||||||
|
$stmt = mysqli_prepare($link, $sql);
|
||||||
|
if ($stmt) {
|
||||||
|
mysqli_stmt_bind_param($stmt, 'isssiss', $catsuperior, $clave, $nombre, $url, $habilitado, $desc, $urlimgrecurso);
|
||||||
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
|
audit_log('recurso_create', 'nombre=' . $nombre . ' cat=' . $catsuperior . ' url=' . $url);
|
||||||
|
echo "Recurso creado";
|
||||||
|
} else {
|
||||||
|
http_response_code(500);
|
||||||
|
echo "Error al crear recurso";
|
||||||
|
}
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
} else {
|
||||||
|
http_response_code(500);
|
||||||
|
echo "Error al preparar la consulta";
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once __DIR__.'/audit.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$ids = isset($_POST['ids']) ? (array)$_POST['ids'] : array();
|
||||||
|
$ids = array_values(array_filter(array_map('intval', $ids), function ($v) { return $v > 0; }));
|
||||||
|
if (!count($ids)) { echo "Sin identificadores"; exit; }
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$lista = implode(', ', $ids);
|
||||||
|
$sql = "UPDATE scormpkg SET habilitado = IF(habilitado=1, 0, 1) WHERE id IN ($lista)";
|
||||||
|
$result = mysqli_query($link, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($link), E_USER_ERROR);
|
||||||
|
audit_log('recurso_toggle', 'ids=' . $lista);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
?>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once("../config.php");
|
||||||
|
//$filelink = "http://localhost/git/estafeta-lms360/site/data/imgcat/tablero051594833914.png";
|
||||||
|
$filelink = $_POST["file"];
|
||||||
|
$filepath = getCurrentOrParentDirectory(parse_url ($filelink,PHP_URL_PATH) );
|
||||||
|
unlink($filepath);
|
||||||
|
function getCurrentOrParentDirectory( $filename )
|
||||||
|
{
|
||||||
|
echo '<p>'.$filename.'</p>';
|
||||||
|
$patharray = explode('/',$filename);
|
||||||
|
$path = $patharray[sizeof($patharray)-3].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-2].DIRECTORY_SEPARATOR.$patharray[sizeof($patharray)-1];
|
||||||
|
return ROOTPATH.$path;
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
$sql = "
|
||||||
|
SELECT
|
||||||
|
scormpkg.id,
|
||||||
|
scormpkg.nombre,
|
||||||
|
scormpkg.idcategoria,
|
||||||
|
categoria.nombre as catname
|
||||||
|
FROM
|
||||||
|
scormpkg
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
";
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
$result = mysqli_query($link, $sql);
|
||||||
|
$return = new stdClass();
|
||||||
|
if ( mysqli_num_rows($result) <= 0 ) {
|
||||||
|
$return->code = "0";
|
||||||
|
$return->msg="Sin recursos";
|
||||||
|
}else{
|
||||||
|
$return->code = "1";
|
||||||
|
$return->msg="recursos";
|
||||||
|
$return->datos = [];
|
||||||
|
while ($row = mysqli_fetch_array ($result)){
|
||||||
|
$return->datos[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
@@ -0,0 +1,277 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
// Subida de paquete SCORM (.zip): descomprime en data/scormpkg y devuelve la URL de index.html
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
$return = new stdClass();
|
||||||
|
|
||||||
|
function responder($return) {
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function slugScorm($text) {
|
||||||
|
$text = trim((string)$text);
|
||||||
|
$text = strtr($text, array(
|
||||||
|
'á'=>'a','à'=>'a','ä'=>'a','â'=>'a','Á'=>'A','À'=>'A','Ä'=>'A','Â'=>'A',
|
||||||
|
'é'=>'e','è'=>'e','ë'=>'e','ê'=>'e','É'=>'E','È'=>'E','Ë'=>'E','Ê'=>'E',
|
||||||
|
'í'=>'i','ì'=>'i','ï'=>'i','î'=>'i','Í'=>'I','Ì'=>'I','Ï'=>'I','Î'=>'I',
|
||||||
|
'ó'=>'o','ò'=>'o','ö'=>'o','ô'=>'o','Ó'=>'O','Ò'=>'O','Ö'=>'O','Ô'=>'O',
|
||||||
|
'ú'=>'u','ù'=>'u','ü'=>'u','û'=>'u','Ú'=>'U','Ù'=>'U','Ü'=>'U','Û'=>'U',
|
||||||
|
'ñ'=>'n','Ñ'=>'N'
|
||||||
|
));
|
||||||
|
$text = strtolower($text);
|
||||||
|
$text = preg_replace('~[^a-z0-9]+~', '-', $text);
|
||||||
|
$text = trim($text, '-');
|
||||||
|
if ($text === '') { $text = 'scorm'; }
|
||||||
|
return substr($text, 0, 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
function limpiarRuta($p) {
|
||||||
|
$p = str_replace('\\', '/', $p);
|
||||||
|
$absoluta = (substr($p, 0, 1) === '/');
|
||||||
|
$parts = array();
|
||||||
|
foreach (explode('/', $p) as $seg) {
|
||||||
|
if ($seg === '' || $seg === '.') continue;
|
||||||
|
if ($seg === '..') { array_pop($parts); continue; }
|
||||||
|
$parts[] = $seg;
|
||||||
|
}
|
||||||
|
return ($absoluta ? '/' : '') . implode('/', $parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buscarArchivoCI($dir, $nombre) {
|
||||||
|
$items = @scandir($dir);
|
||||||
|
if (!$items) return null;
|
||||||
|
foreach ($items as $it) {
|
||||||
|
if ($it === '.' || $it === '..') continue;
|
||||||
|
if (strcasecmp($it, $nombre) === 0 && is_file($dir . '/' . $it)) return $dir . '/' . $it;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function primerHtml($dir) {
|
||||||
|
$items = @scandir($dir);
|
||||||
|
if (!$items) return null;
|
||||||
|
foreach ($items as $it) {
|
||||||
|
if ($it === '.' || $it === '..') continue;
|
||||||
|
$p = $dir . '/' . $it;
|
||||||
|
if (is_file($p) && preg_match('~\.html?$~i', $it)) return $p;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hrefDeManifest($manifest) {
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
libxml_use_internal_errors(true);
|
||||||
|
$ok = @$doc->load($manifest);
|
||||||
|
libxml_clear_errors();
|
||||||
|
if (!$ok) return null;
|
||||||
|
|
||||||
|
$defaultOrg = '';
|
||||||
|
foreach ($doc->getElementsByTagName('organizations') as $orgs) {
|
||||||
|
$defaultOrg = $orgs->getAttribute('default');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ref = '';
|
||||||
|
foreach ($doc->getElementsByTagName('organization') as $org) {
|
||||||
|
if ($defaultOrg !== '' && $org->getAttribute('identifier') !== $defaultOrg) continue;
|
||||||
|
foreach ($org->getElementsByTagName('item') as $item) {
|
||||||
|
$ir = $item->getAttribute('identifierref');
|
||||||
|
if ($ir !== '') { $ref = $ir; break 2; }
|
||||||
|
}
|
||||||
|
if ($defaultOrg !== '') break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$resources = $doc->getElementsByTagName('resource');
|
||||||
|
$href = '';
|
||||||
|
if ($ref !== '') {
|
||||||
|
foreach ($resources as $res) {
|
||||||
|
if ($res->getAttribute('identifier') === $ref) { $href = $res->getAttribute('href'); break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($href === '') {
|
||||||
|
foreach ($resources as $res) {
|
||||||
|
$st = $res->getAttribute('adlcp:scormtype');
|
||||||
|
if ($st === '') { $st = $res->getAttributeNS('http://www.adlnet.org/xsd/adlcp_rootv1p2', 'scormtype'); }
|
||||||
|
if (strtolower($st) === 'sco') { $href = $res->getAttribute('href'); break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($href === '') {
|
||||||
|
foreach ($resources as $res) {
|
||||||
|
$h = $res->getAttribute('href');
|
||||||
|
if ($h !== '') { $href = $h; break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ($href !== '') ? $href : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function detectarEntrada($dest) {
|
||||||
|
// 1) imsmanifest.xml (raíz o un nivel dentro)
|
||||||
|
$manifests = array();
|
||||||
|
if (is_file($dest . '/imsmanifest.xml')) $manifests[] = $dest . '/imsmanifest.xml';
|
||||||
|
foreach (glob($dest . '/*', GLOB_ONLYDIR) as $sub) {
|
||||||
|
if (is_file($sub . '/imsmanifest.xml')) $manifests[] = $sub . '/imsmanifest.xml';
|
||||||
|
}
|
||||||
|
foreach ($manifests as $manifest) {
|
||||||
|
$href = hrefDeManifest($manifest);
|
||||||
|
if ($href) {
|
||||||
|
$cand = limpiarRuta(dirname($manifest) . '/' . urldecode($href));
|
||||||
|
if (is_file($cand)) return $cand;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) nombres comunes (Storyline index_lms.html / story.html, Rise/HTML index.html, etc.)
|
||||||
|
$nombres = array('index.html', 'index_lms.html', 'story.html', 'storyline.html', 'launch.html',
|
||||||
|
'scorm.html', 'scormindex.html', 'default.html', 'start.html', 'index.htm');
|
||||||
|
$dirs = array($dest);
|
||||||
|
foreach (glob($dest . '/*', GLOB_ONLYDIR) as $sub) { $dirs[] = $sub; }
|
||||||
|
foreach ($nombres as $n) {
|
||||||
|
foreach ($dirs as $d) {
|
||||||
|
$p = buscarArchivoCI($d, $n);
|
||||||
|
if ($p) return $p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3) primer .html/.htm
|
||||||
|
foreach ($dirs as $d) {
|
||||||
|
$p = primerHtml($d);
|
||||||
|
if ($p) return $p;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rrmdir($dir) {
|
||||||
|
if (!is_dir($dir)) return;
|
||||||
|
$items = @scandir($dir);
|
||||||
|
if (!$items) return;
|
||||||
|
foreach ($items as $it) {
|
||||||
|
if ($it === '.' || $it === '..') continue;
|
||||||
|
$p = $dir . '/' . $it;
|
||||||
|
if (is_dir($p)) { rrmdir($p); } else { @unlink($p); }
|
||||||
|
}
|
||||||
|
@rmdir($dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($_FILES['files']) || !is_array($_FILES['files']['tmp_name'])) {
|
||||||
|
$return->error = '1'; $return->txt = 'No se recibió ningún archivo.';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp = $_FILES['files']['tmp_name'][0];
|
||||||
|
$errCode = isset($_FILES['files']['error'][0]) ? $_FILES['files']['error'][0] : 1;
|
||||||
|
$orig = '';
|
||||||
|
if (!empty($_FILES['files']['name'][0])) { $orig = $_FILES['files']['name'][0]; }
|
||||||
|
elseif (!empty($_POST['name'])) { $orig = $_POST['name']; }
|
||||||
|
|
||||||
|
if ($errCode !== 0) {
|
||||||
|
$return->error = '1'; $return->txt = 'Error al subir el archivo (código ' . $errCode . ').';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ext = strtolower(pathinfo($orig, PATHINFO_EXTENSION));
|
||||||
|
if ($ext !== 'zip') {
|
||||||
|
$return->error = '1'; $return->txt = 'Solo se aceptan paquetes SCORM en formato .zip';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fh = @fopen($tmp, 'rb');
|
||||||
|
$magic = $fh ? fread($fh, 4) : '';
|
||||||
|
if ($fh) { fclose($fh); }
|
||||||
|
if (substr($magic, 0, 2) !== 'PK') {
|
||||||
|
$return->error = '1'; $return->txt = 'El archivo no es un ZIP válido.';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
$scormBase = dirname(__DIR__) . '/data/scormpkg';
|
||||||
|
if (!is_dir($scormBase)) { @mkdir($scormBase, 0775, true); }
|
||||||
|
if (!is_dir($scormBase) || !is_writable($scormBase)) {
|
||||||
|
$return->error = '1'; $return->txt = 'La carpeta data/scormpkg no existe o no tiene permisos de escritura.';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
$catSlug = 'general';
|
||||||
|
if (!empty($_POST['catid'])) {
|
||||||
|
$cid = intval($_POST['catid']);
|
||||||
|
if ($cid > 0) {
|
||||||
|
dbConnect();
|
||||||
|
global $link;
|
||||||
|
$resCat = mysqli_query($link, "select nombre from categoria where id = $cid limit 1");
|
||||||
|
if ($resCat && ($rowCat = mysqli_fetch_row($resCat))) {
|
||||||
|
$catSlug = slugScorm($rowCat[0]);
|
||||||
|
}
|
||||||
|
if ($resCat) { mysqli_free_result($resCat); }
|
||||||
|
mysqli_close($link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$destBase = $scormBase . '/' . $catSlug;
|
||||||
|
if (!is_dir($destBase)) { @mkdir($destBase, 0775, true); }
|
||||||
|
if (!is_dir($destBase) || !is_writable($destBase)) {
|
||||||
|
$return->error = '1'; $return->txt = 'No se pudo crear la carpeta de la categoría en data/scormpkg.';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
$slug = slugScorm(pathinfo($orig, PATHINFO_FILENAME));
|
||||||
|
$folder = $slug . '_' . time();
|
||||||
|
$dest = $destBase . '/' . $folder;
|
||||||
|
$i = 1;
|
||||||
|
while (file_exists($dest)) { $folder = $slug . '_' . time() . '_' . $i; $dest = $destBase . '/' . $folder; $i++; }
|
||||||
|
|
||||||
|
$zip = new ZipArchive();
|
||||||
|
if ($zip->open($tmp) !== true) {
|
||||||
|
$return->error = '1'; $return->txt = 'No se pudo abrir el paquete .zip';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
$totalSize = 0; $numEntries = 0;
|
||||||
|
for ($idx = 0; $idx < $zip->numFiles; $idx++) {
|
||||||
|
$stat = $zip->statIndex($idx);
|
||||||
|
$name = $stat['name'];
|
||||||
|
$numEntries++;
|
||||||
|
$totalSize += $stat['size'];
|
||||||
|
if (preg_match('~^(/|\\\\|[A-Za-z]:)~', $name) || strpos($name, '..') !== false) {
|
||||||
|
$zip->close();
|
||||||
|
$return->error = '1'; $return->txt = 'El .zip contiene rutas no permitidas.';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
if ($numEntries > 20000 || $totalSize > 2147483648) {
|
||||||
|
$zip->close();
|
||||||
|
$return->error = '1'; $return->txt = 'El paquete es demasiado grande.';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!@mkdir($dest, 0775, true)) {
|
||||||
|
$zip->close();
|
||||||
|
$return->error = '1'; $return->txt = 'No se pudo crear la carpeta destino.';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$zip->extractTo($dest)) {
|
||||||
|
$zip->close();
|
||||||
|
rrmdir($dest);
|
||||||
|
$return->error = '1'; $return->txt = 'No se pudo descomprimir el paquete.';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
$indexPath = detectarEntrada($dest);
|
||||||
|
if (!$indexPath) {
|
||||||
|
rrmdir($dest);
|
||||||
|
$return->error = '1'; $return->txt = 'No se encontró un archivo de inicio (index.html / imsmanifest.xml) en el paquete SCORM.';
|
||||||
|
responder($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
$baseReal = realpath($scormBase);
|
||||||
|
$indexReal = realpath($indexPath);
|
||||||
|
$rel = ltrim(str_replace('\\', '/', substr($indexReal, strlen($baseReal))), '/');
|
||||||
|
|
||||||
|
$return->error = '0';
|
||||||
|
$return->category = $catSlug;
|
||||||
|
$return->folder = $catSlug . '/' . $folder;
|
||||||
|
$return->url = $CFG->wwwroot . 'data/scormpkg/' . $rel;
|
||||||
|
responder($return);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once __DIR__.'/audit.php';
|
||||||
|
require_once "../config.php";
|
||||||
|
|
||||||
|
$idrecurso = isset($_POST['idrecurso']) ? (int)$_POST['idrecurso'] : 0;
|
||||||
|
$catsuperior = isset($_POST['catsuperior']) ? (int)$_POST['catsuperior'] : 0;
|
||||||
|
$nombre = isset($_POST['nombre']) ? $_POST['nombre'] : '';
|
||||||
|
$url = isset($_POST['url']) ? $_POST['url'] : '';
|
||||||
|
$desc = isset($_POST['desc']) ? $_POST['desc'] : '';
|
||||||
|
$clave = isset($_POST['clave']) ? $_POST['clave'] : '';
|
||||||
|
$habilitado = isset($_POST['habilitado']) ? (int)$_POST['habilitado'] : 0;
|
||||||
|
if (isset($_POST['urlimgrecurso']) && $_POST['urlimgrecurso'] !== "") {
|
||||||
|
$urlimgrecurso = $_POST['urlimgrecurso'];
|
||||||
|
} else {
|
||||||
|
$urlimgrecurso = $CFG->wwwroot.'img/icons/211-gift.png';
|
||||||
|
}
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
$sql = "UPDATE scormpkg SET idcategoria=?, clave=?, nombre=?, url=?, descripcion=?, habilitado=?, imagen=? WHERE id=?";
|
||||||
|
$stmt = mysqli_prepare($link, $sql);
|
||||||
|
if ($stmt) {
|
||||||
|
mysqli_stmt_bind_param($stmt, 'issssisi', $catsuperior, $clave, $nombre, $url, $desc, $habilitado, $urlimgrecurso, $idrecurso);
|
||||||
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
|
audit_log('recurso_update', 'id=' . $idrecurso . ' nombre=' . $nombre . ' cat=' . $catsuperior . ' url=' . $url);
|
||||||
|
echo "Actualización correcta";
|
||||||
|
} else {
|
||||||
|
http_response_code(500);
|
||||||
|
echo "Error al actualizar recurso";
|
||||||
|
}
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
} else {
|
||||||
|
http_response_code(500);
|
||||||
|
echo "Error al preparar la consulta";
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
// upload.php
|
||||||
|
require_once "../config.php";
|
||||||
|
$return = new stdClass();
|
||||||
|
$files = $_FILES['files'];
|
||||||
|
$file_path = $files['tmp_name'][0]; // temporary upload path of the first file
|
||||||
|
$file_name = $_POST['name']; // desired name of the file
|
||||||
|
|
||||||
|
$file_basename = substr($file_name, 0, strripos($file_name, '.')); // This returns file name
|
||||||
|
$file_ext = substr($file_name, strripos($file_name, '.')); // This returns file ext
|
||||||
|
$file_name = $file_basename .round(microtime(true)) . $file_ext ;
|
||||||
|
|
||||||
|
$file_type = $files['type'][0]; //returns the mimetype
|
||||||
|
$allowed = array("image/jpeg", "image/gif", "image/png", "image/jpg");
|
||||||
|
if(!in_array($file_type, $allowed)) {
|
||||||
|
$return->txt = 'Solo se aceptan jpg, gif, y png.';
|
||||||
|
$return->error = '1';
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filex = '../data/recursos/' . basename($file_name) ;
|
||||||
|
move_uploaded_file($file_path, $filex); //
|
||||||
|
$return->error = '0';
|
||||||
|
$return->url= $CFG->wwwroot.'data/recursos/' . basename($file_name);
|
||||||
|
//$return->url= $file_path . basename($file_name);
|
||||||
|
echo json_encode($return, JSON_UNESCAPED_UNICODE);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,935 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once("../config.php");
|
||||||
|
require_once("../runtime/encrypt.php");
|
||||||
|
dbConnect();
|
||||||
|
global $link;
|
||||||
|
$resultados = [];
|
||||||
|
$fechainicio = $_GET['fechaini'];
|
||||||
|
$fechafin = $_GET['fechafin'];
|
||||||
|
$estado = $_GET['estado'];
|
||||||
|
$headers = [
|
||||||
|
'Estado del empleado',
|
||||||
|
'Número de empleado',
|
||||||
|
'Nombres(s)',
|
||||||
|
'Apellidos',
|
||||||
|
'Posición',
|
||||||
|
'Sociedad',
|
||||||
|
'División',
|
||||||
|
'Unidad organizativa',
|
||||||
|
'CeCo',
|
||||||
|
'Centro de trabajo',
|
||||||
|
'Distrito',
|
||||||
|
'Supervisor'
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
if ($fechainicio == '' && $fechafin == '' && $estado == 'all' ) {
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.nombre,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
CASE
|
||||||
|
WHEN ( COUNT( rs1.cat) = ( SELECT COUNT( * ) FROM categoria WHERE categoria.padre = rs1.cat AND categoria.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado1
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre as nombre,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
user.distritonom AS nomcentro,
|
||||||
|
user.centrotrabajonom AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN Round( SUM( scormvars.varValue ), 2 ) >= 0 THEN
|
||||||
|
ROUND(
|
||||||
|
(
|
||||||
|
Round( SUM( scormvars.varValue ), 2 ) / ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
),
|
||||||
|
2
|
||||||
|
) ELSE '--'
|
||||||
|
END AS calificacion,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN ( COUNT( scormvars.varValue ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
CASE
|
||||||
|
WHEN scormvars.numempl <> '' THEN
|
||||||
|
CONCAT(
|
||||||
|
COUNT( scormvars.varValue ),
|
||||||
|
' de ',
|
||||||
|
( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1)
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormvars
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.lesson_status'
|
||||||
|
AND (scormvars.varValue = 'completed' OR scormvars.varValue = 'passed')
|
||||||
|
AND scormvars.numempl <> ''
|
||||||
|
AND scormpkg.habilitado = 1
|
||||||
|
GROUP BY
|
||||||
|
scormvars.numempl,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( scormvars.fecha )
|
||||||
|
ORDER BY
|
||||||
|
scormpkg.idcategoria ASC
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE rs1.estado = 'Completado'
|
||||||
|
GROUP BY rs1.numempl,rs1.cat
|
||||||
|
ORDER BY c.nombre,rs1.cat
|
||||||
|
) AS rs2
|
||||||
|
ORDER BY rs2.numempl ASC";
|
||||||
|
}else if ($fechainicio == '' && $fechafin == '' && $estado != 'all') {
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.nombre,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
CASE
|
||||||
|
WHEN ( COUNT( rs1.cat) = ( SELECT COUNT( * ) FROM categoria WHERE categoria.padre = rs1.cat AND categoria.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado1
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre as nombre,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
user.distritonom AS nomcentro,
|
||||||
|
user.centrotrabajonom AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN Round( SUM( scormvars.varValue ), 2 ) >= 0 THEN
|
||||||
|
ROUND(
|
||||||
|
(
|
||||||
|
Round( SUM( scormvars.varValue ), 2 ) / ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
),
|
||||||
|
2
|
||||||
|
) ELSE '--'
|
||||||
|
END AS calificacion,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN ( COUNT( scormvars.varValue ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
CASE
|
||||||
|
WHEN scormvars.numempl <> '' THEN
|
||||||
|
CONCAT(
|
||||||
|
COUNT( scormvars.varValue ),
|
||||||
|
' de ',
|
||||||
|
( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1)
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormvars
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.lesson_status'
|
||||||
|
AND (scormvars.varValue = 'completed' OR scormvars.varValue = 'passed')
|
||||||
|
AND scormvars.numempl <> ''
|
||||||
|
AND scormpkg.habilitado = 1
|
||||||
|
AND user.habilitado = $estado
|
||||||
|
GROUP BY
|
||||||
|
scormvars.numempl,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( fecha )
|
||||||
|
ORDER BY
|
||||||
|
scormpkg.idcategoria ASC
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE rs1.estado = 'Completado'
|
||||||
|
GROUP BY rs1.numempl,rs1.cat
|
||||||
|
ORDER BY c.nombre,rs1.cat
|
||||||
|
) AS rs2
|
||||||
|
ORDER BY rs2.numempl ASC";
|
||||||
|
|
||||||
|
}else if ($fechainicio != '' && $fechafin != '' && $estado == 'all') {
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.nombre,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
CASE
|
||||||
|
WHEN ( COUNT( rs1.cat) = ( SELECT COUNT( * ) FROM categoria WHERE categoria.padre = rs1.cat AND categoria.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado1
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre as nombre,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
user.distritonom AS nomcentro,
|
||||||
|
user.centrotrabajonom AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN Round( SUM( scormvars.varValue ), 2 ) >= 0 THEN
|
||||||
|
ROUND(
|
||||||
|
(
|
||||||
|
Round( SUM( scormvars.varValue ), 2 ) / ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
),
|
||||||
|
2
|
||||||
|
) ELSE '--'
|
||||||
|
END AS calificacion,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN ( COUNT( scormvars.varValue ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
CASE
|
||||||
|
WHEN scormvars.numempl <> '' THEN
|
||||||
|
CONCAT(
|
||||||
|
COUNT( scormvars.varValue ),
|
||||||
|
' de ',
|
||||||
|
( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1)
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormvars
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.lesson_status'
|
||||||
|
AND (scormvars.varValue = 'completed' OR scormvars.varValue = 'passed')
|
||||||
|
AND scormvars.numempl <> ''
|
||||||
|
AND scormpkg.habilitado = 1
|
||||||
|
AND scormvars.fecha BETWEEN '$fechainicio' AND '$fechafin'
|
||||||
|
GROUP BY
|
||||||
|
scormvars.numempl,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( fecha )
|
||||||
|
ORDER BY
|
||||||
|
scormpkg.idcategoria ASC
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE rs1.estado = 'Completado'
|
||||||
|
GROUP BY rs1.numempl,rs1.cat
|
||||||
|
ORDER BY c.nombre,rs1.cat
|
||||||
|
) AS rs2
|
||||||
|
ORDER BY rs2.numempl ASC ";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}else if ($fechainicio != '' && $fechafin == '' && $estado == 'all') {
|
||||||
|
$fechafin = date('Y-m-d');
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.nombre,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
CASE
|
||||||
|
WHEN ( COUNT( rs1.cat) = ( SELECT COUNT( * ) FROM categoria WHERE categoria.padre = rs1.cat AND categoria.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado1
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre as nombre,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
user.distritonom AS nomcentro,
|
||||||
|
user.centrotrabajonom AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN Round( SUM( scormvars.varValue ), 2 ) >= 0 THEN
|
||||||
|
ROUND(
|
||||||
|
(
|
||||||
|
Round( SUM( scormvars.varValue ), 2 ) / ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
),
|
||||||
|
2
|
||||||
|
) ELSE '--'
|
||||||
|
END AS calificacion,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN ( COUNT( scormvars.varValue ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
CASE
|
||||||
|
WHEN scormvars.numempl <> '' THEN
|
||||||
|
CONCAT(
|
||||||
|
COUNT( scormvars.varValue ),
|
||||||
|
' de ',
|
||||||
|
( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1)
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormvars
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.lesson_status'
|
||||||
|
AND (scormvars.varValue = 'completed' OR scormvars.varValue = 'passed')
|
||||||
|
AND scormvars.numempl <> ''
|
||||||
|
AND scormpkg.habilitado = 1
|
||||||
|
AND scormvars.fecha BETWEEN '$fechainicio' AND '$fechafin'
|
||||||
|
GROUP BY
|
||||||
|
scormvars.numempl,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( fecha )
|
||||||
|
ORDER BY
|
||||||
|
scormpkg.idcategoria ASC
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE rs1.estado = 'Completado'
|
||||||
|
GROUP BY rs1.numempl,rs1.cat
|
||||||
|
ORDER BY c.nombre,rs1.cat
|
||||||
|
) AS rs2
|
||||||
|
ORDER BY rs2.numempl ASC";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}else if ($fechainicio == '' && $fechafin != '' && $estado == 'all') {
|
||||||
|
$fechainicio = '2020-07-01';
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.nombre,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
CASE
|
||||||
|
WHEN ( COUNT( rs1.cat) = ( SELECT COUNT( * ) FROM categoria WHERE categoria.padre = rs1.cat AND categoria.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado1
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre as nombre,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
user.distritonom AS nomcentro,
|
||||||
|
user.centrotrabajonom AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN Round( SUM( scormvars.varValue ), 2 ) >= 0 THEN
|
||||||
|
ROUND(
|
||||||
|
(
|
||||||
|
Round( SUM( scormvars.varValue ), 2 ) / ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
),
|
||||||
|
2
|
||||||
|
) ELSE '--'
|
||||||
|
END AS calificacion,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN ( COUNT( scormvars.varValue ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
CASE
|
||||||
|
WHEN scormvars.numempl <> '' THEN
|
||||||
|
CONCAT(
|
||||||
|
COUNT( scormvars.varValue ),
|
||||||
|
' de ',
|
||||||
|
( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1)
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormvars
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.lesson_status'
|
||||||
|
AND (scormvars.varValue = 'completed' OR scormvars.varValue = 'passed')
|
||||||
|
AND scormvars.numempl <> ''
|
||||||
|
AND scormpkg.habilitado = 1
|
||||||
|
AND scormvars.fecha BETWEEN '$fechainicio' AND '$fechafin'
|
||||||
|
GROUP BY
|
||||||
|
scormvars.numempl,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( fecha )
|
||||||
|
ORDER BY
|
||||||
|
scormpkg.idcategoria ASC
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE rs1.estado = 'Completado'
|
||||||
|
GROUP BY rs1.numempl,rs1.cat
|
||||||
|
ORDER BY c.nombre,rs1.cat
|
||||||
|
) AS rs2
|
||||||
|
ORDER BY rs2.numempl ASC";
|
||||||
|
|
||||||
|
}else if ($fechainicio != '' && $fechafin != '' && $estado != 'all') {
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.nombre,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
CASE
|
||||||
|
WHEN ( COUNT( rs1.cat) = ( SELECT COUNT( * ) FROM categoria WHERE categoria.padre = rs1.cat AND categoria.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado1
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre as nombre,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
user.distritonom AS nomcentro,
|
||||||
|
user.centrotrabajonom AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN Round( SUM( scormvars.varValue ), 2 ) >= 0 THEN
|
||||||
|
ROUND(
|
||||||
|
(
|
||||||
|
Round( SUM( scormvars.varValue ), 2 ) / ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
),
|
||||||
|
2
|
||||||
|
) ELSE '--'
|
||||||
|
END AS calificacion,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN ( COUNT( scormvars.varValue ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
CASE
|
||||||
|
WHEN scormvars.numempl <> '' THEN
|
||||||
|
CONCAT(
|
||||||
|
COUNT( scormvars.varValue ),
|
||||||
|
' de ',
|
||||||
|
( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1)
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormvars
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.lesson_status'
|
||||||
|
AND (scormvars.varValue = 'completed' OR scormvars.varValue = 'passed')
|
||||||
|
AND scormvars.numempl <> ''
|
||||||
|
AND scormpkg.habilitado = 1
|
||||||
|
AND scormvars.fecha BETWEEN '$fechainicio' AND '$fechafin'
|
||||||
|
AND user.habilitado = $estado
|
||||||
|
GROUP BY
|
||||||
|
scormvars.numempl,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( fecha )
|
||||||
|
ORDER BY
|
||||||
|
scormpkg.idcategoria ASC
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE rs1.estado = 'Completado'
|
||||||
|
GROUP BY rs1.numempl,rs1.cat
|
||||||
|
ORDER BY c.nombre,rs1.cat
|
||||||
|
) AS rs2
|
||||||
|
ORDER BY rs2.numempl ASC ";
|
||||||
|
|
||||||
|
}else if($fechainicio != '' && $fechafin == '' && $estado != 'all'){
|
||||||
|
$fechafin = date('Y-m-d');
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.nombre,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
CASE
|
||||||
|
WHEN ( COUNT( rs1.cat) = ( SELECT COUNT( * ) FROM categoria WHERE categoria.padre = rs1.cat AND categoria.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado1
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre as nombre,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
user.distritonom AS nomcentro,
|
||||||
|
user.centrotrabajonom AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN Round( SUM( scormvars.varValue ), 2 ) >= 0 THEN
|
||||||
|
ROUND(
|
||||||
|
(
|
||||||
|
Round( SUM( scormvars.varValue ), 2 ) / ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
),
|
||||||
|
2
|
||||||
|
) ELSE '--'
|
||||||
|
END AS calificacion,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN ( COUNT( scormvars.varValue ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
CASE
|
||||||
|
WHEN scormvars.numempl <> '' THEN
|
||||||
|
CONCAT(
|
||||||
|
COUNT( scormvars.varValue ),
|
||||||
|
' de ',
|
||||||
|
( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1)
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormvars
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.lesson_status'
|
||||||
|
AND (scormvars.varValue = 'completed' OR scormvars.varValue = 'passed')
|
||||||
|
AND scormvars.numempl <> ''
|
||||||
|
ANS scormpkg.habilitado = 1
|
||||||
|
AND scormvars.fecha BETWEEN '$fechainicio' AND '$fechafin'
|
||||||
|
AND user.habilitado = $estado
|
||||||
|
GROUP BY
|
||||||
|
scormvars.numempl,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( fecha )
|
||||||
|
ORDER BY
|
||||||
|
scormpkg.idcategoria ASC
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE rs1.estado = 'Completado'
|
||||||
|
GROUP BY rs1.numempl,rs1.cat
|
||||||
|
ORDER BY c.nombre,rs1.cat
|
||||||
|
) AS rs2
|
||||||
|
ORDER BY rs2.numempl ASC";
|
||||||
|
|
||||||
|
}elseif($fechainicio == '' && $fechafin != '' && $estado != 'all'){
|
||||||
|
$fechainicio = '2020-07-01';
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.nombre,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
CASE
|
||||||
|
WHEN ( COUNT( rs1.cat) = ( SELECT COUNT( * ) FROM categoria WHERE categoria.padre = rs1.cat AND categoria.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado1
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre as nombre,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
user.distritonom AS nomcentro,
|
||||||
|
user.centrotrabajonom AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN Round( SUM( scormvars.varValue ), 2 ) >= 0 THEN
|
||||||
|
ROUND(
|
||||||
|
(
|
||||||
|
Round( SUM( scormvars.varValue ), 2 ) / ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
),
|
||||||
|
2
|
||||||
|
) ELSE '--'
|
||||||
|
END AS calificacion,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN ( COUNT( scormvars.varValue ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
CASE
|
||||||
|
WHEN scormvars.numempl <> '' THEN
|
||||||
|
CONCAT(
|
||||||
|
COUNT( scormvars.varValue ),
|
||||||
|
' de ',
|
||||||
|
( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1)
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormvars
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.lesson_status'
|
||||||
|
AND (scormvars.varValue = 'completed' OR scormvars.varValue = 'passed')
|
||||||
|
AND scormvars.numempl <> ''
|
||||||
|
AND scormpkg.habilitado = 1
|
||||||
|
AND scormvars.fecha BETWEEN '$fechainicio' AND '$fechafin'
|
||||||
|
AND user.habilitado = $estado
|
||||||
|
GROUP BY
|
||||||
|
scormvars.numempl,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( fecha )
|
||||||
|
ORDER BY
|
||||||
|
scormpkg.idcategoria ASC
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE rs1.estado = 'Completado'
|
||||||
|
GROUP BY rs1.numempl,rs1.cat
|
||||||
|
ORDER BY c.nombre,rs1.cat
|
||||||
|
) AS rs2
|
||||||
|
ORDER BY rs2.numempl ASC ";
|
||||||
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$sqlusers = "SELECT * FROM viewReporteCategorias;";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$resultusers = mysqli_query($link, $sqlusers);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if( $resultusers ){
|
||||||
|
if (mysqli_num_rows($resultusers) <= 0 ) {
|
||||||
|
$data = [];
|
||||||
|
}else{
|
||||||
|
mysqli_data_seek($resultusers, 0);
|
||||||
|
while ($row = mysqli_fetch_assoc ($resultusers)){
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sqlcolumns = "SELECT
|
||||||
|
categoria.id,
|
||||||
|
categoria.clave,
|
||||||
|
categoria.nombre
|
||||||
|
FROM
|
||||||
|
categoria
|
||||||
|
WHERE
|
||||||
|
padre = 0 AND habilitado = 1
|
||||||
|
ORDER BY categoria.id";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$resultcolumn= mysqli_query($link, $sqlcolumns);
|
||||||
|
|
||||||
|
if( $resultcolumn ){
|
||||||
|
mysqli_data_seek($resultcolumn, 0);
|
||||||
|
while ($row = mysqli_fetch_assoc ($resultcolumn)){
|
||||||
|
$categorias[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$columnasvisibles= array(
|
||||||
|
'Estado del empleado',
|
||||||
|
'Número de empleado',
|
||||||
|
'Nombres(s)',
|
||||||
|
'Apellidos',
|
||||||
|
'Posición',
|
||||||
|
'Sociedad',
|
||||||
|
'División',
|
||||||
|
'Unidad organizativa',
|
||||||
|
'CeCo',
|
||||||
|
'Centro de trabajo',
|
||||||
|
'Distrito',
|
||||||
|
'Supervisor'
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($categorias as $key2 => $cat) {
|
||||||
|
array_push($headers, $cat['nombre']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
for ($i=0; $i < sizeof($headers) ; $i++) {
|
||||||
|
$headers[$i] = array('title' => $headers[$i]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
array_push($resultados,$headers);
|
||||||
|
|
||||||
|
if (!empty($data)) {
|
||||||
|
$anterior = '';
|
||||||
|
$users = 0;
|
||||||
|
foreach ($data as $key1 => $col) {
|
||||||
|
//print_r($col);
|
||||||
|
//echo $col[2]."<br>";
|
||||||
|
if ($col['numempl'] == $anterior) {
|
||||||
|
//echo $col['numempl']." igual - ".$col['nomcat']."- ".$users." <br>";
|
||||||
|
$datos[($users-1)][$col['nomcat']] = $col['estado1'];
|
||||||
|
}else{
|
||||||
|
//echo $col['numempl']." nuevo - ".$col['nomcat']." - ".$users." <br>";
|
||||||
|
|
||||||
|
$datos[$users] = ['estado_empleado' => $col['estado_empleado'],'numempl' => $col['numempl'],'nombre' => $col['nombre'],'apellidos' =>$col['apellidos'],'posicion'=>$col['posicion'],'sociedad'=> $col['sociedad'],'division'=> $col['division'],'unidad_organizativa' => $col['unidad_organizativa'],'ceco'=>$col['ceco'],'nomdistrito'=>$col['nomdistrito'], 'nomcentro' => $col['nomcentro'],'supervisor'=>$col['supervisor']];
|
||||||
|
|
||||||
|
foreach ($categorias as $key2 => $cat) {
|
||||||
|
if ($cat['nombre'] == $col['nomcat']) {
|
||||||
|
$datos[$users][$cat['nombre']] = $col['estado1'];;
|
||||||
|
}else{
|
||||||
|
$datos[$users][$cat['nombre']] = 'No completado';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$users++;
|
||||||
|
}
|
||||||
|
$anterior = $col['numempl'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//print_r($datos[0]);
|
||||||
|
foreach ($datos as $col => $columnas) {
|
||||||
|
$fill = [];
|
||||||
|
foreach ($columnas as $key => $value) {
|
||||||
|
array_push($fill, $value);
|
||||||
|
}
|
||||||
|
$datos[$col] = $fill;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$datos = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($datos as $key => $val) {
|
||||||
|
$obj = [
|
||||||
|
$val[0],
|
||||||
|
$val[1],
|
||||||
|
$val[2],
|
||||||
|
$val[3],
|
||||||
|
$val[4],
|
||||||
|
$val[5],
|
||||||
|
$val[6],
|
||||||
|
$val[7],
|
||||||
|
$val[8],
|
||||||
|
$val[9],
|
||||||
|
$val[10],
|
||||||
|
$val[11],
|
||||||
|
$val[12],
|
||||||
|
$val[13],
|
||||||
|
$val[14],
|
||||||
|
$val[15],
|
||||||
|
$val[16],
|
||||||
|
$val[17],
|
||||||
|
$val[18]
|
||||||
|
];
|
||||||
|
array_push($resultados,$obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function cleanData(&$str)
|
||||||
|
{
|
||||||
|
$str = mb_convert_encoding($str , 'UTF-16LE' ,'UTF-8');
|
||||||
|
$str = preg_replace("/\t/", " ", $str);
|
||||||
|
$str = preg_replace("/\r?\n/", " ", $str);
|
||||||
|
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// filename for download
|
||||||
|
$filename = "reporte - Categorías completadas __" . date('Ymd') . ".csv";
|
||||||
|
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||||
|
header("Content-Type: text/csv");
|
||||||
|
$out = fopen("php://output", 'w');
|
||||||
|
$flag = false;
|
||||||
|
|
||||||
|
foreach ($resultados as $row) {
|
||||||
|
|
||||||
|
array_walk($row, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($row), ',', '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($out);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,340 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
|
||||||
|
require_once("../config.php");
|
||||||
|
|
||||||
|
require_once("../runtime/encrypt.php");
|
||||||
|
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
|
||||||
|
$resultados = [];
|
||||||
|
$fechainicio = $_GET['fechaini'];
|
||||||
|
$fechainiciotxt = $_GET['fechaini'];
|
||||||
|
$fechafin = $_GET['fechafin'];
|
||||||
|
$fechafintxt = $_GET['fechafin'];
|
||||||
|
$estado_ini = $_GET['estado'];
|
||||||
|
|
||||||
|
if ($estado_ini == 'all') {
|
||||||
|
$estado = 'IN (0,1)';
|
||||||
|
}else{
|
||||||
|
$estado = '= '.$estado_ini;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fechainicio == '') {
|
||||||
|
$fechainicio = '2020-07-01';
|
||||||
|
}else{
|
||||||
|
$fechainicio = "'".$fechainicio."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fechafin == '') {
|
||||||
|
$fechafin = date('Y-m-d', strtotime($fechafin."+ 1 days") );
|
||||||
|
}else{
|
||||||
|
$fechafin = "'".$fechafin."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$categoria = $_GET['categoria'];
|
||||||
|
|
||||||
|
$headers = [
|
||||||
|
'Estado del empleado',
|
||||||
|
'Número de empleado',
|
||||||
|
'Nombres(s)',
|
||||||
|
'Apellidos',
|
||||||
|
'Posición',
|
||||||
|
'Sociedad',
|
||||||
|
'División',
|
||||||
|
'Unidad organizativa',
|
||||||
|
'CeCo',
|
||||||
|
'Centro de trabajo',
|
||||||
|
'Distrito',
|
||||||
|
'Supervisor'
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
$sqlasignados = "SELECT user.userid
|
||||||
|
FROM asignacion
|
||||||
|
INNER JOIN user ON asignacion.uid = user.userid
|
||||||
|
INNER JOIN categoria ON asignacion.catid = categoria.id
|
||||||
|
WHERE user.habilitado $estado AND categoria.habilitado = 1 AND catid = $categoria";
|
||||||
|
|
||||||
|
|
||||||
|
$resultasignacion = mysqli_query($link, $sqlasignados);
|
||||||
|
|
||||||
|
|
||||||
|
if( $resultasignacion ){
|
||||||
|
if (mysqli_num_rows($resultasignacion) <= 0 ) {
|
||||||
|
$data_asignacion = [];
|
||||||
|
}else{
|
||||||
|
mysqli_data_seek($resultasignacion, 0);
|
||||||
|
while ($row = mysqli_fetch_assoc ($resultasignacion)){
|
||||||
|
$data_asignacion[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$cad_numempl = '';
|
||||||
|
$total_asignados = sizeof($data_asignacion);
|
||||||
|
foreach ($data_asignacion as $key => $val) {
|
||||||
|
if ($key == ($total_asignados-1)) {
|
||||||
|
$cad_numempl .= $val['userid'];
|
||||||
|
}else{
|
||||||
|
$cad_numempl .= $val['userid'].",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$sqlreporte = "SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
rs1.cat,
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.nombre,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
CASE
|
||||||
|
WHEN ( COUNT( rs1.cat) = ( SELECT COUNT( * ) FROM categoria WHERE categoria.padre = rs1.cat AND categoria.habilitado = 1) ) THEN
|
||||||
|
CASE
|
||||||
|
WHEN rs1.estado = 'Completado' THEN
|
||||||
|
'Completado'
|
||||||
|
ELSE
|
||||||
|
'No Completado'
|
||||||
|
END
|
||||||
|
|
||||||
|
ELSE 'No Completado'
|
||||||
|
END AS estado1
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormresults.userid,
|
||||||
|
user.numempl AS numempl,
|
||||||
|
user.nombre as nombre,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
user.distritonom AS nomcentro,
|
||||||
|
user.centrotrabajonom AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
CASE
|
||||||
|
WHEN ( COUNT( scormresults.status ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id AND scormpkg.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
DATE_FORMAT(scormresults.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormresults
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormresults.scormid
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.userid = scormresults.userid
|
||||||
|
WHERE
|
||||||
|
(scormresults.status = 'completed' OR scormresults.status = 'passed')
|
||||||
|
AND scormresults.userid IN ($cad_numempl)
|
||||||
|
AND scormresults.fecha BETWEEN $fechainicio AND $fechafin
|
||||||
|
AND scormpkg.habilitado = 1
|
||||||
|
AND user.habilitado $estado
|
||||||
|
GROUP BY
|
||||||
|
scormresults.userid,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( fecha )
|
||||||
|
ORDER BY
|
||||||
|
scormpkg.idcategoria ASC
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE rs1.estado = 'Completado' AND rs1.cat = $categoria
|
||||||
|
GROUP BY rs1.numempl,rs1.cat
|
||||||
|
ORDER BY c.nombre,rs1.cat
|
||||||
|
) AS rs2
|
||||||
|
ORDER BY rs2.numempl ASC
|
||||||
|
limit $total_asignados";
|
||||||
|
|
||||||
|
|
||||||
|
$resultusers = mysqli_query($link, $sqlreporte);
|
||||||
|
|
||||||
|
|
||||||
|
if( $resultusers ){
|
||||||
|
if (mysqli_num_rows($resultusers) <= 0 ) {
|
||||||
|
$data = [];
|
||||||
|
}else{
|
||||||
|
mysqli_data_seek($resultusers, 0);
|
||||||
|
while ($row = mysqli_fetch_assoc ($resultusers)){
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$sqlcolumns = "SELECT
|
||||||
|
categoria.id,
|
||||||
|
categoria.clave,
|
||||||
|
categoria.nombre
|
||||||
|
FROM
|
||||||
|
categoria
|
||||||
|
WHERE
|
||||||
|
categoria.id = $categoria AND habilitado = 1
|
||||||
|
ORDER BY categoria.id";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$resultcolumn= mysqli_query($link, $sqlcolumns);
|
||||||
|
|
||||||
|
|
||||||
|
if( $resultcolumn ){
|
||||||
|
mysqli_data_seek($resultcolumn, 0);
|
||||||
|
while ($row = mysqli_fetch_assoc ($resultcolumn)){
|
||||||
|
$categorias[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$columnasvisibles= array(
|
||||||
|
'Estado del empleado',
|
||||||
|
'Número de empleado',
|
||||||
|
'Nombres(s)',
|
||||||
|
'Apellidos',
|
||||||
|
'Posición',
|
||||||
|
'Sociedad',
|
||||||
|
'División',
|
||||||
|
'Unidad organizativa',
|
||||||
|
'CeCo',
|
||||||
|
'Centro de trabajo',
|
||||||
|
'Distrito',
|
||||||
|
'Supervisor'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($categorias as $key2 => $cat) {
|
||||||
|
array_push($headers, $cat['nombre']);
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push($resultados,$headers);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (!empty($data)) {
|
||||||
|
$anterior = '';
|
||||||
|
$users = 0;
|
||||||
|
foreach ($data as $key1 => $col) {
|
||||||
|
|
||||||
|
//print_r($col);
|
||||||
|
//echo $col[2]."<br>";
|
||||||
|
|
||||||
|
if ($col['numempl'] == $anterior) {
|
||||||
|
//echo $col['numempl']." igual - ".$col['nomcat']."- ".$users." <br>";
|
||||||
|
$datos[($users-1)][$col['nomcat']] = $col['estado1'];
|
||||||
|
}else{
|
||||||
|
//echo $col['numempl']." nuevo - ".$col['nomcat']." - ".$users." <br>";
|
||||||
|
|
||||||
|
$datos[$users] = ['estado_empleado' => $col['estado_empleado'],'numempl' => $col['numempl'],'nombre' => $col['nombre'],'apellidos' =>$col['apellidos'],'posicion'=>$col['posicion'],'sociedad'=> $col['sociedad'],'division'=> $col['division'],'unidad_organizativa' => $col['unidad_organizativa'],'ceco'=>$col['ceco'],'nomdistrito'=>$col['nomdistrito'], 'nomcentro' => $col['nomcentro'],'supervisor'=>$col['supervisor']];
|
||||||
|
|
||||||
|
foreach ($categorias as $key2 => $cat) {
|
||||||
|
if ($cat['nombre'] == $col['nomcat']) {
|
||||||
|
$datos[$users][$cat['nombre']] = $col['estado1'];;
|
||||||
|
}else{
|
||||||
|
$datos[$users][$cat['nombre']] = 'No completado';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$users++;
|
||||||
|
}
|
||||||
|
$anterior = $col['numempl'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//print_r($datos[0]);
|
||||||
|
foreach ($datos as $col => $columnas) {
|
||||||
|
$fill = [];
|
||||||
|
foreach ($columnas as $key => $value) {
|
||||||
|
array_push($fill, $value);
|
||||||
|
}
|
||||||
|
$datos[$col] = $fill;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$datos = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($datos as $key => $val) {
|
||||||
|
$obj = [
|
||||||
|
$val[0],
|
||||||
|
$val[1],
|
||||||
|
$val[2],
|
||||||
|
$val[3],
|
||||||
|
$val[4],
|
||||||
|
$val[5],
|
||||||
|
$val[6],
|
||||||
|
$val[7],
|
||||||
|
$val[8],
|
||||||
|
$val[9],
|
||||||
|
$val[10],
|
||||||
|
$val[11],
|
||||||
|
$val[12]
|
||||||
|
];
|
||||||
|
array_push($resultados,$obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function cleanData(&$str)
|
||||||
|
{
|
||||||
|
$str = mb_convert_encoding($str , 'UTF-16LE' ,'UTF-8');
|
||||||
|
$str = preg_replace("/\t/", " ", $str);
|
||||||
|
$str = preg_replace("/\r?\n/", " ", $str);
|
||||||
|
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$nombre_cat = strip_tags($cat['nombre']);
|
||||||
|
|
||||||
|
$fechainicio = strip_tags($fechainicio);
|
||||||
|
$fechafin = strip_tags($fechafin);
|
||||||
|
|
||||||
|
// filename for download
|
||||||
|
$filename = "reporte - Categorías completadas__".$fechainiciotxt."_".$fechafintxt."_"."__".$nombre_cat." __" . date('Ymd') . ".csv";
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||||
|
header("Content-Type: text/csv");
|
||||||
|
$out = fopen("php://output", 'w');
|
||||||
|
$flag = false;
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($resultados as $row) {
|
||||||
|
array_walk($row, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($row), ',', '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($out);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
@@ -0,0 +1,357 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
//ini_set("memory_limit","1024M");
|
||||||
|
require_once "../config.php";
|
||||||
|
require_once "../runtime/encrypt.php";
|
||||||
|
dbConnect();
|
||||||
|
global $link;
|
||||||
|
$resultados = [];
|
||||||
|
$fechainicio = $_GET['fechaini'];
|
||||||
|
$fechainiciotxt = $_GET['fechaini'];
|
||||||
|
$fechafin = $_GET['fechafin'];
|
||||||
|
$fechafintxt = $_GET['fechafin'];
|
||||||
|
$estado_ini = $_GET['estado'];
|
||||||
|
|
||||||
|
if ($estado_ini == 'all') {
|
||||||
|
$estado = 'IN (0,1)';
|
||||||
|
}else{
|
||||||
|
$estado = '= '.$estado_ini;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fechainicio == '') {
|
||||||
|
$fechainicio = '2020-07-01';
|
||||||
|
}else{
|
||||||
|
$fechainicio = "".$fechainicio."";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fechafin == '') {
|
||||||
|
$fechafin = date('Y-m-d', strtotime($fechafin."+ 1 days") );
|
||||||
|
}else{
|
||||||
|
$fechafin = "".$fechafin."";
|
||||||
|
}
|
||||||
|
|
||||||
|
$categoria = $_GET['categoria'];
|
||||||
|
//$categoria = 1;
|
||||||
|
|
||||||
|
$headers = [
|
||||||
|
'Estado del empleado',
|
||||||
|
'Número de empleado',
|
||||||
|
'Nombres(s)',
|
||||||
|
'Apellidos',
|
||||||
|
'Posición',
|
||||||
|
'Sociedad',
|
||||||
|
'División',
|
||||||
|
'Unidad organizativa',
|
||||||
|
'CeCo',
|
||||||
|
'Distrito',
|
||||||
|
'Centro de trabajo',
|
||||||
|
'Supervisor',
|
||||||
|
];
|
||||||
|
|
||||||
|
$sqlasignados = "SELECT user.userid
|
||||||
|
FROM asignacion
|
||||||
|
INNER JOIN user ON asignacion.uid = user.userid
|
||||||
|
INNER JOIN categoria ON asignacion.catid = categoria.id
|
||||||
|
WHERE user.habilitado $estado AND categoria.habilitado = 1 AND catid = $categoria";
|
||||||
|
|
||||||
|
|
||||||
|
$resultasignacion = mysqli_query($link, $sqlasignados);
|
||||||
|
|
||||||
|
|
||||||
|
if( $resultasignacion ){
|
||||||
|
if (mysqli_num_rows($resultasignacion) <= 0 ) {
|
||||||
|
$data_asignacion = [];
|
||||||
|
}else{
|
||||||
|
mysqli_data_seek($resultasignacion, 0);
|
||||||
|
while ($row = mysqli_fetch_assoc ($resultasignacion)){
|
||||||
|
$data_asignacion[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$cad_numempl = '';
|
||||||
|
$total_asignados = sizeof($data_asignacion);
|
||||||
|
foreach ($data_asignacion as $key => $val) {
|
||||||
|
if ($key == ($total_asignados-1)) {
|
||||||
|
$cad_numempl .= $val['userid'];
|
||||||
|
}else{
|
||||||
|
$cad_numempl .= $val['userid'].",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sqlusers = "";
|
||||||
|
|
||||||
|
$sqlusers .= "SELECT
|
||||||
|
q.numempl,
|
||||||
|
q.nombre AS nombre,
|
||||||
|
q.apellidos,
|
||||||
|
q.nomcentro,
|
||||||
|
q.nomdistrito,
|
||||||
|
q.posicion,
|
||||||
|
q.sociedad,
|
||||||
|
q.division,
|
||||||
|
q.unidad_organizativa,
|
||||||
|
q.ceco,
|
||||||
|
q.supervisor,
|
||||||
|
IF(q.habilitado = 1, 'ACTIVO', 'BAJA') AS estado_empleado,
|
||||||
|
categoria.nombre AS nomcat,
|
||||||
|
q.nomcat AS nomcurso,
|
||||||
|
q.visitado AS visitado,
|
||||||
|
q.fecha AS fecha
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
user.numempl AS numempl,
|
||||||
|
user.nombre AS nombre,
|
||||||
|
user.apellido AS apellidos,
|
||||||
|
user.centrotrabajonom AS nomcentro,
|
||||||
|
user.distritonom AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
user.habilitado,
|
||||||
|
categoria.padre,
|
||||||
|
categoria.nombre AS nomcat,
|
||||||
|
categoria.id AS cat0,
|
||||||
|
scormpkg.nombre nomcurso,
|
||||||
|
scormpkg.idcategoria AS idcategoria,
|
||||||
|
CASE WHEN scormresults.userid <> '' THEN CONCAT(
|
||||||
|
COUNT(scormresults.userid),
|
||||||
|
' de ',
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
COUNT(*)
|
||||||
|
FROM
|
||||||
|
scormpkg
|
||||||
|
WHERE
|
||||||
|
scormpkg.idcategoria = categoria.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
scormresults.fecha
|
||||||
|
FROM
|
||||||
|
scormresults
|
||||||
|
INNER JOIN user ON user.userid = scormresults.userid
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormresults.scormid
|
||||||
|
INNER JOIN categoria ON categoria.id = scormpkg.idcategoria
|
||||||
|
WHERE
|
||||||
|
(scormresults.status = 'passed' OR scormresults.status = 'completed') AND user.userid IN ($cad_numempl) AND scormpkg.habilitado = 1";
|
||||||
|
|
||||||
|
if ($estado != 'all') {
|
||||||
|
$sqlusers .= " AND user.habilitado $estado";
|
||||||
|
} else {
|
||||||
|
$sqlusers .= " AND user.habilitado IN (0,1)";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fechainicio != '' && $fechafin != '') {
|
||||||
|
$sqlusers .= " AND scormresults.fecha BETWEEN '$fechainicio' AND '$fechafin'";
|
||||||
|
}
|
||||||
|
|
||||||
|
$sqlusers .= " GROUP BY
|
||||||
|
scormresults.userid,
|
||||||
|
scormpkg.idcategoria
|
||||||
|
ORDER BY
|
||||||
|
scormresults.userid,
|
||||||
|
categoria.id
|
||||||
|
DESC
|
||||||
|
) AS q
|
||||||
|
INNER JOIN categoria ON categoria.id = q.padre
|
||||||
|
WHERE categoria.id = $categoria
|
||||||
|
ORDER BY
|
||||||
|
q.numempl,
|
||||||
|
q.cat0 ASC";
|
||||||
|
|
||||||
|
|
||||||
|
$resultusers = mysqli_query($link, $sqlusers);
|
||||||
|
if ($resultusers) {
|
||||||
|
mysqli_data_seek($resultusers, 0);
|
||||||
|
while ($row = mysqli_fetch_assoc($resultusers)) {
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sqlcolumns = "SELECT
|
||||||
|
categoria.id,
|
||||||
|
categoria.clave,
|
||||||
|
categoria.nombre
|
||||||
|
FROM
|
||||||
|
categoria
|
||||||
|
WHERE
|
||||||
|
padre = 0 AND id = $categoria AND habilitado = 1
|
||||||
|
ORDER BY categoria.id";
|
||||||
|
$resultcolumn = mysqli_query($link, $sqlcolumns);
|
||||||
|
if ($resultcolumn) {
|
||||||
|
mysqli_data_seek($resultcolumn, 0);
|
||||||
|
while ($row = mysqli_fetch_assoc($resultcolumn)) {
|
||||||
|
$categorias[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sqlTotales = "SELECT
|
||||||
|
rs2.total,
|
||||||
|
categoria.nombre
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
COUNT(categoria.padre) AS total,
|
||||||
|
categoria.padre as categoripadre
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormpkg.idcategoria as tema,
|
||||||
|
scormpkg.nombre as nombre_tema
|
||||||
|
FROM
|
||||||
|
scormpkg
|
||||||
|
INNER JOIN categoria ON categoria.id = scormpkg.idcategoria
|
||||||
|
WHERE
|
||||||
|
scormpkg.habilitado = 1
|
||||||
|
AND categoria.habilitado = 1
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria ON categoria.id = rs1.tema
|
||||||
|
GROUP BY categoria.padre
|
||||||
|
) AS rs2
|
||||||
|
INNER JOIN categoria ON categoria.id = rs2.categoripadre";
|
||||||
|
$resultTotales = mysqli_query($link, $sqlTotales);
|
||||||
|
if ($resultTotales) {
|
||||||
|
mysqli_data_seek($resultTotales, 0);
|
||||||
|
while ($row = mysqli_fetch_assoc($resultTotales)) {
|
||||||
|
$totales[$row['nombre']] = $row['total'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$columnasvisibles = array(
|
||||||
|
'Estado del empleado',
|
||||||
|
'Número de empleado',
|
||||||
|
'Nombres(s)',
|
||||||
|
'Apellidos',
|
||||||
|
'Posición',
|
||||||
|
'Sociedad',
|
||||||
|
'División',
|
||||||
|
'Unidad organizativa',
|
||||||
|
'CeCo',
|
||||||
|
'Distrito',
|
||||||
|
'Centro de trabajo',
|
||||||
|
'Supervisor',
|
||||||
|
);
|
||||||
|
foreach ($categorias as $key2 => $cat) {
|
||||||
|
array_push($headers, strip_tags($cat['nombre']));
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
for ($i=0; $i < sizeof($columnasvisibles) ; $i++) {
|
||||||
|
$columnasvisibles[$i] = array('title' => $columnasvisibles[$i]);
|
||||||
|
}
|
||||||
|
$return->columnasvisibles = $columnasvisibles;
|
||||||
|
*/
|
||||||
|
array_push($resultados, $headers);
|
||||||
|
if (!empty($data)) {
|
||||||
|
$anterior = '';
|
||||||
|
$anteriorcat = '';
|
||||||
|
$users = 0;
|
||||||
|
$visitados = 0;
|
||||||
|
foreach ($data as $key1 => $col) {
|
||||||
|
//print_r($col);
|
||||||
|
//echo $col[2]."<br>";
|
||||||
|
if ($col['numempl'] == $anterior) {
|
||||||
|
//echo $col['numempl']." igual - ".$col['nomcat']."- ".$users." <br>";
|
||||||
|
if ($anteriorcat == $col['nomcat']) {
|
||||||
|
$visitas = explode(" de ", $col['visitado']);
|
||||||
|
$visitados = $visitados + $visitas[0];
|
||||||
|
$total = $visitados . " de " . $totales[$col['nomcat']];
|
||||||
|
$datos[($users - 1)][$col['nomcat']] = $total;
|
||||||
|
} else {
|
||||||
|
$visitados = 0;
|
||||||
|
$anteriorcat = $col['nomcat'];
|
||||||
|
$visitas = explode(" de ", $col['visitado']);
|
||||||
|
$visitados = $visitados + $visitas[0];
|
||||||
|
$total = $visitados . " de " . $totales[$col['nomcat']];
|
||||||
|
$datos[($users - 1)][$col['nomcat']] = $total;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//echo $col['numempl']." nuevo - ".$col['nomcat']." - ".$users." <br>";
|
||||||
|
$visitados = 0;
|
||||||
|
$datos[$users] = ['estado_empleado' => $col['estado_empleado'], 'numempl' => $col['numempl'], 'nombre' => $col['nombre'], 'apellidos' => $col['apellidos'], 'posicion' => $col['posicion'], 'sociedad' => $col['sociedad'], 'division' => $col['division'], 'unidad_organizativa' => $col['unidad_organizativa'], 'ceco' => $col['ceco'], 'nomdistrito' => $col['nomdistrito'], 'nomcentro' => $col['nomcentro'], 'supervisor' => $col['supervisor']];
|
||||||
|
$visitas = explode(" de ", $col['visitado']);
|
||||||
|
$visitados = $visitas[0];
|
||||||
|
$anteriorcat = $col['nomcat'];
|
||||||
|
foreach ($categorias as $key2 => $cat) {
|
||||||
|
if ($anteriorcat == $cat['nombre']) {
|
||||||
|
$datos[$users][$cat['nombre']] = $visitados . " de " . $totales[$cat['nombre']];
|
||||||
|
} else {
|
||||||
|
$datos[$users][$cat['nombre']] = "0 de " . $totales[$cat['nombre']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$users++;
|
||||||
|
}
|
||||||
|
$anterior = $col['numempl'];
|
||||||
|
}
|
||||||
|
//print_r($datos[3]);
|
||||||
|
//echo "<br>";
|
||||||
|
foreach ($datos as $col => $columnas) {
|
||||||
|
$fill = [];
|
||||||
|
foreach ($columnas as $key => $value) {
|
||||||
|
array_push($fill, $value);
|
||||||
|
}
|
||||||
|
$datos[$col] = $fill;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$datos = [];
|
||||||
|
}
|
||||||
|
foreach ($datos as $key => $val) {
|
||||||
|
$obj = [
|
||||||
|
$val[0],
|
||||||
|
$val[1],
|
||||||
|
$val[2],
|
||||||
|
$val[3],
|
||||||
|
$val[4],
|
||||||
|
$val[5],
|
||||||
|
$val[6],
|
||||||
|
$val[7],
|
||||||
|
$val[8],
|
||||||
|
$val[9],
|
||||||
|
$val[10],
|
||||||
|
$val[11],
|
||||||
|
$val[12],
|
||||||
|
$val[13],
|
||||||
|
$val[14],
|
||||||
|
$val[15],
|
||||||
|
$val[16],
|
||||||
|
$val[17],
|
||||||
|
$val[18],
|
||||||
|
$val[19],
|
||||||
|
$val[20],
|
||||||
|
$val[21],
|
||||||
|
$val[22],
|
||||||
|
$val[23],
|
||||||
|
$val[24],
|
||||||
|
$val[25],
|
||||||
|
$val[26],
|
||||||
|
|
||||||
|
];
|
||||||
|
array_push($resultados, $obj);
|
||||||
|
}
|
||||||
|
function cleanData(&$str)
|
||||||
|
{
|
||||||
|
$str = mb_convert_encoding($str, 'UTF-16LE', 'UTF-8');
|
||||||
|
$str = preg_replace("/\t/", " ", $str);
|
||||||
|
$str = preg_replace("/\r?\n/", " ", $str);
|
||||||
|
if (strstr($str, '"')) {
|
||||||
|
$str = '"' . str_replace('"', '""', $str) . '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$nombre_cat = strip_tags($cat['nombre']);
|
||||||
|
|
||||||
|
// filename for download
|
||||||
|
$filename = "reporte - Categorías visitadas __".$nombre_cat."__" . date('Ymd') . ".csv";
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||||
|
header("Content-Type: text/csv");
|
||||||
|
$out = fopen("php://output", 'w');
|
||||||
|
$flag = false;
|
||||||
|
foreach ($resultados as $row) {
|
||||||
|
array_walk($row, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($row), ',', '"');
|
||||||
|
}
|
||||||
|
fclose($out);
|
||||||
|
exit;
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
include '../config.php';
|
||||||
|
session_name($CFG->sessionname);
|
||||||
|
session_start();
|
||||||
|
if(!isset($_SESSION['usersession'])){
|
||||||
|
header("Location: ".$CFG->wwwroot);
|
||||||
|
}
|
||||||
|
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
*
|
||||||
|
FROM(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.user,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
rs1.nomcurso,
|
||||||
|
rs1.subtema,
|
||||||
|
rs1.estado
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre as user,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
centrotrabajo.nombrecentro AS nomcentro,
|
||||||
|
distrito.nombredistrito AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
scormpkg.nombre as subtema,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN Round( SUM( scormvars.varValue ), 2 ) >= 0 THEN
|
||||||
|
ROUND(
|
||||||
|
(
|
||||||
|
Round( SUM( scormvars.varValue ), 2 ) / ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
),
|
||||||
|
2
|
||||||
|
) ELSE '--'
|
||||||
|
END AS calificacion,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN ( COUNT( scormvars.varValue ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id ) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
CASE
|
||||||
|
WHEN scormvars.numempl <> '' THEN
|
||||||
|
CONCAT(
|
||||||
|
COUNT( scormvars.varValue ),
|
||||||
|
' de ',
|
||||||
|
( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormvars
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
INNER JOIN centrotrabajo ON centrotrabajo.centroid = user.centrotrabajoid
|
||||||
|
INNER JOIN distrito ON distrito.distritoid = user.distritoid
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.score.raw'
|
||||||
|
AND scormvars.numempl <> ''
|
||||||
|
GROUP BY
|
||||||
|
scormvars.numempl,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( fecha )
|
||||||
|
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE c.id = rs1.cat
|
||||||
|
) as rs2
|
||||||
|
ORDER BY rs2.numempl ASC";
|
||||||
|
|
||||||
|
$resultados = mysqli_query($link, $sqlusers);
|
||||||
|
function cleanData(&$str)
|
||||||
|
{
|
||||||
|
$str = mb_convert_encoding($str , 'UTF-16LE' ,'UTF-8');
|
||||||
|
$str = preg_replace("/\t/", "\\t", $str);
|
||||||
|
$str = preg_replace("/\r?\n/", "\\n", $str);
|
||||||
|
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// filename for download
|
||||||
|
$filename = "reporteEstafetaCategoria__" . date('Ymd') . ".csv";
|
||||||
|
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||||
|
header("Content-Type: text/csv");
|
||||||
|
$out = fopen("php://output", 'w');
|
||||||
|
$flag = false;
|
||||||
|
|
||||||
|
$encabezados = ["Periodo","Estado del empleado","Número de empleado","Nombre(s)","Apellidos","Posición","Sociedad","División","Unidad Organizativa","CeCo","Centro de trabajo","Distrito","Supervisor","Categoría","Tema", "Subtema", "Estado"];
|
||||||
|
array_walk($encabezados, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($encabezados), ',', '"');
|
||||||
|
while ($row = mysqli_fetch_array ($resultados, MYSQLI_NUM)) {
|
||||||
|
array_walk($row, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($row), ',', '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($out);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
include '../config.php';
|
||||||
|
session_name($CFG->sessionname);
|
||||||
|
session_start();
|
||||||
|
if(!isset($_SESSION['usersession'])){
|
||||||
|
header("Location: ".$CFG->wwwroot);
|
||||||
|
}
|
||||||
|
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.user,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
CASE
|
||||||
|
WHEN ( COUNT( rs1.cat) = ( SELECT COUNT( * ) FROM categoria WHERE categoria.padre = rs1.cat AND categoria.habilitado = 1) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado1
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre as user,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
centrotrabajo.nombrecentro AS nomcentro,
|
||||||
|
distrito.nombredistrito AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN Round( SUM( scormvars.varValue ), 2 ) >= 0 THEN
|
||||||
|
ROUND(
|
||||||
|
(
|
||||||
|
Round( SUM( scormvars.varValue ), 2 ) / ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
),
|
||||||
|
2
|
||||||
|
) ELSE '--'
|
||||||
|
END AS calificacion,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN ( COUNT( scormvars.varValue ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
CASE
|
||||||
|
WHEN scormvars.numempl <> '' THEN
|
||||||
|
CONCAT(
|
||||||
|
COUNT( scormvars.varValue ),
|
||||||
|
' de ',
|
||||||
|
( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormvars
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
INNER JOIN centrotrabajo ON centrotrabajo.centroid = user.centrotrabajoid
|
||||||
|
INNER JOIN distrito ON distrito.distritoid = user.distritoid
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.lesson_status'
|
||||||
|
AND scormvars.varValue = 'completed'
|
||||||
|
AND scormvars.numempl <> ''
|
||||||
|
GROUP BY
|
||||||
|
scormvars.numempl,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( fecha )
|
||||||
|
ORDER BY
|
||||||
|
scormpkg.idcategoria ASC
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE rs1.estado = 'Completado'
|
||||||
|
GROUP BY rs1.numempl,rs1.cat
|
||||||
|
ORDER BY c.nombre,rs1.cat
|
||||||
|
) AS rs2
|
||||||
|
ORDER BY rs2.numempl ASC";
|
||||||
|
|
||||||
|
$resultados = mysqli_query($link, $sqlusers);
|
||||||
|
function cleanData(&$str)
|
||||||
|
{
|
||||||
|
$str = mb_convert_encoding($str , 'UTF-16LE' ,'UTF-8');
|
||||||
|
$str = preg_replace("/\t/", "\\t", $str);
|
||||||
|
$str = preg_replace("/\r?\n/", "\\n", $str);
|
||||||
|
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// filename for download
|
||||||
|
$filename = "reporte - categorías completadas Estafeta__" . date('Ymd') . ".csv";
|
||||||
|
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||||
|
header("Content-Type: text/csv");
|
||||||
|
$out = fopen("php://output", 'w');
|
||||||
|
$flag = false;
|
||||||
|
|
||||||
|
$encabezados = ["Periodo","Estado del empleado","Número de empleado","Nombre(s)","Apellidos","Posición","Sociedad","División","Unidad Organizativa","CeCo","Distrito","Centro de trabajo","Supervisor","Categoría","Estado"];
|
||||||
|
array_walk($encabezados, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($encabezados), ',', '"');
|
||||||
|
while ($row = mysqli_fetch_array ($resultados, MYSQLI_NUM)) {
|
||||||
|
array_walk($row, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($row), ',', '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($out);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
include '../config.php';
|
||||||
|
session_name($CFG->sessionname);
|
||||||
|
session_start();
|
||||||
|
if(!isset($_SESSION['usersession'])){
|
||||||
|
header("Location: ".$CFG->wwwroot);
|
||||||
|
}
|
||||||
|
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
|
||||||
|
$sqlusers = "SELECT
|
||||||
|
*
|
||||||
|
FROM(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.user,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as nomcat,
|
||||||
|
rs1.nomcurso,
|
||||||
|
/*rs1.subtema,*/
|
||||||
|
/*rs1.calificacion,*/
|
||||||
|
rs1.visitado
|
||||||
|
/*rs1.estado*/
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre as user,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
centrotrabajo.nombrecentro AS nomcentro,
|
||||||
|
distrito.nombredistrito AS nomdistrito,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.supervisor,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
categoria.padre as cat,
|
||||||
|
categoria.nombre AS nomcurso,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN Round( SUM( scormvars.varValue ), 2 ) >= 0 THEN
|
||||||
|
ROUND(
|
||||||
|
(
|
||||||
|
Round( SUM( scormvars.varValue ), 2 ) / ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
),
|
||||||
|
2
|
||||||
|
) ELSE '--'
|
||||||
|
END AS calificacion,
|
||||||
|
CASE
|
||||||
|
|
||||||
|
WHEN ( COUNT( scormvars.varValue ) = ( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id) ) THEN
|
||||||
|
'Completado' ELSE 'No Completado'
|
||||||
|
END AS estado,
|
||||||
|
CASE
|
||||||
|
WHEN scormvars.numempl <> '' THEN
|
||||||
|
CONCAT(
|
||||||
|
COUNT( scormvars.varValue ),
|
||||||
|
' de ',
|
||||||
|
( SELECT COUNT( * ) FROM scormpkg WHERE scormpkg.idcategoria = categoria.id )
|
||||||
|
)
|
||||||
|
END AS visitado,
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
scormvars
|
||||||
|
INNER JOIN scormpkg ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN categoria ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
INNER JOIN centrotrabajo ON centrotrabajo.centroid = user.centrotrabajoid
|
||||||
|
INNER JOIN distrito ON distrito.distritoid = user.distritoid
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.lesson_status'
|
||||||
|
AND scormvars.varValue = 'completed'
|
||||||
|
AND scormvars.numempl <> ''
|
||||||
|
GROUP BY
|
||||||
|
scormvars.numempl,
|
||||||
|
categoria.clave
|
||||||
|
HAVING
|
||||||
|
max( fecha )
|
||||||
|
ORDER BY
|
||||||
|
scormpkg.idcategoria ASC
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.cat
|
||||||
|
WHERE c.id = rs1.cat
|
||||||
|
) as rs2
|
||||||
|
ORDER BY rs2.numempl ASC";
|
||||||
|
|
||||||
|
$resultados = mysqli_query($link, $sqlusers);
|
||||||
|
function cleanData(&$str)
|
||||||
|
{
|
||||||
|
$str = mb_convert_encoding($str , 'UTF-16LE' ,'UTF-8');
|
||||||
|
$str = preg_replace("/\t/", "\\t", $str);
|
||||||
|
$str = preg_replace("/\r?\n/", "\\n", $str);
|
||||||
|
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// filename for download
|
||||||
|
$filename = "reporte recursos visitados Estafeta__" . date('Ymd') . ".csv";
|
||||||
|
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||||
|
header("Content-Type: text/csv");
|
||||||
|
$out = fopen("php://output", 'w');
|
||||||
|
$flag = false;
|
||||||
|
|
||||||
|
$encabezados = ["Periodo","Estado del empleado","Número de empleado","Nombre(s)","Apellidos","Posición","Sociedad","División","Unidad Organizativa","CeCo","Centro de trabajo","Distrito","Supervisor","Categoría","Tema","Visitados"];
|
||||||
|
array_walk($encabezados, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($encabezados), ',', '"');
|
||||||
|
while ($row = mysqli_fetch_array ($resultados, MYSQLI_NUM)) {
|
||||||
|
array_walk($row, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($row), ',', '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($out);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once("../config.php");
|
||||||
|
|
||||||
|
dbConnect();
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
//Obtener todas las categorias registradas
|
||||||
|
$resultados = [];
|
||||||
|
$headers = ["Número de empleado","Nombre(s)","Apellidos","Centro de trabajo","Distrito","Nombre del curso","Nombre del tema","Calificación","Fecha"];
|
||||||
|
array_push($resultados,$headers);
|
||||||
|
$sqluserstotal ="SELECT
|
||||||
|
scormvars.numempl,
|
||||||
|
user.nombre as nomempl,
|
||||||
|
user.apellido,
|
||||||
|
centrotrabajo.nombrecentro AS nomcentro,
|
||||||
|
distrito.nombredistrito AS nomdistrito,
|
||||||
|
categoria.nombre as catnom,
|
||||||
|
scormpkg.nombre,
|
||||||
|
scormvars.varValue as 'calificacion',
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha
|
||||||
|
FROM
|
||||||
|
categoria
|
||||||
|
INNER JOIN scormpkg ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN scormvars ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
INNER JOIN centrotrabajo ON centrotrabajo.centroid = user.centrotrabajoid
|
||||||
|
INNER JOIN distrito ON distrito.distritoid = user.distritoid
|
||||||
|
WHERE user.habilitado = 1 AND scormvars.varName = 'cmi.core.score.raw' AND scormvars.numempl <> ''";
|
||||||
|
$resultsqluserstotal = mysqli_query($link, $sqluserstotal);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$resultusers = mysqli_query($link, $sqluserstotal);
|
||||||
|
|
||||||
|
if( mysqli_num_rows( $resultusers) > 0 ){
|
||||||
|
|
||||||
|
while ($usuario = mysqli_fetch_assoc ($resultusers)) {
|
||||||
|
|
||||||
|
$cal = floatval($usuario['calificacion']);
|
||||||
|
if( $cal >= 80){
|
||||||
|
$estado = "completed";
|
||||||
|
}else{
|
||||||
|
$estado = "incomplete";
|
||||||
|
}
|
||||||
|
|
||||||
|
$obj = [
|
||||||
|
$usuario['numempl'],
|
||||||
|
$usuario['nomempl'],
|
||||||
|
$usuario['apellido'],
|
||||||
|
$usuario['nomcentro'],
|
||||||
|
$usuario['nomdistrito'],
|
||||||
|
$usuario['catnom'],
|
||||||
|
$usuario['nombre'],
|
||||||
|
$usuario['calificacion'],
|
||||||
|
$usuario['fecha']
|
||||||
|
|
||||||
|
|
||||||
|
];
|
||||||
|
array_push($resultados,$obj);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function cleanData(&$str)
|
||||||
|
{
|
||||||
|
$str = mb_convert_encoding($str , 'UTF-16LE' ,'UTF-8');
|
||||||
|
$str = preg_replace("/\t/", "\\t", $str);
|
||||||
|
$str = preg_replace("/\r?\n/", "\\n", $str);
|
||||||
|
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// filename for download
|
||||||
|
$filename = "reporteEstafetaCurso__" . date('Ymd') . ".csv";
|
||||||
|
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||||
|
header("Content-Type: text/csv");
|
||||||
|
$out = fopen("php://output", 'w');
|
||||||
|
$flag = false;
|
||||||
|
|
||||||
|
foreach ($resultados as $row) {
|
||||||
|
|
||||||
|
array_walk($row, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($row), ',', '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($out);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
require_once("../config.php");
|
||||||
|
require_once("../runtime/encrypt.php");
|
||||||
|
dbConnect();
|
||||||
|
$query = $_GET['query'];
|
||||||
|
$query = encrypt_decrypt('decrypt', $query);
|
||||||
|
|
||||||
|
global $link;
|
||||||
|
//Obtener todas las categorias registradas
|
||||||
|
$resultados = [];
|
||||||
|
$headers = ["Periodo","Estado del empleado","Alta de usuario","Número de empleado","Nombre(s)","Apellidos","Posición","Sociedad","División","Unidad organizativa","CeCo","Distrito","Centro de trabajo","Supervisor","Categoría","Tema","Subtema","Completado"];
|
||||||
|
array_push($resultados,$headers);
|
||||||
|
|
||||||
|
|
||||||
|
if (!isset($query)) {
|
||||||
|
$sqluserstotal ="SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
rs1.fecha,
|
||||||
|
rs1.estado_empleado,
|
||||||
|
rs1.user_creado,
|
||||||
|
rs1.numempl,
|
||||||
|
rs1.nomempl,
|
||||||
|
rs1.apellidos,
|
||||||
|
rs1.posicion,
|
||||||
|
rs1.sociedad,
|
||||||
|
rs1.division,
|
||||||
|
rs1.unidad_organizativa,
|
||||||
|
rs1.ceco,
|
||||||
|
rs1.nomcentro,
|
||||||
|
rs1.nomdistrito,
|
||||||
|
rs1.supervisor,
|
||||||
|
c.nombre as categoria,
|
||||||
|
rs1.tema,
|
||||||
|
rs1.subtema,
|
||||||
|
rs1.estado
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
DATE_FORMAT(scormvars.fecha, '%d-%m-%Y') AS fecha,
|
||||||
|
IF(user.habilitado = 1, 'ACTIVO','BAJA') as estado_empleado,
|
||||||
|
scormvars.numempl AS numempl,
|
||||||
|
user.nombre AS nomempl,
|
||||||
|
user.apellido as apellidos,
|
||||||
|
user.posicion,
|
||||||
|
user.sociedad,
|
||||||
|
user.division,
|
||||||
|
user.unidad_organizativa,
|
||||||
|
user.ceco,
|
||||||
|
user.distritonom AS nomdistrito,
|
||||||
|
user.centrotrabajonom AS nomcentro,
|
||||||
|
user.supervisor,
|
||||||
|
user.creado as user_creado,
|
||||||
|
categoria.padre as categoria,
|
||||||
|
categoria.nombre AS tema,
|
||||||
|
scormpkg.nombre as subtema,
|
||||||
|
IF(scormvars.varValue = 'completed' OR scormvars.varValue = 'passed', 'COMPLETADO','NO COMPLETADO') as estado
|
||||||
|
FROM
|
||||||
|
categoria
|
||||||
|
INNER JOIN scormpkg ON scormpkg.idcategoria = categoria.id
|
||||||
|
INNER JOIN scormvars ON scormpkg.id = scormvars.SCOInstanceID
|
||||||
|
INNER JOIN user ON user.numempl = scormvars.numempl
|
||||||
|
WHERE
|
||||||
|
scormvars.varName = 'cmi.core.lesson_status' AND scormvars.numempl <> ''
|
||||||
|
) AS rs1
|
||||||
|
INNER JOIN categoria as c ON c.id = rs1.categoria
|
||||||
|
WHERE c.id = rs1.categoria
|
||||||
|
) as rs2";
|
||||||
|
}else{
|
||||||
|
$sqluserstotal = $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$resultusers = mysqli_query($link, $sqluserstotal);
|
||||||
|
|
||||||
|
if( mysqli_num_rows( $resultusers) > 0 ){
|
||||||
|
|
||||||
|
while ($usuario = mysqli_fetch_assoc ($resultusers)) {
|
||||||
|
|
||||||
|
|
||||||
|
$obj = [
|
||||||
|
$usuario['fecha'],
|
||||||
|
$usuario['estado_empleado'],
|
||||||
|
$usuario['user_creado'],
|
||||||
|
$usuario['numempl'],
|
||||||
|
$usuario['nomempl'],
|
||||||
|
$usuario['apellidos'],
|
||||||
|
$usuario['posicion'],
|
||||||
|
$usuario['sociedad'],
|
||||||
|
$usuario['division'],
|
||||||
|
$usuario['unidad_organizativa'],
|
||||||
|
$usuario['ceco'],
|
||||||
|
$usuario['nomdistrito'],
|
||||||
|
$usuario['nomcentro'],
|
||||||
|
$usuario['supervisor'],
|
||||||
|
$usuario['categoria'],
|
||||||
|
$usuario['tema'],
|
||||||
|
$usuario['subtema'],
|
||||||
|
$usuario['estado']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
];
|
||||||
|
array_push($resultados,$obj);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function cleanData(&$str)
|
||||||
|
{
|
||||||
|
$str = mb_convert_encoding($str , 'UTF-16LE' ,'UTF-8');
|
||||||
|
$str = preg_replace("/\t/", " ", $str);
|
||||||
|
$str = preg_replace("/\r?\n/", " ", $str);
|
||||||
|
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// filename for download
|
||||||
|
$filename = "reporte - general Estafeta __" . date('Ymd') . ".csv";
|
||||||
|
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||||
|
header("Content-Type: text/csv");
|
||||||
|
$out = fopen("php://output", 'w');
|
||||||
|
$flag = false;
|
||||||
|
|
||||||
|
foreach ($resultados as $row) {
|
||||||
|
|
||||||
|
array_walk($row, __NAMESPACE__ . '\cleanData');
|
||||||
|
fputcsv($out, array_values($row), ',', '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($out);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<div class="col-12 text-primary mt-3">
|
||||||
|
<h1>Reporte de cumplimiento detalle por categoria</h1>
|
||||||
|
</div>
|
||||||
|
<!--
|
||||||
|
<div class="col-12 text-left my-5">
|
||||||
|
<a target="_blank" href="exportDetalle.php?key=<?php echo generateRandomString(); ?>" class="p-3 btn-primary text-white btn-descarga" >Descargar Reporte</a>
|
||||||
|
</div>
|
||||||
|
-->
|
||||||
|
<div class="col-12">
|
||||||
|
<table class="table table-striped table-bordered" style="width:100%" id="estafetaCategoriatable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>NÚMERO DE EMPLEADO</th>
|
||||||
|
<th>CLAVE DEL CURSO</th>
|
||||||
|
<th>NOMBRE DEL CURSO</th>
|
||||||
|
<th>NOMBRE DEL TEMA</th>
|
||||||
|
|
||||||
|
<th>CALIFICACIÓN</th>
|
||||||
|
<th>FECHA</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th>NÚMERO DE EMPLEADO</th>
|
||||||
|
<th>CLAVE DEL CURSO</th>
|
||||||
|
<th>NOMBRE DEL CURSO</th>
|
||||||
|
<th>NOMBRE DEL TEMA</th>
|
||||||
|
|
||||||
|
<th>CALIFICACIÓN</th>
|
||||||
|
<th>FECHA</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var table = $('#estafetaCategoriatable').DataTable({
|
||||||
|
responsive: true,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
},
|
||||||
|
"initComplete": function (settings, json) {
|
||||||
|
$('div.load').remove();
|
||||||
|
$(".nooverflow").removeClass('nooverflow');
|
||||||
|
$("#estafetaCategoriatable").show();
|
||||||
|
|
||||||
|
},
|
||||||
|
"ordering": false,
|
||||||
|
"processing": true,
|
||||||
|
"serverSide": true,
|
||||||
|
"ajax": {
|
||||||
|
url: "reporte_getDataDetalle.php",
|
||||||
|
type: "post"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
include '../config.php';
|
||||||
|
session_name($CFG->sessionname);
|
||||||
|
session_start();
|
||||||
|
if(!isset($_SESSION['usersession'])){
|
||||||
|
header("Location: ".$CFG->wwwroot);
|
||||||
|
}
|
||||||
|
function generateRandomString($length = 10) {
|
||||||
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
|
$charactersLength = strlen($characters);
|
||||||
|
$randomString = '';
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||||
|
}
|
||||||
|
return $randomString;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="col-12 text-primary mt-3">
|
||||||
|
<h1>Reporte categoría</h1>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 text-left my-5">
|
||||||
|
<a target="_blank" href="reporteExportCategoria.php?key=<?php echo generateRandomString(); ?>" class="p-3 btn-primary text-white btn-descarga">Descargar Reporte</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<table class="table table-striped table-bordered" style="width:100%; display: block;" id="estafetatable3">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Periodo</th>
|
||||||
|
<th>Estado del empleado</th>
|
||||||
|
<th>Número de empleado</th>
|
||||||
|
<th>Nombres(s)</th>
|
||||||
|
<th>Apellidos</th>
|
||||||
|
<th>Posición</th>
|
||||||
|
<th>Sociedad</th>
|
||||||
|
<th>División</th>
|
||||||
|
<th>Unidad organizativa</th>
|
||||||
|
<th>CeCo</th>
|
||||||
|
<th>Distrito</th>
|
||||||
|
<th>Centro de trabajo</th>
|
||||||
|
<th>Supervisor</th>
|
||||||
|
<th>Categoría</th>
|
||||||
|
<th>Tema</th>
|
||||||
|
<th>Estado</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr class="text-center"><td colspan="17">Procesando...</td></tr>
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<th>Periodo</th>
|
||||||
|
<th>Estado del empleado</th>
|
||||||
|
<th>Número de empleado</th>
|
||||||
|
<th>Nombres(s)</th>
|
||||||
|
<th>Apellidos</th>
|
||||||
|
<th>Posición</th>
|
||||||
|
<th>Sociedad</th>
|
||||||
|
<th>División</th>
|
||||||
|
<th>Unidad organizativa</th>
|
||||||
|
<th>CeCo</th>
|
||||||
|
<th>Distrito</th>
|
||||||
|
<th>Centro de trabajo</th>
|
||||||
|
<th>Supervisor</th>
|
||||||
|
<th>Categoría</th>
|
||||||
|
<th>Tema</th>
|
||||||
|
<th>Estado</th>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
extractData();
|
||||||
|
|
||||||
|
function extractData(){
|
||||||
|
$(".layer-load").show();
|
||||||
|
var dataSet = [];
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: 'reporte_getCategoria.php'
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
var _data = JSON.parse(data);
|
||||||
|
console.log(_data.columns);
|
||||||
|
//$.each(_data.data, function (index, val) {
|
||||||
|
//dataSet[index] = [val['fecha'],val['estado_empleado'],val['numempl'],val['user'],val['apellidos'],val['posicion'],val['sociedad'],val['division'],val['unidad_organizativa'],val['ceco'],val['nomdistrito'],val['nomcentro'],val['supervisor'],val['nomcat'],val['nomcurso'],val['subtema'],val['estado']];
|
||||||
|
//});
|
||||||
|
|
||||||
|
$('#estafetatable3 tbody').empty();
|
||||||
|
$('#estafetatable3').DataTable({
|
||||||
|
dom: "Bfrtip",
|
||||||
|
buttons: [
|
||||||
|
//'pageLength',
|
||||||
|
{
|
||||||
|
extend: 'excel',
|
||||||
|
exportOptions: {
|
||||||
|
columns: ':visible'
|
||||||
|
},
|
||||||
|
autoFilter: true,
|
||||||
|
title: 'Reporte por categoría - Estafeta',
|
||||||
|
sheetName: 'Reporte general',
|
||||||
|
text: 'Exportar a Excel'
|
||||||
|
},
|
||||||
|
'colvis'
|
||||||
|
],
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
},
|
||||||
|
'order': [
|
||||||
|
[2, 'desc'],
|
||||||
|
[0, 'asc']
|
||||||
|
],
|
||||||
|
"responsive": true,
|
||||||
|
data: _data.data,
|
||||||
|
columns: [
|
||||||
|
{ title: "Periodo" },
|
||||||
|
{ title: "Estado del empleado" },
|
||||||
|
{ title: "Número de empleado" },
|
||||||
|
{ title: "Nombre(s)" },
|
||||||
|
{ title: "Apellidos" },
|
||||||
|
{ title: "Posición" },
|
||||||
|
{ title: "Sociedad" },
|
||||||
|
{ title: "División" },
|
||||||
|
{ title: "Unidad organizativa" },
|
||||||
|
{ title: "CeCo" },
|
||||||
|
{ title: "Distrito" },
|
||||||
|
{ title: "Centro de trabajo" },
|
||||||
|
{ title: "Supervisor" },
|
||||||
|
{ title: "Categoría" },
|
||||||
|
{ title: "Tema" },
|
||||||
|
{ title: "Estado" }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
$("#estafetatable3").show();
|
||||||
|
$(".layer-load").hide();
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
var table = $('#estafetatable').DataTable({
|
||||||
|
responsive: true,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
},
|
||||||
|
"initComplete": function (settings, json) {
|
||||||
|
$('div.load').remove();
|
||||||
|
$(".nooverflow").removeClass('nooverflow');
|
||||||
|
$("#estafetatable").show();
|
||||||
|
},
|
||||||
|
columnDefs: [
|
||||||
|
{ targets: 'no-sort', orderable: false }
|
||||||
|
],
|
||||||
|
"processing": true,
|
||||||
|
"serverSide": true,
|
||||||
|
"ajax": {
|
||||||
|
url: "reporte_getDataDate.php",
|
||||||
|
type: "post"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,364 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
include '../config.php';
|
||||||
|
session_name($CFG->sessionname);
|
||||||
|
session_start();
|
||||||
|
if(!isset($_SESSION['usersession'])){
|
||||||
|
header("Location: ".$CFG->wwwroot);
|
||||||
|
}
|
||||||
|
function generateRandomString($length = 10) {
|
||||||
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
|
$charactersLength = strlen($characters);
|
||||||
|
$randomString = '';
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||||
|
}
|
||||||
|
return $randomString;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="col-12 text-primary mt-3">
|
||||||
|
<h1>Reporte categorías completadas</h1>
|
||||||
|
</div>
|
||||||
|
<!--
|
||||||
|
<div class="col-12 text-left my-5">
|
||||||
|
<a target="_blank" href="reporteExportCategoria_completada.php?key=<?php echo generateRandomString(); ?>" class="p-3 btn-primary text-white btn-descarga">Descargar reporte completo</a>
|
||||||
|
</div>
|
||||||
|
-->
|
||||||
|
<div class="filter col-lg-12 col-md-12 col-12 mt-4 mb-5" style="display: block;">
|
||||||
|
<label>Selecciona un rango o el estado de los usuarios</label>
|
||||||
|
<form class="row">
|
||||||
|
<div id="daterangecat" class="daterange form-control pull-left col-lg-4 col-sm-4 col-12 mr-2 mb-2">
|
||||||
|
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
|
||||||
|
<span></span> <b class="caret"></b>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" class="form-control col-lg-2 col-md-2 col-6 mb-2 mr-sm-2" placeholder="Fecha inicio" id="fechaini-cat" name="fechaini-cat">
|
||||||
|
<input type="hidden" class="form-control col-lg-2 col-md-2 col-6 mb-2 mr-sm-2" placeholder="Fecha fin" id="fechafin-cat" name="fechafin-cat">
|
||||||
|
|
||||||
|
<select class="form-control col-lg-3 col-md-3 col-12 mb-2 mr-sm-2" id="filestadouser-cat" name="filestadouser-cat">
|
||||||
|
<option value="all">Todos</option>
|
||||||
|
<option value="1" selected>Activo</option>
|
||||||
|
<option value="0">Baja</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select class="form-control col-lg-3 col-md-3 col-12 mb-2 mr-sm-2" id="filcategoriauser-cat" name="filcategoriauser-cat">
|
||||||
|
<option value="1" selected>Activo</option>
|
||||||
|
<option value="0">Baja</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<button type="button" class="btn_download btn btn-primary mb-2 mr-3">Descargar</button>
|
||||||
|
<button type="button" class="btnfilter btn btn-primary mb-2">Ver</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-12 col-md-12 col-12">
|
||||||
|
<button type="button" class="btn-advance btn btn-danger mb-4" style="display: none;">Mostrar Filtro avanzado</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-12">
|
||||||
|
<table class="table table-striped table-bordered" style="width:100%; display: none;" id="estafetatable2">
|
||||||
|
<thead></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr class="text-center"><td colspan="17">Procesando...</td></tr>
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr></tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(".layer-load").hide();
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
//------------------------ DATTEPICKER --------------------------------
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
(function (factory) {
|
||||||
|
factory(moment);
|
||||||
|
}(function (moment) {
|
||||||
|
var monthsShortDot = 'Ene._Feb._Mar._Abr._May._Jun._Jul._Ago._Sep._Oct._Nov._Dic.'.split('_'),
|
||||||
|
monthsShort = 'Ene_Feb_Mar_Abr_May_Jun_Jul_Ago_Sep_Oct_Nov_Dic'.split('_');
|
||||||
|
return moment.defineLocale('es', {
|
||||||
|
months : 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
|
||||||
|
monthsShort : function (m, format) {
|
||||||
|
if (/-MMM-/.test(format)) {
|
||||||
|
return monthsShort[m.month()];
|
||||||
|
} else {
|
||||||
|
return monthsShortDot[m.month()];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
weekdays : 'domingo_lunes_martes_miércoles_jueves_viernes_sábado'.split('_'),
|
||||||
|
weekdaysShort : 'dom._lun._mar._mié._jue._vie._sáb.'.split('_'),
|
||||||
|
weekdaysMin : 'Do_Lu_Ma_Mi_Ju_Vi_Sa'.split('_'),
|
||||||
|
longDateFormat : {
|
||||||
|
LT : 'H:mm',
|
||||||
|
LTS : 'LT:ss',
|
||||||
|
L : 'DD/MM/YYYY',
|
||||||
|
LL : 'D [de] MMMM [de] YYYY',
|
||||||
|
LLL : 'D [de] MMMM [de] YYYY LT',
|
||||||
|
LLLL : 'dddd, D [de] MMMM [de] YYYY LT'
|
||||||
|
},
|
||||||
|
calendar : {
|
||||||
|
sameDay : function () {
|
||||||
|
return '[hoy a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
|
||||||
|
},
|
||||||
|
nextDay : function () {
|
||||||
|
return '[mañana a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
|
||||||
|
},
|
||||||
|
nextWeek : function () {
|
||||||
|
return 'dddd [a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
|
||||||
|
},
|
||||||
|
lastDay : function () {
|
||||||
|
return '[ayer a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
|
||||||
|
},
|
||||||
|
lastWeek : function () {
|
||||||
|
return '[el] dddd [pasado a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
|
||||||
|
},
|
||||||
|
sameElse : 'L'
|
||||||
|
},
|
||||||
|
relativeTime : {
|
||||||
|
future : 'en %s',
|
||||||
|
past : 'hace %s',
|
||||||
|
s : 'unos segundos',
|
||||||
|
m : 'un minuto',
|
||||||
|
mm : '%d minutos',
|
||||||
|
h : 'una hora',
|
||||||
|
hh : '%d horas',
|
||||||
|
d : 'un día',
|
||||||
|
dd : '%d días',
|
||||||
|
M : 'un mes',
|
||||||
|
MM : '%d meses',
|
||||||
|
y : 'un año',
|
||||||
|
yy : '%d años'
|
||||||
|
},
|
||||||
|
ordinalParse : /\d{1,2}º/,
|
||||||
|
ordinal : '%dº',
|
||||||
|
week : {
|
||||||
|
dow : 1, // Monday is the first day of the week.
|
||||||
|
doy : 4 // The week that contains Jan 4th is the first week of the year.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
function cb(start, end){
|
||||||
|
$('#daterangecat span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
|
||||||
|
}
|
||||||
|
cb(moment().subtract(1, 'month'),moment());
|
||||||
|
date = $('#daterangecat').daterangepicker({
|
||||||
|
locale: {
|
||||||
|
format: 'YYYY-MM-DD',
|
||||||
|
customRangeLabel: 'Selecciona Rango'
|
||||||
|
},
|
||||||
|
ranges: {
|
||||||
|
'Ultimos 30 Dias': [moment().subtract(29, 'days'), moment()],
|
||||||
|
'Este Mes': [moment().startOf('month'), moment().endOf('month')],
|
||||||
|
'Mes Pasado': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
|
||||||
|
'A\u00f1o pasado': [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')],
|
||||||
|
'A\u00f1o pasado - Hoy': [moment().subtract(1, 'year').startOf('year'), moment()],
|
||||||
|
'Este A\u00f1o': [moment().startOf('year'), moment()]
|
||||||
|
}
|
||||||
|
},cb);
|
||||||
|
$('.applyBtn').text('Aceptar');
|
||||||
|
$('.applyBtn').removeClass('btn-primary');
|
||||||
|
$('.applyBtn').addClass('btn-info');
|
||||||
|
$('.cancelBtn ').text('Cancelar');
|
||||||
|
$('.cancelBtn ').removeClass('btn-default');
|
||||||
|
$('.cancelBtn ').addClass('btn-danger');
|
||||||
|
$('#daterangecat').on('apply.daterangepicker', function(ev, picker) {
|
||||||
|
getJson(picker.startDate.format('YYYY-MM-DD'),picker.endDate.format('YYYY-MM-DD'));
|
||||||
|
});
|
||||||
|
function getJson ( fechaInicio, fechaFin){
|
||||||
|
if(fechaInicio==''){
|
||||||
|
fechaInicio=moment().subtract(1, 'month').format('YYYY-MM-DD');
|
||||||
|
}
|
||||||
|
if(fechaFin==''){
|
||||||
|
fechaFin=moment().format('YYYY-MM-DD');
|
||||||
|
}
|
||||||
|
$('#fechaini-cat').val(fechaInicio);
|
||||||
|
$('#fechafin-cat').val(fechaFin);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
//--------------------------- FILTER ------------------------------------
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
$(".btnfilter").click(function(){
|
||||||
|
$(".btnfilter").html('Buscando...');
|
||||||
|
$("#estafetatable2").hide();
|
||||||
|
$(".layer-load").show();
|
||||||
|
if (!$("#wrapper").hasClass('toggled')) {
|
||||||
|
$("#wrapper").toggleClass("toggled");
|
||||||
|
}
|
||||||
|
if ($('#estafetatable2').hasClass('Initialize')) {
|
||||||
|
$("#estafetatable2").hide();
|
||||||
|
$(".layer-load").show();
|
||||||
|
$(".btn-advance").text('Mostrar filtro avanzado');
|
||||||
|
$("#estafetatable2").dataTable().fnDestroy();
|
||||||
|
setTimeout(function(){ extractData(); }, 800);
|
||||||
|
}else{
|
||||||
|
$('#estafetatable2').addClass('Initialize');
|
||||||
|
extractData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
//--------------------------- DATA ------------------------------------
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
function extractData(){
|
||||||
|
var fechainit = $('#fechaini-cat').val();
|
||||||
|
var fechafin = $('#fechafin-cat').val();
|
||||||
|
var estado = $('#filestadouser-cat').val();
|
||||||
|
if( fechafin == '' ) { fechafin = moment().format('YYYY-MM-DD'); }
|
||||||
|
if( fechainit == '' ) { fechainit = moment().subtract(1, 'month').format('YYYY-MM-DD'); }
|
||||||
|
$("#estafetatable2 tfoot tr").empty();
|
||||||
|
var data = {fechaini:fechainit,fechafin:fechafin,estado:estado};
|
||||||
|
$(".layer-load").show();
|
||||||
|
var dataSet = [];
|
||||||
|
$.ajax({
|
||||||
|
type:'POST',
|
||||||
|
data:data,
|
||||||
|
/*url: 'reporte_getCategoria_completada2.php'*/
|
||||||
|
url: '_reportes_x_cat.php'
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
var _data = JSON.parse(data);
|
||||||
|
//var _data = data;
|
||||||
|
//console.log(_data.columns);
|
||||||
|
//$.each(_data.data, function (index, val) {
|
||||||
|
//dataSet[index] = [val['fecha'],val['estado_empleado'],val['numempl'],val['user'],val['apellidos'],val['posicion'],val['sociedad'],val['division'],val['unidad_organizativa'],val['ceco'],val['nomdistrito'],val['nomcentro'],val['supervisor'],val['nomcat'],val['nomcurso'],val['subtema'],val['estado']];
|
||||||
|
//});
|
||||||
|
$.each(_data.columnasvisibles, function (index, val) {
|
||||||
|
$("#estafetatable2 tfoot tr").append('<th></th>');
|
||||||
|
});
|
||||||
|
$('#estafetatable2 tbody').empty();
|
||||||
|
$('#estafetatable2').DataTable({
|
||||||
|
searchPanes: {
|
||||||
|
viewTotal: true
|
||||||
|
},
|
||||||
|
/*dom: "Bfrtip",*/
|
||||||
|
dom: 'PBfrtip',
|
||||||
|
buttons: [
|
||||||
|
//'pageLength',
|
||||||
|
{
|
||||||
|
extend: 'excel',
|
||||||
|
exportOptions: {
|
||||||
|
//columns: ':visible'
|
||||||
|
},
|
||||||
|
autoFilter: true,
|
||||||
|
title: 'Reporte por categoría completadas - Estafeta',
|
||||||
|
sheetName: 'Reporte por categorías completadas',
|
||||||
|
text: 'Exportar a Excel'
|
||||||
|
},
|
||||||
|
'colvis'
|
||||||
|
],
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
},
|
||||||
|
'order':false,
|
||||||
|
/*
|
||||||
|
'order': [
|
||||||
|
[2, 'desc'],
|
||||||
|
[1, 'asc']
|
||||||
|
],
|
||||||
|
*/
|
||||||
|
"responsive": true,
|
||||||
|
data: _data.data,
|
||||||
|
columns: _data.columnasvisibles,
|
||||||
|
orderCellsTop: true,
|
||||||
|
fixedHeader: true,
|
||||||
|
initComplete: function () {
|
||||||
|
$('.btn-advance').show(300);
|
||||||
|
$('.dtsp-panesContainer').hide();
|
||||||
|
this.api().columns().every( function () {
|
||||||
|
var column = this;
|
||||||
|
var select = $('<select class="myselect"><option value="">TODOS</option></select>')
|
||||||
|
.appendTo( $(column.footer()).after())
|
||||||
|
.on('change', function () {
|
||||||
|
var val = $.fn.dataTable.util.escapeRegex(
|
||||||
|
$(this).val()
|
||||||
|
);
|
||||||
|
column
|
||||||
|
.search( val ? '^'+val+'$' : '', true, false )
|
||||||
|
.draw();
|
||||||
|
});
|
||||||
|
column.data().unique().sort().each( function ( d, j ) {
|
||||||
|
select.append( '<option value="'+d+'">'+d+'</option>' )
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$(".myselect").select2();
|
||||||
|
$(".layer-load").hide();
|
||||||
|
$("#estafetatable2").show();
|
||||||
|
$(".btnfilter").html('Buscar');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$(".btn-advance").click(function(){
|
||||||
|
if($('.dtsp-panesContainer').is(':visible')) {
|
||||||
|
$(".btn-advance").text('Mostrar filtro avanzado');
|
||||||
|
}else{
|
||||||
|
$(".btn-advance").text('Ocultar filtro avanzado');
|
||||||
|
}
|
||||||
|
$('.dtsp-panesContainer').toggle(300);
|
||||||
|
});
|
||||||
|
$(".btn_download").click(function(){
|
||||||
|
var fechainit = $('#fechaini-cat').val();
|
||||||
|
var fechafin = $('#fechafin-cat').val();
|
||||||
|
var estado = $('#filestadouser-cat').val();
|
||||||
|
var categoria = $('#filcategoriauser-cat').val();
|
||||||
|
if( fechafin == '' ) { fechafin = moment().format('YYYY-MM-DD'); }
|
||||||
|
if( fechainit == '' ) { fechainit = moment().subtract(1, 'month').format('YYYY-MM-DD'); }
|
||||||
|
|
||||||
|
window.open('reporteExportCatCompletadasv2.php?categoria='+categoria+'&fechaini='+fechainit+"&fechafin="+fechafin+"&estado="+estado, '_blank');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
listadoDeCategorias();
|
||||||
|
|
||||||
|
function listadoDeCategorias() {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias_list.php',
|
||||||
|
type: 'POST'
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = JSON.parse(response);
|
||||||
|
|
||||||
|
$('#filcategoriauser-cat').empty();
|
||||||
|
|
||||||
|
$.each(_data.datos, function (index, val) {
|
||||||
|
if (val.padre == 0) {
|
||||||
|
$("#filcategoriauser-cat").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(_data);
|
||||||
|
$('.layer-load').hide();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
var table = $('#estafetatable').DataTable({
|
||||||
|
responsive: true,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
},
|
||||||
|
"initComplete": function (settings, json) {
|
||||||
|
$('div.load').remove();
|
||||||
|
$(".nooverflow").removeClass('nooverflow');
|
||||||
|
$("#estafetatable").show();
|
||||||
|
},
|
||||||
|
columnDefs: [
|
||||||
|
{ targets: 'no-sort', orderable: false }
|
||||||
|
],
|
||||||
|
"processing": true,
|
||||||
|
"serverSide": true,
|
||||||
|
"ajax": {
|
||||||
|
url: "reporte_getDataDate.php",
|
||||||
|
type: "post"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,399 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
include '../config.php';
|
||||||
|
session_name($CFG->sessionname);
|
||||||
|
session_start();
|
||||||
|
if(!isset($_SESSION['usersession'])){
|
||||||
|
header("Location: ".$CFG->wwwroot);
|
||||||
|
}
|
||||||
|
function generateRandomString($length = 10) {
|
||||||
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
|
$charactersLength = strlen($characters);
|
||||||
|
$randomString = '';
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||||
|
}
|
||||||
|
return $randomString;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="col-12 text-primary mt-3">
|
||||||
|
<h1>Reporte por recursos revisados</h1>
|
||||||
|
</div>
|
||||||
|
<!--
|
||||||
|
<div class="col-12 text-left my-5">
|
||||||
|
<a target="_blank" href="reporteExportCategoria_visitados.php?key=<?php echo generateRandomString(); ?>" class="p-3 btn-primary text-white btn-descarga">Descargar reporte completo</a>
|
||||||
|
</div>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<div class="filter col-lg-12 col-md-12 col-12 mt-4 mb-5" style="display: block;">
|
||||||
|
<label>Selecciona un rango o el estado de los usuarios</label>
|
||||||
|
<form class="row">
|
||||||
|
|
||||||
|
<div id="daterangevis" class="daterange form-control pull-left col-lg-4 col-sm-4 col-12 mr-2 mb-2">
|
||||||
|
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
|
||||||
|
<span></span> <b class="caret"></b>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" class="form-control col-lg-2 col-md-2 col-6 mb-2 mr-sm-2" placeholder="Fecha inicio" id="fechaini-vis" name="fechaini-vis">
|
||||||
|
|
||||||
|
<input type="hidden" class="form-control col-lg-2 col-md-2 col-6 mb-2 mr-sm-2" placeholder="Fecha fin" id="fechafin-vis" name="fechafin-vis">
|
||||||
|
<!--
|
||||||
|
<input type="number" class="form-control col-lg-2 col-md-2 col-6 mb-2 mr-sm-2" placeholder="Número de empleado" id="numempl" name="numempl">
|
||||||
|
-->
|
||||||
|
<select class="form-control col-lg-3 col-md-3 col-12 mb-2 mr-sm-2" id="filestadouser-vis" name="filestadouser-vis">
|
||||||
|
<option value="all">Todos</option>
|
||||||
|
<option value="1" selected>Activo</option>
|
||||||
|
<option value="0">Baja</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select class="form-control col-lg-3 col-md-3 col-12 mb-2 mr-sm-2" id="filcategoriauser-cat" name="filcategoriauser-cat">
|
||||||
|
<option value="1" selected>Activo</option>
|
||||||
|
<option value="0">Baja</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<input type="hidden" class="form-control col-lg-2 col-md-2 col-6 mb-2 mr-sm-2" placeholder="Número de empleado" id="numempleado" name="numempleado">
|
||||||
|
|
||||||
|
<button type="button" class="btn_download btn btn-primary mb-2 mr-3">Descargar</button>
|
||||||
|
<button type="button" class="btnfilter btn btn-primary mb-2 d-none">Ver</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="col-lg-12 col-md-12 col-12">
|
||||||
|
<button type="button" class="btn-advance btn btn-danger mb-4" style="display: none;">Mostrar Filtro avanzado</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<table class="table table-striped table-bordered" style="width:100%; display: none;" id="estafetatable3">
|
||||||
|
<thead></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr class="text-center"><td colspan="17">Procesando...</td></tr>
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr></tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
$(".layer-load").hide();
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
//------------------------ DATTEPICKER --------------------------------
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
(function (factory) {
|
||||||
|
factory(moment);
|
||||||
|
}(function (moment) {
|
||||||
|
var monthsShortDot = 'Ene._Feb._Mar._Abr._May._Jun._Jul._Ago._Sep._Oct._Nov._Dic.'.split('_'),
|
||||||
|
monthsShort = 'Ene_Feb_Mar_Abr_May_Jun_Jul_Ago_Sep_Oct_Nov_Dic'.split('_');
|
||||||
|
return moment.defineLocale('es', {
|
||||||
|
months : 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
|
||||||
|
monthsShort : function (m, format) {
|
||||||
|
if (/-MMM-/.test(format)) {
|
||||||
|
return monthsShort[m.month()];
|
||||||
|
} else {
|
||||||
|
return monthsShortDot[m.month()];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
weekdays : 'domingo_lunes_martes_miércoles_jueves_viernes_sábado'.split('_'),
|
||||||
|
weekdaysShort : 'dom._lun._mar._mié._jue._vie._sáb.'.split('_'),
|
||||||
|
weekdaysMin : 'Do_Lu_Ma_Mi_Ju_Vi_Sa'.split('_'),
|
||||||
|
longDateFormat : {
|
||||||
|
LT : 'H:mm',
|
||||||
|
LTS : 'LT:ss',
|
||||||
|
L : 'DD/MM/YYYY',
|
||||||
|
LL : 'D [de] MMMM [de] YYYY',
|
||||||
|
LLL : 'D [de] MMMM [de] YYYY LT',
|
||||||
|
LLLL : 'dddd, D [de] MMMM [de] YYYY LT'
|
||||||
|
},
|
||||||
|
calendar : {
|
||||||
|
sameDay : function () {
|
||||||
|
return '[hoy a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
|
||||||
|
},
|
||||||
|
nextDay : function () {
|
||||||
|
return '[mañana a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
|
||||||
|
},
|
||||||
|
nextWeek : function () {
|
||||||
|
return 'dddd [a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
|
||||||
|
},
|
||||||
|
lastDay : function () {
|
||||||
|
return '[ayer a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
|
||||||
|
},
|
||||||
|
lastWeek : function () {
|
||||||
|
return '[el] dddd [pasado a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
|
||||||
|
},
|
||||||
|
sameElse : 'L'
|
||||||
|
},
|
||||||
|
relativeTime : {
|
||||||
|
future : 'en %s',
|
||||||
|
past : 'hace %s',
|
||||||
|
s : 'unos segundos',
|
||||||
|
m : 'un minuto',
|
||||||
|
mm : '%d minutos',
|
||||||
|
h : 'una hora',
|
||||||
|
hh : '%d horas',
|
||||||
|
d : 'un día',
|
||||||
|
dd : '%d días',
|
||||||
|
M : 'un mes',
|
||||||
|
MM : '%d meses',
|
||||||
|
y : 'un año',
|
||||||
|
yy : '%d años'
|
||||||
|
},
|
||||||
|
ordinalParse : /\d{1,2}º/,
|
||||||
|
ordinal : '%dº',
|
||||||
|
week : {
|
||||||
|
dow : 1, // Monday is the first day of the week.
|
||||||
|
doy : 4 // The week that contains Jan 4th is the first week of the year.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
function cb(start, end){
|
||||||
|
$('#daterangevis span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
|
||||||
|
}
|
||||||
|
cb(moment().subtract(1, 'month'),moment());
|
||||||
|
date = $('#daterangevis').daterangepicker({
|
||||||
|
locale: {
|
||||||
|
format: 'YYYY-MM-DD',
|
||||||
|
customRangeLabel: 'Selecciona Rango'
|
||||||
|
},
|
||||||
|
ranges: {
|
||||||
|
'Ultimos 30 Dias': [moment().subtract(29, 'days'), moment()],
|
||||||
|
'Este Mes': [moment().startOf('month'), moment().endOf('month')],
|
||||||
|
'Mes Pasado': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
|
||||||
|
'A\u00f1o pasado': [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')],
|
||||||
|
'A\u00f1o pasado - Hoy': [moment().subtract(1, 'year').startOf('year'), moment()],
|
||||||
|
'Este A\u00f1o': [moment().startOf('year'), moment()]
|
||||||
|
}
|
||||||
|
},cb);
|
||||||
|
$('.applyBtn').text('Aceptar');
|
||||||
|
$('.applyBtn').removeClass('btn-primary');
|
||||||
|
$('.applyBtn').addClass('btn-info');
|
||||||
|
$('.cancelBtn ').text('Cancelar');
|
||||||
|
$('.cancelBtn ').removeClass('btn-default');
|
||||||
|
$('.cancelBtn ').addClass('btn-danger');
|
||||||
|
$('#daterangevis').on('apply.daterangepicker', function(ev, picker) {
|
||||||
|
getJson(picker.startDate.format('YYYY-MM-DD'),picker.endDate.format('YYYY-MM-DD'));
|
||||||
|
});
|
||||||
|
|
||||||
|
function getJson ( fechaInicio, fechaFin){
|
||||||
|
if(fechaInicio==''){
|
||||||
|
fechaInicio=moment().subtract(1, 'month').format('YYYY-MM-DD');
|
||||||
|
}
|
||||||
|
if(fechaFin==''){
|
||||||
|
fechaFin=moment().format('YYYY-MM-DD');
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#fechaini-vis').val(fechaInicio);
|
||||||
|
$('#fechafin-vis').val(fechaFin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
//--------------------------- FILTER ------------------------------------
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
$(".btnfilter").click(function(){
|
||||||
|
$(".btnfilter").html('Buscando...');
|
||||||
|
$("#estafetatable3").hide();
|
||||||
|
$(".layer-load").show();
|
||||||
|
if (!$("#wrapper").hasClass('toggled')) {
|
||||||
|
$("#wrapper").toggleClass("toggled");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($('#estafetatable3').hasClass('Initialize')) {
|
||||||
|
$("#estafetatable3").hide();
|
||||||
|
$(".layer-load").show();
|
||||||
|
$(".btn-advance").text('Mostrar filtro avanzado');
|
||||||
|
$("#estafetatable3").dataTable().fnDestroy();
|
||||||
|
setTimeout(function(){ extractData(); }, 800);
|
||||||
|
}else{
|
||||||
|
$('#estafetatable3').addClass('Initialize');
|
||||||
|
extractData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
//--------------------------- DATA ------------------------------------
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
function extractData(){
|
||||||
|
$(".layer-load").show();
|
||||||
|
var fechainit = $('#fechaini-vis').val();
|
||||||
|
var fechafin = $('#fechafin-vis').val();
|
||||||
|
var estado = $('#filestadouser-vis').val();
|
||||||
|
|
||||||
|
$("#estafetatable3 tfoot tr").empty();
|
||||||
|
var data = {fechaini:fechainit,fechafin:fechafin,estado:estado};
|
||||||
|
|
||||||
|
$(".layer-load").show();
|
||||||
|
var dataSet = [];
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type:'POST',
|
||||||
|
data:data,
|
||||||
|
url: 'reporte_getCategoria_visitados.php'
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
var _data = JSON.parse(data);
|
||||||
|
//console.log(_data.columns);
|
||||||
|
//$.each(_data.data, function (index, val) {
|
||||||
|
//dataSet[index] = [val['fecha'],val['estado_empleado'],val['numempl'],val['user'],val['apellidos'],val['posicion'],val['sociedad'],val['division'],val['unidad_organizativa'],val['ceco'],val['nomdistrito'],val['nomcentro'],val['supervisor'],val['nomcat'],val['nomcurso'],val['subtema'],val['estado']];
|
||||||
|
//});
|
||||||
|
|
||||||
|
|
||||||
|
$.each(_data.columnasvisibles, function (index, val) {
|
||||||
|
$("#estafetatable3 tfoot tr").append('<th></th>');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#estafetatable3 tbody').empty();
|
||||||
|
$('#estafetatable3').DataTable({
|
||||||
|
searchPanes: {
|
||||||
|
viewTotal: true
|
||||||
|
},
|
||||||
|
dom: 'PBfrtip',
|
||||||
|
/*dom: "Bfrtip",*/
|
||||||
|
buttons: [
|
||||||
|
//'pageLength',
|
||||||
|
{
|
||||||
|
extend: 'excel',
|
||||||
|
exportOptions: {
|
||||||
|
//columns: ':visible'
|
||||||
|
},
|
||||||
|
autoFilter: true,
|
||||||
|
title: 'Reporte por recursos revisados - Estafeta',
|
||||||
|
sheetName: 'Reporte por recursos revisados',
|
||||||
|
text: 'Exportar a Excel'
|
||||||
|
},
|
||||||
|
'colvis'
|
||||||
|
],
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
},
|
||||||
|
'order':false,
|
||||||
|
/*
|
||||||
|
'order': [
|
||||||
|
[2, 'desc'],
|
||||||
|
[0, 'asc']
|
||||||
|
],
|
||||||
|
*/
|
||||||
|
"responsive": true,
|
||||||
|
data: _data.data,
|
||||||
|
columns: _data.columnasvisibles,
|
||||||
|
orderCellsTop: true,
|
||||||
|
fixedHeader: true,
|
||||||
|
initComplete: function () {
|
||||||
|
$('.btn-advance').show(300);
|
||||||
|
$('.dtsp-panesContainer').hide();
|
||||||
|
this.api().columns().every( function () {
|
||||||
|
var column = this;
|
||||||
|
var select = $('<br><select class="myselect"><option value="">TODOS</option></select>')
|
||||||
|
.appendTo( $(column.footer()).after())
|
||||||
|
.on('change', function () {
|
||||||
|
var val = $.fn.dataTable.util.escapeRegex(
|
||||||
|
$(this).val()
|
||||||
|
);
|
||||||
|
|
||||||
|
column
|
||||||
|
.search( val ? '^'+val+'$' : '', true, false )
|
||||||
|
.draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
column.data().unique().sort().each( function ( d, j ) {
|
||||||
|
select.append( '<option value="'+d+'">'+d+'</option>' )
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$(".myselect").select2();
|
||||||
|
$("#estafetatable3").show();
|
||||||
|
$(".layer-load").hide();
|
||||||
|
$(".btnfilter").html('Ver');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$(".btn-advance").click(function(){
|
||||||
|
if($('.dtsp-panesContainer').is(':visible')) {
|
||||||
|
$(".btn-advance").text('Mostrar filtro avanzado');
|
||||||
|
}else{
|
||||||
|
$(".btn-advance").text('Ocultar filtro avanzado');
|
||||||
|
}
|
||||||
|
$('.dtsp-panesContainer').toggle(300);
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".btn_download").click(function(){
|
||||||
|
var fechainit = $('#fechaini-vis').val();
|
||||||
|
var fechafin = $('#fechafin-vis').val();
|
||||||
|
var estado = $('#filestadouser-vis').val();
|
||||||
|
var categoria = $('#filcategoriauser-cat').val();
|
||||||
|
window.open('reporteExportCatVisitadasv2.php?categoria='+categoria+'&fechaini='+fechainit+"&fechafin="+fechafin+"&estado="+estado, '_blank');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
listadoDeCategorias();
|
||||||
|
|
||||||
|
function listadoDeCategorias() {
|
||||||
|
$(".layer-load").show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'categorias_list.php',
|
||||||
|
type: 'POST'
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
var _data = JSON.parse(response);
|
||||||
|
|
||||||
|
$('#filcategoriauser-cat').empty();
|
||||||
|
|
||||||
|
$.each(_data.datos, function (index, val) {
|
||||||
|
if (val.padre == 0) {
|
||||||
|
$("#filcategoriauser-cat").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(_data);
|
||||||
|
$('.layer-load').hide();
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
var table = $('#estafetatable').DataTable({
|
||||||
|
responsive: true,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
},
|
||||||
|
"initComplete": function (settings, json) {
|
||||||
|
$('div.load').remove();
|
||||||
|
$(".nooverflow").removeClass('nooverflow');
|
||||||
|
$("#estafetatable").show();
|
||||||
|
},
|
||||||
|
columnDefs: [
|
||||||
|
{ targets: 'no-sort', orderable: false }
|
||||||
|
],
|
||||||
|
"processing": true,
|
||||||
|
"serverSide": true,
|
||||||
|
"ajax": {
|
||||||
|
url: "reporte_getDataDate.php",
|
||||||
|
type: "post"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<div class="col-12 text-primary mt-3">
|
||||||
|
<h1>Reporte de cumplimiento detalle por curso</h1>
|
||||||
|
</div>
|
||||||
|
<!--
|
||||||
|
<div class="col-12 text-left my-5">
|
||||||
|
<a target="_blank" href="export.php?key=<?php echo generateRandomString(); ?>" class="p-3 btn-primary text-white btn-descarga">Descargar Reporte</a>
|
||||||
|
</div>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<table class="table table-striped table-bordered" style="width:100%; display: none;" id="estafetaCursostable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<!-- <th>id</th> -->
|
||||||
|
<th>Número de empleado</th>
|
||||||
|
<th class="no-sort">Clave</th>
|
||||||
|
<th class="no-sort">Curso</th>
|
||||||
|
<th class="no-sort">Calificación promedio</th>
|
||||||
|
<th class="no-sort">Estado</th>
|
||||||
|
<th class="no-sort">Visitados</th>
|
||||||
|
<th class="no-sort">Fecha</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<!-- <th>id</th> -->
|
||||||
|
<th>Número de empleado</th>
|
||||||
|
<th class="no-sort">Clave</th>
|
||||||
|
<th class="no-sort">Curso</th>
|
||||||
|
<th class="no-sort">Calificación promedio</th>
|
||||||
|
<th class="no-sort">Estado</th>
|
||||||
|
<th class="no-sort">Visitados</th>
|
||||||
|
<th class="no-sort">Fecha</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
var table = $('#estafetaCursostable').DataTable({
|
||||||
|
responsive: true,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
},
|
||||||
|
"initComplete": function (settings, json) {
|
||||||
|
$('div.load').remove();
|
||||||
|
$(".nooverflow").removeClass('nooverflow');
|
||||||
|
$("#estafetaCursostable").show();
|
||||||
|
},
|
||||||
|
columnDefs: [
|
||||||
|
{ targets: 'no-sort', orderable: false }
|
||||||
|
],
|
||||||
|
"processing": true,
|
||||||
|
"serverSide": true,
|
||||||
|
"ajax": {
|
||||||
|
url: "reporte_getDataDate.php",
|
||||||
|
type: "post"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__.'/auth_guard.php';
|
||||||
|
include '../config.php';
|
||||||
|
session_name($CFG->sessionname);
|
||||||
|
session_start();
|
||||||
|
if(!isset($_SESSION['usersession'])){
|
||||||
|
header("Location: ".$CFG->wwwroot);
|
||||||
|
}
|
||||||
|
function generateRandomString($length = 10) {
|
||||||
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
|
$charactersLength = strlen($characters);
|
||||||
|
$randomString = '';
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||||
|
}
|
||||||
|
return $randomString;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="col-12 text-primary mt-3">
|
||||||
|
<h1>Reporte de cumplimiento detalle por curso</h1>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 text-left my-5">
|
||||||
|
<a target="_blank" href="reporteExportCursos.php?key=<?php echo generateRandomString(); ?>" class="p-3 btn-primary text-white btn-descarga" >Descargar Reporte</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-12">
|
||||||
|
<table class="table table-striped table-bordered" style="width:100%" id="estafetatable1">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Número de empleado</th>
|
||||||
|
<th>Nombre(s)</th>
|
||||||
|
<th>Apellidos</th>
|
||||||
|
<th>Centro de trabajo</th>
|
||||||
|
<th>Distrito</th>
|
||||||
|
<th>Nombre del curso</th>
|
||||||
|
<th>Nombre del tema</th>
|
||||||
|
<th>Calificación</th>
|
||||||
|
<th>Fecha</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr class="text-center"><td colspan="9">Procesando...</td></tr>
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th>Número de empleado</th>
|
||||||
|
<th>Nombre(s)</th>
|
||||||
|
<th>Apellidos</th>
|
||||||
|
<th>Centro de trabajo</th>
|
||||||
|
<th>Distrito</th>
|
||||||
|
<th>Nombre del curso</th>
|
||||||
|
<th>Nombre del tema</th>
|
||||||
|
<th>Calificación</th>
|
||||||
|
<th>Fecha</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
extractData();
|
||||||
|
|
||||||
|
function extractData(){
|
||||||
|
$(".layer-load").show();
|
||||||
|
var dataSet = [];
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: 'reporte_getCurso.php'
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
var _data = JSON.parse(data);
|
||||||
|
|
||||||
|
$.each(_data.data, function (index, val) {
|
||||||
|
dataSet[index] = [val['numempl'],val['nomempl'],val['apellido'],val['nomcentro'],val['nomdistrito'],val['catnom'],val['nombre'],val['calificacion'],val['fecha']];
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#estafetatable1 tbody').empty();
|
||||||
|
$('#estafetatable1').DataTable({
|
||||||
|
//dom: "Bfrtip",
|
||||||
|
//buttons: [
|
||||||
|
//{
|
||||||
|
//extend: 'excel',
|
||||||
|
//text: 'Exportar a Excel'
|
||||||
|
//},
|
||||||
|
//],
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
},
|
||||||
|
'order': [
|
||||||
|
[0, 'desc'],
|
||||||
|
[8, 'asc']
|
||||||
|
],
|
||||||
|
"responsive": true,
|
||||||
|
data: dataSet,
|
||||||
|
columns: [
|
||||||
|
{ title: "Número de empleado" },
|
||||||
|
{ title: "Nombre(s)" },
|
||||||
|
{ title: "Apellidos" },
|
||||||
|
{ title: "Centro de trabajo" },
|
||||||
|
{ title: "Distrito" },
|
||||||
|
{ title: "Nombre del curso" },
|
||||||
|
{ title: "Nombre del tema" },
|
||||||
|
{ title: "Calificación" },
|
||||||
|
{ title: "Fecha" },
|
||||||
|
|
||||||
|
]
|
||||||
|
});
|
||||||
|
$("#estafetatable1").show();
|
||||||
|
$(".layer-load").hide();
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
var table = $('#estafetatable1').DataTable({
|
||||||
|
responsive: true,
|
||||||
|
"language": {
|
||||||
|
"url": "../json/Spanish.json"
|
||||||
|
},
|
||||||
|
"initComplete": function (settings, json) {
|
||||||
|
$('div.load').remove();
|
||||||
|
$(".nooverflow").removeClass('nooverflow');
|
||||||
|
$("#estafetatable1").show();
|
||||||
|
|
||||||
|
},
|
||||||
|
columnDefs: [
|
||||||
|
{ targets: 'no-sort', orderable: false }
|
||||||
|
],
|
||||||
|
"processing": true,
|
||||||
|
"serverSide": true,
|
||||||
|
"ajax": {
|
||||||
|
url: "reporte_getDataDetalle.php",
|
||||||
|
type: "post"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
</script>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user