Example #1
0
function do_dag($week_id, $dag, $rd)
{
    if (isset($_POST['id' . $week_id . $dag]) && !$rd) {
        mdb2_exec("UPDATE weken SET {$dag} = 1 WHERE week_id = {$week_id}");
    } else {
        if (!isset($_POST['id' . $week_id . $dag]) && $rd) {
            mdb2_exec("UPDATE weken SET {$dag} = 0 WHERE week_id = {$week_id}");
        }
    }
}
Example #2
0
function lock_renew($string)
{
    // we can only renew a lock if it is ours, so we check by including the PID
    mdb2_exec("UPDATE locking SET locking_status = '%q', locking_last_timestamp = " . time() . " WHERE locking_id = 0 AND locking_pid = " . getmypid(), $string);
}
Example #3
0
if (!($until = strtotime($_POST['until']))) {
    fatal_error("het veld 'Zichtbaar vanaf' bevat geen geldige datum");
}
if (isset($_POST['bericht_id'])) {
    if ($_POST['submit'] == 'Opslaan') {
        // we wijzigen een bestaand bericht
        mdb2_exec("UPDATE berichten SET bericht_title = '%q', bericht_body = '%q', bericht_visiblefrom = '%q', bericht_visibleuntil = '%q', bericht_update = {$_SERVER['REQUEST_TIME']} WHERE bericht_id = %i", bbtohtml(htmlenc($_POST['title'])), bbtohtml(htmlenc($_POST['body'])), $from, $until, $_POST['bericht_id']);
        mdb2_exec("DELETE FROM entities2berichten WHERE bericht_id = %i", $_POST['bericht_id']);
        if (isset($_POST['entity_ids'])) {
            foreach ($_POST['entity_ids'] as $entity_id) {
                mdb2_exec("INSERT INTO entities2berichten ( entity_id, bericht_id ) VALUES ( %i, %i )", $entity_id, $_POST['bericht_id']);
            }
        }
    } else {
        if ($_POST['submit'] == 'Wissen') {
            mdb2_exec("DELETE FROM berichten WHERE bericht_id = %i", $_POST['bericht_id']);
            mdb2_exec("DELETE FROM entities2berichten WHERE bericht_id = %i", $_POST['bericht_id']);
        } else {
            fatal_error('onmogelijke submit!');
        }
    }
} else {
    mdb2_exec("INSERT INTO berichten ( bericht_title, bericht_body, bericht_visiblefrom, bericht_visibleuntil, bericht_update ) VALUES ( '%q', '%q', '%q', '%q', {$_SERVER['REQUEST_TIME']} )", bbtohtml(htmlenc($_POST['title'])), bbtohtml(htmlenc($_POST['body'])), $from, $until);
    $bericht_id = mdb2_last_insert_id();
    if (isset($_POST['entity_ids'])) {
        foreach ($_POST['entity_ids'] as $entity_id) {
            mdb2_exec("INSERT INTO entities2berichten ( entity_id, bericht_id ) VALUES ( %i, {$bericht_id} )", $entity_id);
        }
    }
}
header('Location: upload.php?secret=' . $_POST['secret']);
Example #4
0
<?php

require_once 'common.php';
check_roostermaker($_POST['secret']);
header('Content-type: text/plain');
$entities = mdb2_query(<<<EOQ
SELECT entity_id, CASE WHEN entity_active = 1 THEN 1 ELSE 0 END
FROM entities WHERE entity_type != %i AND entity_type != %i AND entity_type != 0
EOQ
, LEERLING, LESGROEP);
$inverted = array();
foreach ($_POST['entity_ids'] as $entity_id) {
    $inverted[$entity_id] = 1;
}
//print_r($inverted);
while ($row = $entities->fetchRow()) {
    if ($row[1] == 1 && !isset($inverted[$row[0]])) {
        mdb2_exec("UPDATE entities SET entity_active = NULL WHERE entity_id = %i", $row[0]);
        //echo("wis {$row[0]}\n");
    } else {
        if ($row[1] == 0 && isset($inverted[$row[0]])) {
            mdb2_exec("UPDATE entities SET entity_active = 1 WHERE entity_id = %i", $row[0]);
            //echo("set {$row[0]}\n");
        }
    }
}
header('Location: upload.php?secret=' . $_POST['secret']);
Example #5
0
function import_wijzigingen($file_id, $week, $tmp_name, $basis_id)
{
    global $wijz, $stamz;
    unset($GLOBALS['wijz']);
    $wijz = array();
    lock_renew_helper(1);
    // fill stamz array, so stuff like 2A.2A1A can be changed to 2A1A
    $stamz = mdb2_all_assoc_rekey('SELECT entities.entity_name, entities2.entity_name AS value FROM entities JOIN grp2grp ON grp2grp.lesgroep_id = entities.entity_id JOIN entities AS entities2 ON entities2.entity_id = grp2grp.lesgroep2_id AND entities2.entity_type = ' . CATEGORIE . ' WHERE entities.entity_type = ' . STAMKLAS);
    // als de roostermakers roosterwijzigingen wissen, dan zou de wijzigingenfile kleiner moeten worden
    // zermelo doet overwrite zonder truncate, na het wissen van roosterwijzigingen kunnen secties dubbel
    // voorkomen. Dat negeren we, want we hebben alleen de eerste sectie nodig
    read_all_sections($sections, $tmp_name, true);
    if ($sections === false) {
        fatal_error('read error on ' . $tmp_name . ', unable to perform update');
    }
    // a previous update may have gone wrong, cleanup just in case
    mdb2_exec("DELETE FROM files2lessen WHERE file_id = {$file_id}");
    //logit('no_sections='.count($sections));
    //foreach ($sections as $section => $lines) {
    //	logit('section name '.$section.', '.count($lines).' lines');
    //}
    $total = count($sections['PREAMBULE']);
    $done = 0;
    lock_renew_helper(2, 0);
    foreach ($sections['PREAMBULE'] as $atoms) {
        incdone($done, $total, 2);
        $old = explode(',', $atoms[1]);
        $max = count($atoms) - 1;
        if ($max > 1) {
            $new = explode(',', $atoms[2]);
        }
        //echo("nieuwe wijziging, aantal entries: $max\n");
        //print_r($old);
        //print_r($new);
        if ($max < 5) {
            // nieuw format roosterwijzigingen?
            if ($max < 1) {
                logit('te weinig records in roosterwijziging');
            }
            if ($max == 3) {
                $notitie = $atoms[3];
                logit("notitie van roostermakers: " . $notitie);
            } else {
                $notitie = NULL;
            }
            if ($atoms[1] == '' && $atoms[2] == '') {
                // dit is een wijziging van niks naar niks WTF?!?!?
                continue;
            }
            if ($max < 2 || $atoms[2] == '') {
                // lesuitval
                //logit("lesuitval {$atoms[1]}");
                if (!preg_match('/^([a-z]{2}) (u\\d+)$/', $old[2], $matches)) {
                    logit("ongeldig format voor 'dag uur'-veld in wijzigingen file: {$old[2]}");
                    continue;
                }
                $dag = $matches[1];
                $uur = $matches[2];
                $zermelo_id = find_les('/', $dag, $uur, $old[1], $old[0], $old[3], $old[4], $basis_id);
                if (!$zermelo_id) {
                    logit("oorspronkelijke les {$atoms[1]} niet gevonden?!?! wijziging {$atom[0]} kan niet worden ingelezen");
                    continue;
                }
                //echo('zermelo_id = '.find_les('/', $dag, $uur, $old[1], $old[0], $old[3], $old[4], $basis_id)."\n");
                insert_les('/', $zermelo_id, '', '', '', '', '', '', $file_id, $notitie);
            } else {
                //logit("echte wijziging {$atoms[1]} {$atoms[2]}");
                // we zetten de zermelo_id vast op 0, alsof er sprake is van een extra les
                // mocht er een oude les zijn, dan passen we de zermelo_id aan
                $zermelo_id = 0;
                if ($atoms[1] != '') {
                    //er is een oude les
                    if (!preg_match('/^([a-z]{2}) (u\\d+)$/', $old[2], $matches)) {
                        logit("ongeldig format voor 'dag uur'-veld in wijzigingen file: {$old[2]}");
                        continue;
                    }
                    $dag = $matches[1];
                    $uur = $matches[2];
                    $zermelo_id = find_les('/', $dag, $uur, $old[1], $old[0], $old[3], $old[4], $basis_id);
                    if (!$zermelo_id) {
                        logit("oorspronkelijke les {$atoms[1]} niet gevonden?!?! wijziging {$atom[0]} kan niet worden ingelezen");
                        continue;
                    }
                    //echo('zermelo_id = '.find_les('/', $dag, $uur, $old[1], $old[0], $old[3], $old[4], $basis_id)."\n");
                }
                if (!preg_match('/^([a-z]{2}) (u\\d+)$/', $new[2], $matches)) {
                    logit("ongeldig format voor 'dag uur'-veld in wijzigingen file: {$old[2]}");
                    continue;
                }
                $dag = $matches[1];
                $uur = $matches[2];
                insert_les_nieuw($zermelo_id, $dag, $uur, $new[1], $new[0], $new[3], $new[4], $file_id, $notitie);
            }
            continue;
        }
        if ($max > 6) {
            logit('(te?) veel records in roosterwijziging');
        }
        if ($atoms[$max - 1] != 'WEEKNUMMERS') {
            logit("onverwachte data in op een-na-laatste record van wijzigingen, verwacht WEEKNUMMERS: ");
            print_r($atoms);
            continue;
        }
        /*
        		if ($atoms[$max] != $week) {
        			logit("onverwachte data in laatste record van wijzigingen, verwacht $week");
        			return;
        		}
        */
        if ($atoms[1] == '0' && $atoms[2] == '0') {
            // dit is een wijziging van niks naar niks WTF?!?!?
            continue;
        }
        if ($max == 6) {
            $notitie = $atoms[4];
            //logit("notitie van roostermakers: ".$atoms[4]);
        } else {
            $notitie = NULL;
        }
        if ($atoms[2] == '0') {
            // lesuitval
            if (!($zermelo_id = add_zermelo_id($old[0]))) {
                return;
            }
            insert_les('/', $zermelo_id, '', '', '', '', '', '', $file_id, $notitie);
        } else {
            // echte wijziging?
            if (count($new) != 9 || $atoms[1] != 0 && count($old) != 9) {
                print_r($old);
                print_r($new);
                logit('rare leswijziging, deze negeren we');
                continue;
            }
            if (!($zermelo_id = add_zermelo_id($new[0]))) {
                return;
            }
            insert_les('/', $zermelo_id, $new[7], $new[5], $new[4], $new[1], $new[2], $new[3], $file_id, $notitie);
        }
    }
    //exit;
    // als we hier zijn, dan is alles goed gegaan
    mdb2_exec("UPDATE files SET file_status = 1 WHERE file_id = {$file_id}");
    lock_renew_helper(3, $done / $total);
}