/**
 * 
 * private_item_storage_limit <= file size of all attachment files registered in private area(not public)
 * : return false.
 * 
 */
function check_private_item_storage_limit()
{
    $xnpsid = $_SESSION['XNPSID'];
    $uid = $_SESSION['xoopsUserId'];
    $account = array();
    if (xnp_get_account($xnpsid, $uid, $account) == RES_OK) {
        if (filesize_private() >= $account['item_storage_limit']) {
            return FALSE;
        }
    }
    return TRUE;
}
                redirect_header('certifyuser.php', 3, sprintf(_US_ACTVMAILNG, $user['uname']));
            }
            redirect_header(XOOPS_URL . '/modules/xoonips/certifyuser.php', 3, _MD_XOONIPS_MODERATOR_UNCERTIFY_SUCCESS);
            exit;
        }
    }
}
$xoopsTpl->assign('op', $op);
$xoopsOption['template_main'] = 'xoonips_certifyuser.html';
$users = array();
$uids = array();
if (xnp_dump_uids($xnpsid, array(), $uids) != 0) {
    redirect_header(XOOPS_URL . '/', 3, _MD_XOONIPS_MODERATOR_ERROR_SELECT_USER);
    exit;
}
if (count($uids) > 0) {
    foreach ($uids as $i) {
        $user = array();
        if (xnp_get_account($xnpsid, $i, $user) == 0) {
            if (@$user['activate'] != 1 && @$user['level'] != 0) {
                // list acitvated & uncertified users only
                $users[] = array('uid' => $user['uid'], 'uname' => $textutil->html_special_chars($user['uname']), 'name' => $textutil->html_special_chars($user['name']), 'email' => $textutil->html_special_chars($user['email']));
            }
        }
    }
    $xoopsTpl->assign('users', $users);
    // token ticket
    $token_ticket = $xoopsGTicket->getTicketHtml(__LINE__, 1800, 'xoonips_certify_user');
    $xoopsTpl->assign('token_ticket', $token_ticket);
}
require XOOPS_ROOT_PATH . '/footer.php';
include_once XOOPS_ROOT_PATH . '/modules/' . $item_type->get('viewphp');
$func = $item_type->get('name') . "GetRegisterBlock";
$body = $func();
$xoopsTpl->assign('body', $body);
if (isset($system_message)) {
    $xoopsTpl->assign("system_message", $system_message);
}
$xoonipsCheckedXID = $formdata->getValue('post', 'xoonipsCheckedXID', 's', false);
if (isset($xoonipsCheckedXID)) {
    $xoopsTpl->assign("index_checked_id", $xoonipsCheckedXID);
}
$xoopsTpl->assign('scrollX', $scrollX);
$xoopsTpl->assign('scrollY', $scrollY);
$xoopsTpl->assign("invalid_doi_message", sprintf(_MD_XOONIPS_ITEM_DOI_INVALID_ID, XNP_CONFIG_DOI_FIELD_PARAM_MAXLEN));
$account = array();
if (xnp_get_account($xnpsid, $uid, $account) == RES_OK) {
    $iids = array();
    if (xnp_get_private_item_id($xnpsid, $uid, $iids) == RES_OK) {
        $xoopsTpl->assign('num_of_items_current', count($iids));
    } else {
        $xoopsTpl->assign('num_of_items_current', 0);
    }
    $xoopsTpl->assign('num_of_items_max', $account['item_number_limit']);
    $xoopsTpl->assign('storage_of_items_max', sprintf("%.02lf", $account['item_storage_limit'] / 1000 / 1000));
    $xoopsTpl->assign('storage_of_items_current', sprintf("%.02lf", filesize_private() / 1000 / 1000));
}
// If the page is made by POST, $_POST is made to save somewhere and page redirects.
// rfc2616 10.3.4 303 See Other
if ($_SERVER["REQUEST_METHOD"] == 'POST') {
    $post_id = uniqid('postid');
    $_SESSION['post_id'] = array($post_id => serialize($_POST));
// check request
if (!in_array($op, array('open', 'register', 'up', 'down', 'rename', 'delete', 'moveto', 'add_to_public'))) {
    die('illegal reuest');
}
if ($op == 'up' || $op == 'down') {
    if ($updown_xid == 0 || !isset($steps[$updown_xid])) {
        die('illegal reuest');
    }
}
if ($op == 'moveto' && $moveto == 0) {
    die('illegal reuest');
}
// get current place
$uid = $xoopsUser->getVar('uid');
$account = array();
if (RES_OK == xnp_get_account($xnpsid, $uid, $account)) {
    $privateXID = $account['private_index_id'];
} else {
    // user has no PrivateIndex.
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
    exit;
}
// check requests
if ($xid == 0) {
    $xid = $privateXID;
}
if ($xid == 1) {
    die('illegal request');
}
// check the right to access.
$index = array();
/**
 *
 * function returns XML that is converted into Basic Information of items
 *
 * When item_id is unknown or error occurs in database, function returns NULL.
 *
 * @param fhdl file handle writes outputs
 * @param item item information to make XML
 * @param is_absolute  true:index tags are absolute path. false: index tags are relative path to base_index_id.
 * @param base_index_id  is_absolute == false && base_index_id == false: outputs only 1 empty index tag "<index></index>"
 *                       is_absolute == false && base_index_id != false: outputs only descendants of base_index_id
 *                       is_absolute == true: ignored
 * @return true:success, false:failure
 */
function xnpBasicInformation2XML($fhdl, $item, $is_absolute, $base_index_id = false)
{
    $myts =& MyTextSanitizer::getInstance();
    if (!$fhdl) {
        return false;
    }
    $xnpsid = $_SESSION['XNPSID'];
    $account = array();
    $res = xnp_get_account($xnpsid, $item['uid'], $account);
    if ($res != RES_OK) {
        return false;
    } else {
        $contributor = $account['name'] . "(" . $account['uname'] . ")";
    }
    $itemtypes = array();
    $res = xnp_get_item_types($itemtypes);
    if ($res != RES_OK) {
        return false;
    } else {
        foreach ($itemtypes as $i) {
            if ($i['item_type_id'] == $item['item_type_id']) {
                $itemtype = $i['name'];
                break;
            }
        }
    }
    if (!isset($itemtype)) {
        return false;
    }
    $last_update_date = gmdate('Y-m-d\\TH:i:s\\Z', $item['last_update_date']);
    $creation_date = gmdate('Y-m-d\\TH:i:s\\Z', $item['creation_date']);
    $index_id = array();
    $res = xnp_get_index_id_by_item_id($xnpsid, $item['item_id'], $index_id);
    if ($res != RES_OK) {
        return false;
    }
    //generate <title>xxx</title> for each title
    $titles = "";
    foreach ($item['titles'] as $title) {
        $titles .= '<title>' . $myts->htmlSpecialChars($title) . '</title>' . "\n";
    }
    $keywords = "";
    foreach ($item['keywords'] as $keyword) {
        $keywords .= '<keyword>' . $myts->htmlSpecialChars($keyword) . '</keyword>' . "\n";
    }
    if (!fwrite($fhdl, "<basic id=\"{$item['item_id']}\">\n" . "<itemtype>{$itemtype}</itemtype>\n" . "<titles>" . $titles . "</titles>\n" . "<contributor uname='" . $myts->htmlSpecialChars($account['uname']) . "'>" . $myts->htmlSpecialChars($contributor) . "</contributor>\n" . "<keywords>" . $keywords . "</keywords>\n" . "<description>" . $myts->htmlSpecialChars($item['description']) . "</description>\n" . "<doi>" . $myts->htmlSpecialChars($item['doi']) . "</doi>\n" . "<last_update_date>{$last_update_date}</last_update_date>\n" . "<creation_date>{$creation_date}</creation_date>\n" . "<publication_year>{$item['publication_year']}</publication_year>\n" . "<publication_month>{$item['publication_month']}</publication_month>\n" . "<publication_mday>{$item['publication_mday']}</publication_mday>\n" . "<lang>{$item['lang']}</lang>\n" . "<url>" . XOOPS_URL . "/modules/xoonips/detail.php?item_id={$item['item_id']}</url>\n")) {
        return false;
    }
    if (!xnpExportChangeLog($fhdl, $item['item_id'])) {
        return false;
    }
    $ar = array();
    $open_level_str = array(OL_PUBLIC => 'public', OL_GROUP_ONLY => 'group', OL_PRIVATE => 'private');
    if ($is_absolute) {
        $base_index_id = IID_ROOT;
        $head = '/';
    } else {
        $head = '';
    }
    if ($base_index_id) {
        foreach ($index_id as $i) {
            $str = xnpGetExportPathString($i, $base_index_id);
            if ($str === false) {
                continue;
            }
            $index = array();
            if (RES_OK != xnp_get_index($xnpsid, $i, $index)) {
                continue;
            }
            if (!fwrite($fhdl, "<index open_level='" . $open_level_str[$index['open_level']] . "'>" . $myts->htmlSpecialChars($head . $str) . "</index>\n")) {
                return false;
            }
        }
    } else {
        if (!fwrite($fhdl, "<index></index>\n")) {
            return false;
        }
    }
    if (!fwrite($fhdl, "</basic>\n")) {
        return false;
    }
    return true;
}