<?php

/*
////////////////////////////////////////////////////
//                  NewsPHP v200                  //
//               http://www.nphp.net/             //
//                                                //
// Installation --------------------------------- //
//   Please see the "readme.txt" file for details //
//   on how to install NewsPHP.                   //
//                                                //
// Introduction --------------------------------- //
//   NewsPHP is a news posting system for web     //
//   sites. It allows for multiple users of       //
//   different access levels to post news onto    //
//   your web site without them knowing any FTP   //
//   information or even having any knowledge in  //
//   HTML. They simply login and type their post! //
//                                                //
// Copyright ------------------------------------ //
//   NewsPHP is copyright (C) 1999-2001           //
//   the newsPHP Development Team and Ben         //
//   O'Neill. All rights reserved. You may not    //
//   redestribute this file without written       //
//   permission from the copyright holders. You   //
//   may not use this script on any web site with //
//   commercial or pornographic content. If you   //
//   wish to use this script on a commercial web  //
//   site you must obtain a registration number   //
//   (these are totally free) from the nPHP site. //
//   If you display banners this does not         //
//   necessarily mean you must obtain a           //
//   registration number.                         //
//                                                //
// Contact Information -------------------------- //
//   For support please only use the forums on    //
//   the web site and the official support email  //
//   address. Support emails to any of the nPHP   //
//   development team will be ignored.            //
//                                                //
//       nPHP Official Support                    //
//        email@example.com                        //
//                                                //
//                                   www.nphp.net //
////////////////////////////////////////////////////
*/

/*
// Functions -------------------------------------
//   NewsPHP relies on these functions to help it
//   perform tasks. Please DO NOT MODIFY THIS FILE
//   IN ANY WAY.
*/

$nphp_versions["nfunc"] = 200;               // The version number of the nFUNC file.

/*
// Load Settings --------------------------------
//   This functions loads in the settings from
//   the configuration file.
*/

  function LoadSettings(&$config, &$users)
  {
    global $nphp_files, $nphp_common;
    $raw_config = file($nphp_files["config"]);

    $id=0;

    for($i=1; $i < count($raw_config); $i++)
    {
      $raw_config_line = explode($nphp_common["confsep"],$raw_config[$i]);

    // If the line in the config file is a user,
    // then add it to the users array, otherwise
    // add it to the config array.

      if($raw_config_line[0] == "user")
      {
        for($x=1; $x < count($raw_config_line); $x++)
        {
          $users[$id][] = eregi_replace("[\n\r]","",$raw_config_line[$x]);
        }
        $id++;
      }
      else
      {
       if(isset($raw_config_line[1]))
       {
        $config[$raw_config_line[0]] = eregi_replace("[\r\n]","",$raw_config_line[1]);
       }
      }
    }

  }

/*
// ----------------------------------------------
*/

/*
// Check Level ----------------------------------
//   When given a username it returns their level.
*/

  function CheckLevel($username)
  {
	  global $nphp_users;

	  for($i = 0; $i < count($nphp_users); $i++)
	  {
		  if($nphp_users[$i][0] == $username)
		  {
			  return $nphp_users[$i][3];
		  }
	  }
  }

/*
// ----------------------------------------------
*/

/*
// Register Function ----------------------------
//   Registers a function and sets it to be
//   executed at a certain time.
*/

  function RegisterFunction($function_name, $function_exectime, $function_setting = "")
  {
    global $nphp_functions;

    $nphp_functions[][0]     = $function_name;
    $cnt = count($nphp_functions);
    $cnt--;

    $nphp_functions[$cnt][1] = $function_exectime;
    $nphp_functions[$cnt][2] = $function_setting;
  }

/*
// ----------------------------------------------
*/

/*
// Output the News ------------------------------
//   Loads in the news file and output the news.
*/

/*
<B><NewsSubject></B> at <NewsDate> by <A HREF="MAILTO:<NewsEmail>"><NewsUser></A><BR>
<NewsText>
<BR>
.
<BR><BR>
*/

  function OutputTheNews($newsdat)
  {
	  global $nphp_config, $nphp_files, $nphp_common, $nphp_notices, $nphp_functions,$nphp_currentuser;
	  $news_raw_data = file($newsdat);

/*
=================================
The following piece of code
caused much stress and death
during the creating of newsPHP.
=================================
*/
	  if($nphp_functions[$i][1] & NPHP_OUTPUTNEWS)
      {
		  $args = "";

		  for($c=0; $c < count($nphp_functions[$i][2]); $c++)
		  {
		   if($nphp_functions[$i][2][$c][0] == 1)
		   {
            eval('global $' . $nphp_functions[$i][2][$c][1] . ';');
		   }
			$args .= '$' . $nphp_functions[$i][2][$c][1];

			if($c < count($nphp_functions[$i][2])-1)
			{
				$args .= ", ";
		    }
		  }

		  eval($nphp_functions[$i][0] . '(' . $args . ');');
		  echo("<!-- Executing Function [" . $nphp_functions[$i][0] . "(" . $args . ")] -->\n");
	  }
/*
=================================
*/

	  if(strtolower($nphp_config["NewsLanguage"]) == "default")
	  {
		  include($nphp_files["dlang"]);
	  }
	  elseif(isset($nphp_config["NewsLanguage"]))
	  {
		  include($nphp_config["NewsLanguage"]);
	  }

	  if(!($news_output = fopen($nphp_files["output"],"w")))
	  {
		  echo($nphp_notices["Build_Unable2Open"]);
		  return;
	  }

	  if(!($archive_output = fopen($nphp_files["archive"],"w")))
	  {
		  echo($nphp_notices["Build_Unable2OpenArc"]);
		  return;
	  }

	  if($nphp_config["GenerateHeadlines"] == 1)
	  {
	  if(!($head_output = fopen($nphp_files["headline"],"w")))
	  {
		  echo($nphp_notices["Build_Unable2OpenHead"]);
		  return;
	  }
	  fputs($head_output, "\n\n<!-- Generated by newsPHP -->\n<!-- http://www.nphp.net/ -->\n\n");
	  }
	  fputs($news_output, "\n\n<!-- Generated by newsPHP -->\n<!-- http://www.nphp.net/ -->\n\n");
	  fputs($archive_output, "\n\n<!-- Generated by newsPHP -->\n<!-- http://www.nphp.net/ -->\n\n");

	  $lastday = -1;
	  $lastdaya = -1;

	  $min = count($news_raw_data) - $nphp_config["NewsLimitNumber"] - 1;
	  if($min < -1) { $min = -1; }

	  for($i=(count($news_raw_data)-1); $i > -1; $i--)
	  {
		  // 980880366<~>SheepCow<~>email@example.com<~>dfgdfgdfg<~>dfgdfgdfg<~>useglos<::>1
		  $data = eregi_replace("[\r\n]","",$news_raw_data[$i]);

		  $news_item_raw_data = explode($nphp_common["confsep"],$data);

		  if($i == (count($news_raw_data)-1))
		  {
			  $newest_post_sse = $news_item_raw_data[0];
		  }

		  if(count($news_item_raw_data) > 4)
		  {

		  if($nphp_config["ShowDateOnce"] == 1)
		  {
			  if($lastday == -1)
			  {
				  $date = MakeADate($nphp_config["DateFormat"], $news_item_raw_data[0]);
				  $news_date_head = eregi_replace("\[NL\]","",$nphp_config["FullDateFormat"]);
				  $news_date_head = eregi_replace("<newsdate>",$date,$news_date_head);
				  //fputs($news_output, $news_date_head . "\r\n");
			  }
			  elseif($lastday != MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]) && $lastday != -1)
			  {
				  $date = MakeADate($nphp_config["DateFormat"], $news_item_raw_data[0]);
				  $news_date_head = eregi_replace("\[NL\]","",$nphp_config["FullDateFormat"]);
				  $news_date_head = eregi_replace("<newsdate>",$date,$news_date_head);
				  //fputs($news_output, $news_date_head . "\r\n");
			  }

			  if($lastdaya == -1)
			  {
				  $date = MakeADate($nphp_config["DateFormat"], $news_item_raw_data[0]);
				  $news_date_head = eregi_replace("\[NL\]","",$nphp_config["FullDateFormat"]);
				  $news_date_head = eregi_replace("<newsdate>",$date,$news_date_head);
				  //fputs($archive_output, $news_date_head . "\r\n");
			  }
			  elseif($lastdaya != MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]) && $lastdaya != -1)
			  {
				  $date = MakeADate($nphp_config["DateFormat"], $news_item_raw_data[0]);
				  $news_date_head = eregi_replace("\[NL\]","",$nphp_config["FullDateFormat"]);
				  $news_date_head = eregi_replace("<newsdate>",$date,$news_date_head);
				  //fputs($archive_output, $news_date_head . "\r\n");
			  }

			  //$lastday = MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]);

	  		  $news_item_date = MakeADate($nphp_config["NewsDateFormat"], $news_item_raw_data[0]);
		  }
		  else
		  {
	  		  $news_item_date = MakeADate($nphp_config["DateFormat"], $news_item_raw_data[0]);
		  }

		  $news_item_id = "nPHP" . $news_item_raw_data[0];
		  $news_item_output = eregi_replace("\[NL\]","\n",$nphp_config["NewsFormat"]);
		  $news_item_subject = stripslashes($news_item_raw_data[3]);
		  $news_item_user = stripslashes($news_item_raw_data[1]);
		  $news_item_email = stripslashes($news_item_raw_data[2]);
		  $news_item_text = stripslashes($news_item_raw_data[4]);

		  if($nphp_config["AllowHTML"] != 1)
		  {
			  $news_item_subject = StripHTML($news_item_subject);
			  $news_item_user = StripHTML($news_item_user);
			  $news_item_email = StripHTML($news_item_email);
			  $news_item_text = StripHTML($news_item_text);
		  }

		  $news_item_text = eregi_replace("\[NL\]","<BR>",$news_item_text);

		  if($nphp_config["AutoLink"] == 1)
		  {
			  $news_item_text = AutoLink($news_item_text);
		  }

		  // Add in the news format
		  $news_item_output = eregi_replace("<newssubject>",$news_item_subject,$news_item_output);
		  $news_item_output = eregi_replace("<newsdate>",$news_item_date,$news_item_output);
		  $news_item_output = eregi_replace("<newsemail>",$news_item_email,$news_item_output);
		  $news_item_output = eregi_replace("<newsuser>",$news_item_user,$news_item_output);
		  $news_item_output = eregi_replace("<newstext>",$news_item_text,$news_item_output);
		  $news_item_output = eregi_replace("<newsid>",$news_item_id,$news_item_output);

		      for($x = 5; $x < count($news_item_raw_data); $x++)
			  {
				$extension_data = explode("<::>",$news_item_raw_data[$x]);
				$news_item_output = eregi_replace("<" . $extension_data[0] . ">",$extension_data[1],$news_item_output);
			  }

			  if($nphp_config["ArchiveType"] == 1)
			  {
				  if($i > $min)
				  {
					  // Post the news
					  if($lastday == -1 && ($nphp_config["ShowDateOnce"] == 1))
					  {
   					    $lastday = MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]);
						fputs($news_output, $news_date_head . "\r\n");
					  }
				      elseif($lastday != MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]) && $lastday != -1 && ($nphp_config["ShowDateOnce"] == 1))
					  {
   					    $lastday = MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]);
						fputs($news_output, $news_date_head . "\r\n");
					  }

					  fputs($news_output, $news_item_output . "\r\n");
				  }
				  else
				  {
					  // Archive it
					  if($lastdaya == -1 && ($nphp_config["ShowDateOnce"] == 1))
					  {
   					    $lastdaya = MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]);
						fputs($archive_output, $news_date_head . "\r\n");
					  }
				      elseif($lastdaya != MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]) && $lastdaya != -1 && ($nphp_config["ShowDateOnce"] == 1))
					  {
   					    $lastdaya = MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]);
						fputs($archive_output, $news_date_head . "\r\n");
					  }

					  fputs($archive_output, $news_item_output . "\r\n");
				  }
			  }
			  else
			  {
				  if($nphp_config["NewsLimitDateType"] == 1)
				  {
					  //$numsecs = $newest_post_sse - ($nphp_config["NewsLimitDate"] * 86400);
					  $numdays = $nphp_config["NewsLimitDate"];
				  }
				  elseif($nphp_config["NewsLimitDateType"] == 2)
				  {
					  //$numsecs = $newest_post_sse - (($nphp_config["NewsLimitDate"] * 7) * 86400);
					  $numdays = ($nphp_config["NewsLimitDate"] * 7);
				  }
				  elseif($nphp_config["NewsLimitDateType"] == 3)
				  {
					  //$numsecs = $newest_post_sse - (floor($nphp_config["NewsLimitDate"] * 365.25) * 86400); // Allows for leap years, sort of. :)
					  $numdays = floor($nphp_config["NewsLimitDate"] * 365.25); // Allows for leap years, sort of. :)
				  }

				  $latestday = date("z",time() + ($nphp_config["DateOffset"]) * 3600);
				  $currentday = date("z",$news_item_raw_data[0] + ($nphp_config["DateOffset"]) * 3600);
				  if(($latestday - $currentday) >= ($numdays)) // JUST REMOVED A -1 (03/02/01 12:08)
				  {
					  // Archive it
					  if($lastdaya == -1 && ($nphp_config["ShowDateOnce"] == 1))
					  {
   					    $lastdaya = MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]);
						fputs($archive_output, $news_date_head . "\r\n");
					  }
				      elseif($lastdaya != MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]) && $lastdaya != -1 && ($nphp_config["ShowDateOnce"] == 1))
					  {
   					    $lastdaya = MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]);
						fputs($archive_output, $news_date_head . "\r\n");
					  }

					  fputs($archive_output, $news_item_output . "\r\n");
				  }
				  else
				  {
					  // Post it
					  if($lastday == -1 && ($nphp_config["ShowDateOnce"] == 1))
					  {
   					    $lastday = MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]);
						fputs($news_output, $news_date_head . "\r\n");
					  }
				      elseif($lastday != MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]) && $lastday != -1 && ($nphp_config["ShowDateOnce"] == 1))
					  {
   					    $lastday = MakeADate("<DayOfMonth>.<MonthNumberA>.<Year4Digits>", $news_item_raw_data[0]);
						fputs($news_output, $news_date_head . "\r\n");
					  }

					  fputs($news_output, $news_item_output . "\r\n");
				  }
			  }

		  // Deal with the headlines
		  if($nphp_config["GenerateHeadlines"] == 1)
		  {
			  if($i > (count($news_raw_data) - $nphp_config["HeadLimitNumber"])-1)
			  {
				  // Do the headline
				  $head_item_output = stripslashes($nphp_config["HeadFormat"]);
				  $head_item_date = MakeADate($nphp_config["HeadlineDateFormat"], $news_item_raw_data[0]);
				  $head_item_output = eregi_replace("<newssubject>",$news_item_subject,$head_item_output);
				  $head_item_output = eregi_replace("<newsdate>",$head_item_date,$head_item_output);
				  $head_item_output = eregi_replace("<newsemail>",$news_item_email,$head_item_output);
				  $head_item_output = eregi_replace("<newsuser>",$news_item_user,$head_item_output);
				  $head_item_output = eregi_replace("<newstext>",$news_item_text,$head_item_output);
				  $head_item_output = eregi_replace("<newsid>",$news_item_id,$head_item_output);

				  fputs($head_output, $head_item_output . "\r\n");
			  }
		  }

		  }
	  }

	  fclose($news_output);
	  fclose($archive_output);

	  if($nphp_config["GenerateHeadlines"] == 1)
	  {
        fclose($head_output);
	  }

	  if(strtolower($nphp_currentuser[4]) == "default")
	  {
		  include($nphp_files["dlang"]);
	  }
	  else
	  {
		  include($nphp_currentuser[4]);
	  }

	  echo($nphp_notices["Build_Complete"]);
  }

/*
// ----------------------------------------------
*/

/*
// Save News Database ---------------------------
//   Saves the news database file.
*/

 function SaveNewsDatabase($data)
 {
	 global $nphp_files, $nphp_common;

	 if(!($dbfile = fopen($nphp_files["newdat"],"w")))
	 {
		 echo($nphp_notices["Build_Unable2Open"]);
		 exit();
	 }

	 for($i=0; $i < count($data); $i++)
	 {
		 if($data[$i] != "")
		 {
			 fputs($dbfile,eregi_replace("[\n\r]","",$data[$i]) . "\n");
		 }
	 }
 }

/*
// ----------------------------------------------
*/

/*
// Sends Emails ---------------------------------
//   Emails the mailing list.
*/

  function SendEmail($mail_file,$data)
  {
	  global $nphp_common, $nphp_config;
	  $mail_list = file($mail_file);

	  $output = eregi_replace("\[NL\]","\n",$nphp_config["EmailFormat"]);

	  $newstext = StripHTML($data[4]); // HTML is not sent in emails
	  $subject = StripHTML($data[3]);
	  $poster = $data[1];
	  $poster_email = $data[2];
	  $date = MakeADate($nphp_config["EmailDateFormat"],$data[0]);

	  $output = eregi_replace("<NewsText>", $newstext, $output);
	  $output = eregi_replace("<NewsEmail>", $poster_email, $output);
	  $output = eregi_replace("<NewsUser>", $poster, $output);
	  $output = eregi_replace("<NewsSubject>", $subject, $output);
	  $output = eregi_replace("<NewsDate>", $date, $output);
	  $output = eregi_replace("\[NL\]","\n",$output);

      for($x = 5; $x < count($news_item_raw_data); $x++)
	  {
		$extension_data = explode("<::>",$data[$x]);
		$output = eregi_replace("<" . $extension_data[0] . ">",$extension_data[1],$output);
	  }

	  for($x = 0; $x < count($mail_list); $x++)
	  {
		  $mail_list[$x] = eregi_replace("[\n\r]","",$mail_list[$x]);
	  }

	  $maillist = implode(", ",$mail_list);
	  mail($nphp_config["EmailReplyAddress"],"News Update From " . $nphp_config["SiteName"], $output, "Reply-To: " . $nphp_config["SiteName"] . " News <" . $nphp_config["EmailReplyAddress"] . ">\nFrom: " . $nphp_config["SiteName"] . " News <" . $nphp_config["EmailReplyAddress"] . ">\nBCC: " . $maillist . "\n");
  }

/*
// ----------------------------------------------
*/

/*
// Auto Linking Code ----------------------------
//   Automatically links URLS and email addresses
*/

  function AutoLink($input)
  {
	  // Written by Kit O'Neill
	  $output = eregi_replace("(http|https|ftp)://([a-z0-9\-\./]+)","<a href=\"\\0\" target=\"_blank\">\\0</a>",$input);
	  $output = eregi_replace("(([a-z0-9\-\.]+)@([a-z0-9\-\.]+)\.([a-z0-9]+))","<a href=\"mailto:\\0\">\\0</a>",$output);
	  return $output;
  }

/*
// ----------------------------------------------
*/

/*
// Strip HTML -----------------------------------
//   Really strips all HTML code from a string
*/

  function StripHTML($input)
  {
	  // NOT AN ARRAY INPUT!!
	  $start = -1;
      $z = 0;
	  $output = "";

	  while($z < strlen($input))
	  {
		  if($input[$z] == "<")
		  {
			  $start = $z;
			  $input[$z] = "";
		  }
		  elseif($input[$z] == ">" && $start != -1)
		  {
			  $start = -1;
			  $input[$z] = "";
		  }
		  elseif($start != -1)
		  {
			  $input[$z] = "";
		  }
		  else
		  {
			  $output .= $input[$z];
		  }
		  $z++;
	  }

	  return $output;
  }

/*
// ----------------------------------------------
*/

/*
// Add News Item --------------------------------
//   Adds a news item into the database.
*/

  function AddNewsItem($data)
  {
	  global $nphp_common, $nphp_files, $nphp_config;

// Praise be to Dez for reminding me of this function!
	  $output = implode($data,$nphp_common["confsep"]);

	  $fp = fopen($nphp_files["newdat"], "a");
	  fputs($fp, eregi_replace("[\n\r]","",$output) . "\n");



	  fclose($fp);
	  return true;
  }

/*
// ----------------------------------------------
*/

/*
// Save Settings --------------------------------
//   This functions saves the settings to the
//   configuration file.
*/

  function SaveSettings($config, $users)
  {
   global $nphp_files, $nphp_notices, $nphp_common;

   if($settings_file = fopen($nphp_files["config"],"w"))
   {
    fputs($settings_file, "<?php die(\"You may not access this file.\"); ?>\n");
    for(reset($config); $key = key($config); next($config))
    {
     if($key != "")
     {
      $value = eregi_replace("\n","[NL]",$config[$key]);
      fputs($settings_file,$key . $nphp_common["confsep"] . stripslashes($value) . "\n");
     }
    }

    for($s=0; $s < count($users); $s++)
    {
     if($users[$s][0] != "")
     {
      $user_output = "user<~>";
      for($d=0; $d < count($users[$s]); $d++)
      {
        $user_output .= $users[$s][$d];

        if($d < count($users[$s]) - 1)
        {
         $user_output .= $nphp_common["confsep"];
        }
       }

      fputs($settings_file, stripslashes($user_output) . "\n");
      }
     }

     fclose($settings_file);
   }
   else
   {
     die($nphp_notices["UnableToOpenConfig"]);
   }
  }

/*
// ----------------------------------------------
*/

/*
// Create Extension -----------------------------
//   This creates a new extension. Most extensions
//   will run this function.
*/

  function CreateExtension($extName, $extShowName, $extDescription, $extMinLvl, $extShowTool, $extShowMain, $extQLine)
  {
    global $nphp_extensions;

    $nphp_extensions[][0]     = $extName;
    $cnt = count($nphp_extensions);
    $cnt--;

    $nphp_extensions[$cnt][1] = $extShowName;

    $nphp_extensions[$cnt][2] = $extDescription;
    $nphp_extensions[$cnt][3] = $extMinLvl;
    $nphp_extensions[$cnt][4] = $extShowTool;
    $nphp_extensions[$cnt][5] = $extShowMain;
    $nphp_extensions[$cnt][6] = $extQLine;
  }

/*
// ----------------------------------------------
*/

/*
// Create Setting -------------------------------
//   Adds a settings under Extensions Settings
//   on the settings page.
*/

  function CreateSetting($setName, $setSettingName, $setDescription, $setDefault)
  {
    global $nphp_settings;

    $nphp_settings[]["DisplayName"]     = $setName;
    $cnt = count($nphp_settings);
    $cnt--;

    $nphp_settings[$cnt]["SettingName"] = $setSettingName;
    $nphp_settings[$cnt]["Description"] = $setDescription;
    $nphp_settings[$cnt]["DefaultValue"] = $setDefault;
  }

/*
// ----------------------------------------------
*/

/*
// Create Submit Field --------------------------
//   This creates a new extension. Most extensions
//   will run this function.
*/

  function CreateSubmitField($fldName, $fldShowName, $fldType, $fldValues, $fldDefaultValue)
  {

  //
  // Differenet Types
  //  1 = Text Box
  //  2 = Text Area
  //  3 = Select Box
  //  4 = Radio
  //  5 = Check Box
  //  6 = File
  //

    global $nphp_submitfields;

    $nphp_submitfields[]["Name"]     = $fldName;
    $cnt = count($nphp_submitfields);
    $cnt--;

    $nphp_submitfields[$cnt]["ShowName"] = $fldShowName;
    $nphp_submitfields[$cnt]["DefaultValue"] = $fldDefaultValue;

    if($fldType == 1)
    {
      $nphp_submitfields[$cnt]["Type"]   = 1;
      $nphp_submitfields[$cnt]["Values"] = "";
    }
    elseif($fldType == 2)
    {
      $nphp_submitfields[$cnt]["Type"]   = 2;
      $nphp_submitfields[$cnt]["Values"] = "";
    }
    elseif($fldType == 3)
    {
      $nphp_submitfields[$cnt]["Type"]   = 3;
      $nphp_submitfields[$cnt]["Values"] = "";

      for($i=0; $i < count($fldValues); $i++)
      {
        $nphp_submitfields[$cnt]["Values"][] = array("Value"=>$fldValues[$i][0],"Text"=>$fldValues[$i][1]);
      }

    }
    elseif($fldType == 4)
    {
      $nphp_submitfields[$cnt]["Type"]   = 4;
      $nphp_submitfields[$cnt]["Values"] = "";

      for($i=0; $i < count($fldValues); $i++)
      {
        $nphp_submitfields[$cnt]["Values"][] = array("Value"=>$fldValues[$i][0],"Text"=>$fldValues[$i][1]);
      }

    }
    elseif($fldType == 5)
    {
      $nphp_submitfields[$cnt]["Type"]   = 5;
      $nphp_submitfields[$cnt]["Values"] = $fldValues;
    }
    elseif($fldType == 6)
    {
      $nphp_submitfields[$cnt]["Type"]   = 6;
      $nphp_submitfields[$cnt]["Values"] = "";
    }
    else
    {
      $nphp_submitfields[$cnt]["Type"]   = 1;
      $nphp_submitfields[$cnt]["Values"] = "";
    }
  }

/*
// ----------------------------------------------
*/

/*
// Get The Date ---------------------------------
//   Gets the date right now and puts it into
//   the correct format.
*/

  function GetTheDate($formatname)
  {
    global $nphp_config,$nphp_notices;

	if(isset($nphp_config[$formatname]))
	{
	  $date = $nphp_config[$formatname];

	  if(isset($nphp_config["DateOffset"]))
	  {
		  $offset = date("U") + ($nphp_config["DateOffset"] * 3600);
	  }
	  else
	  {
		  $offset = date("U");
	  }


      $date = eregi_replace("<DOW3CharText>",$nphp_notices["DATE_DayOfWeek3CharText_" . date("w",$offset)],$date);
      $date = eregi_replace("<DOWNumbers>",date("w",$offset),$date);
      $date = eregi_replace("<DOWText>",$nphp_notices["DATE_DayOfWeekText_" . date("w",$offset)],$date);

      $date = ereg_replace("<AMPM>",date("a",$offset),$date);
      $date = ereg_replace("<ampm>",date("A",$offset),$date);
      $date = eregi_replace("<Hour12a>",date("h",$offset),$date);
      $date = eregi_replace("<Hour24a>",date("H",$offset),$date);
      $date = eregi_replace("<Hour12b>",date("g",$offset),$date);
      $date = eregi_replace("<Hour24b>",date("G",$offset),$date);
      $date = eregi_replace("<Minutes>",date("i",$offset),$date);
      $date = eregi_replace("<Seconds>",date("s",$offset),$date);

      $date = eregi_replace("<Year2Digits>",date("y",$offset),$date);
      $date = eregi_replace("<Year4Digits>",date("Y",$offset),$date);
      $date = eregi_replace("<DayOfYear>",date("z",$offset),$date);

      $date = eregi_replace("<DOM2Digits>",date("d",$offset),$date);
      $date = eregi_replace("<DayOfMonth>",date("j",$offset),$date);
      $date = eregi_replace("<MonthNumberA>",date("m",$offset),$date);
      $date = eregi_replace("<MonthNumberB>",date("n",$offset),$date);
      $date = eregi_replace("<3LetterMonth>",$nphp_notices["DATE_3Month_" . date("n",$offset)],$date);
      $date = eregi_replace("<Month>",$nphp_notices["DATE_Month_" . date("n",$offset)],$date);
      $date = eregi_replace("<MonthLength>",date("t",$offset),$date);

      $date = eregi_replace("<SSE>",date("U",$offset),$date);
      $date = eregi_replace("<OrdinalPrefix>",date("S",$offset),$date);

	  return $date;
    }
    else
    {
      return $nphp_notices["DateNotSet"];
	}
  }


/*
// ----------------------------------------------
*/

/*
// Make a Date ----------------------------------
//   Makes a date.
*/

  function MakeADate($date, $sse)
  {
    global $nphp_config,$nphp_notices;

	  if(isset($nphp_config["DateOffset"]))
	  {
		  $offset = $sse + ($nphp_config["DateOffset"] * 3600);
	  }
	  else
	  {
		  $offset = $sse;
	  }


      $date = eregi_replace("<DOW3CharText>",$nphp_notices["DATE_DayOfWeek3CharText_" . date("w",$offset)],$date);
      $date = eregi_replace("<DOWNumbers>",date("w",$offset),$date);
      $date = eregi_replace("<DOWText>",$nphp_notices["DATE_DayOfWeekText_" . date("w",$offset)],$date);

      $date = ereg_replace("<AMPM>",date("a",$offset),$date);
      $date = ereg_replace("<ampm>",date("A",$offset),$date);
      $date = eregi_replace("<Hour12a>",date("h",$offset),$date);
      $date = eregi_replace("<Hour24a>",date("H",$offset),$date);
      $date = eregi_replace("<Hour12b>",date("g",$offset),$date);
      $date = eregi_replace("<Hour24b>",date("G",$offset),$date);
      $date = eregi_replace("<Minutes>",date("i",$offset),$date);
      $date = eregi_replace("<Seconds>",date("s",$offset),$date);

      $date = eregi_replace("<Year2Digits>",date("y",$offset),$date);
      $date = eregi_replace("<Year4Digits>",date("Y",$offset),$date);
      $date = eregi_replace("<DayOfYear>",date("z",$offset),$date);

      $date = eregi_replace("<DOM2Digits>",date("d",$offset),$date);
      $date = eregi_replace("<DayOfMonth>",date("j",$offset),$date);
      $date = eregi_replace("<MonthNumberA>",date("m",$offset),$date);
      $date = eregi_replace("<MonthNumberB>",date("n",$offset),$date);
      $date = eregi_replace("<3LetterMonth>",$nphp_notices["DATE_3Month_" . date("n",$offset)],$date);
      $date = eregi_replace("<Month>",$nphp_notices["DATE_Month_" . date("n",$offset)],$date);
      $date = eregi_replace("<MonthLength>",date("t",$offset),$date);

      $date = eregi_replace("<SSE>",date("U",$offset),$date);
      $date = eregi_replace("<OrdinalPrefix>",date("S",$offset),$date);

	  return $date;
    }


/*
// ----------------------------------------------
*/

?>
