<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v3.1 www.exoops.info 2006/03
##################################################################################
# Friend Finder for e-xoops  Version 3.02 beta                                 #
#                                                                                #
# Script design  : PhpMeet  :   Copyright 2002 Jeremy Ross-webmaster@phprank.com #
# Created 15/01/02              Last Modified 15/01/02                           #
# Scripts Home              :   http://www.jrscripts.com                         #
#                                                                                #
# Xoops-RC2 French Version  :   jokerman@free.fr                                 #
# Web Home                     :   http://www.webetfric.com                      #
#                                                                                #
# Xoops-RC2 English Version :          Neon@neon.qldgamers.com                   #
# Web Home                  :   http://neon.qldgamers.com                        #
#                                                                                #
#                 Redesigned and new improvemends by                             #
#        eagle81 Manuel Caballero       Manuel@dancepartner.net                  #
#                    http://www.dancepartner.net                                 #
#                             2002-09-12                                         #
##################################################################################
// ORIGINAL FILE INFO
include_once("../../mainfile.php");
include_once(XOOPS_ROOT_PATH."/header.php");
include_once(XOOPS_ROOT_PATH."/modules/friendfinder/cache/config.php");
include_once(XOOPS_ROOT_PATH."/modules/friendfinder/header.php");
include_once(XOOPS_ROOT_PATH."/include/xoopscodes.php");
include_once(XOOPS_ROOT_PATH."/class/upload.class.php");
$xoopsOption['show_rblock'] =1;
global $dateformat, $autoactive, $imagesize, $heightunit, $weightunit, $bcoosConfig, $db, $xoopsTheme,$xoopsUser,$_FILES;
if($autoactive==0){ $textdateformat = _ttmmjjjj;
} else { $textdateformat = _jjjjmmtt; }
if (!$xoopsUser) {
include_once(XOOPS_ROOT_PATH."/header.php");
OpenTable();
echo "<DIV ALIGN=\"center\">"._TEXTNOXOOPSUSER."<A HREF=\"".XOOPS_URL."/register.php\">"._CLA_REGISTER."</A><BR>"._CLA_OR." <A HREF=\"".XOOPS_URL."/user.php\">"._CLA_CONECT."</A> "._CLA_IFAREMEMBER."</DIV>";
CloseTable();
include_once("../../footer.php");
} else {
        OpenTable();
//************************************************************
include_once(XOOPS_ROOT_PATH."/header.php");
if ($page == "add") {
	$sql = "SELECT * FROM ".$db->prefix("friendfinder")." WHERE user = '$user'";
	$result = $db->query($sql);
	while ($i = $db->fetchArray($result)) {
		if ($user == $i[user]) {	
			echo "<font face=arial size=2><br>"._USEREXISTS."<br><br><br><br></font>";
			include_once "admin/foot.php";
			die;
		}
	}
	if (empty($sex) || $sex == "0") {
		echo "<font face=arial size=2>"._TEXTSEXMISSING."</font>";
		include_once "admin/foot.php";
		die;
	}
	if (empty($state) || $state == "0") {
		echo "<font face=arial size=2>"._TEXTSTATEMISSING."</font>";
		include_once "admin/foot.php";
		die;
	}	
	if (empty($partner) || $partner == "0") {
		echo "<font face=arial size=2>"._TEXTPARTNERMISSING."</font>";
		include_once "admin/foot.php";
		die;
	}
	if (empty($category) || $category == "0") {
		echo "<font face=arial size=2>"._TEXTCATEGORYEMISSING."</font>";
		include_once "admin/foot.php";
		die;
	}
	if (empty($city) || $city == "") {
		echo "<font face=arial size=2>"._TEXTCITYMISSING."</font>";
		include_once "admin/foot.php";
		die;
	}
if (empty($year) || $year == "") {
echo "<font face=arial size=2>"._TEXTYEARMISSING."</font>";
include_once "admin/foot.php";
die;
}
$birth=($day.".".$month.".".$year);
$date = date( "d.m.Y" );
$time = time();
if ( !empty($_FILES['image']['name']) ) {
	$upload = new Upload();
	$upload->setAllowedMimeTypes(".gif|.jpg|.jpeg|.png");
	$upload->setUploadPath(XOOPS_ROOT_PATH."/modules/friendfinder/members/uploads");
	$upload->setDestinationFileName("image");
	$upload->setFileName($xoopsUser->uid());
	$result = $upload->doUpload();
	
	if ($result) {
		$pic = $upload->FileName.".".$upload->getFileExtension();
	} else {
		$errors = $upload->getUploadErrors();
		$errorstring = "";
		$errorstring .= "<strong>::Errors occured::</strong><br />\n";
		while(list($filename,$values) = each($errors)) {
			$errorstring .= "File: " . $filename . "<br />";
			$count = count($values);
			for($i=0; $i<$count; $i++) { $errorstring .= "==>" . $values[$i] . "<br />"; }
		}
		redirect_header("index.php", 3, $errorstring);
		exit();
	}
}
$sql = "INSERT INTO ".$db->prefix("friendfinder")." (id, sex, category, date, user, active, name, email, city, country, state, hobby, partner, height, weight, birth, pic, Description, imgname, imgtime) VALUES ('', '$sex', '$category', '$date','$user', '$active', '$name', '$email', '$city', '$country', '$state', '$hobby', '$partner', '$height', '$weight', '$birth', '$pic', '$comment', '$file1_name', '$time')";
$db->query($sql);
redirect_header("index.php",4,_TEXTADDSUCCESSFUL."");
  		
     	if ( !empty($bcoosConfig['new_user_notify_group']) ) {
				$xoopsMailer =& getMailer();
				$xoopsMailer->useMail();
				$xoopsMailer->setToGroups(new XoopsGroup($bcoosConfig['new_user_notify_group']));
				$xoopsMailer->setFromEmail($bcoosConfig['adminmail']);
				$xoopsMailer->setFromName($bcoosConfig['title']);
				$xoopsMailer->setSubject(sprintf(_US_NEWUSERREGAT));
				$xoopsMailer->setBody(sprintf(_US_HASJUSTREG));
				$xoopsMailer->send();
		
	} else {
	       	$xoopsMailer =& getMailer();
		$xoopsMailer->useMail();
		$xoopsMailer->setToEmail(new XoopsGroup($bcoosConfig['adminmail']));
		$xoopsMailer->setFromEmail($bcoosConfig['adminmail']);
		$xoopsMailer->setFromName($bcoosConfig['title']);
		$xoopsMailer->setSubject(sprintf(_US_NEWUSERREGAT));
		$xoopsMailer->setBody(sprintf(_US_HASJUSTREG));
		$xoopsMailer->send();
	}
} else {
    echo"
    <form action=add.php?page=add method=post enctype=multipart/form-data>
    <INPUT TYPE=hidden NAME=user SIZE=30 ";?>
    value=<?php if($xoopsUser) echo $xoopsUser->uname("E"); ?>>
 <?
   echo"<Input TYPE=hidden NAME=email SIZE=30 value="; if($xoopsUser) echo $xoopsUser->email("E");
   echo" ";
   echo"</td>";
   echo"     <INPUT TYPE=hidden name=MAX_FILE_SIZE value=".$imagesize.">
             <INPUT TYPE=hidden name=active value='1'>
             <table border=0 cellpadding=5 cellspacing=0 align=center width=550>
             <tr>
             <td>"._TEXTSEX."</td>
             <td>";
             list($numrows) = $db->fetchRow($db->query("select sid, sextitle from ".$db->prefix("friendfinder_sex").""));
             if ($numrows>0) {
	         $result = $db->query("select sid, sextitle from ".$db->prefix("friendfinder_sex")." order by sextitle");
	         echo "<select class=\"select\" name=\"sex\"><option value=\"0\">"._CLA_SELECTCAT."</option>";
	         while(list($sid, $sextitle) = $db->fetchRow($result)) {
	         echo "<option value=".$sid.">$sextitle</option>";
             }
             }
             echo" ></td>
             </tr>
             <TR>
             <TD WIDTH=150>"._TEXTREALNAME."</TD> ";
   echo"     <TD WIDTH=450><INPUT TYPE=text class=\"text\" NAME=name SIZE=30 value="; if($xoopsUser) echo $xoopsUser->name("E");
   echo"    > </TD>
             </TR>
             <tr>
             <TD WIDTH=150>"._TEXTCOUNTRY."</TD>
             <TD WIDTH=450>"._SELECTCOUNTRY."</TD>
             </TR>
             <TR>
             <TD WIDTH=150>"._TEXTREGION."</TD>
             <TD WIDTH=450>   ";
             list($numrows) = $db->fetchRow($db->query("select cid, title from ".$db->prefix("friendfinder_state").""));
	         if ($numrows>0) {
	         $result = $db->query("select cid, title from ".$db->prefix("friendfinder_state")." order by title");
	         echo "<select class=\"select\" name=\"state\"><option value=\"0\">"._CLA_SELECTCAT."</option>";
	         while(list($cid, $title) = $db->fetchRow($result)) {
	         echo "<option value=".$cid.">$title</option>";
             }
             }
	
   echo " </TD>
          </TR>
          <TR>
          <TD WIDTH=150>"._TEXTCITY."</TD>
          <TD WIDTH=450><INPUT TYPE=text class=\"text\" NAME=city SIZE=30 value=";  if($xoopsUser) echo $xoopsUser->user_from("E"); 
   echo" >
         </TD>
         </TR>
         <tr>
         <td>"._TEXTPSEX."</td>
         <td>";
             list($numrows) = $db->fetchRow($db->query("select sid, sextitle from ".$db->prefix("friendfinder_sex").""));
             if ($numrows>0) {
	         $result = $db->query("select sid, sextitle from ".$db->prefix("friendfinder_sex")." order by sextitle");
	         echo "<select class=\"select\" name=\"partner\"><option value=\"0\">"._CLA_SELECTCAT."</option>";
	         while(list($sid, $sextitle) = $db->fetchRow($result)) {
	         echo "<option value=".$sid.">$sextitle</option>";
             }
             }
             echo"</td>
         </tr>
         <tr>
         <TD WIDTH=150>"._CATEGORY.':'."</td>
         <TD WIDTH=450>";
             list($numrows) = $db->fetchRow($db->query("select catid, cattitle from ".$db->prefix("friendfinder_category").""));
             if ($numrows>0) {
	         $result = $db->query("select catid, cattitle from ".$db->prefix("friendfinder_category")." order by cattitle");
	         echo "<select class=\"select\" name=\"category\"><option value=\"0\">"._CLA_SELECTCAT."</option>";
	         while(list($catid, $cattitle) = $db->fetchRow($result)) {
	         echo "<option value=".$catid.">$cattitle</option>";
             }
             }
             echo"</td>
         </tr>
         <tr>
         <TD WIDTH=150>"._TEXTTANZ."</TD>
         <TD WIDTH=450>
         <TEXTAREA class='textarea' name=hobby rows=5 cols=50 wrap=VIRTUAL></TEXTAREA>
         </TD>
         </TR>
         <TR>
         <TD WIDTH=150><BR>"._TEXTDESCRIPTION."</TD>
         <TD WIDTH=450><br>  ";
         xoopsCodeTarea("comment");
  echo"  </TD>
         </TR>
         <TR>
         <TD WIDTH=150>"._TEXTHEIGHT."</TD>
         <TD WIDTH=450><INPUT TYPE=text class='text' NAME=height SIZE=30>
         ".$heightunit."
         </TD>
         </TR>
         <TR>
         <TD WIDTH=150>"._TEXTWEIGHT."</TD>
         <TD WIDTH=450><INPUT TYPE=text class='text' NAME=weight SIZE=30>
         ".$weightunit."
         </TD>
         </TR>
         <TR>
         <TD WIDTH=150>"._TEXTBIRTHDAY."</TD>
         <TD WIDTH=450>
          <select class='select' size=1 name=day>
          <option value=01>01</option>
          <option value=02>02</option>
          <option value=03>03</option>
          <option value=04>04</option>
          <option value=05>05</option>
          <option value=06>06</option>
          <option value=07>07</option>
          <option value=08>08</option>
          <option value=09>09</option>
          <option value=10>10</option>
          <option value=11>11</option>
          <option value=12>12</option>
          <option value=13>13</option>
          <option value=14>14</option>
          <option value=15>15</option>
          <option value=16>16</option>
          <option value=17>17</option>
          <option value=18>18</option>
          <option value=19>19</option>
          <option value=20>20</option>
          <option value=21>21</option>
          <option value=22>22</option>
          <option value=23>23</option>
          <option value=24>24</option>
          <option value=25>25</option>
          <option value=26>26</option>
          <option value=27>27</option>
          <option value=28>28</option>
          <option value=29>29</option>
          <option value=30>30</option>
          <option value=31>31</option>
          </select>
          <select class='select' size=1  name=month>
          <option value=01>01</option>
          <option value=02>02</option>
          <option value=03>03</option>
          <option value=04>04</option>
          <option value=05>05</option>
          <option value=06>06</option>
          <option value=07>07</option>
          <option value=08>08</option>
          <option value=09>09</option>
          <option value=10>10</option>
          <option value=11>11</option>
          <option value=12>12</option> </select>
          <INPUT TYPE=text class='text' NAME=year SIZE=4 MAXLENGTH=4>
          ".$textdateformat."
          </TD>
          </TR>
          <TR>
          <TD WIDTH=150>"._TEXTUPLOAD."</TD>
          <TD WIDTH=450>";
	  $upload = new Upload();
	  $upload->printFormField("image");
	  echo "</TD>
          </TR>
          <tr colspan=2>
          <td><input type=\"submit\" class=\"button\" value=\""._TEXTADDBUTTON."\">
          </table>
          </form> ";
}
 CloseTable();
include_once("../../footer.php");
}
?>
