<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.9 www.exoops.info 2006/05
// $Id: registerform.php,v 1.8 2003/08/17 17:58:08 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
include_once(XOOPS_ROOT_PATH."/class/xoopslists.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsform/formselecttimezone.php");
// initialize form vars
$uname           = isset($_POST['uname'])           ? $myts->makeTboxData4PreviewInForm($_POST['uname']) : "";
$email           = isset($_POST['email'])           ? $myts->makeTboxData4PreviewInForm($_POST['email']) : "";
$user_viewemail  = isset($_POST['user_viewemail'])  ? $_POST['user_viewemail']                           : "";
$url             = isset($_POST['url'])             ? $myts->makeTboxData4PreviewInForm($_POST['url'])   : "";
$timezone_offset = isset($_POST['timezone_offset']) ? $_POST['timezone_offset']                          : "";
$user_avatar     = isset($_POST['user_avatar'])     ? $_POST['user_avatar']                              : "blank.gif";
$nickname_text = new XoopsFormText(_US_NICKNAME, "uname", 26, 25, $uname);
$email_tray   = new XoopsFormElementTray(_EMAIL, "<br />");
$email_text   = new XoopsFormText("", "email", 25, 60, $email);
$email_option = new XoopsFormCheckBox("", "user_viewemail", $user_viewemail);
$email_option->addOption(1, _US_ALLOWVIEWEMAIL);
$email_tray->addElement($email_text);
$email_tray->addElement($email_option);
$url_text = new XoopsFormText(_US_WEBSITE, "url", 26, 255, $url);
$selected = ($timezone_offset != "") ? $timezone_offset : $bcoosConfig['default_TZ'];
$timezone_select = new XoopsFormSelectTimezone(_US_TIMEZONE, "timezone_offset", $selected);
$avatar_select   = new XoopsFormSelect("", "user_avatar", $user_avatar);
$avatar_array    =& XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH."/images/avatar/");
$avatar_select->addOptionArray($avatar_array);
$a_dirlist      =& XoopsLists::getDirListAsArray(XOOPS_ROOT_PATH."/images/avatar/");
$a_dir_labels   = array();
$a_count        = 0;
$a_dir_link     = "<a href=\"javascript:openWithSelfMain('".XOOPS_URL."/misc.php?action=showpopups&amp;type=avatars&amp;start=".$a_count."','avatars',600,400);\">exoops</a>";
$a_count        = $a_count + count($avatar_array);
$a_dir_labels[] = new XoopsFormLabel("", $a_dir_link);
foreach ($a_dirlist as $a_dir) {
	if ( $a_dir == "users" ) {
		continue;
	}
	$avatars_array =& XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH."/images/avatar/".$a_dir."/", $a_dir."/");
	$avatar_select->addOptionArray($avatars_array);
	$a_dir_link     = "<a href=\"javascript:openWithSelfMain('".XOOPS_URL."/misc.php?action=showpopups&amp;type=avatars&amp;subdir=".$a_dir."&amp;start=".$a_count."','avatars',600,400);\">".$a_dir."</a>";
	$a_dir_labels[] = new XoopsFormLabel("", $a_dir_link);
	$a_count        = $a_count + count($avatars_array);
}
$avatar_select->setExtra("onchange='showImgSelected(\"avatar\", \"user_avatar\", \"images/avatar\")'");
$avatar_label = new XoopsFormLabel("", "<img src='images/avatar/blank.gif' name='avatar' id='avatar' alt='' />");
$avatar_tray  = new XoopsFormElementTray(_US_AVATAR, "&nbsp;");
$avatar_tray->addElement($avatar_select);
$avatar_tray->addElement($avatar_label);
foreach ($a_dir_labels as $a_dir_label) {
	$avatar_tray->addElement($a_dir_label);
}
$pwd_text      = new XoopsFormPassword(_US_PASSWORD  , "pass" , 26, 20);
$pwd_text2     = new XoopsFormPassword(_US_VERIFYPASS, "vpass", 26, 20);
$mailok_radio  = new XoopsFormRadioYN(_US_MAILOK, 'user_mailok', 1);
$img_verify    = 0;
if ( $bcoosConfig['img_verify'] && function_exists('imagecreate') ) {
	include_once(XOOPS_ROOT_PATH."/class/rc4.crypt.php");
	$checksum   = "verified";
	$pass       = strtoupper(makepass());
	$rc4        = new rc4_crypt();
	$rc4->key($pass);
	$rc4->crypt($checksum);
	$im         = imagecreatefrompng('images/verify.png');
	$text_color = imagecolorallocate($im, 50, 50, 50);
	imagestring($im, 5, 2, 2, $pass, $text_color);
	imagepng($im, "cache/verify.png");
	imagedestroy($im);
	$verify_crc  = new XoopsFormHidden("verify_crc", base64_encode($checksum));
	$verify_text = new XoopsFormText('&nbsp;<img src="cache/verify.png?'.time().'" /><br />', "verify_text", 12, 8);
	$verify_tray = new XoopsFormElementTray(_US_ENTERVERIF, " ");
	$verify_tray->addElement($verify_text);
	if (@file_exists("cache/verify.png")) {
		$img_verify = 1;
	}
}
$op_hidden     = new XoopsFormHidden("op", "newuser");
$submit_button = new XoopsFormButton("", "submit", _SUBMIT, "submit");
$reg_form      = new XoopsThemeForm(_US_USERREG, "userinfo", "register.php");
$reg_form->addElement($nickname_text);
$reg_form->addElement($email_tray);
$reg_form->addElement($url_text);
$reg_form->addElement($timezone_select);
$reg_form->addElement($avatar_tray);
$reg_form->addElement($pwd_text);
$reg_form->addElement($pwd_text2);
$reg_form->addElement($mailok_radio);
if ($img_verify == 1) {
	$reg_form->addElement($verify_tray);
	$reg_form->addElement($verify_crc);
	$required = array("uname", "email", "pass", "vpass", "verify_text");
	} else {
		$required = array("uname", "email", "pass", "vpass");
	}
$reg_form->addElement($op_hidden);
$reg_form->addElement($submit_button);
$reg_form->setRequired($required);
?>
