<?php

  /*** 
   *  just for modifications of users outside the board administration
   *  especially for moderators
   ***/      

  $uid = intval($_REQUEST["uid"]);
  $this_user = forum_user($uid);
  
  if (!$this_user) {
  
    /************
     * initiate template and assign variables
     ************/         
    $QuickSkin = new QuickSkin("status_messages.html");
    $QuickSkin->assign("INFO",lang("usernotfound"));
    $content .= $QuickSkin->result();
    unset($QuickSkin);

  
  //mod like to edit other mod or admin
  } elseif (($is_mod && !$is_admin) && ($this_user->is_mod || $this_user->is_admin)) {
  
    /************
     * initiate template and assign variables
     ************/         
    $QuickSkin = new QuickSkin("status_messages.html");
    $QuickSkin->assign("INFO",lang("mods_mod_only_nonmods"));
    $content .= $QuickSkin->result();
    unset($QuickSkin);

  //admin like to edit other admin
  } elseif (!$is_board_admin && $this_user->is_admin) {

    /************
     * initiate template and assign variables
     ************/         
    $QuickSkin = new QuickSkin("status_messages.html");
    $QuickSkin->assign("INFO",lang("admins_mod_only_nonadmins"));
    $content .= $QuickSkin->result();
    unset($QuickSkin);
  } else {
  
    if (!$action) {
      $fuser = $this_user->user;
      $femail = $this_user->email;
      $fusermail = $this_user->usermail;
      $fforummail = $this_user->forummail;
      $fis_mod = $this_user->is_mod;
      $fis_admin = $this_user->is_admin;
      $fstatus = $this_user->status;
      if ($fis_admin) $userlevel = "is_admin";
      elseif ($fis_mod) $userlevel = "is_mod";
      else $userlevel = "is_default";
      $signature = $this_user->signature;
      $website = $this_user->website;
      $interests = $this_user->interests;
      $occupation = $this_user->occupation;
      $location = $this_user->location;
      $birthday = $this_user->birthday;
      $rank_id = $this_user->rank_id;
    }
    $age = $this_user->age;
    $fstatus_checked[intval($fstatus)] = "checked='checked'";
    $userlevel_checked[$userlevel] = "checked='checked'";
    
    if ($birthday && $birthday != "0000-00-00") {
      list ($by,$bm,$bd) = explode("-",$birthday);
      if (!$age) $by = "1900";
    }
    //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);

    //ranks
    if (!$userrank) {
      $NO_RANKS_DEFINED = lang("no_ranks_defined");
    } else {
      $TEMPLATE_FLAGS["USERRANKS"] = true;
      $rank_options = "<option value='0'>" . lang("no_rank") . "</option>\n";
      while (list($key, $val) = each($userrank)) {
        $rank_options .= "<option value='$key'>" . $val->descr . "</option>\n";
      }
    }
    $rank_options = str_replace("value='$rank_id'","value='$rank_id' selected='selected'",$rank_options);
    
    //Template Variables
    $HEADLINE = sprintf(lang("hl_edituser"), $this_user->user);
    
    $USER_ID = $uid;
    $USER_NAME = $this_user->user;
    $FORM_VAL_FUSER = he($fuser);
    $FORM_VAL_FEMAIL = $femail;
    $DESCR_PASS = lang("password");
    $DESCR_PASSCONF = lang("confpassword");    
    $DESCR_SETTINGS = lang("moresettings");
    $DESCR_FUSERMAIL = lang("acceptumails");
    $DESCR_FFORUMMAIL = lang("acceptbmails");
    $DESCR_MORESETTINGS = lang("morefunctions");
    $DESCR_DELUSER = lang("deluser");
    $DESCR_KEEPPOSTS = lang("keepposts");
    $DESCR_DELPOSTS = lang("delposts");
    $DESCR_SIGNATURE = lang("signature");
    $DESCR_AVATAR = lang("avatar");
    $DESCR_DELAVATAR = lang("delavatar");
    
    $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_USERRANK = lang("user_rank");
    $FORM_OPTIONS_RANK_ID = $rank_options;
    
    $DESCR_UPDATEUSER = lang("updateuser");
    
    $FORM_CHECKED_FFORUMMAIL = ($fforummail ? "checked='checked'" : "");
    $FORM_CHECKED_FUSERMAIL = ($fusermail ? "checked='checked'" : "");
    $FORM_CHECKED_STATON = $fstatus_checked[1];
    $FORM_CHECKED_STATOFF = $fstatus_checked[0];
    $FORM_CHECKED_LVLADM = $userlevel_checked["is_admin"];
    $FORM_CHECKED_LVLMOD = $userlevel_checked["is_mod"];
    $FORM_CHECKED_LVLDEF = $userlevel_checked["is_default"];
    
    $FORM_VAL_SIGNATURE = $signature;
    $IMG_AVATAR_SRC = ($this_user->avatar ? $conf_data_dir . "/" . $this_user->id . "/avatar/" . $this_user->avatar : "$rel_path/images/spacer.png");
    $FORM_CHECKED_DELAVATAR = ($delavatar ? "checked='checked'" : "");
    $FORM_VAL_AVATAR = $this_user->avatar;    
    
    $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);
    
    if (!$this_user->deleteable) {
      //user cannot be deleted, disable fields, hide deletingblock
      $FORM_DISABLE = "disabled='disabled'";
    } else {
      $TEMPLATE_FLAGS["DELETEABLE"] = true;
    }
    
      

  /************
   * initiate template and assign variables
     ************/     
   $edituseraccountVARS = array('HEADLINE' => $HEADLINE,
                                'USER_NOT_FOUND' => $USER_NOT_FOUND,
                                'DESCR_PASS' => $DESCR_PASS,
                                'DESCR_PASSCONF' => $DESCR_PASSCONF,
                                'DESCR_SETTINGS' => $DESCR_SETTINGS,
                                'DESCR_FUSERMAIL' => $DESCR_FUSERMAIL,
                                'DESCR_FFORUMMAIL' => $DESCR_FFORUMMAIL,
                                'DESCR_MORESETTINGS' => $DESCR_MORESETTINGS,
                                'DESCR_DELUSER' => $DESCR_DELUSER,
                                'DESCR_KEEPPOSTS' => $DESCR_KEEPPOSTS,
                                'DESCR_DELPOSTS' => $DESCR_DELPOSTS,
                                'DESCR_SIGNATURE' => $DESCR_SIGNATURE,
                                'DESCR_AVATAR' => $DESCR_AVATAR,
                                'DESCR_DELAVATAR' => $DESCR_DELAVATAR,
                                'DESCR_WEBSITE' => $DESCR_WEBSITE,
                                'DESCR_INTERESTS' => $DESCR_INTERESTS,
                                'DESCR_OCCUPATION' => $DESCR_OCCUPATION,
                                'DESCR_LOCATION' => $DESCR_LOCATION,
                                'DESCR_BIRTHDAY' => $DESCR_BIRTHDAY,
                                'DESCR_YEAR' => $DESCR_YEAR,
                                'DESCR_MONTH' => $DESCR_MONTH,
                                'DESCR_DAY' => $DESCR_DAY,
                                'DESCR_UPDATEUSER' => $DESCR_UPDATEUSER,
                                'FORM_OPTIONS_BD' => $FORM_OPTIONS_BD,
                                'FORM_OPTIONS_BM' => $FORM_OPTIONS_BM,
                                'FORM_VAL_BY' => $FORM_VAL_BY,
                                'FORM_VAL_WEBSITE' => $FORM_VAL_WEBSITE,
                                'FORM_VAL_INTERESTS' => $FORM_VAL_INTERESTS,
                                'FORM_VAL_OCCUPATION' => $FORM_VAL_OCCUPATION,
                                'FORM_VAL_LOCATION' => $FORM_VAL_LOCATION,
                                'NO_RANKS_DEFINED' => $NO_RANKS_DEFINED,
                                'DESCR_USERRANK' => $DESCR_USERRANK,
                                'FORM_OPTIONS_RANK_ID' => $FORM_OPTIONS_RANK_ID,
                                'USER_ID' => $USER_ID,
                                'USER_NAME' => $USER_NAME,
                                'FORM_VAL_FUSER' => $FORM_VAL_FUSER,
                                'FORM_VAL_FEMAIL' => $FORM_VAL_FEMAIL,
                                'FORM_CHECKED_FUSERMAIL' => $FORM_CHECKED_FUSERMAIL,
                                'FORM_CHECKED_FFORUMMAIL' => $FORM_CHECKED_FFORUMMAIL,
                                'FORM_CHECKED_STATON' => $FORM_CHECKED_STATON,
                                'FORM_CHECKED_STATOFF' => $FORM_CHECKED_STATOFF,
                                'FORM_DISABLE' => $FORM_DISABLE,
                                'FORM_CHECKED_LVLADM' => $FORM_CHECKED_LVLADM,
                                'FORM_CHECKED_LVLMOD' => $FORM_CHECKED_LVLMOD,
                                'FORM_CHECKED_LVLDEF' => $FORM_CHECKED_LVLDEF,
                                'FORM_VAL_SIGNATURE' => $FORM_VAL_SIGNATURE,
                                'FORM_CHECKED_DELAVATAR' => $FORM_CHECKED_DELAVATAR,
                                'IMG_AVATAR_SRC' => $IMG_AVATAR_SRC,
                                'FORM_VAL_AVATAR' => $FORM_VAL_AVATAR,
                                'DESCR_NICKNAME' => lang("nickname"),
                                'DESCR_EMAIL' => lang("email"),
                                'DESCR_STATUS' => lang("descr_status"),

                                'CONF' => $GLOBAL_TEMPLATE_VARS,
                                'FLAGS' => $TEMPLATE_FLAGS
          );
          $QuickSkin = new QuickSkin("edituseraccount.html");
          $QuickSkin->assign($edituseraccountVARS);
          $content .= $QuickSkin->result();
          unset($QuickSkin);

  } //user found and editable (else)
  
?>