Example #1
0
function get_config()
{
    global $config_info;
    $config_local = mdb2_all_assoc_rekey("SELECT config_key, config_value FROM config");
    foreach ($config_info as $key => $value) {
        if (!isset($config_local[$key])) {
            $config_local[$key] = $value;
            mdb2_exec("INSERT INTO config ( config_key, config_value ) VALUES ( '%q', '%q' )", $key, $value);
        }
    }
    return $config_local;
}
Example #2
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);
}