<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: eventfunctions.php,v 1.5.2.2 2004/04/18 12:45:42 ajvwaay Exp $



$Cal_Ver    = "EventCal 2.0a v BlackV_Life";     # Program version
/************************************************************************/
/* MyPhPNuke: Event Calendar Module                                     */
/* Events Function File                                         */
/* ==================================================================== */
/*  Displays calendar of events and allows admin maintenance        */
/*                                                                      */
/* Copyright (c) 2001 by Daniel C. Raney (Daniel@Raney.net)             */
/* All rights reserved                                                  */
/* New Version by BlackV_Life for myphpnuke 1.8 (www.black-voodoo.de)   */
/* Adapted by BlackV_Life for myphpnuke 1.8                             */
/* Adapted by MiDnighT www.midnight.fr.st for phpnuke 5.0               */
/* ==================================================================== */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

/******************************************************************************
 *
 * Function: HTMLbuttons_eventname1, HTMLbuttons_eventmail,
 * HTMLbuttons_eventweb, HTMLbuttons_eventdesc
 * Purpose : HTMLbuttons for messagebox eventname1, eventmail, eventweb and eventdesc
 * Input   :
 * Output  :
 * Author  : BlackV_Life
 *
 * History
 * Date        Comments
 * ----------------------------------------------------------------------------
 * 2001-06-29  o Initial Version
 *
 ******************************************************************************/

function HTMLbuttons_eventname1()   {
    echo "<script type=\"text/javascript\"><!--\n\n";
    echo "function x () {\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "function DoPrompt1(action) {\n";
    echo "var revisedMessage;\n";
    echo "var currentMessage = document.coolsus.eventname1.value;\n";
    echo "\n";
    echo "if (action == \"url\") {\n";
    echo "var thisURL = prompt(\"".Translate("Enter the URL for the link you want to add.")."\", \"http://\");\n";
    echo "var thisTitle = prompt(\"".Translate("Enter the web site title.")."\", \"".Translate("Page title")."\");\n";
    echo "var urlBBCode = \"<a href=\"+thisURL+\" target=blank>\"+thisTitle+\"</a>\";\n";
    echo "revisedMessage = currentMessage+urlBBCode;\n";
    echo "document.coolsus.eventname1.value=revisedMessage;\n";
    echo "document.coolsus.eventname1.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"email\") {\n";
    echo "var thisEmail = prompt(\"".Translate("Enter the email address you want to add.")."\", \"\");\n";
    echo "var emailBBCode = \"<a href=mailto:\"+thisEmail+\">\"+thisEmail+\"</a>\";\n";
    echo "revisedMessage = currentMessage+emailBBCode;\n";
    echo "document.coolsus.eventname1.value=revisedMessage;\n";
    echo "document.coolsus.eventname1.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"bold\") {\n";
    echo "var thisBold = prompt(\"".Translate("Enter the text that you want to make bold.")."\", \"\");\n";
    echo "var boldBBCode = \"<b>\"+thisBold+\"</b>\";\n";
    echo "revisedMessage = currentMessage+boldBBCode;\n";
    echo "document.coolsus.eventname1.value=revisedMessage;\n";
    echo "document.coolsus.eventname1.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"italic\") {\n";
    echo "var thisItal = prompt(\"".Translate("Enter the text that you want to make italic.")."\", \"\");\n";
    echo "var italBBCode = \"<i>\"+thisItal+\"</i>\";\n";
    echo "revisedMessage = currentMessage+italBBCode;\n";
    echo "document.coolsus.eventname1.value=revisedMessage;\n";
    echo "document.coolsus.eventname1.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"quote\") {\n";
    echo "var quoteBBCode = \"<blockquote><i> </i></blockquote>\";\n";
    echo "revisedMessage = currentMessage+quoteBBCode;\n";
    echo "document.coolsus.eventname1.value=revisedMessage;\n";
    echo "document.coolsus.eventname1.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"listopen\") {\n";
    echo "var liststartBBCode = \"<ul>\";\n";
    echo "revisedMessage = currentMessage+liststartBBCode;\n";
    echo "document.coolsus.eventname1.value=revisedMessage;\n";
    echo "document.coolsus.eventname1.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"listclose\") {\n";
    echo "var listendBBCode = \"</ul>\";\n";
    echo "revisedMessage = currentMessage+listendBBCode;\n";
    echo "document.coolsus.eventname1.value=revisedMessage;\n";
    echo "document.coolsus.eventname1.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"listitem\") {\n";
    echo "var thisItem = prompt(\"".Translate("Enter the new list item. Note that each list group must be preceeded by a List Close and must be ended with List Close.")."\", \"\");\n";
    echo "var itemBBCode = \"<li>\"+thisItem+\"</li>\";\n";
    echo "revisedMessage = currentMessage+itemBBCode;\n";
    echo "document.coolsus.eventname1.value=revisedMessage;\n";
    echo "document.coolsus.eventname1.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "}\n";
    echo "//--></script>\n";
    echo "\n\n\n";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt1('url');\"><img src = \"images/forum/b_url.gif\" alt = \"".Translate("Web Address")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt1('email');\"><img src = \"images/forum/b_email.gif\" alt = \"".Translate("Email Address")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt1('bold');\"><img src = \"images/forum/b_bold.gif\" alt = \"".Translate("Bold Text")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt1('italic');\"><img src = \"images/forum/b_italic.gif\" alt = \"".Translate("Italic Text")."\" border = 0></a><br />";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt1('quote');\"><img src = \"images/forum/b_quote.gif\" alt = \"".Translate("Quote")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt1('listopen');\"><img src = \"images/forum/b_listopen.gif\" alt = \"".Translate("Open List")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt1('listitem');\"><img src = \"images/forum/b_listitem.gif\" alt = \"".Translate("List Item")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt1('listclose');\"><img src = \"images/forum/b_listclose.gif\" alt = \"".Translate("Close List")."\" border = 0></a>";
}

function HTMLbuttons_eventmail() {
    echo "<script type=\"text/javascript\"><!--\n\n";
    echo "function x () {\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "function DoPrompt2(action) {\n";
    echo "var revisedMessage;\n";
    echo "var currentMessage = document.coolsus.eventmail.value;\n";
    echo "\n";
    echo "if (action == \"email\") {\n";
    echo "var thisEmail = prompt(\"".Translate("Enter the email address you want to add.")."\", \"\");\n";
    echo "var emailBBCode = \"<a href=mailto:\"+thisEmail+\">\"+thisEmail+\"</a>\";\n";
    echo "revisedMessage = currentMessage+emailBBCode;\n";
    echo "document.coolsus.eventmail.value=revisedMessage;\n";
    echo "document.coolsus.eventmail.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "}\n";
    echo "//--></script>\n";
    echo "\n\n\n";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt2('email');\"><img src = \"images/forum/b_email.gif\" alt = \"".Translate("Email Address")."\" border = 0></a>";

}

function HTMLbuttons_eventweb() {
    echo "<script type=\"text/javascript\"><!--\n\n";
    echo "function x () {\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "function DoPrompt3(action) {\n";
    echo "var revisedMessage;\n";
    echo "var currentMessage = document.coolsus.eventweb.value;\n";
    echo "\n";
    echo "if (action == \"url\") {\n";
    echo "var thisURL = prompt(\"".Translate("Enter the URL for the link you want to add.")."\", \"http://\");\n";
    echo "var thisTitle = prompt(\"".Translate("Enter the web site title.")."\", \"".Translate("Page title")."\");\n";
    echo "var urlBBCode = \"<a href=\"+thisURL+\" target=blank>\"+thisTitle+\"</a>\";\n";
    echo "revisedMessage = currentMessage+urlBBCode;\n";
    echo "document.coolsus.eventweb.value=revisedMessage;\n";
    echo "document.coolsus.eventweb.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "}\n";
    echo "//--></script>\n";
    echo "\n\n\n";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt3('url');\"><img src = \"images/forum/b_url.gif\" alt = \"".Translate("Web Address")."\" border = 0></a>";

}

function HTMLbuttons_eventdesc() {
    echo "<script type=\"text/javascript\"><!--\n\n";
    echo "function x () {\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "function DoPrompt4(action) {\n";
    echo "var revisedMessage;\n";
    echo "var currentMessage = document.coolsus.eventdesc.value;\n";
    echo "\n";
    echo "if (action == \"url\") {\n";
    echo "var thisURL = prompt(\"".Translate("Enter the URL for the link you want to add.")."\", \"http://\");\n";
    echo "var thisTitle = prompt(\"".Translate("Enter the web site title.")."\", \"".Translate("Page title")."\");\n";
    echo "var urlBBCode = \"<a href=\"+thisURL+\" target=blank>\"+thisTitle+\"</a>\";\n";
    echo "revisedMessage = currentMessage+urlBBCode;\n";
    echo "document.coolsus.eventdesc.value=revisedMessage;\n";
    echo "document.coolsus.eventdesc.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"email\") {\n";
    echo "var thisEmail = prompt(\"".Translate("Enter the email address you want to add.")."\", \"\");\n";
    echo "var emailBBCode = \"<a href=mailto:\"+thisEmail+\">\"+thisEmail+\"</a>\";\n";
    echo "revisedMessage = currentMessage+emailBBCode;\n";
    echo "document.coolsus.eventdesc.value=revisedMessage;\n";
    echo "document.coolsus.eventdesc.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"bold\") {\n";
    echo "var thisBold = prompt(\"".Translate("Enter the text that you want to make bold.")."\", \"\");\n";
    echo "var boldBBCode = \"<b>\"+thisBold+\"</b>\";\n";
    echo "revisedMessage = currentMessage+boldBBCode;\n";
    echo "document.coolsus.eventdesc.value=revisedMessage;\n";
    echo "document.coolsus.eventdesc.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"italic\") {\n";
    echo "var thisItal = prompt(\"".Translate("Enter the text that you want to make italic.")."\", \"\");\n";
    echo "var italBBCode = \"<i>\"+thisItal+\"</i>\";\n";
    echo "revisedMessage = currentMessage+italBBCode;\n";
    echo "document.coolsus.eventdesc.value=revisedMessage;\n";
    echo "document.coolsus.eventdesc.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"quote\") {\n";
    echo "var quoteBBCode = \"<blockquote><i> </i></blockquote>\";\n";
    echo "revisedMessage = currentMessage+quoteBBCode;\n";
    echo "document.coolsus.eventdesc.value=revisedMessage;\n";
    echo "document.coolsus.eventdesc.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"listopen\") {\n";
    echo "var liststartBBCode = \"<ul>\";\n";
    echo "revisedMessage = currentMessage+liststartBBCode;\n";
    echo "document.coolsus.eventdesc.value=revisedMessage;\n";
    echo "document.coolsus.eventdesc.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"listclose\") {\n";
    echo "var listendBBCode = \"</ul>\";\n";
    echo "revisedMessage = currentMessage+listendBBCode;\n";
    echo "document.coolsus.eventdesc.value=revisedMessage;\n";
    echo "document.coolsus.eventdesc.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "if (action == \"listitem\") {\n";
    echo "var thisItem = prompt(\"".Translate("Enter the new list item. Note that each list group must be preceeded by a List Close and must be ended with List Close.")."\", \"\");\n";
    echo "var itemBBCode = \"<li>\"+thisItem+\"</li>\";\n";
    echo "revisedMessage = currentMessage+itemBBCode;\n";
    echo "document.coolsus.eventdesc.value=revisedMessage;\n";
    echo "document.coolsus.eventdesc.focus();\n";
    echo "return;\n";
    echo "}\n";
    echo "\n";
    echo "}\n";
    echo "//--></script>\n";
    echo "\n\n\n";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt4('url');\"><img src = \"images/forum/b_url.gif\" alt = \"".Translate("Web Address")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt4('email');\"><img src = \"images/forum/b_email.gif\" alt = \"".Translate("Email Address")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt4('bold');\"><img src = \"images/forum/b_bold.gif\" alt = \"".Translate("Bold Text")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt4('italic');\"><img src = \"images/forum/b_italic.gif\" alt = \"".Translate("Italic Text")."\" border = 0></a><br />";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt4('quote');\"><img src = \"images/forum/b_quote.gif\" alt = \"".Translate("Quote")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt4('listopen');\"><img src = \"images/forum/b_listopen.gif\" alt = \"".Translate("Open List")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt4('listitem');\"><img src = \"images/forum/b_listitem.gif\" alt = \"".Translate("List Item")."\" border = 0></a>";
    echo "<a href=\"javascript: x()\" onClick=\"DoPrompt4('listclose');\"><img src = \"images/forum/b_listclose.gif\" alt = \"".Translate("Close List")."\" border = 0></a>";
}


/******************************************************************************
 *
 * Function: daysinmonth
 * Purpose : calculate the days of a month
 * Input   : $month, $year string date to check ("yyyy-mm-dd")
 * Output  : seconds of days
 * Author  : Daniel C. Raney (Daniel@Raney.net)
 *
 * History
 * Date        Comments
 * ----------------------------------------------------------------------------
 * xxx-xx-xx  o Initial Version
 *
 ******************************************************************************/

function daysinmonth($month,$year) {
$x=1;
while(checkdate($month,$x,$year)) {
$x++;
}
return $x-1;
}
/******************************************************************************
 *
 * Function: ValidDate
 * Purpose : calculate the days of a month
 * Input   : $date - string date to check ("yyyy-mm-dd")
 * Output  : bool: true=ok, false=fail
 * Author  : Daniel C. Raney (Daniel@Raney.net)
 *
 * History
 * Date        Comments
 * ----------------------------------------------------------------------------
 * xxx-xx-xx  o Initial Version
 *
 ******************************************************************************/
function ValidDate ($date)
{
    global $Cal_CurYear, $Cal_MaxAdminAdvanceYears;

    $rc = FALSE;
    $parts = explode("-", $date);
    if (count($parts) == 3) {
        $rc = checkdate( $parts[1], $parts[2], $parts[0]);
        if ($rc) {
            if (($parts[0] < $Cal_CurYear) || ($parts[0] > ($Cal_CurYear+$Cal_MaxAdminAdvanceYears))) $rc = FALSE;
        }
    }
    return $rc;
}
/******************************************************************************
 *
 * Function: ValidDateSpan
 * Purpose : Test for a valid date range span
 * Input   :    from        string FROM date to check ("yyyy-mm-dd")
        $to     string TO date to check ("yyyy-mm-dd")
 * Output  : bool: true=ok, false=fail
 * Author  : Daniel C. Raney (Daniel@Raney.net)
 *
 * History
 * Date        Comments
 * ----------------------------------------------------------------------------
 * xxx-xx-xx  o Initial Version
 *
 ******************************************************************************/
function ValidDateSpan ($from, $to)
{
    global $Cal_MaxEventDays;

    $rc = TRUE;
    $m = GetDatePart($from, "m");
    $d = GetDatePart($from, "d");
    $y = GetDatePart($from, "y");
    $sfrom = mktime (0, 0, 0, $m, $d, $y);
    $m = GetDatePart($to, "m");
    $d = GetDatePart($to, "d");
    $y = GetDatePart($to, "y");
    $sto = mktime (0, 0, 0, $m, $d, $y);
    if ($sto < $sfrom) $rc = FALSE;
    if ($sto > ($sfrom + ($Cal_MaxEventDays * 86400))) $rc = FALSE;
    return $rc;
}
/******************************************************************************
 *
 * Function: DatesOkay
 * Purpose : Tests dates for validity and range
 * Input   :    $from       Date
        $to     Date
 * Output  : bool: true=ok, false=fail
 * Author  : Daniel C. Raney (Daniel@Raney.net)
 *
 * History
 * Date        Comments
 * ----------------------------------------------------------------------------
 * xxx-xx-xx  o Initial Version
 *
 ******************************************************************************/
function DatesOkay ($from, $to)
{
    global $phpEx;
    if (!ValidDate($from) || !ValidDate($to) || !ValidDateSpan($from, $to)) {
        $rc = FALSE;
        echo "<center><FONT COLOR=\"#FF0000\"><b>".translate("Invalid Date(s) or Date Range!!")."</b></FONT><br><br>";
        echo "[<a href=\"javascript:history.go(-1)\">".translate("Previous Page")."</a>]";
    } else {
        $rc = TRUE;
    }
    return $rc;
}
/******************************************************************************
 *
 * Function: FieldsOkay
 * Purpose : Tests fields for validity and size
 * Input   :    $name       Event name
        $desc       Event desc
 * Output  : bool: true=ok, false=fail
 * Author  : Daniel C. Raney (Daniel@Raney.net)
 *
 * History
 * Date        Comments
 * ----------------------------------------------------------------------------
 * xxx-xx-xx  o Initial Version
 *
 ******************************************************************************/
function FieldsOkay( $name, $desc)
{
    global $Cal_MaxEventNameLen, $Cal_MaxEventDescLen;
    global $phpEx;
    $rc = FALSE;
    if (!$name || !$desc) {
        $problem = "<FONT COLOR=\"#FF0000\">".translate("Blank field(s) !!")."</FONT>";
    } else {
        if (strlen($name) > $Cal_MaxEventNameLen) {
            $problem = "".translate("Event Name Exceeds Max Length!!")." ($Cal_MaxEventNameLen chars)";
        } elseif (strlen($desc) > $Cal_MaxEventDescLen) {
            $problem = "".translate("Description Name Exceeds Max Length!!")." ($Cal_MaxEventDescLen chars)";
        } else {
            $rc = TRUE;
        }
    }
    if (!$rc) {
        echo "<center><font size=2>
        <b>$problem</b></font</font><br><br>
[<a href=\"javascript:history.go(-1)\">".translate("Previous Page")."</a>]";
        }
    return $rc;
}
/******************************************************************************
 *
 * Function: GetDatePart
 * Purpose : Returns part of a string date
 * Input   :    $date       string date ("yyyy-mm-dd")
        $part       string: "y", "m", or "d"
 * Output  : string
 * Author  : Daniel C. Raney (Daniel@Raney.net)
 *
 * History
 * Date        Comments
 * ----------------------------------------------------------------------------
 * xxx-xx-xx  o Initial Version
 *
 ******************************************************************************/
function GetDatePart ($date, $part)
{
    if ( $date == '' ) { return; }

    $ret = 0;
    $part = strtolower($part);
    $dtparts = explode("-", $date);

    if ( sizeof( $dtparts ) == 3 )
    {
        if ($part =='y') {
            $ret = $dtparts[0];
        } elseif ($part == 'm') {
            $ret = $dtparts[1];
        } elseif ($part == 'd') {
            $ret = $dtparts[2];
        }
    }

    return $ret;
}

?>
