home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magazyn Internet 2001 November
/
MICD2001_11_NR2.iso
/
PHP
/
Listing3.php
Wrap
Text File
|
2001-10-02
|
10KB
|
326 lines
//(Listing 3. Biblioteka funkcji - fnews.inc)
==============================================
<?
function newsHeader(){
global $PHP_SELF, $HTTP_ENV_VARS, $newsy, $cfg;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Administracja</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2">
<script language=JavaScript>
<!-ukrywanie
function deleteNews(cmd){
var winConfirm = window.confirm('Skasowaµ? Czy na pewno?');
if(winConfirm){
location.href=(cmd);
}
}
// -->
</script>
</head>
<body>
<div align="center">
<a href="<? echo $cfg["adres"]; ?>">G│≤wna</a> |
<a href="<? echo basename($PHP_SELF)."?cmd=new"; ?>">Dodaj</a> |
<a href="<? echo basename($PHP_SELF)."?cmd=list"; ?>">Wykaz</a> <br>
<? }
function newsFooter(){
?>
<br></div></body></html>
<?
}
function LiczMaxL(){
global $id, $newsy;
$content = file($newsy["newsFile"]);
$size = count($content);
$maxID = 0;
for($line=1; $line<=$size; $line++){
$tmpLINE = explode("|",$content[$line-1]);
$tmpID = $tmpLINE[0];
if($tmpID > $maxID) $maxID = $tmpID;
}
return $maxID;
}
/* wykaz wpis≤w */
function ListNewsAdm(){
global $PHP_SELF, $PHP_AUTH_USER, $newsy, $pos;
$count = 5;
$content = file($newsy["newsFile"]);
$size = count($content);
echo "<hr>";
for($i=0; $i<count($content); $i++){
$myLINES[$i] = explode("|",$content[$i]);
} ?>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<?
$tmp = $size-$pos-1;
for($i=$tmp; $i>($tmp-$count); $i--){
if(($content[$i] != '') && ($myLINES[$i][0] != "#")){
$viewADR = basename($PHP_SELF)."?cmd=view&id=".$myLINES[$i][0];
$nameADR = stripslashes($myLINES[$i][2]);
$editADR = basename($PHP_SELF)."?cmd=edit&id=".$myLINES[$i][0];
$delADR = basename($PHP_SELF)."?cmd=del&id=".$myLINES[$i][0];
echo "<tr bgcolor=\"".($i % 2 == 0 ? '#EFEFFF' : '#FFFFFF')."\">";
echo "<td valign=\"top\" align=\"left\" width=\"80\">"
.$myLINES[$i][1]."</td>"; ?>
<td valign="top" align="left" width="440">
<a href="<? echo $viewADR; ?>"><? echo $nameADR; ?></a></td>
<td valign="top" align="center" width="20">
<a href="<? echo $editADR; ?>">Edytuj</a> | </td>
<td valign="top" align="center" width="20">
<a href="javascript:deleteNews('
<? echo $delADR; ?>');"> Kasuj</a> </td></tr>
<?
}
}
?>
</table><hr>
<!-- stopka tabeli -->
<table width="600" align="center">
<tr>
<?
for($i=0; $i<$size; $i++){
if(!($i % $count)) $pages++;
}
?>
<td align="left" valign="top" width="50%">
<?
for($i=0; $i<$pages; $i++){
if($pos == $i*$count){
echo "<font color='red'><b>".($i+1)."</b></font> ";
} else {
?><a href="<? echo basename($PHP_SELF)."?cmd=list&pos="
.($i*$count); ?>" style="font-size: 8pt"><? echo $i+1; ?>
</a>
<?
}
} ?></td>
<td align="right" valign="top" width="50%">DostΩpnych jest
<? echo $size; ?> pozycji. <?
if ($pos > 0){
?> <b><a href="?cmd=list&pos=
<? echo $pos-$count;?>"><<</a></b><?
}
if($size > $pos+$count){
?> <b><a href="?cmd=list&pos=
<? echo $pos+$count;?>">>></a></b><?
}
?>
</td>
</tr>
</table>
<?
}
/* przegl╣danie wiadomo£ci */
function viewNews(){
global $id, $newsy;
$content = file($newsy["newsFile"]);
for($i=0; $i<count($content); $i++){
$myLINES[$i] = explode("|",$content[$i]);
if($myLINES[$i][0] == $id) break;
}
if( $id != "" ){
echo "Nr wiadomosci:<b>".$id."</b><br>";
?>
<table width="550" border="0" cellspacing="0" cellpadding="0">
<tr><td>
<p><? echo stripslashes($myLINES[$i][1])." - "
.stripslashes($myLINES[$i][5]); ?><p>
</td></tr><tr><td>
<h2><? echo stripslashes($myLINES[$i][2]); ?></h2>
</td></tr><tr><td>
<? echo stripslashes($myLINES[$i][3]); ?>
</td></tr><tr><td>
<? echo stripslashes($myLINES[$i][4]); ?>
</td></tr><tr><td>
<hr width="100%" noshade size="1">
</td></tr><tr><td align="right">
<a href="<? echo basename($PHP_SELF)."?cmd=edit&id="
.$id; ?>">Edytuj</a> | <a href=
"javascript:history.go(-1);">Powr≤t</a>
</td></tr></table>
<?
}
}
/* uruchom formularz do edycji wybranego wpisu */
function editNews(){
global $PHP_SELF, $newsy, $id;
if($id != ""){
$content = file($newsy["newsFile"]);
for($i=0; $i<count($content); $i++) {
$line = stripslashes($content[$i]);
$myLINES[$i] = explode("|",$line);
if( $myLINES[$i][0] == $id ) {
break;
}
}
$tmp1 = str_replace("<br>", "\n", $myLINES[$i][3]);
$tmp2 = str_replace("<br>", "\n", $myLINES[$i][4]);
$tmp1 = stripslashes($tmp1);
$tmp2 = stripslashes($tmp2);
?>
<form name="editform" action="
<? echo basename($PHP_SELF); ?>" method="post"
enctype="multipart/form-data">
<input type="hidden" name="cmd" value="modify">
<input type="hidden" name="id" value="<? echo $id; ?>">
<table width="550" border="0">
<tr>
<th colspan="3">Modyfikacja nr <? echo $id; ?></th></tr>
<tr><td><strong>Data:</strong></td>
<td><input type="text" name="newsDate" class=w300 value="
<? echo htmlspecialchars($myLINES[$i][1]); ?>"></td>
<tr><td><strong>Tytu│:</strong></td>
<td><input type="text" name="tytul" value="
<? echo htmlspecialchars($myLINES[$i][2]); ?>"></td></tr>
<tr valign="top">
<td><strong>WstΩp:</strong></td>
<td><textarea name="intro" cols="40" rows="5">
<? echo htmlspecialchars($tmp1); ?></textarea></td></tr>
<tr>
<td valign="top"><strong>Tre£µ:</strong></td>
<td><textarea name="text" cols="40" rows="12">
<? echo htmlspecialchars($tmp2); ?></textarea></td></tr>
<tr>
<td><strong>Autor:</strong></td>
<td><input type="text" name="autor" value="
<? echo htmlspecialchars($myLINES[$i][5]); ?>" >
<input type="submit" value="Modyfikuj"></td></tr>
</table>
</form>
<?
}
}
/* wyslij formularz ze zmodyfikowanymi danymi */
function modifyNews(){
global $id, $newsDate, $intro, $tytul, $text, $autor, $newsy;
$content = file($newsy["newsFile"]);
if($newsDate == ""){
$newsDate = date("d.m.Y");
}
$intro = str_replace("|", "/", $intro);
$text = str_replace("|", "/", $text);
$tytul = str_replace("|", "/", $tytul);
$autor = str_replace("|", "/", $autor);
$tmp = $id."|".$newsDate."|".$tytul."|".$intro."|".$text."|".$autor;
$tmp = str_replace("\n", "<br>", $tmp);
$tmp = str_replace("\r", "", $tmp);
$content = file($newsy["newsFile"]);
$size = count($content);
$fp = @fopen($newsy["newsFile"].".tmp", "w+");
for($line=0; $line<count($content); $line++) {
$myLINES[$line] = explode("|", $content[$line] );
if($myLINES[$line][0] != $id) {
fputs($fp, $content[$line] );
} else {
fputs($fp, $tmp."\n");
}
}
fclose($fp);
unlink($newsy["newsFile"]);
rename($newsy["newsFile"].".tmp", $newsy["newsFile"]);
}
/* formularz dla nowych wpis≤w */
function doForm(){
global $PHP_SELF, $newsy;
?>
<hr>
<form action="<? echo basename($PHP_SELF); ?>"
method="post" enctype="multipart/form-data">
<input type="hidden" name="cmd" value="add">
<table width="550" border="0">
<tr><td colspan="2" align="center">
<strong>Dodaj artyku│</strong>
</td></tr><tr valign="top"><td>
<strong>Data:</strong></td><td>
<input type="text" name="newsDate">
</td></tr><tr valign="top"><td>
<strong>Tytu│:</strong></td><td>
<input type="text" name="tytul">
</td></tr><tr valign="top"><td>
<strong>Wprowadzenie:</strong></td><td>
<textarea name="intro" cols="40" rows="3"></textarea>
</td></tr><tr valign="top"><td>
<strong>Tre£µ</strong></td><td>
<textarea name="text" cols="40" rows="10"></textarea>
</td></tr><tr><td>
<strong>Autor:</strong></td><td>
<input type="text" name="autor">
<input type="submit" value="Dopisz">
</td></tr></table>
</form>
<hr>
<?
}
/* dodawanie nowej pozycji */
function addNews(){
global $newsDate, $tytul, $intro, $text, $autor, $publish, $newsy;
if($newsDate == "") $newsDate = date("d.m.Y");
$content = file($newsy["newsFile"] );
$size = count($content);
$id = LiczMaxL()+1; // nowy numer
$intro = str_replace("|", "/", $intro);
$text = str_replace("|", "/", $text);
$tytul = str_replace("|", "/", $tytul);
$autor = str_replace("|", "/", $autor);
$tmp = $id."|".$newsDate."|".$tytul."|".$intro."|".$text."|".$autor;
$tmp = addslashes($tmp);
$tmp = str_replace("\n", "<br>", $tmp);
$tmp = str_replace("\r", "", $tmp);
$fp=@fopen($newsy["newsFile"], "a");
if($fp <= 0){
echo "B│╣d otwarcia zbioru";
}
fputs($fp, $tmp."\n");
fclose($fp);
}
/* kasowanie */
function delNews(){
global $newsy, $id;
$content = file($newsy["newsFile"] );
$size = count($content);
$fp = @fopen($newsy["newsFile"].".tmp", "w+");
for($i=0; $i<count($content); $i++){
$myLINES[$i] = explode("|", $content[$i]);
if($myLINES[$i][0] != $id){
fputs($fp,$content[$i]);
}
}
fclose($fp);
unlink($newsy["newsFile"] );
rename($newsy["newsFile"] .".tmp", $newsy["newsFile"] );
}
function redirect($prm){
global $PHP_SELF;
?>
<script language=JavaScript>
window.location.href="<? echo basename($PHP_SELF).$prm; ?>";
</script>
<?
}
?>