<?php

/*---------------------------------------------
  MAIAN EVENTS v2.0
  Written by David Ian Bennett
  E-Mail: support@maianscriptworld.co.uk
  Website: www.maianscriptworld.co.uk
  This File: Main Parsing File
----------------------------------------------*/

// Set error reporting level..E_ALL for development..
error_reporting (0);

// Define path..
define ('FOLDER_PATH',dirname(__FILE__).'/');
define ('PARENT',1);

include(FOLDER_PATH.'inc/db_connection.inc.php');
include(FOLDER_PATH.'lib/Savant2.php');
include(FOLDER_PATH.'inc/functions.php');
include(FOLDER_PATH.'inc/defined.inc.php');
include(FOLDER_PATH.'classes/class_generic.inc.php');
include(FOLDER_PATH.'classes/class_calendar.inc.php');
include(FOLDER_PATH.'classes/class_mail.inc.php');
include(FOLDER_PATH.'classes/class_rss.inc.php');
include(FOLDER_PATH.'classes/class_comments.inc.php');
include(FOLDER_PATH.'classes/PaginateIt.php');

// Collation..
@mysql_query("SET CHARACTER SET 'utf8'");
@mysql_query("SET NAMES 'utf8'");

//------------------------
// Load settings
//------------------------

$SETTINGS = mysql_fetch_object(mysql_query("SELECT * FROM ".$database['prefix']."settings LIMIT 1")) or die(mysql_error());

// Load language file..
include(FOLDER_PATH.'lang/'.$SETTINGS->language);

// Assign vars..
$cmd           = (isset($_GET['cmd']) ? strip_tags($_GET['cmd']) : 'home');
$theme         = (isset($_COOKIE['mevents_theme_cookie']) ? $_COOKIE['mevents_theme_cookie'] : ($SETTINGS->theme ? $SETTINGS->theme : 'standard'));
$title         = str_replace("{website_name}",cleanData($SETTINGS->website),$p_header);
$page          = (isset($_GET['page']) ? strip_tags($_GET['page']) : '1');
$year          = (isset($_GET['year']) ? strip_tags($_GET['year']) : date("Y"));
$month         = (isset($_GET['month']) ? strip_tags($_GET['month']) : date("m"));
$count         = 0;
$limit         = EVENTS_PER_PAGE;
$limitvalue    = $page * $limit - ($limit); 
$mKeys         = cleanData($SETTINGS->meta_keys);
$mDesc         = cleanData($SETTINGS->meta_desc);
$cryptinstall  = FOLDER_PATH.'captcha/cryptographp.fct.php';
include $cryptinstall;

// Check theme..
if ($theme && !is_dir(FOLDER_PATH.'themes/'.$theme)) {
  exit;
}

// Check variables..
checkVar($page);
checkVar($month);
checkVar($year);

// Create objects of class files..
$MEV_CALENDAR               = new calendar();
$MEV_COMMENTS               = new eventComments();
$MEV_MAIL                   = new mailClass();
$MEV_RSS                    = new rss_Feed();
$MEV_CALENDAR->prefix       = $database['prefix'];
$MEV_COMMENTS->prefix       = $database['prefix'];
$MEV_CALENDAR->settings     = $SETTINGS;
$MEV_CALENDAR->month        = $month;
$MEV_CALENDAR->year         = $year;
$MEV_CALENDAR->shortDays    = $calendar3;
$MEV_CALENDAR->days         = $calendar4;
$MEV_CALENDAR->shortMonths  = $calendar;
$MEV_CALENDAR->months       = $calendar2;
$MEV_MAIL->smtp             = $SETTINGS->smtp;
$MEV_MAIL->smtp_host        = $SETTINGS->smtp_host;
$MEV_MAIL->smtp_user        = $SETTINGS->smtp_user;
$MEV_MAIL->smtp_pass        = $SETTINGS->smtp_pass;
$MEV_MAIL->smtp_port        = $SETTINGS->smtp_port;
$MEV_MAIL->addTag('{WEBSITE_NAME}',$SETTINGS->website);
$MEV_MAIL->addTag('{WEBSITE_URL}',$SETTINGS->folder);
$MEV_MAIL->addTag('{WEBSITE_EMAIL}',$SETTINGS->email);
$MEV_RSS->path              = $SETTINGS->folder.'/themes/'.$theme;

// If theme switcher is enabled and new theme has been set, reload..
if ($SETTINGS->tswitch && isset($_GET['load_theme'])) {
  updateEventTheme($_GET['load_theme']);
}

// Archive events..
archiveEvents();

switch ($cmd)
{
  // Home..
  case 'home':
  
  $title = $title.' - '.$MEV_CALENDAR->getCurrentMonth($month-1).' '.$year;
  
  include(FOLDER_PATH.'inc/header.php');
  
  $tpl_home = new Savant2();
  $tpl_home->assign('MESSAGE',$p_calendar);
  $tpl_home->assign('MONTHS',$MEV_CALENDAR->calendarNavigation('months',$month,$cmd));
  $tpl_home->assign('YEARS',$MEV_CALENDAR->calendarNavigation('years',$year,$cmd));
  $tpl_home->assign('CALENDAR',$MEV_CALENDAR->showEventCalendar('home',FOLDER_PATH,$theme));
  $tpl_home->display('themes/'.$theme.'/calendar.tpl.php');
  
  include(FOLDER_PATH.'inc/footer.php');
  break;
  
  // Event..
  case 'event':
  
  // Check event var..
  checkVar($_GET['event']);
  $conData  = '';
  $comData  = '';
  
  // Get event data..
  // Parse page title with event name and event dates..
  $event  = getEvent($_GET['event']);
  $title  = str_replace("{event}",cleanData($event->title),($event->is_archived ? $p_header8 : $p_header6)).' - '.
           ($event->fromDate===$event->toDate ? translateCalendar($event->f_date) : 
            translateCalendar($event->f_date).' / '.translateCalendar($event->t_date)
            );
  
  // Overwrite meta keywwords & description if specified for this event..
  if ($event->keywords) {
    $mKeys = cleanData($event->keywords);
  }
  if ($event->description) {
    $mDesc = cleanData($event->description);
  }
  
  // Is the contact option enabled?
  if ($event->contact) {
    $conData = str_replace(array('{url}','{txt}','{txt2}','{window}'),
                           array(
                           $SETTINGS->folder.'/'.($SETTINGS->modr ? 'contact/'.$_GET['event'].'/'.cleanEventName(cleanData($event->title)).'/index.html' : 'index.php?cmd=contact&amp;event='.$_GET['event']),
                           $p_event7,
                           $p_event8,
                           CONTACT_POP_WINDOW
                           ),
                           file_get_contents(FOLDER_PATH.'themes/'.$theme.'/tpl_files/contact.tpl')
                           );
  } else {
    $conData = str_replace('{txt}',$p_event6,
                           file_get_contents(FOLDER_PATH.'themes/'.$theme.'/tpl_files/no_contact.tpl')
                           );
  }
  
  // Overwrite for comments..
  $limit         = COMMENTS_PER_PAGE;
  $limitvalue    = $page * $limit - ($limit); 
  
  // Are comments enabled?
  if ($event->en_comments) {
    if (rowCount('comments',' WHERE eventid = \''.$_GET['event'].'\' AND is_active = \'1\'')>0) {
      $comData = loadEventComments($_GET['event'],$limitvalue,$limit);
    } else {
      $comData = str_replace('{txt}',$p_event14,
                             file_get_contents(FOLDER_PATH.'themes/'.$theme.'/tpl_files/general_message.tpl')
                             );
    }
  } else {
    $comData = str_replace('{txt}',$p_event15,
                           file_get_contents(FOLDER_PATH.'themes/'.$theme.'/tpl_files/general_message.tpl')
                           );
  }
  
  include(FOLDER_PATH.'inc/header.php');
  
  $tpl_event = new Savant2();
  $tpl_event->assign('EVENT',$p_event);
  $tpl_event->assign('NAME',cleanData($event->title));
  $tpl_event->assign('DATES_TXT',$p_event2);
  $tpl_event->assign('DATES',($event->fromDate===$event->toDate ? translateCalendar($event->f_date) : translateCalendar($event->f_date).' / '.translateCalendar($event->t_date)).($event->is_archived ? ' <span class="archived">'.$p_event5.'</span>' : ''));
  $tpl_event->assign('COMMENTS',($event->comments ? nl2br(cleanData($event->comments)) : $p_event3));
  $tpl_event->assign('PICTURES', pictureGallery($_GET['event']));
  $tpl_event->assign('SHOW_PICTURES', pictureGallery($_GET['event'],true));
  $tpl_event->assign('EVENT_PICS',$p_event4);
  $tpl_event->assign('CONTACT',$conData);
  $tpl_event->assign('ADD_COMMENT_URL',($event->en_comments ? '<a href="'.$SETTINGS->folder.'/'.($SETTINGS->modr ? 'comment/'.$event->id.'/'.cleanEventName(cleanData($event->title)).'/index.html' : 'index.php?cmd=leave-comment&amp;event='.$_GET['event']).'" title="'.$p_event18.'" rel="gb_page_center['.COMMENT_POP_WINDOW.']">'.$p_event18.'</a>' : ''));
  $tpl_event->assign('COMMENTS_TXT',str_replace("{count}",rowCount('comments',' WHERE eventid = \''.$_GET['event'].'\' AND is_active = \'1\''),$p_event12));
  $tpl_event->assign('VIS_COMMENTS',$comData);
  $tpl_event->assign('PAGE_NUMBERS',($event->en_comments && rowCount('comments',' WHERE eventid = \''.$_GET['event'].'\' AND is_active = \'1\'')>0 ? page_numbers(rowCount('comments',' WHERE eventid = \''.$_GET['event'].'\' AND is_active = \'1\''),$limit,$page,($SETTINGS->modr ? $SETTINGS->folder.'/event/'.$event->id.'/{page}/'.cleanEventName(cleanData($event->title)).'/index.html' : 'index.php?cmd=event&amp;event='.$_GET['event'].'&amp;page={page}')) : ''));
  $tpl_event->display('themes/'.$theme.'/event.tpl.php');
  
  include(FOLDER_PATH.'inc/footer.php');
  break;
  
  // Archive..
  case 'archive':
  
  $title = $title.' - '.$p_header3.' - '.$MEV_CALENDAR->getCurrentMonth($month-1).' '.$year;
  
  include(FOLDER_PATH.'inc/header.php');
  
  $tpl_archive = new Savant2();
  $tpl_archive->assign('MESSAGE',$p_calendar2);
  $tpl_archive->assign('MONTHS',$MEV_CALENDAR->calendarNavigation('months',$month,$cmd));
  $tpl_archive->assign('YEARS',$MEV_CALENDAR->calendarNavigation('years',$year,$cmd,ARCHIVE_START_YEAR));
  $tpl_archive->assign('CALENDAR',$MEV_CALENDAR->showEventCalendar('archive',FOLDER_PATH,$theme));
  $tpl_archive->display('themes/'.$theme.'/calendar.tpl.php');
  
  include(FOLDER_PATH.'inc/footer.php');
  break;
  
  // Search..
  case 'search':
  
  $title  = $title.' - '.$p_header5;
  $query  = '';
  
  // Perform search..
  if (isset($_GET['search'])) {
    // Apply call back element to trim get vars and clear nasty tags..
    $_GET = array_map('cleanEvilTags',$_GET);
    // Are keywords specified..
    if ($_GET['keywords']) {
      // Split keywords..
      $words = explode(" ",$_GET['keywords']);
      for ($i=0; $i<count($words); $i++) {
        $query .= ($i ? "OR title LIKE '%".mysql_real_escape_string($words[$i])."%' OR comments LIKE '%".mysql_real_escape_string($words[$i])."%' " : "WHERE (title LIKE '%".mysql_real_escape_string($words[$i])."%' OR comments LIKE '%".mysql_real_escape_string($words[$i])."%' ");
      }
      // Is archive set..
      $query .= ") ".(isset($_GET['archive']) && $_GET['archive'] ? '' : ' AND is_archived = \'0\'')."";
    } else {
      header("Location: ".($SETTINGS->modr ? 'index.html' : 'index.php')."");
      exit;
    }
  } else {
    header("Location: ".($SETTINGS->modr ? 'index.html' : 'index.php')."");
    exit;
  }
  
  include(FOLDER_PATH.'inc/header.php');
  
  $tpl_search = new Savant2();
  $tpl_search->assign('MESSAGE',$p_search);
  $tpl_search->assign('SEARCH',str_replace('{count}',rowCount('events',' '.$query),$p_search2));
  $tpl_search->assign('SEARCH_DATA',buildEvents('',$query));
  $tpl_search->assign('PAGE_NUMBERS',(rowCount('events',' '.$query)>0 ? page_numbers(rowCount('events',' '.$query),$limit,$page,($SETTINGS->modr ? $SETTINGS->folder.'/search/'.cleanData(urlencode($_GET['keywords'])).'/'.(isset($_GET['archive']) ? '1' : '0').'/{page}/index.html' : $SETTINGS->folder.'/index.php?cmd=search&amp;search=1&amp;keywords='.cleanData(urlencode($_GET['keywords'])).'&amp;archive='.(isset($_GET['archive']) ? '1' : '0').'&amp;page={page}')) : ''));
  $tpl_search->display('themes/'.$theme.'/search.tpl.php');
  
  include(FOLDER_PATH.'inc/footer.php');
  break;
  
  // Coming Soon..
  case 'coming-soon':
  
  $title = $title.' - '.$p_header7;
  
  // Set date for limit..
  $date = date("Y-m-d",strtotime("+".EVENTS_COMING_SOON_MONTHS." months"));
  
  include(FOLDER_PATH.'inc/header.php');
  
  $tpl_csoon = new Savant2();
  $tpl_csoon->assign('MESSAGE',str_replace('{months}',EVENTS_COMING_SOON_MONTHS,$p_soon));
  $tpl_csoon->assign('COMING_SOON',str_replace('{count}',rowCount('events',' WHERE (fromDate > \''.date("Y-m-d").'\' AND fromDate <= \''.$date.'\') AND is_archived  = \'0\''),$p_soon2));
  $tpl_csoon->assign('COMING_SOON_DATA',buildEvents($date));
  $tpl_csoon->assign('PAGE_NUMBERS',(rowCount('events',' WHERE (fromDate > \''.date("Y-m-d").'\' AND fromDate <= \''.$date.'\') AND is_archived  = \'0\'')>0 ? page_numbers(rowCount('events',' WHERE (fromDate > \''.date("Y-m-d").'\' AND fromDate <= \''.$date.'\') AND is_archived  = \'0\''),$limit,$page,($SETTINGS->modr ? $SETTINGS->folder.'/coming-soon/{page}/index.html' : $SETTINGS->folder.'/index.php?cmd=coming-soon&amp;page={page}')) : ''));
  $tpl_csoon->display('themes/'.$theme.'/coming_soon.tpl.php');
  
  include(FOLDER_PATH.'inc/footer.php');
  break;
  
  // View Picture..
  case 'view-picture':
  
  // Check picture var..
  checkVar($_GET['picture']);
  
  // Get picture information..
  $picture = getSinglePicture($_GET['picture']);
  
  $tpl_picture = new Savant2();
  $tpl_picture->assign('CHARSET',$charset);
  $tpl_picture->assign('BASE_HREF',$SETTINGS->folder);
  $tpl_picture->assign('THEME',$theme);
  $tpl_picture->assign('TITLE', $title);
  $tpl_picture->assign('PIC_URL',($picture->image ? $picture->image : $picture->thumb));
  $tpl_picture->assign('NAME',($picture->name ? cleanData($picture->name) : $p_event11));
  $tpl_picture->display('themes/'.$theme.'/view_picture.tpl.php');
  
  break;
  
  // Contact..
  case 'contact':
  
  // Check event var..
  checkVar($_GET['event']);
  
  // Event data..
  $event  = getEvent($_GET['event']);
  
  // Process contact option..
  if (isset($_POST['process']))
  {
    // Apply call back element to trim post vars and clear nasty tags..
    $_POST = array_map('cleanEvilTags',$_POST);
               
    if ($_POST['name']=='') {
      $N_ERROR = true;
      $count++;
    }
    if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST['email'])) {
      $E_ERROR = true;
      $count++;
    }
    if ($_POST['comments']=='') {
      $C_ERROR = true;
      $count++;
    }
    if ($SETTINGS->captcha && isset($_POST['code'])) {
      if (!chk_crypt($_POST['code'])) {
       $SUM_ERROR = true;
       $count++;
      }
    }
               
    if ($count==0) {
      $MEV_MAIL->addTag('{NAME}',$_POST['name']);
      $MEV_MAIL->addTag('{EMAIL}',$_POST['email']);
      $MEV_MAIL->addTag('{COMMENTS}',$_POST['comments']);
      $MEV_MAIL->addTag('{IP}',$_SERVER['REMOTE_ADDR']);
      $MEV_MAIL->addTag('{EVENT}',$event->title);
      $MEV_MAIL->addTag('{DATES}',($event->fromDate===$event->toDate ? translateCalendar($event->f_date) : translateCalendar($event->f_date).' / '.translateCalendar($event->t_date)));
      $MEV_MAIL->addTag('{EVENT_URL}',($SETTINGS->modr ? $SETTINGS->folder.'/event/'.$_GET['event'].'/'.cleanEventName(cleanData($event->title)).'/index.html' : $SETTINGS->folder.'/index.php?cmd=event&event='.$_GET['event']));
       
      // Send to webmaster..
      $MEV_MAIL->sendMail($SETTINGS->website,
                          $SETTINGS->email,
                          $_POST['name'],
                          $_POST['email'],
                          '['.$SETTINGS->website.'] '.$contact19,
                          $MEV_MAIL->template('themes/email/contact_message.txt')
                          );
       
      // Send auto responder..
      $MEV_MAIL->sendMail($_POST['name'],
                          $_POST['email'],
                          $SETTINGS->website,
                          $SETTINGS->email,
                          '['.$SETTINGS->website.'] '.$contact20,
                          $MEV_MAIL->template('themes/email/contact_auto.txt')
                          );
      
      // Clear post vars..
      $_POST['name']      = '';
      $_POST['email']     = '';
      $_POST['comments']  = '';
      
      $SENT = true;                    
    }
  }
  
  $tpl_contact = new Savant2();
  $tpl_contact->assign('CHARSET', $charset);
  $tpl_contact->assign('TITLE', $title);
  $tpl_contact->assign('BASE_HREF', $SETTINGS->folder);
  $tpl_contact->assign('THEME',$theme);
  $tpl_contact->assign('URL',($SETTINGS->modr ? 'contact/'.$_GET['event'].'/'.cleanEventName(cleanData($event->title)).'/index.html' : 'index.php?cmd=contact&amp;event='.$_GET['event']));
  $tpl_contact->assign('NAME_TEXT', $contact3);
  $tpl_contact->assign('EMAIL_TEXT', $contact4);
  $tpl_contact->assign('COMMENT_TEXT', $contact6);
  $tpl_contact->assign('NAME_VALUE', (isset($_POST['name']) ? cleanData($_POST['name']) : ''));
  $tpl_contact->assign('EMAIL_VALUE', (isset($_POST['email']) ? cleanData($_POST['email']) : ''));
  $tpl_contact->assign('COMMENT_VALUE', (isset($_POST['comments']) ? cleanData($_POST['comments']) : str_replace('{event}',cleanData($event->title),$contact)));
  $tpl_contact->assign('CAPTCHA',showCaptcha((isset($SUM_ERROR) ? '<span class="error">'.$contact15.'</span>' : '')));
  $tpl_contact->assign('N_ERROR', (isset($N_ERROR) ? '<span class="error">'.$contact11.'</span>' : ''));
  $tpl_contact->assign('E_ERROR', (isset($E_ERROR) ? '<span class="error">'.$contact12.'</span>' : ''));
  $tpl_contact->assign('S_ERROR', (isset($S_ERROR) ? '<span class="error">'.$contact13.'</span>' : ''));
  $tpl_contact->assign('C_ERROR', (isset($C_ERROR) ? '<span class="error">'.$contact14.'</span>' : ''));
  $tpl_contact->assign('SEND_TEXT', $contact7);
  $tpl_contact->assign('DIV_1',(isset($SENT) ? ' style="display:none"' : ''));
  $tpl_contact->assign('DIV_2',(!isset($SENT) ? ' style="display:none"' : ''));
  $tpl_contact->assign('THANKS',$contact17);
  $tpl_contact->assign('MESSAGE',$contact18);
  $tpl_contact->display('themes/'.$theme.'/contact.tpl.php');
  
  break;
  
  // Comments..
  case 'leave-comment':
  
  // Check event var..
  checkVar($_GET['event']);
  
  // Event data..
  $event = getEvent($_GET['event']);
  
  // Are comments enabled for this event?
  if (!$event->en_comments) {
    echo $p_event15;
    exit;
  }
  
  // Process comment..
  if (isset($_POST['process']))
  {
    // Apply call back element to trim post vars and clear nasty tags..
    $_POST = array_map('cleanEvilTags',$_POST);
               
    if ($_POST['name']=='') {
      $N_ERROR = true;
      $count++;
    }
    if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST['email'])) {
      $E_ERROR = true;
      $count++;
    }
    if ($_POST['comments']=='') {
      $C_ERROR = true;
      $count++;
    }
    if ($SETTINGS->captcha && isset($_POST['code'])) {
      if (!chk_crypt($_POST['code'])) {
       $SUM_ERROR = true;
       $count++;
      }
    }
               
    if ($count==0) {
      // Log comments in database..
      $MEV_COMMENTS->addCommentsToDatabase($_POST,$event->id,$SETTINGS->approve);
      
      $MEV_MAIL->addTag('{NAME}',$_POST['name']);
      $MEV_MAIL->addTag('{COMMENTS}',$_POST['comments']);
      $MEV_MAIL->addTag('{IP}',$MEV_COMMENTS->getIP());
      $MEV_MAIL->addTag('{EVENT}',$event->title);
      $MEV_MAIL->addTag('{DATES}',($event->fromDate===$event->toDate ? translateCalendar($event->f_date) : translateCalendar($event->f_date).' / '.translateCalendar($event->t_date)));
      $MEV_MAIL->addTag('{EVENT_URL}',($SETTINGS->modr ? $SETTINGS->folder.'/event/'.$_GET['event'].'/'.cleanEventName(cleanData($event->title)).'/index.html' : $SETTINGS->folder.'/index.php?cmd=event&event='.$_GET['event']));
       
      // Send to webmaster..
      $MEV_MAIL->sendMail($SETTINGS->website,
                          $SETTINGS->email,
                          $SETTINGS->website,
                          $SETTINGS->email,
                          '['.$SETTINGS->website.'] '.$contact21,
                          $MEV_MAIL->template('themes/email/new_comment.txt')
                          );
      
      // Clear post vars..
      $_POST['name']      = '';
      $_POST['email']     = '';
      $_POST['comments']  = '';
      
      $SENT = true;                    
    }
  }
  
  $tpl_comment = new Savant2();
  $tpl_comment->assign('CHARSET', $charset);
  $tpl_comment->assign('TITLE', $title);
  $tpl_comment->assign('BASE_HREF', $SETTINGS->folder);
  $tpl_comment->assign('EVENT_TEXT',$contact24);
  $tpl_comment->assign('EVENT_NAME',cleanData($event->title));
  $tpl_comment->assign('THEME',$theme);
  $tpl_comment->assign('URL',($SETTINGS->modr ? 'comment/'.$_GET['event'].'/'.cleanEventName(cleanData($event->title)).'/index.html' : 'index.php?cmd=leave-comment&amp;event='.$_GET['event']));
  $tpl_comment->assign('NAME_TEXT', $contact3);
  $tpl_comment->assign('EMAIL_TEXT', $contact22);
  $tpl_comment->assign('COMMENT_TEXT', $contact6);
  $tpl_comment->assign('NAME_VALUE', (isset($_POST['name']) ? cleanData($_POST['name']) : ''));
  $tpl_comment->assign('EMAIL_VALUE', (isset($_POST['email']) ? cleanData($_POST['email']) : ''));
  $tpl_comment->assign('COMMENT_VALUE', (isset($_POST['comments']) ? cleanData($_POST['comments']) : ''));
  $tpl_comment->assign('CAPTCHA',showCaptcha((isset($SUM_ERROR) ? '<span class="error">'.$contact15.'</span>' : '')));
  $tpl_comment->assign('N_ERROR', (isset($N_ERROR) ? '<span class="error">'.$contact11.'</span>' : ''));
  $tpl_comment->assign('E_ERROR', (isset($E_ERROR) ? '<span class="error">'.$contact12.'</span>' : ''));
  $tpl_comment->assign('S_ERROR', (isset($S_ERROR) ? '<span class="error">'.$contact13.'</span>' : ''));
  $tpl_comment->assign('C_ERROR', (isset($C_ERROR) ? '<span class="error">'.$contact14.'</span>' : ''));
  $tpl_comment->assign('SEND_TEXT', $contact23);
  $tpl_comment->assign('DIV_1',(isset($SENT) ? ' style="display:none"' : ''));
  $tpl_comment->assign('DIV_2',(!isset($SENT) ? ' style="display:none"' : ''));
  $tpl_comment->assign('THANKS',$contact17);
  $tpl_comment->assign('MESSAGE',($SETTINGS->approve ? $contact26 : $contact25));
  $tpl_comment->display('themes/'.$theme.'/comment.tpl.php');
  
  break;
  
  // RSS Feed..
  case 'rss-feed':
  
  $rss_feed    = '';
  $build_date  = date('D, j M Y H:i:s').' GMT';
  
  // Open channel..
  $rss_feed = $MEV_RSS->open_channel();
   
  // Feed info..
  $rss_feed .= $MEV_RSS->feed_info(str_replace("{website_name}",$SETTINGS->website,$msg_rss),
                                   ($SETTINGS->modR ? $SETTINGS->folder.'/index.html' : $SETTINGS->folder.'/index.php'),
                                   $build_date,
                                   str_replace(array("{count}","{website_name}"),
                                               array(RSS_FEEDS_TO_DISPLAY,$SETTINGS->website),
                                               $msg_rss2),
                                   $SETTINGS->website
                                   );
   
  // Get latest posts..
  $query = mysql_query("SELECT *,DATE_FORMAT(fromDate,'".$SETTINGS->formatdate."') AS f_date,
                        DATE_FORMAT(toDate,'".$SETTINGS->formatdate."') AS t_date 
                        FROM ".$database['prefix']."events
                        WHERE fromDate > '".date("Y-m-d")."' 
                        ORDER BY id DESC 
                        LIMIT ".RSS_FEEDS_TO_DISPLAY."
                        ") or die(mysql_error());

  while ($RSS = mysql_fetch_object($query)) {
    $rss_feed .= $MEV_RSS->add_item($msg_rss3.$RSS->title.' ('.translateCalendar($RSS->f_date).' / '.translateCalendar($RSS->t_date).')',
                                    $SETTINGS->folder.'/'.($SETTINGS->modr ? 'event/'.$RSS->id.'/'.$MEV_CALENDAR->cleanEventName($MEV_CALENDAR->strip_slashes($RSS->title)).'/index.html' : 'index.php?cmd=event&amp;event='.$RSS->id),
                                    ($RSS->rss_date ? $RSS->rss_date : $build_date),
                                    nl2br($RSS->comments)
                                    );
  }
   
  // Close channel..
  $rss_feed .= $MEV_RSS->close_channel();
   
  // Display RSS feed..
  header('Content-Type: text/xml');
  echo (get_magic_quotes_gpc() ? stripslashes(trim($rss_feed)) : trim($rss_feed));
   
  break;
  
  // Default if CMD isn`t recognised..
  default:
  header("Location: ".($SETTINGS->modr ? 'index.html' : 'index.php')."");
  break;
}

?>
