 <?
  /* Main include info */
  ini_set('include_path',"/usr/web/sites/tuve.tv/include/");
  include("site.inc");

  /* Assign the page title */
  $data[tpl]->assign("PAGE_TITLE","Register for a TUve account");

  /* Main defines */
  $data[tpl]->define(array(index=>"index/index.html"));

  //DoSession();

  if ($data['register'] != "") {
    if (strlen($data['firstname']) < 3)
      $message .= "Invalid First Name ";
    if (strlen($data['lastname']) < 3)
      $message .= "Invalid Last Name ";
    if ($data['postal_code'] == "")
      $message .= "Please Enter Your Postal Code";
    if ($data['country'] == "ZZ")
      $message .= "Please Select A Country ";
    if ($data['bmonth'] == 0)
      $message .= "Invalid Birth Month ";
    if ($data['bday'] == 0)
      $message .= "Invalid Birth Day ";
    if ($data['byear'] == 0)
      $message .= "Invalid Birth Year ";
    if ($data['username'] == "")
      $message .= "Invalid Username ";
    if ($data['gender'] == 0)
      $message .= "Please Select A Gender ";
    $query = "SELECT uid FROM users WHERE username = \"$data[username]\"";
    $res = mysql_query($query);
    if (mysql_num_rows($res) > 0)
      $message .= "Username is not available ";
    if ($data['password1'] != $data['password2']) 
      $message .= "Password Mismatch<br>";
    $query = "SELECT uid FROM users WHERE email like \"$data[email1]\"";
    if (mysql_num_rows(mysql_query($query)) > 0)
      $message .= "This E-Mail Address Is Already Registered ";
    if ($data['email1'] != $data['email2'])
      $message .= "E-Mail Mismatch ";
    if (!$data['tos'])
      $message .= "Please Agree To The Terms Of Use and Privacy Policy";
    }

  if (($message == "") && ($data['register'] != "")) {
    $data['tpl']->define(array(body=>"/register-success.html"));

    $active = time();

    if ($data['gender'] == 2)
      $pImage = 2;
    else
      $pImage = 3;
 
    $query = "INSERT INTO users (firstname,lastname,postal_code,country,bmonth,bday,byear,email,username,password,gid,active,gender,profile_image) VALUES(\"$data[firstname]\",\"$data[lastname]\",\"$data[postal_code]\",\"$data[country]\",$data[bmonth],$data[bday],$data[byear],\"$data[email1]\",\"$data[username]\",\"$data[password1]\",3,$active,$data[gender],$pImage)";
    mysql_query($query);

    $message = "$data[firstname],<br><br>Thank you for registering with TUve. Please click or go to the following link to activate your account. <A HREF=\"http://www.tuve.tv/activate.php?active=$active&email=$data[email1]\">http://www.tuve.tv/activate.php?active=$active&email=$data[email1]</a><br><br>Another useful link is <a href=\"http://www.tuve.tv/faq.php\">http://www.tuve.tv/faq.php</a> where you can find answers to the most frequently asked questions.<br><br>Thank you,<br>The TUve Staff<br>";

    send_mail("$data[firstname] $data[lastname] <$data[email1]>",$message,"Please Confirm Your E-Mail Address","support@tuve.tv","TUve Support");

    send_mail("Christopher Olsen <cwolsen@domainatlantic.com>","New registration<br><br>E-Mail: $data[email1]<BR>Activation: $active<br>Source: $data[source]<br><br>","New Registration","support@tuve.tv","TUve Support");
    }
  else {
    $data['tpl']->define(array(body=>"/register.html"));
    if ($data['tos'])
      $data['tpl']->assign("TOS","CHECKED");
    else
      $data['tpl']->assign("TOS","");
    $data['tpl']->assign("FIRSTNAME",$data['firstname']);
    $data['tpl']->assign("LASTNAME",$data['lastname']);
    $data['tpl']->assign("POSTAL_CODE",$data['postal_code']);
    $data['tpl']->assign("USERNAME",$data['username']);
    $data['tpl']->assign("EMAIL1",$data['email1']);
    $data['tpl']->assign("EMAIL2",$data['email2']);
    $data['tpl']->assign("PASSWORD1",$data['password1']);
    $data['tpl']->assign("PASSWORD2",$data['password2']);
    $data['tpl']->assign("SOURCE",$data['source']);

    $months = array('Month','January','February','March','April','May','June','July','August','September','October','November','December');
    $countries = array("US"=>"United States","AF"=>"Afghanistan","AL"=>"Albania","DZ"=>"Algeria","AS"=>"American Samoa","AD"=>"Andorra","AO"=>"Angola","AI"=>"Anguilla","AQ"=>"Antarctica","AG"=>"Antigua and Barbuda","AR"=>"Argentina","AM"=>"Armenia","AW"=>"Aruba","AU"=>"Australia","AT"=>"Austria","AZ"=>"Azerbaijan","BS"=>"Bahamas","BH"=>"Bahrain","BD"=>"Bangladesh","BB"=>"Barbados","BY"=>"Belarus","BE"=>"Belgium","BZ"=>"Belize","BJ"=>"Benin","BM"=>"Bermuda","BT"=>"Bhutan","BO"=>"Bolivia","BA"=>"Bosnia and Herzegowina","BW"=>"Botswana","BV"=>"Bouvet Island","br"=>"Brazili","IO"=>"British Indian Ocean Territory","BN"=>"Brunei Darussalam","BG"=>Bulgaria,"BF"=>"Burkina Faso","BI"=>"Burundi","KH"=>"Cambodia","CM"=>"Cameroon","CA"=>"Canada","CV"=>"Cape Verde","KY"=>"Cayman Islands","CF"=>"Central African Republic","TD"=>"Chad","CL"=>"Chile","CN"=>"China","CX"=>"Christmas Island","CC"=>"Cocoa (Keeling) Islands","CO"=>"Colombia","KM"=>"Comoros","CG"=>"Congo","CK"=>"Cook Islands","CR"=>"Costa Rica","CI"=>"Cote Divoire","CT"=>"Croatia (Hrvatska)","CU"=>"Cuba","CY"=>"Cyprus","CZ"=>"Czech Republic","DK"=>"Denmark","DJ"=>"Djibouti","DS"=>"DoDDs Schools","DM"=>"Dominica","DO"=>"Dominican Republic","TP"=>"East Timor","EC"=>"Ecuador","EG"=>"Egypt","SV"=>"El Salvador","GQ"=>"Equatorial Guinea","ER"=>"Eritrea","EE"=>"Estonia","ET"=>"Ethiopia","FK"=>"Falkland Islands (Malvinas)","FO"=>"Faroe Islands","FJ"=>"Fiji","FI"=>"Finland","FR"=>"France","GA"=>"Gabon","GM"=>"Gambia","GE"=>"Georgia","DE"=>"Germany","GH"=>"Ghana","GI"=>"Gibraltar","GR"=>"Greece","GL"=>"Greenland","GD"=>"Grenada","GU"=>"Guam","GT"=>"Guatemala","GN"=>"Guinea","GW"=>"Guinea-Bissau","GY"=>"Guyana","HT"=>"Haiti","HM"=>"Heard and Mc Donald Islands","HN"=>"Honduras","HK"=>"Hong Kong","HU"=>"Hungary","IS"=>"Iceland","IN"=>"India","ID"=>"Indonesia","IR"=>"Iran (Islamic Republic of)","IQ"=>"Iraq","IE"=>"Ireland","IL"=>"Israel","IT"=>"Italy","JM"=>"Jamaica","JP"=>"Japan","JO"=>"Jordan","KZ"=>"Kazakhstan","KE"=>"Kenya","KI"=>"Kiribati","KP"=>"Korea,  Democratic Peoples Republic of","KR"=>"Korea,  Republic of","KW"=>"Kuwait","KG"=>"Kyrgyzstan","LA"=>"Lao Peoples Democratic Republic","LV"=>"Latvia","LB"=>"Lebanon","LS"=>"Lesotho","LR"=>"Liberia","LY"=>"Libyan Arab Jamahiriya","LI"=>"Liechtenstein","LT"=>"Lithuania","LU"=>"Luxembourg","MO"=>"Macau","MK"=>"Macedonia, The Former Yugoslav Republic of","MG"=>"Madagascar","MW"=>"Malawi","MY"=>"Malaysia","MV"=>"Maldives","ML"=>"Mali","MT"=>"Malta","MH"=>"Marshall Islands","MR"=>"Mauritania","MU"=>"Mauritius","MX"=>"Mexico","FM"=>"Micronesia, Federated States of","MD"=>"Moldova,  Republic of","MC"=>"Monaco","MN"=>"Mongolia","MS"=>"Montserrat","MA"=>"Morocco","MZ"=>"Mozambique","MM"=>"Myanmar","NA"=>"Namibia","NR"=>"Nauru","NP"=>"Nepal","NL"=>"Netherlands","AN"=>"Netherlands Antilles","NZ"=>"New Zealand","NI"=>"Nicaragua","NE"=>"Niger","NG"=>"Nigeria","NU"=>"Niue","NF"=>"Norfolk Island","MP"=>"Northern Mariana Islands","NO"=>"Norway","OM"=>"Oman","PK"=>"Pakistan","PW"=>"Palau","PA"=>"Panama","PG"=>"Papua New Guinea","PY"=>"Paraguay","PE"=>"Peru","PH"=>"Philippines","PN"=>"Pitcairn","PL"=>"Poland","PT"=>"Portugal","PR"=>"Puerto Rico","QA"=>"Qatar","RO"=>"Romania","RU"=>"Russian Federation","RW"=>"Rwanda","KN"=>"Saint Kitts and Nevis","LC"=>"Saint Lucia","VC"=>"Saint Vincent and the Grenadines","WS"=>"Samoa","SM"=>"San Marino","ST"=>"Sao Tome and Principe","SA"=>"Saudi Arabia","SN"=>"Senegal","SC"=>"Seychelles","SL"=>"Sierra Leone","SG"=>"Singapore","SK"=>"Slovakia (Slovak Republic)","SI"=>"Slovenia","Sb"=>"Solomon Islands","SO"=>"Somalia","ZA"=>"South Africa","GS"=>"South Georgia and the South Sandwich Islands","ES"=>"Spain","LK"=>"Sri Lanka","SH"=>"St. Helena","SD"=>"Sudan","SR"=>"Suriname","SJ"=>"Svalbard and Jan Mayen Islands","SZ"=>"Swaziland","SE"=>"Sweden","CH"=>"Switzerland","SY"=>"Syrian ArabRepublic","TW"=>"Taiwan","TJ"=>"Tajikistan","TZ"=>"Tanzania,  United Republic of","TH"=>"Thailand","TG"=>"Togo","TK"=>"Tokelau","TO"=>"Tonga","TT"=>"Trinidad and Tobago","TN"=>"Tunisia","TR"=>"Turkey","TM"=>"Turkmenistan","TC"=>"Turks and Caicos Islands","TV"=>"Tuvalu","UG"=>"Uganda","UA"=>"Ukraine","AE"=>"United ArabEmirates","UK"=>"United Kingdom","UM"=>"United States Minor Outlying Islands","UY"=>"Uruguay","UZ"=>"Uzbekistan","VU"=>"Vanuatu","VA"=>"Vatican City State(Holy See)","VE"=>"Venezuela","VN"=>"Viet Nam","VG"=>"Virgin Islands (British)","VI"=>"Virgin Islands (U.S.)","EH"=>"Western Sahara","YE"=>"Yeman","YU"=>"Yugoslavia","ZR"=>"Zaire","ZM"=>"Zambia","ZW"=>"Zimbabwe");

    for ($i = 0;$i < 13;$i++) {
      if ($i == $data['bmonth'])
        $bmonth .= "<OPTION VALUE=\"$i\" SELECTED>$months[$i]</OPTION>\n";
      else
        $bmonth .= "<OPTION VALUE=\"$i\">$months[$i]</OPTION>\n";
      }
    $data['tpl']->assign("BMONTH",$bmonth);

    $bday = "<OPTION VALUE=\"0\">Day</OPTION>\n";
    for ($i = 1;$i <= 31;$i++) {
      if ($i == $data['bday'])
        $bday .= "<OPTION VALUE=\"$i\" SELECTED>$i</OPTION>\n";
      else
        $bday .= "<OPTION VALUE=\"$i\">$i</OPTION>\n";
      }
    $data['tpl']->assign("BDAY",$bday);

    $byear = "<OPTION VALUE=\"0\">Year</OPTION>\n";
    for ($i = 2008;$i >= 1908;$i--) {
      if ($i == $data['byear'])
        $byear .= "<OPTION VALUE=\"$i\" SELECTED>$i</OPTION>\n";
      else
        $byear .= "<OPTION VALUE=\"$i\">$i</OPTION>\n";
      }
    $data['tpl']->assign("BYEAR",$byear);

    $country = "<OPTION VALUE=\"ZZ\">Country</OPTION>\n";

    foreach ($countries as $key => $val) {
      if ($key == $data['country'])
        $country .= "<OPTION VALUE=\"$key\" SELECTED>$val</OPTION>\n";
      else
        $country .= "<OPTION VALUE=\"$key\">$val</OPTION>\n";
      }
    $data['tpl']->assign("COUNTRY",$country);

    if ($data['gender'] == 1)
      $data['tpl']->assign("GENDER","<OPTION VALUE=\"0\">Please Select</OPTION><OPTION VALUE=\"2\" SELECTED>Female</OPTION><OPTION VALUE=\"1\">Male</OPTION>");
    else if ($data['gender'] == 2)
      $data['tpl']->assign("GENDER","<OPTION VALUE=\"0\">Please Select</OPTION><OPTION VALUE=\"2\">Female</OPTION><OPTION VALUE=\"1\" SELECTED>Male</OPTION>");
    else
      $data['tpl']->assign("GENDER","<OPTION VALUE=\"0\">Please Select</OPTION>\n<OPTION VALUE=\"2\">Female</OPTION>\n<OPTION VALUE=\"1\">Male</OPTION>\n");
    }



  $data['tpl']->assign("MESSAGE",$message);

  /* Parse and print */
  $data[tpl]->parse(BODY, array("body"));
  $data[tpl]->parse(INDEX, array("index"));
  $data[tpl]->FastPrint("INDEX");
?>
