<?php

// -----------------------------------------------------------------
// tady můžete nastavit práva (1 - 3)
// here you can set the rights (1 - 3)
if ($rights>=3):
// -----------------------------------------------------------------

if ($a=="new_backup") {

$kcms_articles_data="";
$kcms_articles=mysql_query("SELECT quick, title, type, hp, complete, confirmed, discussion, section, perex, text, added, published, author, publisher, edited, pereximg, views FROM kcms_articles ORDER by id");
while (list($quick, $title, $type, $hp, $complete, $confirmed, $discussion, $section, $perex, $text, $added, $published, $author, $publisher, $edited, $pereximg, $views) = mysql_fetch_row($kcms_articles)) {
$kcms_articles_data=$kcms_articles_data."\$sql=mysql_query(\"INSERT INTO kcms_articles values ('', '$quick', '$title', '$type', '$hp', '$complete', '$confirmed', '$discussion', '$section', '$perex', '$text', '$added', '$published', '$author', '$publisher', '$edited', '$pereximg', '$views');\", \$dbserver);\n";
}

$kcms_comments_data="";
$kcms_comments=mysql_query("SELECT article, added, author, text, confirmed, user FROM kcms_comments ORDER by id");
while (list($article, $added, $author, $text, $confirmed, $user) = mysql_fetch_row($kcms_comments)) {
$kcms_comments_data=$kcms_comments_data."\$sql=mysql_query(\"INSERT INTO kcms_comments values ('', '$article', '$added', '$author', '$text', '$confirmed', '$user');\", \$dbserver);\n";
}

$kcms_files_data="";
$kcms_files=mysql_query("SELECT file, added FROM kcms_files ORDER by id");
while (list($file, $added) = mysql_fetch_row($kcms_files)) {
$kcms_files_data=$kcms_files_data."\$sql=mysql_query(\"INSERT INTO kcms_files values ('', '$file', '$added');\", \$dbserver);\n";
}

$kcms_images_data="";
$kcms_images=mysql_query("SELECT section, file, added FROM kcms_images ORDER by id");
while (list($section, $file, $added) = mysql_fetch_row($kcms_images)) {
$kcms_images_data=$kcms_images_data."\$sql=mysql_query(\"INSERT INTO kcms_images values ('', '$section', '$file', '$added');\", \$dbserver);\n";
}

$kcms_images_sections_data="";
$kcms_images_sections=mysql_query("SELECT quick, name, public FROM kcms_images_sections ORDER by id");
while (list($quick, $name, $public) = mysql_fetch_row($kcms_images_sections)) {
$kcms_images_sections_data=$kcms_images_sections_data."\$sql=mysql_query(\"INSERT INTO kcms_images_sections values ('', '$quick', '$name', '$public');\", \$dbserver);\n";
}

$kcms_sections_data="";
$kcms_sections=mysql_query("SELECT quick, name, highlight, outlink FROM kcms_sections ORDER by id");
while (list($quick, $name, $highlight, $outlink) = mysql_fetch_row($kcms_sections)) {
$kcms_sections_data=$kcms_sections_data."\$sql=mysql_query(\"INSERT INTO kcms_sections values ('', '$quick', '$name', '$highlight', '$outlink');\", \$dbserver);\n";
}

$kcms_users_data="";
$kcms_users=mysql_query("SELECT login, password, rights, age, jabber, skype, about, mail, realname, regdate, lastvisit FROM kcms_users ORDER by id");
while (list($login, $password, $rights, $age, $jabber, $skype, $about, $mail, $realname, $regdate, $lastvisit) = mysql_fetch_row($kcms_users)) {
$kcms_users_data=$kcms_users_data."\$sql=mysql_query(\"INSERT INTO kcms_users values ('', '$login', '$password', '$rights', '$age', '$jabber', '$skype', '$about', '$mail', '$realname', '$regdate', '$lastvisit');\", \$dbserver);\n";
}

$kcms_variables_data="\$sql=mysql_query(\"UPDATE kcms_variables SET value='$lang' WHERE variable='lang';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$sitename' WHERE variable='sitename';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$login_for_comments' WHERE variable='login_for_comments';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$show_text' WHERE variable='show_text';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$sort_sections_by_name' WHERE variable='sort_sections_by_name';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$articles_number' WHERE variable='articles_number';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$left_column' WHERE variable='left_column';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$right_column' WHERE variable='right_column';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$selected_theme' WHERE variable='selected_theme';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$show_news_box' WHERE variable='show_news_box';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$show_promo_box' WHERE variable='show_promo_box';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$news_box_items' WHERE variable='news_box_items';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$promo_box_items' WHERE variable='promo_box_items';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$show_infolane' WHERE variable='show_infolane';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$show_sitename' WHERE variable='show_sitename';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$header_wallpaper' WHERE variable='header_wallpaper';\", \$dbserver);
\$sql=mysql_query(\"UPDATE kcms_variables SET value='$header_wallpaper_height' WHERE variable='header_wallpaper_height';\", \$dbserver);";

// spojime data do sql souboru

$sql="<?php\n\n/* Záloha systému K:CMS $version (KCMS $version backup)\n\n".date("d.m.Y, H:i", time())." */\n\n".$kcms_articles_data."\n\n".$kcms_comments_data."\n\n".$kcms_files_data."\n\n".$kcms_images_data."\n\n".$kcms_images_sections_data."\n\n".$kcms_sections_data."\n\n".$kcms_users_data."\n\n".$kcms_variables_data."\n\n?".">";

$db_backup=fopen("./backups/k_cms_db_backup_".date("d_m_y_H_i", time()).".php", "w+");
fwrite($db_backup, $sql);
fclose($db_backup);

echo "<div class=\"popup-success\">$lang_alert_success</div>";

}

if ($a=="load_backup") {
include ("./backups/".$_POST["backup_file"]);
if ($sql) {
echo "<div class=\"popup-success\">$lang_alert_success</div>";
} else {
echo "<div class=\"popup-error\">$lang_alert_error</div>";
}
}

?>

<h2><?php echo($lang_backup); ?></h2>

<form action="./admin.php?f=backup&amp;a=new_backup" method="post">

<div><strong><?php echo($lang_form_new_backup); ?>:</strong><br />
<input type="submit" value="<?php echo($lang_button_create_new_backup); ?>" />
</div>

</form>

<form action="./admin.php?f=backup&amp;a=load_backup" method="post">

<div><strong><?php echo($lang_form_load_backup); ?>:</strong><br />
<select name="backup_file" style="width: 300px;">
<?php
$dir=opendir("./backups/");
while ($file=readdir($dir)){
$file=explode(".", $file);
if ($file[0]!="" AND $file[1]=="php") {
echo "<option value=\"".$file[0].".php\">".$file[0]."</option>\n";
}
}
?>
</select> <input type="submit" onclick="if (!confirm('<?php echo($lang_alert_sure); ?>')) return false;" value="<?php echo($lang_form_load_backup); ?>" />
</div>

</form>

<?php else: $access_denied=1; endif; ?>