<?php

# HA NINCS ID, AKKOR BEÁLLÍTÁSOK
# HA VAN ID, AKKOR ADOTT BEÁLLÍTÁS
if ($this->is_id()) {
    # ADOTT BEÁLLÍTÁS

    //először ellenőrizzük, hogy létezik-e hozzá setting_value, ha nem, akkor létrehozzuk
    if (!$sql->num_of_rows('SELECT * FROM setting_value WHERE setv_setting_set_id = ' . $this->get_id())) {
        $new_set = new setting();
        $new_set->set_setting_data_by_id($this->get_id());
        $new_setting_value_id = $sql->insert_into('setting_value', array(
                'setv_set_date' => date('Y-m-d H:i:s'),
                'setv_setting_set_id' => $this->get_id()
            ));
    }
    $new_setting = new setting_value();
    $new_setting->set_setting_value_data_by_id($this->get_id());

    if ($new_setting->get_setv_setting()->get_set_setting_type_st_id() == 1) {
        //textarea
    }

    elseif ($new_setting->get_setv_setting()->get_set_setting_type_st_id() == 2) {
        //biztonsági mentés
        $backup_assoc_array = $sql->assoc_array("SELECT * FROM backup WHERE bu_deleted = 0 ORDER BY bu_date DESC, bu_id DESC limit 14;");
        $backups = array();
        foreach ($backup_assoc_array as $value) {
            $new_backup = new backup();
            $new_backup->set_backup_data_by_id($value['bu_id']);
            $backups[] = $new_backup;
        }
        $smarty->assign('backups', $backups);
    }

    elseif ($new_setting->get_setv_setting()->get_set_setting_type_st_id() == 3) {
        //url -> hozzáfűzi az admin után a varcharban lévő url-t
        header('Location: /admin/' . $new_setting->get_setv_varchar());
    }

    elseif ($new_setting->get_setv_setting()->get_set_setting_type_st_id() == 4) {

    }



    $smarty->assign("setting", $new_setting);

    $smarty->display("setting_data_edit.tpl");

}
else {
    # BEÁLLÍTÁSOK

    $settings_query = "SELECT * FROM setting ORDER BY set_name ASC";
    $settings_assoc_array = $sql->assoc_array($settings_query);

    $settings = array();

    foreach ($settings_assoc_array as $value) {
        $new_setting = new setting();
        $new_setting->set_setting_data_by_id($value['set_id']);
        $settings[] = $new_setting;
    }

    $smarty->assign('settings',$settings);
    $smarty->display('settings.tpl');



}

?>
