<?php

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

if ($a=="delete_file" AND $id!="") {

$filename=mysql_query("SELECT file FROM kcms_files WHERE id='".addslashes($id)."'");
$filename=mysql_fetch_array($filename);

if ($filename["file"]!="") {

unlink("./files/".$filename["file"]);

$sql=mysql_query("DELETE FROM kcms_files WHERE id='".addslashes($id)."'", $dbserver);

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

}

}

if ($a=="rename_file" AND $id!="") {

if ($filename!="") {

$old_filename=mysql_query("SELECT file FROM kcms_files WHERE id='".addslashes($id)."'");
$old_filename=mysql_fetch_array($old_filename);

if ($old_filename["file"]!=$filename) {

$check=mysql_query("SELECT id FROM kcms_files WHERE file='".addslashes($filename)."'");
$check=mysql_fetch_array($check);

}

if ($check["id"]=="") {

rename("./files/".$old_filename["file"], "./files/".$filename);

$sql=mysql_query("UPDATE kcms_files SET file='".addslashes($filename)."' WHERE id='".addslashes($id)."'", $dbserver);

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

} else {

echo "<div class=\"popup-error\">$lang_alert_existing_file</div>";

}

} else {

echo "<div class=\"popup-error\">$lang_alert_empty_name</div>";

}

}

if ($a=="add_file") {

if ($file!="") {

$check=mysql_query("SELECT id FROM kcms_files WHERE file='".$_FILES["file"]["name"]."'");
$check=mysql_fetch_array($check);

if ($check["id"]=="") {

move_uploaded_file($_FILES["file"]["tmp_name"], "./files/".$_FILES["file"]["name"]);

$sql=mysql_query("INSERT INTO kcms_files values ('', '".$_FILES["file"]["name"]."', '".time()."')", $dbserver);

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

} else {

echo "<div class=\"popup-error\">$lang_alert_existing_file</div>";

}

} else {

echo "<div class=\"popup-error\">$lang_alert_empty_inputs</div>";

}

}

?>

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

<?php if ($f2==""): ?>

<form action="./admin.php?f=files&amp;a=add_file" method="post" enctype="multipart/form-data">

<div><strong><?php echo($lang_form_upload_file); ?>:</strong><?php if ($a=="add_file" AND $_FILES["file"]["name"]=="") { echo " <span class=\"input-error\">&nbsp;!&nbsp;</span>"; } ?>
<br />
<input type="file" name="file" />
<br />
<input type="submit" name="submit" value="<?php echo($lang_button_save); ?>" /></div>

</form>

<table>
<tr>
<th style="width: 30%;"><?php echo($lang_form_informations); ?></th>
<th style="width: 55%;"><?php echo($lang_form_kcms_code); ?></th>
<th style="width: 15%;"><?php echo($lang_form_options); ?></th>
</tr>
<?php

$print=mysql_query("SELECT id, file, added FROM kcms_files ORDER by added DESC");
while (list($id, $file, $added) = mysql_fetch_row($print)) {

echo "<tr>
<td>$file<span class=\"desc\">".date("d.m.Y, H:i", $added)."<br />".round(filesize("./files/$file")/1024)." kB</span></td>
<td style=\"text-align: center;\"><input type=\"text\" value=\"[.link.]/files/".$file."[.]".$file."[./link.]\" style=\"width: 375px;\" /></code></td>
<td style=\"text-align: center;\"><input type=\"button\" value=\"$lang_button_rename\" onclick=\"parent.location='./admin.php?f=files&amp;f2=rename_file&amp;id=$id';\" />";

// tedy můžeš nastavit práva pro manipulaci se soubory (tlačítko Smazat)
// here you can set the rights for actions with files (Delete button)
if ($rights>=2) {
echo "<input type=\"button\" value=\"$lang_button_delete\" onclick=\"if (!confirm('$lang_alert_sure')) return false; parent.location='./admin.php?f=files&amp;a=delete_file&amp;id=$id';\" />";
}

echo "</td>
</tr>\n";

}

?>
</table>

<?php

endif; if ($f2=="rename_file"):

$filename=mysql_query("SELECT file FROM kcms_files WHERE id='".addslashes($id)."'");
$filename=mysql_fetch_array($filename);

?>

<form action="./admin.php?f=files&amp;a=rename_file&amp;id=<?php echo($id); ?>" method="post">

<div><strong><?php echo($lang_form_rename_file." ".$filename["file"]); ?>:</strong><br /><input type="text" name="filename" style="width: 150px;" value="<?php echo($filename["file"]); ?>" /> <input type="submit" name="submit" value="<?php echo($lang_button_rename); ?>" /></div>

</form>

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