Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules
Author Message
ironhorse
New Member
New Member


Joined: Oct 26, 2005
Posts: 23

PostPosted: Fri Aug 08, 2008 7:12 am Reply with quote

Hello all,

I am having a small bit of trouble getting WoW Application and Recruitment v2 working. I have installed it ok and it configures and everything, the only issue I have is when someone tries to submit an application it goes to the next page and doesn't show the confirmation page and doesn't post the information on the forums.

You can get to the site its having trouble on Only registered users can see links on this board! Get registered or login!

Not sure whats going on, I will post the code for it (not sure which you need).

confirmation.php
Code:
<?php

/*
==========================================
 PHP-NUKE: Guild Application module
Version 2.2.1
==========================================
 Copyright (c) 2007
  by Nathan Burke
  based on work by:
    Arioch - http://www.black-blades.org

 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
 
==========================================
*/


$module_name = basename(dirname(__FILE__));
define('NO_EDITOR', TRUE);  //Supress WYSIWYG editor - comment out if not applicable

include("header.php");
require_once("variables.php");

OpenTable();
initialize($Variables, $KeyData, $TextBoxData);
gimmeCharData($CharData, $Variables['numalts']['value']);
gimmeData($UserData, "userinfo");

if(!$_POST)  //if there's no post data, there's nothing we can do so return to form
{
   include("request_form.php");
   requestform();
   CloseTable();
   include("footer.php");
   exit;
}

//We can rebuild him, we have the technoligy
//Turn the postdata into a properly formatted array
$tempArray1 = array_values($_POST);
$tempArray2 = array_keys($_POST);
for($i = 0; $i < count($_POST); $i++)
{
   $field = explode("_", $tempArray2[$i]);
   $PostData[$i] = array('name' => $field[0], $field[1] => $tempArray1[$i]);
}

foreach($PostData as $key => $row)
{
   switch(strtoupper($row['name'][0]))
   {
      case 'M':
         fillCharArray($PostData[$key]['name'], 0, $row['text'], $CharData);
         break;
      case 'A':
         fillCharArray($PostData[$key]['name'], $row['name'][3] + 1, $row['text'], $CharData);
         break;
      case 'U':
         fillArray($PostData[$key]['name'], $row['text'], $UserData);
         break;
      case 'K':
         fillKeyArray($PostData[$key]['name'], $row['text'], $KeyData);
         break;
      case 'T':
         fillArray($PostData[$key]['name'], $row['text'], $TextBoxData);
   }
}

// Are all required fields entered?
$missing = 0;

//character fields
$i = 0;
foreach($CharData as $index => $Char)
{
   foreach($Char as $key => $field)
   {
      if($field['name'] == "resist") continue;
      if($field['name'] == "name" && $field['text'] != "")
         $i = 2;
      if($field['text'] == "" && $field['required'] == 1 && $field['name'] != "" && ($i == 0 || $i == 2))
      {
         $CharData[$index][$key]['missing'] = 1;
         $missing++;
      }
   }
   if($Char['build']['required'] == 1 && ($i == 0 || $i == 2))
   {
      if($Char['build']['text'] == "")
      {
         $CharData[$index]['build']['missing'] = 1;
         $missing++;
      }
      if($Char['build0']['text'] == "")
      {
         $CharData[$index]['build0']['missing'] = 1;
         $missing++;
      }
      if($Char['build1']['text'] == "")
      {
         $CharData[$index]['build1']['missing'] = 1;
         $missing++;
      }
      if($Char['build2']['text'] == "")
      {
         $CharData[$index]['build2']['missing'] = 1;
         $missing++;
      }
   }
   if($Char['resist']['required'] == 1 && ($i == 0 || $i == 2))
      foreach($Char['resistances'] as $key => $resist)
         if($resist['text'] == "")
         {
            $CharData[$index]['resistances'][$key]['missing'] = 1;
            $missing++;
         }
   $i = 1;
}

//TextBoxes
foreach($TextBoxData as $key => $text)
{
   if($text['required'] == 1 && $text['text'] == "")
   {
      $TextBoxData[$key]['missing'] = 1;
      $missing++;
   }
}

//Keys
foreach($KeyData as $key0 => $type)
   foreach($type['keys'] as $key1 => $gamekey)
   {
      if($gamekey['required'] == 1 && $KeyData[$key0]['keys'][$key1]['text'] == "")
      {
         $KeyData[$key0]['keys'][$key1]['missing'] = 1;
         $missing++;
      }
   }

//User info
foreach($UserData as $key => $user)
   if($user['required'] == 1 && $user['text'] == "")
   {
      $UserData[$key]['missing'] = 1;
      $missing++;
   }

/*
//Refferals
if($Variables['referral']['required'] == 1 && $Variables['referral']['text'] == "")
{
   $Variables['referral']['missing'] = true;
   $missing++;
}
*/
// If something is missing (or several things are missing) reload form
if ($missing > 0)
{
   echo "<font color=\"#FF0000\"><center><h1><strong>Please fill in the missing";
   if ($missing == 1)
      echo " field";
   else
      echo " fields";
   echo " and re-submit</strong></center></h1></font>";
   include("request_form.php");
   requestform($UserData, $CharData, $KeyData, $TextBoxData, $Variables, true);
   CloseTable();
   include("footer.php");
   exit;
}

// Check the email address for validity
include("validateEmailFormat.php");  //This is the file that actually does the checking
$isValid = validateEmailFormat($UserData['email']['text']); //Make the call to the function loaded from the other file
if(!$isValid && $UserData['email']['required'] == 1)
{
  echo "<center><font color=\"#FF0000\"><strong>Your Email Address does not appear to be in the correct format!<br>
     Please check and resubmit form</strong></font></center><br><br>";
  include("request_form.php");
  requestform($UserData, $CharData, $KeyData, $TextBoxData, $Variables, true);
  CloseTable();
  include("footer.php");
  exit;
}
// Address format is valid or email not required, continue...

//Transform selection numbers into text
foreach($CharData as $key => $char)
{
   transClass($CharData[$key]['class']['text']);
   transProf($CharData[$key]['prof1']['text']);
   transProf($CharData[$key]['prof2']['text']);
}
transUser($UserData);

//start building the message string
//Escape special chars (prevents SQL injection, and SQL failures)
foreach($TextBoxData as $key => $value) //TextBoxes
   $TextBoxData[$key]['value'] = mysql_real_escape_string($value['value']);
foreach($KeyData as $key0 => $type) //Keys
{
   foreach($type['keys'] as $key1 => $gamekey)
         $KeyData[$key0]['keys'][$key1]['value'] = mysql_real_escape_string($gamekey['value']);
   $KeyData[$key0]['type']['value'] = mysql_real_escape_string($type['type']['value']);
}      
foreach($UserData as $key => $user) //User info
      $UserData[$key]['value'] = mysql_real_escape_string($user['value']);
foreach($CharData as $char => $chararray) //Character info
   foreach($chararray as $name => $vararray)
      if($name != "resistances")
         $CharData[$char][$name]['value'] = mysql_real_escape_string($vararray['value']);
      else
         foreach($vararray as $resistname => $resistvalue)
            $CharData[$char][$name][$resistname]['value'] = mysql_real_escape_string($resistvalue['value']);

/*
Array (
   [username] => Array ( [name] => username [value] => Your Name [show] => 1 [required] => 1 [text] => Bob Dole )
   [useremail] => Array ( [name] => useremail [value] => E-Mail [show] => 1 [required] => 1 [text] => Only registered users can see links on this board! Get registered or login! )
   [userage] => Array ( [name] => userage [value] => Age [show] => 1 [required] => 0 [text] => )
   [usertime] => Array ( [name] => usertime [value] => Timezone [show] => 1 [required] => 0 [text] => )
   [userplay] => Array ( [name] => userplay [value] => Play Style [show] => 1 [required] => 0 [text] => )
   )
*/

if($UserData['username']['text'] != "")
   $msg = "{$UserData['username']['text']} has submitted an application <br />";
else
   $msg = "A visitor to the {$Variables['guildname']['value']} website has submitted a guild application <br />";

$first = 1;
foreach($UserData as $row)
   if($row['text'] != "")
   {
      if($first == 1)
      {
         showDivider("Personal Information", $msg);
         $first = 0;
      }
      $msg .= "- " . $row['value'] . ": <strong>" . $row['text'] . "</strong><br />";
   }
/*
showDivider("Personal Information", $msg);
if($UserData['username']['text'] != "")
   $msg .= "- Applicants Name: {$UserData['username']['text']} <br />";
if($UserData['useremail']['text'] != "")
   $msg .= "- Email Address: {$UserData['useremail']['text']} <br />";
if($UserData['usertime']['text'] != "")
   $msg .= "- Time Zone: {$UserData['usertime']['text']} <br />";
if($UserData['userage']['text'] != "")
   $msg .= "- Age: {$UserData['userage']['text']} <br />";
if($UserData['userplay']['text'] != "")
   $msg .= "- Play Style(1-casual, 10-hardcore): {$UserData['userplay']['text']} <br />";
*/

//showDivider("Main Character Information", $msg);
showCharInfo($CharData[0], $msg, "Main Character Information");
$first = 1;
foreach($CharData as $Char)
{
   if($first == 1)
   {
      $first = 0;
      continue;
   }
   if($Char['name']['text'] != "")
   {
//      if($first == 1)
//         showDivider("Alt Character(s) Information", $msg);
      showCharInfo($Char, $msg, "Alt Character(s) Information");
   }
}

$first = 2;
foreach($KeyData as $type)
{
   foreach($type['keys'] as $key)
   {
      if($key['text'] == "on")
      {
         if($first == 2)
         {
            showDivider("Keys/Attunements", $msg);
            $first = 1;
         }
         if($first == 1)
         {
            $msg .= "- <i>{$type['type']['value']}</i><br />";
            $first = 0;
         }
         $msg .= "    <strong>{$key['value']}</strong><br />";
      }
   }
   $msg .= "<br />";
   if($first == 0) $first = 1;
}
/*
//References
if($Variables['referral']['text'] != "")
{
   $msg .= "------------------------------------------------------------ <br />";
   $msg .= "-                Has the following references <br />";
   $msg .= "------------------------------------------------------------ <br />";
   $msg .= "- {$Variables['referral']['text']} <br />";
}
*/
$first = 1;
foreach($TextBoxData as $text)
{
   if($text['text'] != "")
   {
      if($first == 1)
      {
         showDivider("Has the following additional information to share", $msg);
         $first = 0;
      }
      $lineText = filter_text($text['value'], "nohtml");
      $msg .= "- In Response to: <br />";
      $msg .= "    <i>".filter_text($text['value'], "nohtml")."</i><br />";
      $msg .= " - They said : <br />";
      $msg .= "     <strong>".filter_text($text['text'], "nohtml")."</strong><br />";
      $msg .= "<br />";
   }
}

$postto = explode("_", $Variables['postto']['value']);
$success0 = true;
$success1 = true;
if($postto[0] == "email" || count($postto) == 3)
{
   //add From: header
   $mailheaders = "From: {$Variables['guildname']['value']} Application Processing <{$Variables['recipient']['value']}>\r\n";
   //specify MIME version 1.0
   $mailheaders .= "MIME-Version: 1.0\r\n";
   //unique boundary
   $boundary = uniqid("HTMLAPP");
   //tell e-mail client this e-mail contains alternate versions
   $mailheaders .= "Content-Type: multipart/alternative; boundary = $boundary\r\n\r\n";
   //message to people with clients who don't
   //understand MIME
   $mailheaders .= "This is a MIME encoded message.\r\n\r\n";
   //plain text version of message
   $mailheaders .= "--$boundary\r\nContent-Type: text/plain; charset=ISO-8859-1\r\nContent-Transfer-Encoding: base64\r\n\r\n";
   $mailheaders .= chunk_split(base64_encode(filter_text(str_replace("<br />", "\n", stripslashes($msg)), "nohtml")));
   //HTML version of message
   $mailheaders .= "--$boundary\r\nContent-Type: text/html; charset=ISO-8859-1\r\nContent-Transfer-Encoding: base64\r\n\r\n";
   $mailheaders .= chunk_split(base64_encode(stripslashes($msg)));
   //send message
   $subject = "{$Variables['guildname']['value']} Application";
   //Send the mail
   if ($UserData['name']['text'] == $Variables['testname']['value'])
      $success0 = mail($Variables['testrecipient']['value'], $subject, "", $mailheaders);
   else
      $success0 = mail($Variables['recipient']['value'], $subject, "", $mailheaders);
}
if($postto[0] == "forum")
{
   if($CharData[0]['name']['text'] != "" && $CharData[0]['class']['text'] != "")
      $subject = "Applicant: {$CharData[0]['name']['text']} - {$CharData[0]['class']['text']}";
   else
      $subject = "New Application to {$Variables['guildname']['value']}";
   $success1 = submit_post($postto[1], $subject, $msg, $Variables['postfrom']['value'], $Variables['postpoll']['show']);
}

//If we made it this far, everything should be ok to send.
if($success0 == true && $success1 == true)
   echo "<p><center><img src=\"../images/blocks/Recruitment/happy.gif\" alt=\"Thank You!\" border=\"0\"><br><br>
       <strong>Thank you for submitting your request.</strong><br>
       Your application has been submitted and we will be contacting you shortly.
       </center></p>";
else
   echo "<p><center><img src=\"../images/blocks/Recruitment/stop.gif\" alt=\"Stop!\" border=\"0\"><br><br>
       <strong>There was an error while submitting your application.</strong><br>
       </center></p>";

CloseTable();
include("footer.php");

function fillCharArray($valueType, $arrayIndex, $value, &$array)
{
   switch(strtoupper($valueType[4]))
   {
      case 'R':
         $array[$arrayIndex]['resistances'][substr($valueType, 10, strlen($valueType) - 4)]['text'] = $value;
         break;
      default:
         $array[$arrayIndex][substr($valueType, 4, strlen($valueType) - 4)]['text'] = $value;
         break;
   }
}

function fillArray($valueType, $value, &$array)
{
   $array[$valueType]['text'] = $value;
}

function fillKeyArray($keyName, $value, &$array)
{
   $keys = 0;
   $index = 0;
   $keyNum = substr($keyName, 3, strlen($keyName) - 3);
   foreach($array as $type)
   {
      $keys += count($type['keys']);
      if($keys >= (int)$keyNum)
      {
         $keys = 0;
         foreach($type['keys'] as $key)
            if($key['name'] == $keyName)
               break;
            else
               $keys++;
         break;
      }
      else
         $index++;
   }
   $array[$index]['keys'][$keys]['text'] = $value;
}

function transUser(&$array)
{
   if($array['userage']['text'] != "")
   {
      switch($array['userage']['text'])
      {
         case 1:   $array['userage']['text'] = "Under 16";   break;
         case 2:   $array['userage']['text'] = "16-20";   break;
         case 3:   $array['userage']['text'] = "21-30";   break;
         case 4:   $array['userage']['text'] = "Over 30";   break;
         default: $array['userage']['text'] = "Unknown"; break;
      }
   }
   if($array['usertime']['text'] != "")
   {
      switch($array['usertime']['text'])
      {
         case 1: $array['usertime']['text'] = "Eastern"; break;
         case 2: $array['usertime']['text'] = "Central"; break;
         case 3: $array['usertime']['text'] = "Mountian"; break;
         case 4: $array['usertime']['text'] = "Pacific"; break;
         case 5: $array['usertime']['text'] = "Other"; break;
         default: $array['usertime']['text'] = "Unknown"; break;
      }
   }
}

//Prepare strings from selection boxes
function transClass(&$ClassNum)
{
   if($ClassNum != "")
   {
      switch($ClassNum)
      {
         case 1:   $ClassNum = "Warrior";   break;
         case 2:   $ClassNum = "Hunter";   break;
         case 3:   $ClassNum = "Rogue";   break;
         case 4:   $ClassNum = "Priest";   break;
         case 5:   $ClassNum = "Shaman";   break;
         case 6:   $ClassNum = "Druid";   break;
         case 7:   $ClassNum = "Mage";   break;
         case 8:   $ClassNum = "Warlock";   break;
         case 9:   $ClassNum = "Paladin";   break;
         default:   $ClassNum = "Unknown"; break;
      }
   }
}

function transProf(&$value)
{
   if($value != "")
   {
      switch($value)
      {
         case 1: $value = "Alchemy"; break;
         case 2: $value = "Blacksmithing"; break;
         case 3: $value = "Enchanting"; break;
         case 4: $value = "Engineering"; break;
         case 5: $value = "Herbalism"; break;
         case 6: $value = "Leatherworking"; break;
         case 7: $value = "Mining"; break;
         case 8: $value = "Skinning"; break;
         case 9: $value = "Tailoring"; break;
         case 10: $value = "Jewel Crafting"; break;
      }
   }
}

function showDivider($title, &$text)
{
   $text .= "<hr><center><h3>$title</h3></center><hr>";
}

/*
function showDivider($title, &$text)
{
   $maxlength = 100;
   $length = (($maxlength - strlen($title)) / 2) - 1;
   $text .= "\n";
   for($i = 0; $i < $maxlength; $i++)
      $text .= "-";
   $text .="\n";
   $text .= "-";
   for($i = 0; $i < $length; $i++)
      $text .= " ";
   $text .= "$title \n";
   for($i = 0; $i < $maxlength; $i++)
      $text .= "-";
   $text .="\n";
}
*/

function showCharInfo($array, &$text, $title)
{
   $first = 1;
   foreach($array as $field)
      if($field['name'] != "" && $field['text'] != "")
         if($field['name'] != "gear")
         {
            if($first == 1)
            {
               showDivider($title, $text);
               $first = 0;
            }
            $text .= "- {$field['value']}: <strong>{$field['text']}</strong> <br />";
         }
   if($array['gear']['text'] != "")
   {
      if($first == 1)
      {
         showDivider($title, $text);
         $first = 0;
      }
      global $db;
      $sql = "select * from recruitment_config where type='geardata'";
      $result = $db->sql_query($sql);
      while($row = $db->sql_fetchrow($result))
         $gearData[$row['name']] = array('name' => $row['name'], 'value' => $row['value'], 'show' => $row['show'], 'required' => $row['required']);
      if($gearData['geartype']['value'] == "link")
         $text .= "- {$gearData['geartitle']['value']} link: <strong>{$array['gear']['text']}</strong><br />";
      else
         $text .= "- Has the following gear:<br /><strong>{$array['gear']['text']}</strong><br />";
   }
   if($array['build']['text'] != "")
   {
      if($first == 1)
      {
         showDivider($title, $text);
         $first = 0;
      }
      $text .= "- Has the following Talent build: <br />";
      $text .= "   Name: <strong>{$array['build']['text']}</strong><br />";
      $text .= "   Point Distribution: <strong>{$array['build0']['text']}</strong> / <strong>{$array['build1']['text']}</strong> / <strong>{$array['build2']['text']}</strong><br />";
   }
   $firstResist = 1;
   foreach($array['resistances'] as $resist)
      if($resist['text'] != "")
      {
         if($first == 1)
         {
            showDivider($title, $text);
            $first = 0;
         }
         if($firstResist == 1)
         {
            $text .= "- Has the following resistances: <br />";
            $firstResist = 0;
         }
         $text .= "    {$resist['value']}: <strong>{$resist['text']}</strong><br />";
      }
}

/***************************************************************************
 *                            functions_post.php
 *                            -------------------
 *   begin                : Saturday, Feb 13, 2001
 *   copyright            : (C) 2001 The phpBB Group
 *   email                : Only registered users can see links on this board! Get registered or login!
 *
 *   $Id: functions_post.php,v 1.9.2.52 2006/05/06 13:38:55 grahamje Exp $
 *
 *
 ***************************************************************************
*    Gutted and specialized by Nathan Burke to work with the application module
/***************************************************************************
 *
 *   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, or
 *   (at your option) any later version.
 *
 ***************************************************************************/
//
// Post a new topic/reply/poll or edit existing post/poll
//
function submit_post($forum_id, $post_subject, $post_message, $user_id = 1, $addPoll = 0, $pollLength = 7)
{
   global $prefix, $db;
   $current_time = time();
   $success = true;
   $sql = "INSERT INTO " . $prefix . "_bbtopics (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote) VALUES ('$post_subject', $user_id, $current_time, $forum_id, 0, 0, $addPoll)";
   if (!$db->sql_query($sql))
   {
      $sql = "INSERT INTO " . $prefix . "_bbtopics (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote) VALUES ('".mysql_real_escape_string($post_subject)."', $user_id, $current_time, $forum_id, 0, 0, $addPoll)";
      if (!$db->sql_query($sql))
      {
         echo "Error 1 while submitting application, your application has not been submitted<br />Please inform the webmaster.";
         $success = false;
      }
   }
   $topic_id = $db->sql_nextid();
   $sql = "INSERT INTO " . $prefix . "_bbposts (topic_id, forum_id, poster_id, post_time) VALUES ($topic_id, $forum_id, $user_id, $current_time)";
   if (!$db->sql_query($sql, BEGIN_TRANSACTION))
   {
      echo "Error 2 while submitting application, your application has not been submitted<br />Please inform the webmaster.";
      $success = false;
   }
   $post_id = $db->sql_nextid();
   $sql = "INSERT INTO " . $prefix . "_bbposts_text (post_id, post_subject, post_text) VALUES ($post_id, '$post_subject', '$post_message')";
   if (!$db->sql_query($sql))
   {
      $sql = "INSERT INTO " . $prefix . "_bbposts_text (post_id, post_subject, post_text) VALUES ($post_id, '".mysql_real_escape_string($post_subject)."', '".mysql_real_escape_string($post_message)."')";
      if (!$db->sql_query($sql))
      {
         echo "Error 3 while submitting application, your application has not been submitted<br />Please inform the webmaster.";
         $success = false;
      }
   }
   $sql = "UPDATE " . $prefix . "_bbtopics SET topic_last_post_id='$post_id', topic_first_post_id='$post_id' WHERE topic_id=$topic_id";
   if (!$db->sql_query($sql))
   {
      echo "Error 4 while submitting application, your application has not been submitted<br />Please inform the webmaster.";
      $success = false;
   }
   if ($addPoll == 1)
   {
      $poll_title = "Approve Application?";
      $sql = "INSERT INTO " . $prefix . "_bbvote_desc (topic_id, vote_text, vote_start, vote_length) VALUES ($topic_id, '$poll_title', $current_time, " . ($pollLength * 86400) . ")";
      if (!$db->sql_query($sql))
      {
         echo "Error 5 while submitting application, your application has not been submitted<br />Please inform the webmaster.";
         $success = false;
      }
      $poll_id = $db->sql_nextid();
      $poll_options = array(array(1, "Yes"), array(2, "No"), array(3, "Abstain"));
      foreach($poll_options as $option)
      {
         $sql = "INSERT INTO " . $prefix . "_bbvote_results (vote_id, vote_option_id, vote_option_text) VALUES ($poll_id, {$option[0]}, '{$option[1]}')";
         if (!$db->sql_query($sql))
         {
            echo "Error 6 while submitting application, your application has not been submitted<br />Please inform the webmaster.";
            $success = false;
         }
      }
   }
   $sql = "select forum_posts, forum_topics, forum_last_post_id from " . $prefix . "_bbforums where forum_id='$forum_id'";
   $result = $db->sql_query($sql);
   $forumdata = $db->sql_fetchrow($result);
   $forumdata['forum_posts'] = (int)$forumdata['forum_posts'] + 1;
   $forumdata['forum_topics'] = (int)$forumdata['forum_topics'] + 1;
   $forumdata['forum_last_post_id'] = $post_id;
   $sql = "UPDATE " . $prefix . "_bbforums SET forum_last_post_id='{$forumdata['forum_last_post_id']}', forum_posts='{$forumdata['forum_posts']}', forum_topics='{$forumdata['forum_topics']}' where forum_id='$forum_id'";
   $db->sql_query($sql);
   return $success;
}
?>


Ironhorse
 
View user's profile Send private message
ironhorse
PostPosted: Fri Aug 08, 2008 7:15 am Reply with quote

request_form.php
Code:
<?php


/*
==========================================
 PHP-NUKE: Application Settings module
 Version 2.2.2
==========================================
 Copyright (c) 2007
  by Nathan Burke
  based on work by:
    Arioch - http://www.black-blades.org

 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
 
==========================================
*/

/*
A note on function abstraction:
   The functions were written such to make rearranging the form simple.
   The main function calls any number of get function. 
   get function extract some informtion from the arrays and then call display functions
   display functions have harcoded formatting information (eg. a field size of 2 for a level field) then call show functions
   show function are what actually output the html code.  they do little to no data shaping, simply outputting what was passed to them.
   Nearly every html tag that is output is contained within the show functions.
      The exception being table and row tags, those can be found in the new/exit table/row functions
All get functions are completely independant and can be called in any order, any number of times.
showSubmit can be called wherever you feel submit/reset buttons would be useful(calling it multiple times is ok)

If any function doens't follow the guidelines above, I aplogise, this code was expanded, shrunk, rewritten, sliced, diced and fed the Ravenous Bug-Bladder Beast of Trall during construction
*/

//Array References
/*   Keys Array

Array (
   [0] => Array (
         [type] => Array ( [name] => KeyType1 [value] => Pre-BC Attunements/Keys [show] => 0 )
         [keys] => Array (
               [0] => Array ( [name] => Key1 [value] => Onyxia [show] => 0 [required] => 0 )
               [1] => Array ( [name] => Key2 [value] => Molten Core [show] => 0 [required] => 0 )
               [2] => Array ( [name] => Key3 [value] => Blackwing Lair [show] => 0 [required] => 0 )
               [3] => Array ( [name] => Key4 [value] => Naxxramas [show] => 0 [required] => 0 )
               )
         )
   [1] => Array (
         [type] => Array ( [name] => KeyType2 [value] => Heroic Mode Keys [show] => 1 )
         [keys] => Array (
               [0] => Array ( [name] => Key5 [value] => Auchenai [show] => 1 [required] => 0 )
               [1] => Array ( [name] => Key6 [value] => Warpforged [show] => 1 [required] => 0 )
               [2] => Array ( [name] => Key7 [value] => Reservoir [show] => 1 [required] => 0 )
               [3] => Array ( [name] => Key8 [value] => Flamewrought [show] => 1 [required] => 0 )
               [4] => Array ( [name] => Key9 [value] => Key of Time [show] => 1 [required] => 0 )
               )
         )
   [2] => Array (
         [type] => Array ( [name] => KeyType3 [value] => BC Instance Keys [show] => 0 )
         [keys] => Array (
               [0] => Array ( [name] => Key10 [value] => Shattered Halls [show] => 0 [required] => 0 )
               [1] => Array ( [name] => Key11 [value] => Shadow Labyrinth [show] => 0 [required] => 0 )
               [2] => Array ( [name] => Key12 [value] => Arcatraz [show] => 0 [required] => 0 )
               )
         )
   [3] => Array (
         [type] => Array ( [name] => KeyType4 [value] => Endgame Keys [show] => 1 )
         [keys] => Array (
               [0] => Array ( [name] => Key13 [value] => Karazhan [show] => 1 [required] => 0 )
               [1] => Array ( [name] => Key14 [value] => Tempest Keep: The Eye [show] => 1 [required] => 0 )
               [2] => Array ( [name] => Key15 [value] => Serpentshrine Cavern [show] => 1 [required] => 0 )
               )
         )
   )
*/
//CharData
/*
     Array (
      [0] => Array (
            [name] => Array ( [name] => name [value] => Name [show] => 1 [required] => 1 )
            [class] => Array ( [name] => class [value] => Class [show] => 1 [required] => 1 )
            [level] => Array ( [name] => level [value] => Level [show] => 1 [required] => 1 )
            [prof1] => Array ( [name] => prof1 [value] => Profession 1 [show] => 1 [required] => 1 )
            [prof2] => Array ( [name] => prof2 [value] => Profession 2 [show] => 1 [required] => 1 )
            [aid] => Array ( [name] => aid [value] => First Aid [show] => 1 [required] => 1 )
            [gear] => Array ( [name] => gear [value] => Gear [show] => 1 [required] => 1 )
            [build] => Array ( [name] => build [value] => Talent Build [show] => 1 [required] => 1 )
            [resist] => Array ( [name] => resist [value] => Resistance (Unbuffed) [show] => 1 [required] => 1 )
            [resistances] => Array (
                        [fire] => Array ( [name] => fire [value] => Fire [show] => 1 [required] => 1 )
                        [shadow] => Array ( [name] => shadow [value] => Shadow [show] => 1 [required] => 1 )
                        [nature] => Array ( [name] => nature [value] => Nature [show] => 1 [required] => 1 )
                        [arcane] => Array ( [name] => arcane [value] => Arcane [show] => 1 [required] => 1 )
                        [frost] => Array ( [name] => frost [value] => Frost [show] => 1 [required] => 1 )
                        )
            )
      [1] => Array (
            [name] => Array ( [name] => name [value] => Name [show] => 1 [required] => 0 )   
            [class] => Array ( [name] => class [value] => Class [show] => 1 [required] => 1 )
            [level] => Array ( [name] => level [value] => Level [show] => 1 [required] => 1 )
            [prof1] => Array ( [name] => prof1 [value] => Profession 1 [show] => 1 [required] => 1 )
            [prof2] => Array ( [name] => prof2 [value] => Profession 2 [show] => 1 [required] => 1 )
            [aid] => Array ( [name] => aid [value] => First Aid [show] => 1 [required] => 1 )
            [gear] => Array ( [name] => gear [value] => Gear [show] => 1 [required] => 1 )
            [build] => Array ( [name] => build [value] => Talent Build [show] => 1 [required] => 1 )
            [resist] => Array ( [name] => resist [value] => Resistance (Unbuffed) [show] => 1 [required] => 1 )
            [resistances] => Array (
                        [fire] => Array ( [name] => fire [value] => Fire [show] => 1 [required] => 1 )
                        [shadow] => Array ( [name] => shadow [value] => Shadow [show] => 1 [required] => 1 )
                        [nature] => Array ( [name] => nature [value] => Nature [show] => 1 [required] => 1 )
                        [arcane] => Array ( [name] => arcane [value] => Arcane [show] => 1 [required] => 1 )
                        [frost] => Array ( [name] => frost [value] => Frost [show] => 1 [required] => 1 )
                        )
            )
      [2] => Array ( [name] => Array ( [name] => name [value] => Name [show] => 1 [required] => 0 ) [class] => Array ( [name] => class [value] => Class [show] => 1 [required] => 1 ) [level] => Array ( [name] => level [value] => Level [show] => 1 [required] => 1 ) [prof1] => Array ( [name] => prof1 [value] => Profession 1 [show] => 1 [required] => 1 ) [prof2] => Array ( [name] => prof2 [value] => Profession 2 [show] => 1 [required] => 1 ) [aid] => Array ( [name] => aid [value] => First Aid [show] => 1 [required] => 1 ) [gear] => Array ( [name] => gear [value] => Gear [show] => 1 [required] => 1 ) [build] => Array ( [name] => build [value] => Talent Build [show] => 1 [required] => 1 ) [resist] => Array ( [name] => resist [value] => Resistance (Unbuffed) [show] => 1 [required] => 1 ) [resistances] => Array ( [fire] => Array ( [name] => fire [value] => Fire [show] => 1 [required] => 1 ) [shadow] => Array ( [name] => shadow [value] => Shadow [show] => 1 [required] => 1 ) [nature] => Array ( [name] => nature [value] => Nature [show] => 1 [required] => 1 ) [arcane] => Array ( [name] => arcane [value] => Arcane [show] => 1 [required] => 1 ) [frost] => Array ( [name] => frost [value] => Frost [show] => 1 [required] => 1 ) ) ) [3] => Array ( [name] => Array ( [name] => name [value] => Name [show] => 1 [required] => 0 ) [class] => Array ( [name] => class [value] => Class [show] => 1 [required] => 1 ) [level] => Array ( [name] => level [value] => Level [show] => 1 [required] => 1 ) [prof1] => Array ( [name] => prof1 [value] => Profession 1 [show] => 1 [required] => 1 ) [prof2] => Array ( [name] => prof2 [value] => Profession 2 [show] => 1 [required] => 1 ) [aid] => Array ( [name] => aid [value] => First Aid [show] => 1 [required] => 1 ) [gear] => Array ( [name] => gear [value] => Gear [show] => 1 [required] => 1 ) [build] => Array ( [name] => build [value] => Talent Build [show] => 1 [required] => 1 ) [resist] => Array ( [name] => resist [value] => Resistance (Unbuffed) [show] => 1 [required] => 1 ) [resistances] => Array ( [fire] => Array ( [name] => fire [value] => Fire [show] => 1 [required] => 1 ) [shadow] => Array ( [name] => shadow [value] => Shadow [show] => 1 [required] => 1 ) [nature] => Array ( [name] => nature [value] => Nature [show] => 1 [required] => 1 ) [arcane] => Array ( [name] => arcane [value] => Arcane [show] => 1 [required] => 1 ) [frost] => Array ( [name] => frost [value] => Frost [show] => 1 [required] => 1 ) ) ) )
 */
//TextBoxes   
/*
Array (
   [TextBox1] => Array ( [name] => TextBox1 [value] => List any guilds (and their server) that you have been in or are currently in and reason(s) for leaving.<br>If you are a transfer to Anvilmar, why have you chosen this server? [show] => 1 [required] => 1 )
   [TextBox2] => Array ( [name] => TextBox2 [value] => Please tell us a little bit about yourself.<br>What hours/days are you usually logged into WoW?<br>Why do you want to join Hybrid? [show] => 1 [required] => 1 )
   [TextBox3] => Array ( [name] => TextBox3 [value] => Please describe in detail your pre-BC raiding experience. [show] => 1 [required] => 1 )
   [TextBox4] => Array ( [name] => TextBox4 [value] => Are you currently on or have you completed 'The Trials of the Naaru'?<br>If have not completed this quest line, what step are you on? [show] => 1 [required] => 1 )
   )
*/

define('NO_EDITOR', TRUE); //Supress WYSIWYG editor
$module_name = basename(dirname(__FILE__));

function requestform($UserData=array(), $CharData="", $KeyData="", $TextBoxData="", $Variables="", $Processed=false)
{
   //Load variables into arrays
   require_once("variables.php");
   if($Processed == false)
   {
      initialize($Variables, $KeyData, $TextBoxData);
      gimmeData($UserData, "userinfo");
      gimmeCharData($CharData, $Variables['numalts']['value']);
      gimmeData($GearData, "geardata");
   }
   $show = 0;
   //The application form itself
   echo "<form action=\"modules.php?name=Application&amp;file=confirm\" method=\"POST\">\n";
   //The order of the get...() calls below can be changed at will
   //TODO:  Integrate rearranging into admin module
   getTitle("{$Variables['guildname']['value']} Application");  //The title of the form
   getHeader($Variables['headertext']);  //The header text
   showRequired(); //The * info
   $show += getUserinfo($UserData);  //Information about the player
   $show += getMaininfo($CharData[0]);  //Information about the main character
   $show += getAltinfo($CharData);  //Information about their alts
   $show += getKeys($KeyData);  //Information about the keys
   $show += getTextBoxes($TextBoxData);  //Multiline text boxes
   $show += getOther();  //Anything that didn't fit into the above
   if($show != 0)
      showSubmit();  //The submit/reset buttons
   //Do not move any of the get...() calls below this line
   echo "</form>";
}

function getHeader($text) //Shows the header information
{
   if($text == "")
      return 0;
   newTable();
   if ($text['show'])
      echo $text['value'];
   exitTable();
   return 1;
}

function getTitle($text) //Shows the title of the application
{
   if($text == "")
      return 0;
   newTable();
   hDivider($text, 1);
   exitTable();
   return 1;
}

function getUserinfo($UserData) //Shows the user information fields
{
   $show = 0;
   foreach($UserData as $row)
      $show += $row['show'];
   if($show == 0)
      return 0;
   newTable();
   hDivider("Your Information");
   exitTable();
   newTable();
   newRow();
   displayUserName($UserData['username']);
   displayUserEmail($UserData['useremail']);
   exitRow();
   exitTable();
   newTable();
   newRow();
   displayUserAge($UserData['userage']);
   displayUserTime($UserData['usertime']);
   displayUserPlay($UserData['userplay']);
   exitRow();
   exitTable();
   displayCustom($UserData);
   return 1;
}

function getMaininfo($MainData) //Show main character fields
{
   $show = 0;
   foreach($MainData as $row)
      $show += $row['show'];
   if($show == 0)
      return 0;
   newTable();
   hDivider("Main Character Information");
   exitTable();
   newTable();
   newRow();
   displayCharName("mainname", $MainData['name']);
   displayClassMenu("mainclass", $MainData['class']);
   displayCharLevel("mainlevel", $MainData['level']);
   exitRow();
   exitTable();
   newTable();
   newRow();
   displayCharFirstAid("mainaid", $MainData['aid']);
   displayProfMenu("mainprof1", $MainData['prof1']);
   displayProfMenu("mainprof2", $MainData['prof2']);
   exitRow();
   exitTable();
   displayArmory("maingear", $MainData['gear']);
   displayBuild("mainbuild", $MainData);
   displayResist("mainresist", $MainData['resist'], $MainData['resistances']);
   displayCustom($MainData);
   return 1;
}

function getAltinfo($CharData)
{
   if(count($CharData) == 1)
      return 0;
   newTable();
   hDivider("Alternate Character(s)");
   exitTable();
   showRequired(1);
   $i = -1;
   foreach($CharData as $row)
   {
      if($i == -1)//skip the first row because it contains main character data
      {
         $i = 0;
         continue;
      }
      newTable();
      newRow();
      displayCharName("alt".$i."name", $row['name'], 1);
      displayClassMenu("alt".$i."class", $row['class'], 1);
      displayCharLevel("alt".$i."level", $row['level'], 1);
      exitRow();
      exitTable();
      newTable();
      newRow();
      displayCharFirstAid("alt".$i."aid", $row['aid'], 1);
      displayProfMenu("alt".$i."prof1", $row['prof1'], 1);
      displayProfMenu("alt".$i."prof2", $row['prof2'], 1);
      exitRow();
      exitTable();
      displayArmory("alt".$i."gear", $row['gear'], 1);
      displayBuild("alt".$i."build", $row, 1);
      displayResist("alt".$i."resist", $row['resist'], $row['resistances'], 1);
      displayCustom($row, 1);
      if($i < count($CharData) - 2)
         hSpace();
      $i++;
   }
   return 1;
}

function getKeys($KeyData)
{   
   $first = 2;
   foreach($KeyData as $type)
      if($type['type']['show'] == 1)
      {
         if($first == 2)
         {
            newTable();
            hDivider("Keys");
            exitTable();
            $first = 1;
         }
         if($first != 1)
         {
            hSpace();
            $first = 1;
         }
         displayKeyType($type['type']);
         displayKeys($type['keys']);
         $first = 0;
      }
   if($first == 0)
      return 1;
   else
      return 0;
}

function getTextBoxes($TextBoxData)
{
   $show = 0;
   foreach($TextBoxData as $row)
      $show += $row['show'];
   if($show == 0)
      return 0;
   newTable();
   hDivider("Additional Information");
   exitTable();
   foreach($TextBoxData as $box)
   {
      displayTextBox($box['name'], $box);
      newTable();
      newRow(2);
      exitRow(2);
      exitTable();
   }
   return 1;
}

function getOther()
{   
   return 0;
   newTable();
   //TODO: MAKE THIS DO SOMETHING
   exitTable();
}

function displayBuild($ID, $array, $isAlt = 0)
{
   if($array['build']['show'] == 1)
   {
      if($isAlt == 1)
         $fontColor = "#FFFF00";
      else
         $fontColor = "#FF0000";
      newTable("Provide information on your Talent Build");
      showTextField($ID, $array['build'], $fontColor);
      showText("Point Distribution", $array['build']['missing'], 2);
      showTextField($ID."0", $array['build0'], $fontColor, 1, 2, 2, 1);
      showText("/&nbsp;&nbsp;", $array['build']['missing'], 2, 1);
      showTextField($ID."1", $array['build1'], $fontColor, 1, 2, 2, 1);
      showText("/&nbsp;&nbsp;", $array['build']['missing'], 2, 1);
      showTextField($ID."2", $array['build2'], $fontColor, 1, 2, 2, 1);
      exitTable();
   }
}
function displayResist($ID, $title, $array, $isAlt = 0)
{
   if($title['show'] == 1)
   {
      if($isAlt == 1)
         $fontColor = "#FFFF00";
      else
         $fontColor = "#FF0000";
      newTable($title['value']);
      foreach($array as $row)
      {
         $row['required'] = $title['required'];
         showText($row['value'], $row['missing'], 2);
         showTextField($ID.$row['name'], $row, $fontColor, 1, 2, 3, 1);
      }
      exitTable();
   }
}

function displayTextBox($ID, $array)
{
   if($array['show'] == 1)
   {
      newTable();
      showTextBox($ID, $array);
      exitTable();
   }
}

function displayUsername($array)
{
   if($array['show'] == 1)
      showTextField($array['name'], $array);
}

function displayUserEmail($array)
{
   if($array['show'] == 1)
      showTextField($array['name'], $array);
}

function displayUserAge($array)
{
   if($array['show'] == 1)
      showOptions($array['name'], "age", $array['text'], $array);
}

function displayUserTime($array)
{
   if($array['show'] == 1)
      showOptions($array['name'], "time", $array['text'], $array);
}

function displayUserPlay($array)
{
   if($array['show'] == 1)
      showOptions($array['name'], "play", $array['text'], $array);
}

function displayCharFirstAid($ID, $array, $isAlt = 0)
{
   if($array['show'] == 1)
   {
      if($isAlt == 1)
         $fontColor = "#FFFF00";
      else
         $fontColor = "#FF0000";
      showTextField($ID, $array, $fontColor, "", $size = 3, 3);
   }

}

function displayCustom($array)
{
   $i = 0;
   foreach($array as $row) //Check for custom fields and output
      if(strtolower(substr($row['name'], 4, 4)) == "cust" && $row['show'] == 1)
      {
         newTable();
         newRow();
         showLgTextField($row['name'], $row);
         exitRow();
         exitTable();
      }
}

function displayKeyType($array)
{
   if($array['show'])
   {
      newTable();
      newRow();
//      echo "<td align = \"center\" height=\"25\" bgcolor=\"#333333\">";
      echo "<td align = \"center\" height=\"25\"><strong>";
      showText($array['value'], $array['missing'], 3, 1);
      echo "</strong>";
      exitRow();
      exitTable();
   }
}
   
function displayKeys($array)
{
   newTable();
   newRow();
   $LineLength = 0;
   foreach($array as $key)
   {
      if($key['show'])
      {
         $CurrLength = ceil(strlen($key['value']) * 10);
         $LineLength += $CurrLength;
         if($LineLength > 550)
         {
            exitRow();
            exitTable();
            newTable();
            newRow();
         }
         showCheckBox($key['name'], $key);
      }
   }
   exitRow();
   exitTable();
}

function displayCharName($ID, $array, $isAlt = 0)
{
   if($array['show'] == 1)
   {
      if($isAlt == 1)
         $fontColor = "#FFFF00";
      else
         $fontColor = "#FF0000";
      showTextField($ID, $array, $fontColor, "", 35);
   }
}

function displayClassMenu($ID, $array, $isAlt = 0)
{
   if($array['show'] == 1)
   {
      if($isAlt == 1)
         $fontColor = "#FFFF00";
      else
         $fontColor = "#FF0000";
      showOptions($ID, "class", $array['text'], $array, $fontColor);
   }
}

function displayProfMenu($ID, $array, $isAlt = 0)
{
   if($array['show'] == 1)
   {
      if($isAlt == 1)
         $fontColor = "#FFFF00";
      else
         $fontColor = "#FF0000";
      showOptions($ID, "prof", $array['text'], $array, $fontColor);
   }
}

function displayCharLevel($ID, $array, $isAlt = 0)
{
   if($array['show'] == 1)
   {
      if($isAlt == 1)
         $fontColor = "#FFFF00";
      else
         $fontColor = "#FF0000";
      showTextField($ID, $array, $fontColor, "", $size = 2, 2);
   }
}

function displayArmory($ID, $array, $isAlt = 0)
{
   if($isAlt == 1)
      $fontColor = "#FFFF00";
   else
      $fontColor = "#FF0000";
   if($array['show'])
   {
      gimmeData($GearData, "geardata");
      if($GearData['geartype']['value'] == "link")
      {
         showArmoryText($GearData['gearlink']['value'], $GearData['geartitle']['value'], $array);
         newTable();
         newRow();
         showTextField($ID, $array, $fontColor, 0, 90, "", 1);
         exitRow();
         exitTable();
      }
      else
      {
         $tempArray = array('value' => $GearData['geartitle']['value'], 'missing' => $array['missing'], 'text' => $array['text']);
         showTextBox($ID, $tempArray);
      }
   }
}

function showArray($array)
{
   newTable();
   newRow();
   echo print_r($array);
   exitRow();
   exitTable();
}

function showRequired($isAlt = 0) //Outputs the description of the *
{
   newTable();
   newRow(2);
   if($isAlt == 1)
      echo "<div align=\"center\"><font color=\"#FFF000\">*</font> Required if Name entered</p></div>\n";
   else
      echo "<div align=\"center\"><font color=\"#FF0000\">*</font> Required Items</p></div>\n";
   exitRow(2);
   exitTable();
}

function showCheckBox($ID, $array)
{
   showText($array['value'], $array['missing'], 2, 1);
   if($array['required'] == 1)
      echo "<font color=\"#FF0000\">*</font>";
   echo "<input id=\"".$ID."_text\" type=\"checkbox\" name=\"".$ID."_text\"";
   if ($array['text'] == "on")
      echo "checked";
   echo "></td>\n";
}

function showTextBox($ID, $array)//Displays a multi-line text box
{
   newRow();
   showText($array['value'], $array['missing'], 2, 1, "center");
   if($array['required'] == 1)
      echo "<font color=\"#FF0000\">*</font>";
   exitRow(2);
   newRow(2);
   echo "    <textarea id=\"".$ID."_text\" name=\"".$ID."_text\" rows=\"15\" cols=\"99\" >{$array['text']}</textarea>\n";
   exitRow(2);
}

function showSubmit()  //
{
   newTable();
   newRow(1);
   echo "    <td align=\"center\">";
   echo "    <input id=\"Submit_value\" name=\"Submit_value\" type=\"SUBMIT\" value=\"Submit\">&nbsp;&nbsp;\n";
   echo "    <input id=\"Reset\" name=\"Reset\" type=\"RESET\" value=\"Reset Form\">\n";
   exitRow(2);
   exitTable();
}

function showOptions($ID, $type = "", $selected, $array = "", $requireColor = "FF0000")
{
   if($array != "")
      showText($array['value'], $array['missing']);
   echo "<td>\n<select id=\"".$ID."_text\" name=\"".$ID."_text\">\n";
   switch(strtolower($type))
   {
      case "age":
         echo "   <option value=\"\">Age</option>\n";
         echo "   <option value=\"1\""; if($selected == 1) echo " selected=\"selected\""; echo ">Under 16</option>\n";
         echo "   <option value=\"2\""; if($selected == 2) echo " selected=\"selected\""; echo ">16-20</option>\n";
         echo "   <option value=\"3\""; if($selected == 3) echo " selected=\"selected\""; echo ">21-30</option>\n";
         echo "   <option value=\"4\""; if($selected == 4) echo " selected=\"selected\""; echo ">Over 30</option>\n";
         break;
      case "class":
         echo "   <option value=\"\">Class</option>\n";
         echo "   <option value=\"1\""; if($selected == 1) echo " selected=\"selected\""; echo ">Warrior</option>\n";
         echo "   <option value=\"2\""; if($selected == 2) echo " selected=\"selected\""; echo ">Hunter</option>\n";
         echo "   <option value=\"3\""; if($selected == 3) echo " selected=\"selected\""; echo ">Rogue</option>\n";
         echo "   <option value=\"4\""; if($selected == 4) echo " selected=\"selected\""; echo ">Priest</option>\n";
         echo "   <option value=\"5\""; if($selected == 5) echo " selected=\"selected\""; echo ">Shaman</option>\n";
         echo "   <option value=\"6\""; if($selected == 6) echo " selected=\"selected\""; echo ">Druid</option>\n";
         echo "   <option value=\"7\""; if($selected == 7) echo " selected=\"selected\""; echo ">Mage</option>\n";
         echo "   <option value=\"8\""; if($selected == 8) echo " selected=\"selected\""; echo ">Warlock</option>\n";
         echo "   <option value=\"9\""; if($selected == 9) echo " selected=\"selected\""; echo ">Paladin</option>\n";
         break;
      case "time":
         echo "   <option value=\"\">Timezone</option>\n";
         echo "   <option value=\"1\""; if($selected == 1) echo " selected=\"selected\""; echo ">Eastern</option>\n";
         echo "   <option value=\"2\""; if($selected == 2) echo " selected=\"selected\""; echo ">Central</option>\n";
         echo "   <option value=\"3\""; if($selected == 3) echo " selected=\"selected\""; echo ">Mountain</option>\n";
         echo "   <option value=\"4\""; if($selected == 4) echo " selected=\"selected\""; echo ">Pacific</option>\n";
         echo "   <option value=\"5\""; if($selected == 5) echo " selected=\"selected\""; echo ">Other</option>\n";
         break;
      case "play":
         echo "   <option value=\"\">PlayStyle\n";
         echo "   <option value=\"1\""; if($selected == 1) echo " selected=\"selected\""; echo ">1(casual)</option>\n";
         echo "   <option value=\"2\""; if($selected == 2) echo " selected=\"selected\""; echo ">2</option>\n";
         echo "   <option value=\"3\""; if($selected == 3) echo " selected=\"selected\""; echo ">3</option>\n";
         echo "   <option value=\"4\""; if($selected == 4) echo " selected=\"selected\""; echo ">4</option>\n";
         echo "   <option value=\"5\""; if($selected == 5) echo " selected=\"selected\""; echo ">5</option>\n";
         echo "   <option value=\"6\""; if($selected == 6) echo " selected=\"selected\""; echo ">6</option>\n";
         echo "   <option value=\"7\""; if($selected == 7) echo " selected=\"selected\""; echo ">7</option>\n";
         echo "   <option value=\"8\""; if($selected == 8) echo " selected=\"selected\""; echo ">8</option>\n";
         echo "   <option value=\"9\""; if($selected == 9) echo " selected=\"selected\""; echo ">9</option>\n";
         echo "   <option value=\"10\""; if($selected == 10) echo " selected=\"selected\""; echo ">10(hardcore)</option>\n";
         break;
      case "prof":
         echo "<option value=\"\">Profession</option>\n";
         echo "<option value=\"1\""; if($selected == 1) echo " selected=\"selected\""; echo ">Alchemy</option>\n";
         echo "<option value=\"2\""; if($selected == 2) echo " selected=\"selected\""; echo ">Blacksmithing</option>\n";
         echo "<option value=\"3\""; if($selected == 3) echo " selected=\"selected\""; echo ">Enchanting</option>\n";
         echo "<option value=\"4\""; if($selected == 4) echo " selected=\"selected\""; echo ">Engineering</option>\n";
         echo "<option value=\"5\""; if($selected == 5) echo " selected=\"selected\""; echo ">Herbalism</option>\n";
         echo "<option value=\"6\""; if($selected == 6) echo " selected=\"selected\""; echo ">Leatherworking</option>\n";
         echo "<option value=\"7\""; if($selected == 7) echo " selected=\"selected\""; echo ">Mining</option>\n";
         echo "<option value=\"8\""; if($selected == 8) echo " selected=\"selected\""; echo ">Skinning</option>\n";
         echo "<option value=\"9\""; if($selected == 9) echo " selected=\"selected\""; echo ">Tailoring</option>\n";
         echo "<option value=\"10\""; if($selected == 10) echo " selected=\"selected\""; echo ">Jewel Crafting</option>\n";
         break;
   }
   echo "</select>";
   if($array != "" && $array['required'] == 1)
      echo "<font color=\"$requireColor\">*</font>\n";
   echo "</td>\n";
}

function showArmoryText($url, $title, $array)
{
   newTable();
   newRow();
   showText("Provide a link to your profile on&nbsp;", $array['missing'], 2, 1, "center");
   echo "<a href=\"#\" onClick=window.open(\"$url\",\"\")>$title</a>";
   showText("", $array['missing'], 1);
   exitRow();
   exitTable();
}

function showText($text, $missing = 0, $noTags = 0, $noColon = 0, $align = "right")
{
   if($noColon == 0)
      $text = $text.":";
   if($noTags != 1 && $noTags != 3)
      echo "<td align=\"$align\">";
   if($missing == 1)
      echo "<font color=\"#FF0000\">$text</font>";
   else
      echo $text;
   if($noTags != 2 && $noTags != 3)
      echo "</td>\n";
}

function showTextField($ID, $array, $requiredColor = "#FF0000", $noTags = 0, $size = 28, $maxLength = "", $noText = 0)
{
   if($noText == 0)
      showText($array['value'], $array['missing']);
   if($noTags != 1 && $noTags != 3)
      if($noText == 0)
         echo "<td align=\"left\">";
      else
         echo "<td align=\"center\">";
   echo "<input type=\"text\" id=\"".$ID."_text\" name=\"".$ID."_text\" value=\"{$array['text']}\" size=\"$size\" maxlength=\"$maxLength\">";
   if($array['required'] == 1)
      echo "<font color=\"$requiredColor\">*</font>";
   if($noTags != 2 && $noTags != 3)
      echo "</td>\n";
}
   
function showLgTextField($ID, $array)//Displays a line of text with a single-line input box below it
{
   newRow();
   echo "  <td width=\"150\">{$array['value']}</td>\n";
   if($array['required'] == 1)
      $size == 68;
   else
      $size == 70;
   echo "<td width=\"400\"><input type=\"text\" id=\"".$ID."_text\" name=\"".$ID."_text\" value=\"{$array['text']}\" size=\"$size\" />";
   if($array['required'] == 1)
      echo "<font color=\"$requiredColor\">*</font>";
   exitRow(2);
}

function exitRow($tags = 1)
{
   if($tags == 1)
      echo "</tr>\n";
   elseif($tags == 2)
      echo "</td>\n</tr>\n";
}

function newRow($tags = 1)
{
   if($tags == 1)
      echo "<tr>\n";
   elseif($tags == 2)
      echo "<tr>\n<td>\n";
}

function newTable($title = "", $width = 550)
{
   if($title != "")
      echo "<center><font class=\"option\"><b>$title</b></font></center>\n";
   echo "<table align=\"center\" width=\"$width\" border=\"0\" cellpadding=\"0\">\n";
}
function exitTable()
{
   echo "</table>\n";
}

function hDivider($text, $size = 0)
{
   echo "<tr><td height=\"20\"></td></tr>\n";
   echo "<tr>\n";
   echo "  <td colspan=\"4\"><table border=\"0\" cellpading=\"0\">\n";
   echo "    <tr>\n";
   echo "       <td width=\"100\"></td><td width=\"350\"><hr></td><td />\n";
   echo "    </tr>\n";
   echo "    <tr>\n";
   echo "       <td colspan=\"3\" width=\"550\"><center>";
   if($size == 0)
      echo "<strong>$text</strong>";
   else
      echo "<h1>$text</h1>";
   echo "</center></td><td />\n";
   echo "    </tr>\n";
   echo "    <tr>\n";
   echo "       <td width=\"100\"></td><td width=\"350\"><hr></td>\n";
   echo "    </tr>\n";
   echo "  </table></td>\n";
   echo "</tr>\n";
}

function hSpace()
{
   newTable();
   newRow();
   echo "<td height=\"10\" width=\"250\"></td><td height=\"10\" width=\"50\"><hr></td><td height=\"10\" width=\"250\"></td>";
   exitRow();
   exitTable();
}
?>
 
Guardian2003
Site Admin


Joined: Aug 28, 2003
Posts: 6793
Location: Ha Noi, Viet Nam

PostPosted: Fri Aug 08, 2008 9:16 am Reply with quote

Those scripts look like they were written for one of the *nuke versions that had the tinyMCE editor which of course RN does not have, it uses it's own WYSIWYG editor (CFKEditor).
IUnless someone can see any other obvious problems with the code, I would suggest you turn on error reporting in your config.php file and see what happens.
 
View user's profile Send private message Send e-mail
ironhorse
PostPosted: Fri Aug 08, 2008 9:55 am Reply with quote

right turned it on and got

Fatal error: Cannot redeclare validateemailformat() (previously declared in mainfile.php:1493) in
modules/Application/validateEmailFormat.php on line 69
Code:


<?php
////////////////////////////////////////////////////////////////////////
//
// validateEmailFormat.php - v 1.0
//
// PHP translation of Email Regex Program (optimized)
// Derived from:
//   Appendix B - Email Regex Program
//   _Mastering Regular Expressions_ (First Edition, May 1997 revision)
//     by Jeffrey E.F. Friedl
//     Copyright 1997 O'Reilly & Associates
//     ISBN: 1-56592-257-3
//   For more info on this title, see:
//     http://www.oreilly.com/catalog/regex/
//   For original perl version, see:
//     http://examples.oreilly.com/regex/
//
// Follows RFC 822 about as close as is possible.
// http://www.faqs.org/rfcs/rfc822.html
//
//
// DESCRIPTION:
//  bool validateEmailFormat ( string string )
//
//  Returns TRUE if the email address passed is in a valid format
//  according to RFC 822, returns FALSE if email address passed
//  is not in a valid format.
//
// EXAMPLES:
//  Example #1:
//  $email = "Jeffy <\"That Tall Guy\"@foo.com (blah blah blah)";
//  $isValid = validateEmailFormat($email);
//  if($isValid) {
//    ...  // Yes, the above address is a valid format!
//  } else {
//    echo "sorry, that address isn't formatted properly.";
//  }
//
//  Example #2:
//  $email = "foo@bar.co.il";
//  $isValid = validateEmailFormat($email);
//  if($isValid) {
//    ...
//  } else {
//    echo "sorry ...";
//  }
//
// Translated by Clay Loveless <clay@killersoft.com> on March 11, 2002
// ... in hopes that the "here's how to check an e-mail address!"
// discussion can finally end. After all ...
//
//       Friedl is the master -- Hail to the King, baby!
//
////////////////////////////////////////////////////////////////////////
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// Hell, it might not even work for you.
//
// By using this code you agree to indemnify Clay Loveless,
// KillerSoft, and Crawlspace, Inc. from any liability that might
// arise from its use.
//
// Have fun!
//
////////////////////////////////////////////////////////////////////////
function validateEmailFormat ( $email ) {

   // Some shortcuts for avoiding backslashitis
   $esc        = '\\\\';               $Period      = '\.';
   $space      = '\040';               $tab         = '\t';
   $OpenBR     = '\[';                 $CloseBR     = '\]';
   $OpenParen  = '\(';                 $CloseParen  = '\)';
   $NonASCII   = '\x80-\xff';          $ctrl        = '\000-\037';
   $CRlist     = '\n\015';  // note: this should really be only \015.

   // Items 19, 20, 21 -- see table on page 295 of 'Mastering Regular Expressions'
   $qtext = "[^$esc$NonASCII$CRlist\"]";            // for within "..."
   $dtext = "[^$esc$NonASCII$CRlist$OpenBR$CloseBR]";   // for within [...]
   $quoted_pair = " $esc [^$NonASCII] ";   // an escaped character

   // *********************************************
   // Items 22 and 23, comment.
   // Impossible to do properly with a regex, I make do by allowing at most
   // one level of nesting.
   $ctext = " [^$esc$NonASCII$CRlist()] ";
   
   // $Cnested matches one non-nested comment.
   // It is unrolled, with normal of $ctext, special of $quoted_pair.
   $Cnested = "";
      $Cnested .= "$OpenParen";               // (
       $Cnested .= "$ctext*";                  //      normal*
       $Cnested .= "(?: $quoted_pair $ctext* )*";   //      (special normal*)*
       $Cnested .= "$CloseParen";               //                   )
   
   // $comment allows one level of nested parentheses
   // It is unrolled, with normal of $ctext, special of ($quoted_pair|$Cnested)
   $comment = "";
      $comment .= "$OpenParen";                  //  (
      $comment .= "$ctext*";                     //     normal*
      $comment .= "(?:";                        //       (
      $comment .= "(?: $quoted_pair | $Cnested )";   //         special
      $comment .= "$ctext*";                     //         normal*
      $comment .= ")*";                        //            )*
      $comment .= "$CloseParen";                  //                )
      
   // *********************************************
   // $X is optional whitespace/comments
   $X = "";
      $X .= "[$space$tab]*";               // Nab whitespace
      $X .= "(?: $comment [$space$tab]* )*";   // If comment found, allow more spaces
      
      
   // Item 10: atom
   $atom_char = "[^($space)<>\@,;:\".$esc$OpenBR$CloseBR$ctrl$NonASCII]";
   $atom = "";
      $atom .= "$atom_char+";      // some number of atom characters ...
      $atom .= "(?!$atom_char)";   // ... not followed by something that
                           //     could be part of an atom
                           
   // Item 11: doublequoted string, unrolled.
   $quoted_str = "";
      $quoted_str .= "\"";                     // "
      $quoted_str .= "$qtext *";                  //   normal
      $quoted_str .= "(?: $quoted_pair $qtext * )*";   //   ( special normal* )*
      $quoted_str .= "\"";                     //        "
   
   
   // Item 7: word is an atom or quoted string
   $word = "";
      $word .= "(?:";
      $word .= "$atom";      // Atom
      $word .= "|";         // or
      $word .= "$quoted_str";   // Quoted string
      $word .= ")";
      
   // Item 12: domain-ref is just an atom
   $domain_ref = $atom;
   
   // Item 13: domain-literal is like a quoted string, but [...] instead of "..."
   $domain_lit = "";
      $domain_lit .= "$OpenBR";                  // [
      $domain_lit .= "(?: $dtext | $quoted_pair )*";   //   stuff
      $domain_lit .= "$CloseBR";                  //         ]

   // Item 9: sub-domain is a domain-ref or a domain-literal
   $sub_domain = "";
      $sub_domain .= "(?:";
      $sub_domain .= "$domain_ref";
      $sub_domain .= "|";
      $sub_domain .= "$domain_lit";
      $sub_domain .= ")";
      $sub_domain .= "$X"; // optional trailing comments
      
   // Item 6: domain is a list of subdomains separated by dots
   $domain = "";
      $domain .= "$sub_domain";
      $domain .= "(?:";
      $domain .= "$Period $X $sub_domain";
      $domain .= ")*";
      
   // Item 8: a route. A bunch of "@ $domain" separated by commas, followed by a colon.
   $route = "";
      $route .= "\@ $X $domain";
      $route .= "(?: , $X \@ $X $domain )*"; // additional domains
      $route .= ":";
      $route .= "$X"; // optional trailing comments
      
   // Item 5: local-part is a bunch of $word separated by periods
   $local_part = "";
      $local_part .= "$word $X";
      $local_part .= "(?:";
      $local_part .= "$Period $X $word $X"; // additional words
      $local_part .= ")*";
      
   // Item 2: addr-spec is local@domain
   $addr_spec = "$local_part \@ $X $domain";

   // Item 4: route-addr is <route? addr-spec>
   $route_addr = "";
      $route_addr .= "< $X";
      $route_addr .= "(?: $route )?"; // optional route
      $route_addr .= "$addr_spec";   // address spec
      $route_addr .= ">";
      
   // Item 3: phrase........
   $phrase_ctrl = '\000-\010\012-\037'; // like ctrl, but without tab
   
   // Like atom-char, but without listing space, and uses phrase_ctrl.
   // Since the class is negated, this matches the same as atom-char plus space and tab
   $phrase_char = "[^()<>\@,;:\".$esc$OpenBR$CloseBR$NonASCII$phrase_ctrl]";

   // We've worked it so that $word, $comment, and $quoted_str to not consume trailing $X
   // because we take care of it manually.
   $phrase = "";
      $phrase .= "$word";                           // leading word
      $phrase .= "$phrase_char *";                  // "normal" atoms and/or spaces
      $phrase .= "(?:";
      $phrase .= "(?: $comment | $quoted_str )";    // "special" comment or quoted string
      $phrase .= "$phrase_char *";               //  more "normal"
      $phrase .= ")*";

   // Item 1: mailbox is an addr_spec or a phrase/route_addr
   $mailbox = "";
      $mailbox .= "$X";               // optional leading comment
      $mailbox .= "(?:";
      $mailbox .= "$addr_spec";         // address
      $mailbox .= "|";               // or
      $mailbox .= "$phrase  $route_addr";   // name and address
      $mailbox .= ")";

   // test it and return results
   $isValid = preg_match("/^$mailbox$/xS",$email);
   
   return($isValid);
} // END validateEmailFormat
?>


Ironhorse

EDITED - paths removed for your safety - G
 
ironhorse
PostPosted: Fri Aug 08, 2008 10:03 am Reply with quote

its ok I have managed to fix it by adding a 1 to the end of the function name and wherever its called and it worked, thanks.

Ironhorse
 
Guardian2003
PostPosted: Fri Aug 08, 2008 10:29 am Reply with quote

Glad you are working now.
I edited your paths as you really shouldn't post full server path info Smile
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©