View file edittitle.php

File size: 3.47Kb
<?php
require('includes/header.php');
require('includes/utils.php');
require('includes/db.php');
require('includes/auth.php');

if((isset($_GET['page']) && preg_match('/[^\w\.]/', $_GET['page'])) || (isset($_POST['page']) && preg_match('/[^\w\.]/', $_POST['page'])))
{
?>
<wml>
<card id="error" title="error" ontimer="main.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>"><timer value="15"/>
<p align="center">
Неправильное имя страницы
</p>
</card>
</wml>
<?php
   exit;
}


if(isset($_POST['action']))
{
   if($_POST['action'] == 'create')
   {
         // creating new page
         $fp = fopen("$login/" . $_POST['page'], 'w');
         $clear_page = '<?xml version="1.0" encoding="UTF-8"?>';
         $clear_page .= <<<CLEARPAGE
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<card id="index" title="$_POST[title]">
<do type="prev" label="&#x041D;&#x0430;&#x0437;&#x0430;&#x0434;"><prev/></do>
<p align="center">
<br/>
</p>
</card>
</wml>
CLEARPAGE;
         fputs($fp, $clear_page);
         fclose($fp);
         $message = 'C&#x0442;pa&#x043D;&#x0438;&#x0446;a "' . $_POST['page'] . '" co&#x0437;&#x0434;a&#x043D;a';
   }
   else if($_POST['action'] == 'change')
   {
     if(file_exists("$login/" . $_POST['page']))
     {
        $contents = join('', file("$login/" . $_POST['page']));
        $contents = preg_replace('/<card id=\"(.*?)\" title=".*?">/i', '<card id="$1" title="' . $_POST['title'] . '">', $contents);
        $fp = fopen("$login/" . $_POST['page'], 'w');
        fputs($fp, $contents);
        fclose($fp);
        $message = '&#x0417;a&#x0433;o&#x043B;o&#x0432;o&#x043A; c&#x0442;pa&#x043D;&#x0438;&#x0446;&#x044B; "' . $_GET['page'] . '" &#x0438;&#x0437;&#x043C;e&#x043D;e&#x043D;';
     }
     else
     {
       $message = 'Страница с именем "' . $_POST['page'] . '" не найдена';
     }
   }
?>
<wml>
<card id="added" title="added" ontimer="edit.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_POST['page']; ?>"><timer value="15"/>
<p>
<?php echo $message; ?><br/>
</p>
</card>
</wml>
<?php
   exit;
}
?>
<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<card id="Edit" title="Pe&#x0434;a&#x043A;&#x0442;op">
<p>
<b>index.wml</b><br/>
&#x0418;&#x043C;&#x044F; c&#x0442;pa&#x043D;&#x0438;&#x0446;&#x044B;(&#x0431;&#x0435;&#x0437; wml)<br/>
<input name="page" emptyok="true" maxlength="20" value="<?php echo preg_replace('/\..*?$/',"",$_GET['page']); ?>" title="page"/><br/>
&#x0417;a&#x0433;o&#x043B;o&#x0432;o&#x043A;:<br/>
<input name="title" emptyok="true" maxlength="20" title="title"/><br/>
<select name="action">
<option value="create">Co&#x0437;&#x0434;a&#x0442;&#x044C;</option>
<option value="change">&#x0418;&#x0437;&#x043C;.&#x0417;a&#x0433;o&#x043B;o&#x0432;o&#x043A;</option>
</select><br/>
<anchor title="go">Ok<go href="edittitle.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_GET['page']; ?>" method="post">
<postfield name="action" value="$(action)"/>
<postfield name="page" value="$(page).wml"/>
<postfield name="title" value="$(title)"/>
</go></anchor><br/>
*********<br/>
<a href="edit.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_GET['page']; ?>">Ha&#x0437;a&#x0434;</a><br/>
</p>
</card>
</wml>