home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Internet 2001 November / MICD2001_11_NR2.iso / PHP / Listing3.php
Text File  |  2001-10-02  |  10KB  |  326 lines

  1. //(Listing 3. Biblioteka funkcji - fnews.inc)
  2. ==============================================
  3.  
  4.  
  5.  
  6. <?
  7. function newsHeader(){
  8.   global $PHP_SELF, $HTTP_ENV_VARS, $newsy, $cfg;
  9.   ?>
  10.   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  11.   <html><head><title>Administracja</title>
  12.   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2">
  13.   <script language=JavaScript>
  14.   <!-ukrywanie
  15.   function deleteNews(cmd){
  16.     var winConfirm = window.confirm('Skasowaµ? Czy na pewno?');
  17.     if(winConfirm){
  18.       location.href=(cmd);
  19.     }
  20.   }
  21.   // -->
  22.   </script>
  23.   </head>
  24.   <body>
  25.   <div align="center">
  26.   <a href="<? echo  $cfg["adres"]; ?>">G│≤wna</a> |
  27.   <a href="<? echo basename($PHP_SELF)."?cmd=new"; ?>">Dodaj</a> |
  28.   <a href="<? echo basename($PHP_SELF)."?cmd=list"; ?>">Wykaz</a> <br>
  29. <? }
  30.  
  31. function newsFooter(){
  32.   ?>
  33.   <br></div></body></html>
  34.   <?
  35. }
  36.  
  37. function LiczMaxL(){
  38.   global $id, $newsy;
  39.   $content = file($newsy["newsFile"]);
  40.   $size = count($content);
  41.   $maxID = 0;
  42.   for($line=1; $line<=$size; $line++){
  43.     $tmpLINE = explode("|",$content[$line-1]);
  44.     $tmpID = $tmpLINE[0]; 
  45.     if($tmpID > $maxID) $maxID = $tmpID;
  46.   }
  47.   return $maxID;
  48. }
  49.  
  50. /* wykaz wpis≤w  */
  51. function ListNewsAdm(){
  52.   global $PHP_SELF, $PHP_AUTH_USER, $newsy, $pos;
  53.   $count = 5;
  54.   $content = file($newsy["newsFile"]);
  55.   $size = count($content);
  56.   echo "<hr>";
  57.   for($i=0; $i<count($content); $i++){
  58.     $myLINES[$i] = explode("|",$content[$i]);
  59.   } ?>
  60.   <table border="0" cellspacing="0" cellpadding="0" width="600">
  61.   <?
  62.   $tmp = $size-$pos-1;
  63.   for($i=$tmp; $i>($tmp-$count); $i--){
  64.     if(($content[$i] != '') && ($myLINES[$i][0] != "#")){
  65.     $viewADR = basename($PHP_SELF)."?cmd=view&id=".$myLINES[$i][0];
  66.     $nameADR = stripslashes($myLINES[$i][2]);
  67.     $editADR = basename($PHP_SELF)."?cmd=edit&id=".$myLINES[$i][0];
  68.     $delADR = basename($PHP_SELF)."?cmd=del&id=".$myLINES[$i][0];
  69.     echo "<tr bgcolor=\"".($i % 2 == 0 ? '#EFEFFF' : '#FFFFFF')."\">";
  70.     echo "<td valign=\"top\" align=\"left\" width=\"80\">"
  71.     .$myLINES[$i][1]."</td>"; ?>
  72.     <td valign="top" align="left" width="440">
  73.     <a href="<? echo $viewADR; ?>"><? echo $nameADR; ?></a></td>
  74.     <td valign="top" align="center" width="20">
  75.     <a href="<? echo $editADR; ?>">Edytuj</a> | </td>
  76.     <td valign="top" align="center" width="20">
  77.     <a href="javascript:deleteNews('
  78.     <? echo $delADR; ?>');"> Kasuj</a> </td></tr>
  79.     <?
  80.     }
  81.   }
  82.   ?>
  83.   </table><hr>
  84.   <!-- stopka tabeli -->
  85.  <table width="600" align="center">
  86.    <tr>
  87.    <?
  88.    for($i=0; $i<$size; $i++){
  89.      if(!($i % $count)) $pages++;
  90.    }
  91.    ?>
  92.    <td align="left" valign="top" width="50%">
  93.    <?
  94.    for($i=0; $i<$pages; $i++){
  95.      if($pos == $i*$count){
  96.        echo "<font color='red'><b>".($i+1)."</b></font>  ";
  97.      } else {
  98.        ?><a href="<? echo basename($PHP_SELF)."?cmd=list&pos="
  99.        .($i*$count); ?>" style="font-size: 8pt"><? echo $i+1; ?>
  100.        </a> 
  101.        <?
  102.      }
  103.    } ?></td>
  104.    <td align="right" valign="top" width="50%">DostΩpnych jest  
  105.    <? echo $size; ?> pozycji. <?
  106.    if ($pos > 0){
  107.      ?>  <b><a href="?cmd=list&pos=
  108.      <? echo $pos-$count;?>"><<</a></b><?
  109.    }
  110.    if($size > $pos+$count){
  111.      ?> <b><a href="?cmd=list&pos=
  112.      <? echo $pos+$count;?>">>></a></b><?
  113.    }
  114.    ?>
  115.    </td>
  116.    </tr>
  117.  </table>
  118.   <?
  119. }
  120.  
  121. /* przegl╣danie wiadomo£ci */
  122. function viewNews(){
  123.   global $id, $newsy;
  124.   $content = file($newsy["newsFile"]);
  125.   for($i=0; $i<count($content); $i++){
  126.     $myLINES[$i] = explode("|",$content[$i]);
  127.     if($myLINES[$i][0] == $id) break;
  128.   }
  129.   if( $id != "" ){
  130.     echo "Nr wiadomosci:<b>".$id."</b><br>";
  131.   ?>
  132.     <table width="550" border="0" cellspacing="0" cellpadding="0">
  133.     <tr><td>
  134.     <p><? echo stripslashes($myLINES[$i][1])." - "
  135.     .stripslashes($myLINES[$i][5]); ?><p>
  136.     </td></tr><tr><td>
  137.     <h2><? echo stripslashes($myLINES[$i][2]); ?></h2>
  138.     </td></tr><tr><td>
  139.     <? echo stripslashes($myLINES[$i][3]); ?>
  140.     </td></tr><tr><td>
  141.     <? echo stripslashes($myLINES[$i][4]); ?>
  142.     </td></tr><tr><td>
  143.     <hr width="100%" noshade size="1">
  144.     </td></tr><tr><td align="right">
  145.     <a href="<? echo basename($PHP_SELF)."?cmd=edit&id="
  146.     .$id; ?>">Edytuj</a> | <a href=
  147.     "javascript:history.go(-1);">Powr≤t</a>
  148.     </td></tr></table>
  149.    <?
  150.   }
  151. }
  152.  
  153. /* uruchom formularz do edycji wybranego wpisu */
  154. function editNews(){ 
  155.   global $PHP_SELF, $newsy, $id;
  156.   if($id != ""){
  157.     $content = file($newsy["newsFile"]);  
  158.     for($i=0; $i<count($content); $i++) {
  159.       $line = stripslashes($content[$i]);
  160.       $myLINES[$i] = explode("|",$line);
  161.       if( $myLINES[$i][0] == $id ) {
  162.         break;
  163.       }
  164.     }
  165.     $tmp1 = str_replace("<br>", "\n", $myLINES[$i][3]);
  166.     $tmp2 = str_replace("<br>", "\n", $myLINES[$i][4]);
  167.     $tmp1 = stripslashes($tmp1);
  168.     $tmp2 = stripslashes($tmp2);
  169.     ?>
  170.     <form name="editform" action="
  171.     <? echo basename($PHP_SELF); ?>" method="post" 
  172.     enctype="multipart/form-data">
  173.     <input type="hidden" name="cmd" value="modify">
  174.     <input type="hidden" name="id" value="<? echo $id; ?>">
  175.     <table width="550" border="0">
  176.     <tr>
  177.       <th colspan="3">Modyfikacja nr <? echo $id; ?></th></tr>
  178.     <tr><td><strong>Data:</strong></td>
  179.       <td><input type="text" name="newsDate" class=w300 value="
  180.       <? echo htmlspecialchars($myLINES[$i][1]); ?>"></td>
  181.     <tr><td><strong>Tytu│:</strong></td>
  182.       <td><input type="text" name="tytul" value="
  183.       <? echo htmlspecialchars($myLINES[$i][2]); ?>"></td></tr>
  184.     <tr valign="top">
  185.       <td><strong>WstΩp:</strong></td>
  186.       <td><textarea name="intro" cols="40" rows="5">
  187.       <? echo htmlspecialchars($tmp1); ?></textarea></td></tr>
  188.     <tr>
  189.       <td valign="top"><strong>Tre£µ:</strong></td>
  190.       <td><textarea name="text" cols="40" rows="12">
  191.       <? echo htmlspecialchars($tmp2); ?></textarea></td></tr>
  192.     <tr>
  193.       <td><strong>Autor:</strong></td>
  194.       <td><input type="text" name="autor" value="
  195.       <? echo htmlspecialchars($myLINES[$i][5]); ?>" > 
  196.       <input type="submit" value="Modyfikuj"></td></tr>
  197.     </table>
  198.     </form>
  199. <?
  200.   }
  201. }
  202.  
  203. /* wyslij formularz ze zmodyfikowanymi danymi */
  204. function modifyNews(){
  205.   global $id, $newsDate, $intro, $tytul, $text, $autor, $newsy;
  206.   $content = file($newsy["newsFile"]);
  207.   if($newsDate == ""){
  208.     $newsDate = date("d.m.Y");
  209.   }
  210.   $intro = str_replace("|", "/", $intro);
  211.   $text = str_replace("|", "/", $text);
  212.   $tytul = str_replace("|", "/", $tytul);
  213.   $autor = str_replace("|", "/", $autor);
  214.   $tmp = $id."|".$newsDate."|".$tytul."|".$intro."|".$text."|".$autor;
  215.   $tmp = str_replace("\n", "<br>", $tmp);
  216.   $tmp = str_replace("\r", "", $tmp);
  217.  
  218.   $content = file($newsy["newsFile"]);
  219.   $size = count($content);
  220.  
  221.   $fp = @fopen($newsy["newsFile"].".tmp", "w+");
  222.  
  223.   for($line=0; $line<count($content); $line++) {
  224.     $myLINES[$line] = explode("|", $content[$line] );
  225.     if($myLINES[$line][0] != $id) {
  226.       fputs($fp, $content[$line] );
  227.     } else {
  228.       fputs($fp, $tmp."\n");
  229.     }
  230.   }
  231.  
  232.   fclose($fp);
  233.   unlink($newsy["newsFile"]);
  234.   rename($newsy["newsFile"].".tmp", $newsy["newsFile"]);
  235. }
  236.  
  237. /* formularz dla nowych wpis≤w */
  238. function doForm(){
  239.   global $PHP_SELF, $newsy;
  240.   ?>
  241.   <hr>
  242.   <form action="<? echo basename($PHP_SELF); ?>" 
  243.    method="post" enctype="multipart/form-data">
  244.   <input type="hidden" name="cmd" value="add">
  245.   <table width="550" border="0">
  246.   <tr><td colspan="2" align="center">
  247.     <strong>Dodaj artyku│</strong>
  248.   </td></tr><tr valign="top"><td>
  249.     <strong>Data:</strong></td><td>
  250.     <input type="text" name="newsDate">
  251.   </td></tr><tr valign="top"><td>
  252.     <strong>Tytu│:</strong></td><td>
  253.     <input type="text" name="tytul">
  254.   </td></tr><tr valign="top"><td>
  255.     <strong>Wprowadzenie:</strong></td><td>
  256.     <textarea name="intro" cols="40" rows="3"></textarea>
  257.   </td></tr><tr valign="top"><td>
  258.     <strong>Tre£µ</strong></td><td>
  259.     <textarea name="text" cols="40" rows="10"></textarea>
  260.   </td></tr><tr><td>
  261.     <strong>Autor:</strong></td><td>
  262.     <input type="text" name="autor">  
  263.     <input type="submit" value="Dopisz">
  264.   </td></tr></table>
  265.   </form>
  266.   <hr>
  267. <?
  268. }
  269.  
  270.  
  271. /* dodawanie nowej pozycji */
  272. function addNews(){
  273.   global $newsDate, $tytul, $intro, $text, $autor, $publish, $newsy;
  274.  
  275.   if($newsDate == "") $newsDate = date("d.m.Y");
  276.   $content = file($newsy["newsFile"] );
  277.   $size = count($content);
  278.   $id = LiczMaxL()+1; // nowy numer
  279.  
  280.   $intro = str_replace("|", "/", $intro);  
  281.   $text = str_replace("|", "/", $text);
  282.   $tytul = str_replace("|", "/", $tytul);
  283.   $autor = str_replace("|", "/", $autor);
  284.   $tmp = $id."|".$newsDate."|".$tytul."|".$intro."|".$text."|".$autor;
  285.   $tmp = addslashes($tmp);
  286.   $tmp = str_replace("\n", "<br>", $tmp);
  287.   $tmp = str_replace("\r", "", $tmp);
  288.  
  289.   $fp=@fopen($newsy["newsFile"], "a");
  290.   if($fp <= 0){
  291.     echo "B│╣d otwarcia zbioru";
  292.   }
  293.   fputs($fp, $tmp."\n");
  294.   fclose($fp);
  295. }
  296.  
  297. /* kasowanie */
  298. function delNews(){
  299.   global $newsy, $id;
  300.   $content = file($newsy["newsFile"] );
  301.   $size = count($content);
  302.   $fp = @fopen($newsy["newsFile"].".tmp", "w+");
  303.   for($i=0; $i<count($content); $i++){
  304.     $myLINES[$i] = explode("|", $content[$i]);
  305.     if($myLINES[$i][0] != $id){
  306.       fputs($fp,$content[$i]);
  307.     }
  308.   }
  309.  
  310.   fclose($fp);
  311.   unlink($newsy["newsFile"] );
  312.   rename($newsy["newsFile"] .".tmp", $newsy["newsFile"] );
  313. }
  314.  
  315. function redirect($prm){
  316.   global $PHP_SELF;
  317.   ?>
  318.   <script language=JavaScript>
  319.     window.location.href="<? echo basename($PHP_SELF).$prm; ?>";
  320.   </script>
  321. <?
  322. }
  323. ?>
  324.  
  325.  
  326.