<?php

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

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

  ++++++++++++++++++++++++++++++++++++++++
  
  This File: class_emails.inc.php
  Description: E-Mail Address Class
  New in v2.0

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


class emailAddress extends genericOptions {

var $prefix;

// Add address..
function add($DATA)
{
  mysql_query("INSERT INTO ".$this->prefix."allowed_emails (email) VALUES ('".$this->safe_import($DATA['email'])."')") or die(mysql_error());
}

// Remove selected..
function delete($DATA)
{
  mysql_query("DELETE FROM ".$this->prefix."allowed_emails WHERE id IN(".implode(",",$DATA['email']).")") or die(mysql_error());
}

// Remove all..
function clear()
{
  mysql_query("TRUNCATE TABLE ".$this->prefix."allowed_emails") or die(mysql_error());
}

// Import to CSV..
function csv($txt,$path)
{
  $string = $txt.$this->define_newline();
  
  $query = mysql_query("SELECT * FROM ".$this->prefix."allowed_emails ORDER BY email") or die(mysql_error());
  
  while ($row = mysql_fetch_object($query)) {
    $string .= $row->email.$this->define_newline();
  }
  
  if (is_writeable($path.'log/')) {
    $filename  = $path.'log/csv_dump.csv';
    $fp        = fopen($filename, 'ab');

    if ($fp) {
      fwrite($fp,trim($string));
      fclose($fp);
    }
  } else {
    echo 'log directory needs to be writeable!!';
    exit;
  }
                                           
  unset($string);

  if(ini_get('zlib.output_compression')) {
    ini_set('zlib.output_compression', 'Off');
  }
                                           
  header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  header('Pragma: public');
	header('Expires: 0');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header('Cache-Control: private',false);
	header('Content-Type: '.$this->get_mime_type());
	header('Content-Disposition: attachment; filename='.basename($filename).';');
	header('Content-Transfer-Encoding: binary');
	header('Content-Length: '.filesize($filename));
		                           
  readfile($filename);

  if (file_exists($filename)) {
    unlink($filename);
    unset($filename);
  }
}

}

?>
