<?php
/**
* AkoComment - A User Comments Component
* @version 2.0
* @package AkoComment
* @copyright (C) 2004 by Arthur Konze - All rights reserved!
* @license http://www.konze.de/content/view/8/26/ Copyrighted Commercial Software
**/

# Don't allow direct linking
  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

# Variables - Don't change anything here!!!
  require_once($mosConfig_absolute_path."/administrator/components/com_akocomment/config.akocomment.php");

# Get the right language if it exists
  if (file_exists($mosConfig_absolute_path.'/components/com_akocomment/languages/'.$mosConfig_lang.'.php')) {
    include($mosConfig_absolute_path.'/components/com_akocomment/languages/'.$mosConfig_lang.'.php');
  } else {
    include($mosConfig_absolute_path.'/components/com_akocomment/languages/english.php');
  }

# Check if email adress is right
  function is_email($email){
    $rBool=false;
    if(preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $email)) {
      $rBool=true;
    }
    return $rBool;
  }

# Check for Editor rights
  $is_editor = (strtolower($my->usertype) == 'editor' || strtolower($my->usertype) == 'publisher' || strtolower($my->usertype) == 'manager' || strtolower($my->usertype) == 'administrator' || strtolower($my->usertype) == 'super administrator' );
  $is_user   = (strtolower($my->usertype) <> '');

# Check if Registered Users only
  if (!$ac_anonentry AND !$is_user) {
    echo "<SCRIPT>alert('"._AKOCOMMENT_ONLYREGISTERED."'); document.location.href='".sefRelToAbs("index.php?option=content&task=view&id=$contentid")."';</SCRIPT>";
  } else {
    # Clear any HTML and SQL injections
    $title   = strip_tags($title);
    $comment = strip_tags($comment);
    $title   = mysql_escape_string($title);
    $comment = mysql_escape_string($comment);

    # Perform database query
    $date      = date( "Y-m-d H:i:s" );
    $ip        = getenv('REMOTE_ADDR');
    $query2 = "INSERT INTO #__akocomment SET contentid='$contentid', ip='$ip', name='$acname', title='$title', comment='$comment', date='$date', published='$ac_autopublish';";
    $database->setQuery( $query2 );
    $database->query();

//    # Send out admin mail
//    if ($ac_notify AND is_email($ac_notify_email) ) {
//      $acmailtext =_AKOCOMMENT_ADMINMAIL."\r\n\r\nName: ".$acname."\r\nTitle: ".$title."\r\nText: ".$comment."\r\n\r\n"._AKOCOMMENT_ADMINMAILFOOTER;
//      mail($ac_notify_email,_AKOCOMMENT_ADMINMAILHEADER,$acmailtext,"From: ".$ac_notify_email);
//    }

    # Send out admin mail
    if ($ac_notify AND is_email($ac_notify_email) ) {

       //Filter Bad words
       if (  $ac_badwords2 ) {
          require_once( 'components/com_badwords2/class.badwords2.php' );
          $badword_flag = Badword::filter ( "$title $comment", $my );
          if ($badword_flag) {
             $title_flush = Badword::flush($title, $my);
             $comment_flush = Badword::flush($comment, $my);
          }
       }

      $acmailtext =_AKOCOMMENT_ADMINMAIL;
      if ( $badword_flag ) $acmailtext .=  _BW2_MODERATED_ENTRY_MAIL . _BW2_ADMIN_ORIG_ENTRY_NOTIF_MAIL;
      $acmailtext .= "\r\n\r\nName: " . $acname . "\r\nTitle: " . $title . "\r\nText: " . $comment;
      if ( $badword_flag ) {
         $acmailtext .=  "\r\n\r\n" . _BW2_ADMIN_MODERATED_ENTRY_NOTIF_MAIL . "\r\n\r\n" . $acname . "\r\nTitle: " . $title_flush."\r\nText: " . $comment_flush;
      }

      $acmailtext .= "\r\n\r\n"._AKOCOMMENT_ADMINMAILFOOTER;
      mail($ac_notify_email,_AKOCOMMENT_ADMINMAILHEADER,$acmailtext,"From: ".$ac_notify_email);
    }

    # Check if new window or not
    $redirectlink = ($ac_openingmode) ? "document.location.href='".sefRelToAbs("index2.php?option=com_content&task=view&id=$contentid&pop=1&page=0")."';" : "document.location.href='".sefRelToAbs("index.php?option=com_content&task=view&id=$contentid&Itemid=$acitemid")."';";

    echo "<SCRIPT>alert('"._AKOCOMMENT_SAVED."'); $redirectlink</SCRIPT>";
  }
?>