Subversion Repositories svnkaklik

Rev

Blame | Last modification | View Log | Download

<?
/*
 +-------------------------------------------------------------------+
 |                      S H O U T B O X   (v1.0)                     |
 |                          P a r t   II                             |
 |                                                                   |
 | Copyright Gerd Tentler               http://www.gerd-tentler.de   |
 | Created: Jun. 1, 2004                Last modified: Jul. 21, 2005 |
 +-------------------------------------------------------------------+
 | This program may be used and hosted free of charge by anyone for  |
 | personal purpose as long as this copyright notice remains intact. |
 |                                                                   |
 | Obtain permission before selling the code for this program or     |
 | hosting this software on a commercial website or redistributing   |
 | this software over the Internet or in any other medium. In all    |
 | cases copyright must remain intact.                               |
 +-------------------------------------------------------------------+
*/
  error_reporting(E_WARNING);

//========================================================================================================
// Cookies
//========================================================================================================

  if(isset($Name)) {
    $shouter = $Name;
    setcookie('shouter', $shouter);
  }
  if(isset($EMail)) {
    $shouter_mail = $EMail;
    setcookie('shouter_mail', $shouter_mail);
  }

//========================================================================================================
// Includes
//========================================================================================================

  include('config.inc.php');
  include('smilies.inc');

//========================================================================================================
// Functions
//========================================================================================================

  function db_connect() {
    global $db_name, $db_server, $db_user, $db_pass;

    $status = true;
    if(!@mysql_connect($db_server, $db_user, $db_pass)) {
      echo '<font color=red>' . mysql_errno() . ': ' . mysql_error() . '</font><br>';
      $status = false;
    }
    else if(!@mysql_select_db($db_name)) {
      echo '<font color=red>' . mysql_errno() . ': ' . mysql_error() . '</font><br>';
      $status = false;
    }
    return $status;
  }

  function timeStamp($ts) {
    return substr($ts, 0, 4) . '-' . substr($ts, 4, 2) . '-' . substr($ts, 6, 2) . ' ' . substr($ts, 8, 2) . ':' . substr($ts, 10, 2) . ':' . substr($ts, 12);
  }

//========================================================================================================
// Main
//========================================================================================================

  if(db_connect()) {
    $error = '';

    header('Cache-control: private, no-cache, must-revalidate');
    header('Expires: Sat, 01 Jan 2000 00:00:00 GMT');
    header('Date: Sat, 01 Jan 2000 00:00:00 GMT');
    header('Pragma: no-cache');
?>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
    <meta http-equiv="refresh" content="<? echo $boxRefresh; ?>; URL=<? echo basename($PHP_SELF); ?>">
    <title>Output</title>
    <link rel="stylesheet" href="shoutbox.css" type="text/css">
    </head>
    <body marginwidth=0 marginheight=0 topmargin=0 leftmargin=0>
<?
    if($Text) {
      $tstamp = date('YmdHis');
      $sql = "INSERT INTO $tbl_name ($fld_timestamp, $fld_name, $fld_email, $fld_text) ";
      $sql .= "VALUES ('$tstamp', '$Name', '$EMail', '$Text')";
      if(!mysql_query($sql)) $error .= mysql_error() . '<br>';

      $sql = "SELECT $fld_id FROM $tbl_name ORDER BY $fld_timestamp DESC LIMIT 1";
      $id = mysql_result(mysql_query($sql), $fld_id) - $boxEntries;
      if($id > 0) {
        $sql = "DELETE FROM $tbl_name WHERE $fld_id<=$id";
        if(!mysql_query($sql)) $error .= mysql_error() . '<br>';
      }
    }
?>
    <table border=0 cellspacing=0 cellpadding=2 width=100%><tr>
    <td>
<?
    if($error) echo "<font color=red>$error</font><br>";
?>
    <table border=0 cellspacing=0 cellpadding=0 width=100%>
<?
    $sm_code = $sm_img = array();

    while(list($code, $img) = each($sm)) {
      $sm_code[] = $code;
      $sm_img[] = "<img src='smilies/$img' width=15 height=15 align=top>";
    }

    $sql = "SELECT * FROM $tbl_name ORDER BY $fld_timestamp DESC LIMIT $boxEntries";
    $result = mysql_query($sql);

    while($row = mysql_fetch_array($result)) {
      $tstamp = timeStamp($row[$fld_timestamp]);
      $name = $row[$fld_name] ? htmlentities($row[$fld_name]) : '???';
      $email = $row[$fld_email];
      $text = htmlentities($row[$fld_text]);
      $text = str_replace($sm_code, $sm_img, $text);
      $bgcolor = ($bgcolor != '#FFFFFF') ? '#FFFFFF' : '#F6F6F6';
?>
      <tr bgcolor=<? echo $bgcolor; ?>>
      <td class="cssSmall" align=right><font color=#A0A0A0><? echo $tstamp; ?></font></td>
      </tr><tr bgcolor=<? echo $bgcolor; ?>>
      <td class="cssShoutText"><? if($email) echo '<a href="mailto:' . $email . '">'; ?>
      <b><? echo $name; ?>:</b><? if($email) echo '</a>'; ?> <? echo $text; ?></td>
      </tr>
<?
    }
    mysql_close();
?>
    </table>
    </td>
    </tr></table>
    </body>
    </html>
<?
  }
?>