<?php
if (!defined('_GNUBOARD_'))
  exit;

$character = get_character($member['ch_id']);
if ($is_member && ($member['mb_id'] != $character['mb_id'] || $member['ch_id'] == '' || !$character['ch_id'])) {
  $character_sql = "SELECT * FROM {$g5['character_table']} where mb_id = '{$member['mb_id']}' limit 0, 1";
  $character = sql_fetch($character_sql);
  if ($character['ch_id']) {
    sql_query("UPDATE {$g5['member_table']} SET ch_id = '{$character['ch_id']}' where mb_id = '{$member['mb_id']}'");
  }
}

if ($character['ch_id']) {
  if ($character['ch_search_date'] != G5_TIME_YMD) {
    $time = G5_TIME_YMD;
    sql_query("UPDATE {$g5['character_table']} 
                SET ch_search = 0,
                ch_search_date = '{$time}'
                WHERE ch_id = '{$character['ch_id']}'
    ");
    $character['ch_search'] = 0;
    $character['ch_search_date'] = G5_TIME_YMD;
  }
}

function get_character_name($ch_id)
{
  global $g5;
  $character = sql_fetch("SELECT ch_name FROM {$g5['character_table']} where ch_id = '{$ch_id}'");
  return $character['ch_name'];
}

function get_member_character_name($mb_id)
{
  global $g5;
  $character = sql_fetch("SELECT ch.ch_name FROM {$g5['character_table']} ch, {$g5['member_table']} mb where mb.mb_id= '{$mb_id}' and ch.mb_id = mb.mb_id");
  return $character['ch_name'];
}

function get_character_head($ch_id)
{
  global $g5;
  $ch = sql_fetch("SELECT ch_thumb FROM {$g5['character_table']} where ch_id = '{$ch_id}'");
  return $ch['ch_thumb'];
}

function get_member_name($mb_id)
{
  global $g5;
  $member = sql_fetch("SELECT mb_nick FROM {$g5['member_table']} where mb_id = '{$mb_id}'");
  return $member['mb_nick'];
}

function get_character($ch_id)
{
  global $g5;
  $character = sql_fetch("SELECT * FROM {$g5['character_table']} where ch_id = '{$ch_id}'");
  return $character;
}

function get_character_info($ch_id, $ar_code)
{
  global $g5;
  $ch = sql_fetch("SELECT av_value FROM {$g5['value_table']} where ch_id = '{$ch_id}' and ar_code = '{$ar_code}'");
  return $ch['av_value'];
}

function get_character_list($side = '', $class = '', $state = '승인')
{
  global $g5;
  $character = [];
  $sql_search = '';

  if ($side) {
    $sql_search .= " and ch_side = '{$side}' ";
  }

  if ($class) {
    $sql_search .= " and ch_class = '{$class}' ";
  }

  $sql_common = "SELECT * FROM {$g5['character_table']}
      WHERE ch_state = '{$state}'
        {$sql_search}
      ORDER BY ch_id ASC";
  $result = sql_query($sql_common);
  for ($i = 0; $row = sql_fetch_array($result); $i++) {
    $character[] = $row;
  }
  return $character;
}

function add_profile_article($theme, $code, $name, $type = 'text', $pice = '', $help = '', $order = '')
{
  global $g5;
}
