<?php

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

// Is webmaster logged in..
function isWebmasterLoggedIn() {
  global $database;
  if (!isset($_SESSION['mevents_admin_session']) && !isset($_COOKIE[$database['cookieName']])) {
    header("Location: index.php?cmd=login");
    exit;
  } else {
    if (isset($_COOKIE[$database['cookieName']])) {
      if ($_COOKIE[$database['cookieName']]!=encrypt($database['cookieKey'])) {
        header("Location: index.php?cmd=login");
        exit;
      }
    }
  }
}

function encrypt($data) {
  return (function_exists('sha1') ? sha1($data) : md5($data));
}

// Show message..
function ok($msg)
{
  return '
  <div id="ok">
   <p><img src="img/message.gif" style="vertical-align:bottom" alt="" title="" />&nbsp;&nbsp;'.$msg.'</p>
  </div>';
}

// Show error..
function error($msg)
{
  return '
  <div id="error">
   <p><img src="img/error.gif" style="vertical-align:bottom" alt="" title="" />&nbsp;&nbsp;'.$msg.'</p>
  </div>';
}

// Page numbers..
function admin_page_numbers($count,$limit,$page,$stringVar='page')
{
  global $script5,$script6;

  $PaginateIt = new PaginateIt();
  $PaginateIt->SetCurrentPage($page);
  $PaginateIt->SetItemCount($count);
  $PaginateIt->SetItemsPerPage($limit);
  $PaginateIt->SetLinksToDisplay(50);
  $PaginateIt->SetQueryStringVar($stringVar);
  $PaginateIt->SetLinksFormat('&laquo; '.$script5,
                              ' &bull; ',
                              $script6.' &raquo;'
                              );
                              
  return '<div id="page_numbers">'.$PaginateIt->GetPageLinks().'</div>';                            
}

// Check date...
function checkCalendarDate($date)
{
  $dt = explode("-",$date);
  
  if (isset($dt[0]) && isset($dt[1]) && isset($dt[2])) {
    return (checkdate($dt[1],$dt[2],$dt[0]) ? true : false);
  } else {
    return false;
  }
}


?>
