View file sman/set/edit.php

File size: 3.48Kb
<?php

include_once '../../sman/includs/configurations.php';

$file_opt = 'true';

include_once '../../sman/includs/head.php';


echo '<div><a href="show.php?path='.htmlspecialchars($_GET['path']).'"><img src = "/sman/style/icons/show.png"> Посмотреть</a></div>';

if (isset($_GET['path']) && isset($_GET['id']) && isset($_GET['edit']) || isset($_GET['path']) && isset($_GET['id']) && isset($_GET['add']) || isset($_GET['path']) && isset($_GET['id']) && isset($_GET['delete_str'])) {

$post_str = trim($_POST['str_txt'])."\n";

$file_path = htmlspecialchars($_GET['path']);

$id_str = intval($_GET['id']);

$str = file(ROOT.'/'.$_GET['path']);

if (isset($_GET['add'])) {

$str[$id_str] .= $post_str;

} else if (isset($_GET['edit'])) {

$str[$id_str] = $post_str;

} else if (isset($_GET['delete_str'])) {

unset($str[$id_str]);

}
$files = fopen(ROOT.$file_path, "w");

foreach($str as $key => $value) { 


fwrite($files, $value);

}

fclose($files);

}





if (isset($_GET['path']))

$path = ROOT.'/'.trim($_GET['path']);

else {

header("Location: /sman/index.php");

exit;

}

$files = file($path);



if (count($files) == 0) {

echo '<center><a href="?id=0&amp;path='.$_GET['path'].'&amp;add_strs">Добавить строку</a></center>';
$files = array(" ");

}
for($i=$min_str; $i<=$max_str; $i++) {

if (!empty($files[$i])) {

$color = NULL;


$string = 0;

if (isset($_GET['id']) && isset($_GET['add'])) {


$string = 1;

}

if (isset($_GET['id']) && $_GET['id']+$string == $i && isset($_GET['to_str'])) {

echo '<a name = "to_str"></a>';
$color = '<span style = "color: red;">';
}
echo '<br />';

echo '<font color = "red">'.$i.')</font> <a href="?id='.$i.'&amp;path='.htmlspecialchars($_GET['path']).'&amp;page='.intval($_GET['page']).'&amp;edit_str#to_edit_str">';

echo $color.htmlspecialchars($files[$i]).'</span></a> ';

echo '<a href="?id='.$i.'&amp;path='.$_GET['path'].'&amp;page='.intval($_GET['page']).'&amp;add_str#to_add_str"><img src = "/sman/style/icons/add_str.png" height = "13" width = "13"></a> <a href="?id='.$i.'&amp;path='.$_GET['path'].'&amp;page='.intval($_GET['page']).'&amp;'.rand(0, 9999999).'&amp;delete_str&amp;to_str#to_str"><img src = "/sman/style/icons/delete_str.png" height = "13" width = "13"></a><br />';


if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] == $i && isset($_GET['edit_str']) || isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] == $i && isset($_GET['add_str']) || isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] == 0 && isset($_GET['add_strs'])) {


if (isset($_GET['add_str'])) {

$get = 'add';

$input = 'Добавить';

$files[$i] = NULL;

} else if (isset($_GET['edit_str'])) {

$get = 'edit';

$input = 'Изменить';

}


echo '<a name = "to_edit_str"></a>';

if (isset($_GET['id']) && $_GET['id'] == $i && isset($_GET['add_str']))  {



echo '<a name = "to_add_str"></a>'
;
}

echo '<br />';

echo '<form action = "?path='.htmlspecialchars($_GET['path']).'&page='.intval($_GET['page']).'&id='.$i.'&'.$get.'&to_str#to_str" method = "POST">';

echo '<center><textarea name = "str_txt">'.trim($files[$i]).'</textarea><br />';

echo '<br />';


echo '<input type = "submit" value = "'.$input.'"></center><br />';
}

}

}

include_once '../../sman/includs/paginator.php';

echo '<br />';
echo '<div><a href="show.php?path='.htmlspecialchars($_GET['path']).'"><img src = "/sman/style/icons/show.png"> Посмотреть</a></div>';
include_once '../../sman/includs/foot.php';

?>