Просмотр файла includes/wap/admin/news.php

Размер файла: 5.77Kb
<?php
error_reporting(7);

Header("Content-type:text/vnd.wap.wml; charset=Utf-8");
Header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
Header("Cache-Control: no-cache, must-relative");

touch($userpath.'/news-free-message.dat');

$page=$query2+0;
if ($page<1) $page=1;

if (($page==1)&&(($query3!='delete')||($query3!='edit')||($query2!='add')))
	{
	$f=fopen($userpath.'/news-free-message.dat','r+');
	$tmp=$_tmp='';
	while (!feof($f))
		{
		$_tmp=trim(fgets($f,65536));
		if ($_tmp!='') $tmp.=$_tmp."\n";
		}
	fseek($f,0,SEEK_SET);
	fwrite($f,$tmp);
	$tr=strlen($tmp);
	ftruncate($f,$tr);
	fclose($f);
	}

if ($query2=='add')
	{
	$f=fopen($userpath.'/news-free-message.dat','r+');
	$tmpa=explode("\t",trim(fgets($f,65536)),2);
	fclose($f);

	$newtext=trim(utf2cyr(str_replace("\n"," ",str_replace("\r"," ",stripslashes($HTTP_POST_VARS['t'])))));
	if ($HTTP_POST_VARS['tr2cyr']=='yes') $newtext=trim(tr2rus($newtext));
	if ($newtext=='')
		{
		print $head.cyr2utf('<card id="news" title="Добавляем новость"><p>'.
        '<br/>Текст новости:<br/><input name="text'.$nocache.'" type="text" title="Текст" value="" maxlength="512"/>'.
        '<br/><select name="tr2cyr'.$nocache.'" multiple="true" value=""><option value="yes">Транслит</option></select>'.
        '<br/><anchor>Добавить'.
        '<go href="/?'.$id.'/admin/news/add" method="post">'.
        '<postfield name="t" value="$(text'.$nocache.')"/>'.
        '<postfield name="tr2cyr" value="$(tr2cyr'.$nocache.')"/>'.
        '</go>'.
        '</anchor>'.
		' <br/> <br/><a href="?'.$id.'/admin/news">Отмена</a>'.
		'</p></card></wml>');
		exit();
		}
	elseif (trim($tmpa[1])!=$newtext)
		{
		$message2file=time()."\t".$newtext."\n";
		$f=fopen($userpath.'/news-free-message.dat','r+');
		fseek($f,0,SEEK_SET);
		$text=fread($f,102400);
		fseek($f,0,SEEK_SET);
		fwrite($f,$message2file.$text);
		$tr=strlen($message2file.$text);
		if ($tr<102400) ftruncate($f,$tr);
		else ftruncate($f,102400);
		fclose($f);
		}
	}

if (($query3=='delete')||($query3=='edit'))
	{
	$query4=$query4+0;
	$f=fopen($userpath.'/news-free-message.dat','r+');
	for ($i=0;(!feof($f));$i++)
		{
		if ($i<$query4) $tmp_begin.=trim(fgets($f,65536))."\n";
		if ($i==$query4) $tmp_news=explode("\t",trim(fgets($f,65536)),2);
		if ($i>$query4) $tmp_end.=trim(fgets($f,65536))."\n";
		}
	fclose($f);

	$newtext=trim(utf2cyr(str_replace("\n"," ",str_replace("\r"," ",stripslashes($HTTP_POST_VARS['t'])))));
	if ($HTTP_POST_VARS['tr2cyr']=='yes') $newtext=trim(tr2rus($newtext));
	if ($query3=='edit')
		{
		if ($newtext=='')
			{
			print $head.cyr2utf('<card id="news" title="Изменяем новость"><p>'.
   			'<br/>Текст новости:<br/><input name="text'.$nocache.'" type="text" title="Текст" value="'.str_replace("$","$$",htmlspecialchars($tmp_news[1])).'" maxlength="512"/>'.
			'<br/><select name="tr2cyr'.$nocache.'" multiple="true" value=""><option value="yes">Транслит</option></select>'.
			'<br/><anchor>Заменить'.
			'<go href="/?'.$id.'/admin/news/'.$page.'/edit/'.$query4.'" method="post">'.
			'<postfield name="t" value="$(text'.$nocache.')"/>'.
			'<postfield name="tr2cyr" value="$(tr2cyr'.$nocache.')"/>'.
			'</go>'.
			'</anchor>'.
			' <br/> <br/><a href="?'.$id.'/admin/news">Отмена</a>'.
			'</p></card></wml>');
			exit();
			}
		else
			{
			$message2file=$tmp_begin.$tmp_news[0]."\t".$newtext."\n".$tmp_end;
			$f=fopen($userpath.'/news-free-message.dat','r+');
			fseek($f,0,SEEK_SET);
			fseek($f,0,SEEK_SET);
			fwrite($f,$message2file);
			$tr=strlen($message2file);
			if ($tr<102400) ftruncate($f,$tr);
			else ftruncate($f,102400);
			fclose($f);
			}
		}
	if ($query3=='delete')
		{
		$message2file=$tmp_begin."\n".$tmp_end;
		$f=fopen($userpath.'/news-free-message.dat','r+');
		fseek($f,0,SEEK_SET);
		$text=fread($f,102400);
		fseek($f,0,SEEK_SET);
		fwrite($f,$message2file);
		$tr=strlen($message2file);
		if ($tr<102400) ftruncate($f,$tr);
		else ftruncate($f,102400);
		fclose($f);
		}
	}

print $head.cyr2utf('<card id="news" title="Админка:Новости"><do name="x" type="options" label="xPanel"><go href="?'.$id.'"/></do><do name="m" type="options" label="Админская"><go href="?'.$id.'/admin"/></do><p>');

if ($page==1) print cyr2utf('<a href="?'.$id.'/admin/news/add">Добавить</a> <br/> <br/>');

print '<small>';

$f=fopen($userpath.'/news-free-message.dat','r+');
fseek($f,0,SEEK_SET);
$cntpage=1;
$screen='';
$i=0;
while ($cntpage<=$page)
    {
    while (true)
        {
        if (feof($f)) { print $screen; $screen=''; break; }
        $printmsg='';
		$i++;
        $tmpa=explode("\t",fgets($f,65536),2);
        if ((trim($tmpa[0])=='')&&(trim($tmpa[1])=='')) continue;
        $printmsg='<u><b><anchor>'.date("j.m.Y",$tmpa[0]).'<go href="#op"><setvar name="l" value="'.($i-1).'"/></go></anchor></b></u> <br/>';
        $printmsg.=cyr2utf(str_replace("$","$$",htmlspecialchars($tmpa[1]))).' <br/> <br/>';
        if (strlen($screen.$printmsg)>2200)
            {
            if ($cntpage==$page) { print $screen; $screen=''; break; }
            else { $screen=$printmsg; break; }
            }
        $screen.=$printmsg;
        }
    $cntpage++;
	if ($screen=='') break;
    }

print '</small>';

if ($page>1)   print '<a href="?'.$id.'/admin/news/'.($page-1).'">&lt;&lt;&lt;</a> <br/>';
if (!feof($f)) print '<a href="?'.$id.'/admin/news/'.($page+1).'">&gt;&gt;&gt;</a> <br/>';

print '<a href="http://'.$user.'.kmx.ru" accesskey="#">На главную</a>';
print '</p></card>';

print cyr2utf('<card id="op" title="Новость"><p>'.
'<a href="?'.$id.'/admin/news/'.$page.'/edit/$(l)">Исправить</a> <br/>'.
'<a href="?'.$id.'/admin/news/'.$page.'/delete/$(l)">Удалить</a> <br/>'.
' <br/><a href="#news">Назад</a> <br/>'.
'</p></card></wml>');
exit();
?>