<?php
  // used for registering and for profile selfediting
  if ($forum_user && (!$action)) {
    $fuser = $forum_user->user;
    $femail = $forum_user->email;
    $fusermail = $forum_user->usermail;
    $fforummail = $forum_user->forummail;
    $signature = $forum_user->signature;
    $website = $forum_user->website;
    $interests = $forum_user->interests;
    $occupation = $forum_user->occupation;
    $location = $forum_user->location;
    $birthday = $forum_user->birthday;
    $gravatar = $forum_user->gravatar;
  }
  
  //Template Variables
  $DESCR_PASS = lang("password");
  $DESCR_PASSCONF = lang("confpassword");
  $DESCR_SETTINGS = lang("moresettings");
  $DESCR_FUSERMAIL = lang("acceptumails");
  $DESCR_FFORUMMAIL = lang("acceptbmails");
  $DESCR_SIGNATURE = lang("signature");
  $DESCR_AVATAR = lang("avatar");
  $DESCR_SBBAVATAR = lang("sbbavatar");
  $DESCR_AVATARINFOS = sprintf(lang("avatar_dimensions"), $board_config->avatar_width, $board_config->avatar_height);
  $DESCR_SBBAVATARINFOS = lang("sbbavatar_infos");
  $DESCR_DELAVATAR = lang("delavatar");
  $DESCR_SBBAVATARGAL = lang("descr_avatargal");
  
  $DESCR_GRAVATAR = lang("descr_gravatar");
  $DESCR_EN_GRAVATAR = lang("descr_en_gravatar");
  
  $DESCR_WEBSITE = lang("website");
  $DESCR_INTERESTS = lang("interests");
  $DESCR_OCCUPATION = lang("occupation");
  $DESCR_LOCATION = lang("location");
  $DESCR_BIRTHDAY = lang("birthday");
  $DESCR_YEAR = lang("year");
  $DESCR_MONTH = lang("month");
  $DESCR_DAY = lang("day");
  
  $DESCR_NICKNAME = lang("nickname");
  $DESCR_LOGIN = lang("login");
  $FORGOTTEN_LINKING = sprintf(lang("login_forgotten"), "$main_script?todo=reset_password");
  
  
  if (!$forum_user) {
  
    if (!$board_config->en_registering) {
      $hide_blocks[] = "REGISTER";
    }
  
    //Template Variables
    $REGISTER_INTRO_TEXT = lang("join_intro") . "<br /><br />";
    $TABLE_HEADLINE = lang("createaccount");
    $DESCR_SUBMIT = lang("createaccount");
    

    if ($show_login && !$hide_login_form) {
      //if the login_form should be displayed on the registering page too

      //LOGIN-Template
      //Template Variables

      //initiate template and assign variables (login) - will be included on edit_account.html - template
      $tpl->load_file("login", "$template_path/login.html");
      if ($hide_blocks) $tpl->parse_hide('login', $hide_blocks);
      $LOGIN_FORM = $tpl->pget('login', array('CONF_MAINSCRIPT', 'CONF_RELPATH', 'CONF_LANG', 'CONF_TEMPLATE_PATH', 'CONF_FORUMTITLE',
        'DESCR_PASS', 'LOGIN_INTROTEXT', 'REGISTER_LINKING', 'FORM_VAL_FUSER'));
    
    }

  } else {
  
    //Template Variables
    $TABLE_HEADLINE = lang("editaccount");
    $DESCR_SUBMIT = lang("updateaccount");
  
    if ($birthday && $birthday != "0000-00-00") {
      list ($by,$bm,$bd) = explode("-",$birthday);
    }
    //months
    $month_options = "<option value=''>MM</option>\n";
    for ($i=1;$i<13;$i++) {
      $month_options .= "<option value='" . add0($i) . "'>" . add0($i) . "</option>\n";
    }
    //days
    $day_options = "<option value=''>DD</option>\n";
    for ($i=1;$i<32;$i++) {
      $day_options .= "<option value='" . add0($i) . "'>" . add0($i) . "</option>\n";
    }
    $bd_options = str_replace("value='$bd'","value='$bd' selected='selected'",$day_options);
    $bm_options = str_replace("value='$bm'","value='$bm' selected='selected'",$month_options);
    
    //SBB Avatars
    $avatars = avatars();
    if ($avatars) {
      $sbb_avcat_options = "<option value=''>" . lang("please_select") . "</option>\n";
      $cat_cnt = count($avatars);
      for ($i=0;$i<$cat_cnt;$i++) {
        $sbb_avcat_options .= "<option value='" . $avatars[$i]["cat"] . "'>" . $avatars[$i]["cat"] . "</option>\n";
      }
    } else {
      $hide_blocks[] = "SBBAVATARS";
    }
    
  }
  
  //The Form
  
  //Template Variables
  $FORM_VAL_FUSER = he($fuser);
  if ($forum_user) $FORM_DISABLED_FUSER = "disabled='disabled'";
  $FORM_VAL_FEMAIL = $femail;
  $FORM_CHECKED_FUSERMAIL = ($fusermail ? "checked='checked'" : "");
  $FORM_CHECKED_FFORUMMAIL = ($fforummail ? "checked='checked'" : "");
  
  $FORM_VAL_SIGNATURE = $signature;
  $IMG_AVATAR_SRC = ($forum_user->avatar ? $conf_data_dir . "/" . $forum_user->id . "/avatar/" . $forum_user->avatar : "$rel_path/images/spacer.png");
  $FORM_CHECKED_DELAVATAR = ($delavatar ? "checked='checked'" : "");
  
  $FORM_CHECKED_GRAVATAR = ($gravatar ? "checked='checked'" : "");
  
  $IMG_SBBAVATAR_SRC = ($forum_user->sbb_avatar ? "$rel_path/images/avatars/" . $forum_user->sbb_avatar : "$rel_path/images/spacer.png");  
  $IMG_SBBAVATAR_VAL = ($forum_user->sbb_avatar ? "$rel_path/images/avatars/" . $forum_user->sbb_avatar : "");  
  
  $FORM_OPTIONS_SBBAVCATS = $sbb_avcat_options;
    
  $FORM_VAL_WEBSITE = $website;
  $FORM_VAL_INTERESTS = $interests;
  $FORM_VAL_OCCUPATION = $occupation;
  $FORM_VAL_LOCATION = $location;
  $FORM_OPTIONS_BD = $bd_options;
  $FORM_OPTIONS_BM = $bm_options;
  $FORM_VAL_BY = ($by==1900||!$by?"YYYY":$by);  
  
  $IMG_RELOADTITLE = lang("reloadimage");
  
  $fusermail = $forum_user->usermail;
  $fforummail = $forum_user->forummail;

  //prevent from auto registering
  //only if use_captcha is enabled and user is about to register
  if (($todo == "register" || ($action && !$forum_user)) || (!$forum_user && !$board_config->en_guest_viewing)) { 
    if ($board_config->use_cap) {
      //Template Variables
      $DESCR_CAPTCHA = lang("captcha_descr");
      $DESCR_CAPTCHAINFOS = lang("captcha_info");
      $DESCR_CAPTCHACODE = lang("captcha_code");
      $FORM_VAL_SID = md5(uniqid(time()));
      
      
      if ($board_config->use_cap == 1) {  //GD CAPTCHA
        $hide_blocks[] = "CAP2";  //hiding non GD CAPTCHA
        $hide_blocks[] = "CAP3";  //hiding reCAPTCHA
      } elseif ($board_config->use_cap == 2) {  //GD less CAPTCHA
        $hide_blocks[] = "CAP1";  //hiding GD CAPTCHA
        $hide_blocks[] = "CAP3";  //hiding reCAPTCHA
      } elseif ($board_config->use_cap == 3) {  //reCAPTCHA
        $hide_blocks[] = "CAP1";  //hiding GD CAPTCHA
        $hide_blocks[] = "CAP2";  //hiding non GD CAPTCHA
        $hide_blocks[] = "CAPTCHACODENEEDED";  //hiding CAPTCHA code field

        $RECAPTCHA_OUTPUT = "<script type='text/javascript'>var RecaptchaOptions = {theme:'" . $board_config->recaptcha_style . "'};</script>";
        require_once('recaptchalib.php');
        $RECAPTCHA_OUTPUT .= recaptcha_get_html($board_config->recaptcha_pubkey);
      }
      
      
    } else {
      //hide captcha bock
      $hide_blocks[] = "CAPTCHA";
    }
  } else {
    //hide captcha bock
    $hide_blocks[] = "CAPTCHA";
  }
  //hide more setting while registering
  if (!$f_auth_uid) $hide_blocks[] = "MORESETTINGS";
  //hide avatar part if disabled
  if (!$board_config->en_avatar) $hide_blocks[] = "AVATARSETTINGS";
  //hide gravatar part if disabled
  if (!$board_config->en_gravatar) $hide_blocks[] = "GRAVATAR";
  

        /************
         * initiate template and assign variables
         ************/         
        $tpl->load_file("edit_account", "$template_path/edit_account.html");
        if ($hide_blocks) $tpl->parse_hide('edit_account', $hide_blocks);
        $content .= $tpl->pget('edit_account', array('CONF_MAINSCRIPT', 'CONF_RELPATH', 'CONF_LANG', 'CONF_TEMPLATE_PATH', 'CONF_FORUMTITLE', 'CONF_DATAPATH',
          'REGISTER_INTRO_TEXT', 'TABLE_HEADLINE', 'LOGIN_FORM', 'DESCR_PASS', 'DESCR_PASSCONF', 'DESCR_SETTINGS', 'DESCR_FUSERMAIL', 'DESCR_FFORUMMAIL', 'DESCR_SUBMIT', 'DESCR_CAPTCHA', 'DESCR_CAPTCHAINFOS', 'DESCR_CAPTCHACODE', 'DESCR_SIGNATURE', 'DESCR_AVATAR', 'DESCR_AVATARINFOS', 'DESCR_SBBAVATAR', 'DESCR_SBBAVATARINFOS', 'DESCR_DELAVATAR', 'IMG_RELOADTITLE',
          'DESCR_WEBSITE', 'DESCR_INTERESTS', 'DESCR_OCCUPATION', 'DESCR_LOCATION', 'DESCR_BIRTHDAY', 'DESCR_YEAR', 'DESCR_MONTH', 'DESCR_DAY', 'DESCR_SBBAVATARGAL',
          'DESCR_NICKNAME', 'DESCR_LOGIN', 'FORGOTTEN_LINKING', 'DESCR_GRAVATAR', 'DESCR_EN_GRAVATAR', 
          'FORM_OPTIONS_BD', 'FORM_OPTIONS_BM', 'FORM_VAL_BY', 'FORM_VAL_WEBSITE', 'FORM_VAL_INTERESTS', 'FORM_VAL_OCCUPATION', 'FORM_VAL_LOCATION', 'FORM_CHECKED_GRAVATAR', 'FORM_OPTIONS_SBBAVCATS', 'IMG_SBBAVATAR_VAL',
          'FORM_VAL_FUSER', 'FORM_VAL_FEMAIL' , 'FORM_CHECKED_FUSERMAIL', 'FORM_CHECKED_FFORUMMAIL', 'FORM_VAL_SID', 'FORM_VAL_SIGNATURE', 'FORM_CHECKED_DELAVATAR','IMG_AVATAR_SRC', 'IMG_SBBAVATAR_SRC', 'FORM_DISABLED_FUSER',
          'RECAPTCHA_OUTPUT'
          
          ));

      

?>