<?php

/*++++++++++++++++++++++++++++++++++++++++

  Script: Maian Events v2.0
  Written by: David Ian Bennett
  E-Mail: support@maianscriptworld.co.uk
  Website: http://www.maianscriptworld.co.uk

  ++++++++++++++++++++++++++++++++++++++++
  
  This File: class_events.inc.php
  Description: Events Class

  ++++++++++++++++++++++++++++++++++++++++*/


class calEvent extends genericOptions {
  
var $prefix;

// Add event..
function add($DATA)
{
  // Use callback function to prepare data for importing..
  $DATA = array_map(array($this,'safe_import'),$DATA);
  
  mysql_query("INSERT INTO ".$this->prefix."events (
               title,
               fromDate,
               toDate,
               addDate,
               keywords,
               description,
               contact,
               email,
               en_comments,
               finish,
               comments,
               is_archived,
               rss_date
               ) VALUES (
               '{$DATA['title']}',
               '{$DATA['fromDate']}',
               '{$DATA['toDate']}',
               '".date("Y-m-d")."',
               '{$DATA['keywords']}',
               '{$DATA['description']}',
               '".(isset($DATA['contact']) ? '1' : '0')."',
               '{$DATA['email']}',
               '".(isset($DATA['en_comments']) ? '1' : '0')."',
               '".(isset($DATA['finish']) ? $DATA['finish'] : '3')."',
               '{$DATA['comments']}',
               '0',
               '".date('D, j M Y H:i:s')." GMT'
               )") or die(mysql_error());
               
  // Add pictures..
  $this->pictures($DATA,mysql_insert_id());             
}

// Clear events/comments..
function clear($DATA)
{
  mysql_query("DELETE FROM ".$this->prefix."events WHERE id IN ('".implode(",",$DATA['id'])."')") or die(mysql_error());  
  mysql_query("DELETE FROM ".$this->prefix."comments WHERE eventid IN ('".implode(",",$DATA['id'])."')") or die(mysql_error());  
}

// Add pictures..
function pictures($DATA,$id)
{
  // Clear current pictures..
  mysql_query("DELETE FROM ".$this->prefix."pictures WHERE eventid = '{$id}'") or die(mysql_error());
  
  // Add pictures..
  for ($i=1; $i<5; $i++) {
    if ($DATA['image_'.$i]) {
      mysql_query("INSERT INTO ".$this->prefix."pictures (
                   identifier,
                   eventid,
                   name,
                   thumb,
                   image
                   ) VALUES (
                   '{$i}',
                   '{$id}',
                   '".$this->safe_import($DATA['name_'.$i])."',
                   '".$this->safe_import($DATA['thumb_'.$i])."',
                   '".$this->safe_import($DATA['image_'.$i])."'
                   )") or die(mysql_error()); 
    }
  }
}

// Update event..
function update($DATA)
{
  // Use callback function to prepare data for importing..
  $DATA = array_map(array($this,'safe_import'),$DATA);
  
  mysql_query("UPDATE ".$this->prefix."events SET
               title        = '{$DATA['title']}',
               fromDate     = '{$DATA['fromDate']}',
               toDate       = '{$DATA['toDate']}',
               keywords     = '{$DATA['keywords']}',
               description  = '{$DATA['description']}',
               contact      = '".(isset($DATA['contact']) ? '1' : '0')."',
               email        = '{$DATA['email']}',
               en_comments  = '".(isset($DATA['en_comments']) ? '1' : '0')."',
               finish       = '".(isset($DATA['finish']) ? $DATA['finish'] : '3')."',
               comments     = '{$DATA['comments']}',
               is_archived  = '0',
               rss_date     = '".date('D, j M Y H:i:s')." GMT'
               WHERE id     = '{$DATA['id']}'
               LIMIT 1
               ") or die(mysql_error());
               
  // Update pictures..
  $this->pictures($DATA,$DATA['id']);              
}

// Approve/reject comment..
function comment($id,$reject=false)
{
  if ($reject) {
    mysql_query("DELETE FROM ".$this->prefix."comments
                 WHERE id   = '{$id}'
                 LIMIT 1
                 ") or die(mysql_error());
  } else {
    mysql_query("UPDATE ".$this->prefix."comments SET
                 is_active    = '1'
                 WHERE id     = '{$id}'
                 LIMIT 1
                 ") or die(mysql_error());
  }
}

}

?>
