source: admin/WebConsole/principal/calendars.php

lgromero-new-oglive
Last change on this file was dcc225a, checked in by Natalia Serrano <natalia.serrano@…>, 18 months ago

Attach calendars to aulas

  • Property mode set to 100644
File size: 3.4 KB
Line 
1<?php
2include_once("../includes/ctrlacc.php");
3include_once("../includes/CreaComando.php");
4include_once("../clases/AdoPhp.php");
5
6function del_cal_from_db ($id) {
7    global $cadenaconexion;
8    $cmd = CreaComando ($cadenaconexion);
9    if (!$cmd) {
10        die ($TbMsg['ACCESS_ERROR']);
11    }
12    $cmd->CreaParametro ('@id', $id, 0);
13    $cmd->texto = 'DELETE FROM calendarios WHERE idcalendario=@id;';
14    if (!$cmd->Ejecutar()) {
15        return $cmd->DescripUltimoError();
16    }
17    return;
18}
19
20function fetch_cals() {
21    global $cadenaconexion;
22    $tbl = array();
23
24    $cmd = CreaComando ($cadenaconexion);
25    if (!$cmd) die ($TbMsg['ACCESS_ERROR']);
26
27    $cmd->texto = 'SELECT idcalendario, description, json_text FROM calendarios';
28    $rs = new Recordset;
29    $rs->Comando = &$cmd;
30
31    if (!$rs->Abrir()) return (false);
32
33    $rs->Primero();
34    if ($rs->EOF) {
35        return ($tbl);
36    }
37    $id = $rs->campos['idcalendario'];
38    $desc = $rs->campos['description'];
39    $txt = $rs->campos['json_text'];
40    array_push ($tbl, array (
41        'id'        => $id,
42        'desc'      => (empty ($desc) ? 'none' : $desc),
43        'json_text' => (empty ($txt) ? 'none' : $txt),
44    ));
45
46    while (1) {
47        $rs->Siguiente();
48        if ($rs->EOF) {
49            break;
50        }
51        $id = $rs->campos['idcalendario'];
52        $desc = $rs->campos['description'];
53        $txt = $rs->campos['json_text'];
54        array_push ($tbl, array (
55            'id'        => $id,
56            'desc'      => (empty ($desc) ? 'none' : $desc),
57            'json_text' => (empty ($txt) ? 'none' : $txt),
58        ));
59    }
60
61    $rs->Cerrar();     
62    return ($tbl);
63}
64
65function count_rules ($t1) {
66    if (0 === sizeof ($t1)) {
67        return $t1;
68    }
69    foreach (range (0, count ($t1)-1) as $idx) {
70        $cal = json_decode ($t1[$idx]['json_text'], true);
71        if ($cal) {
72            $ruleset = $cal['remotepc_calendar']['ruleset'];
73            $t1[$idx]['_count'] = count ($ruleset);
74        } else {
75            $t1[$idx]['_count'] = '(error decoding json)';
76        }
77    }
78    return $t1;
79}
80
81function build_html_table_cal_list ($tbl) {
82    $tbl_str = '<table border="1">';
83   
84    //$tbl_str .= '<tr><th>Calendario</th><th>Número de reglas</th></tr>';
85    foreach ($tbl as $row) {
86        $tbl_str .= sprintf ('<tr><td><a href="calendars-modify.php?cal_id=%s">%s</a></td><td>%s reglas</td><td><input type="submit" value="Borrar" onclick=\'document.forms[0].cal_to_del.value=%s;\' /></td></tr>', $row['id'], $row['desc'], $row['_count'], $row['id']);
87    }
88
89    $tbl_str .= '</table>';
90    return ($tbl_str);
91}
92
93$db_err = '';
94if (isset ($_POST['cal_to_del'])) {
95    $db_err = del_cal_from_db ($_POST['cal_to_del']);
96}
97$tbl = fetch_cals();
98$tbl = count_rules ($tbl);
99$table_html = build_html_table_cal_list ($tbl);
100?>
101
102<html>
103<head>
104<title>Administración web de calendarios</title>
105<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
106<link rel="shortcut icon" href="images/iconos/logocirculos.png" type="image/png" />
107<link rel="stylesheet" type="text/css" href="estilos.css" />
108</head>
109
110<body>
111    <?php if ($db_err) { printf ('<p>Error: (%s)</p>', $db_err); } ?>
112    <form method="post">
113        <input type="hidden" name="cal_id" value="-1" />
114        <input type="hidden" name="cal_to_del" value="" />
115        <p><?= $table_html ?></p>
116        <input type="submit" value="Nuevo calendario" onclick='document.forms[0].action="./calendars-modify.php";' />
117    </form>
118</body>
119</html>
Note: See TracBrowser for help on using the repository browser.