function download_create_zipfile($file_id, $item_id, $file_name, $metadata)
{
    $file_handler =& xoonips_gethandler('xoonips', 'file');
    $file_path = $file_handler->getFilePath($file_id);
    if (!file_exists($file_path)) {
        // file not found
        return false;
    }
    // open metafile
    $dirutil =& xoonips_getutility('directory');
    $metafile_path = $dirutil->get_template('XooNIpsDownloadMetaFile');
    $metafile_fp = $dirutil->mkstemp($metafile_path);
    if ($metafile_fp === false) {
        // failed to create temporary file for metadata
        return false;
    }
    register_shutdown_function('download_unlink', $metafile_path);
    // write metafile
    $unicode =& xoonips_getutility('unicode');
    $metafile_body = '';
    foreach ($metadata as $key => $val) {
        $metafile_body .= $key;
        // convert dos and mac new line code to unix
        $val = str_replace("\r", "\n", str_replace("\r\n", "\n", $val));
        $ar = explode("\n", $val);
        $metafile_body .= ': ';
        if (count($ar) <= 1) {
            $metafile_body .= $val;
        } else {
            $metafile_body .= "\r\n  " . implode("\r\n  ", $ar);
        }
        $metafile_body .= "\r\n";
    }
    $metafile_body .= _MD_XOONIPS_ITEM_DETAIL_URL . ': ' . xnpGetItemDetailURL($item_id) . "\r\n";
    $metafile_body = $unicode->encode_utf8($metafile_body);
    fwrite($metafile_fp, $metafile_body);
    // close metafile
    fclose($metafile_fp);
    // open zipfile
    $zipfile_path = $dirutil->get_template('XooNIpsDownloadZipFile');
    $zipfile_fp = $dirutil->mkstemp($zipfile_path);
    if ($zipfile_fp === false) {
        // failed to create temporary file for zip
        return false;
    }
    register_shutdown_function('download_unlink', $zipfile_path);
    fclose($zipfile_fp);
    $ziputil =& xoonips_getutility('zip');
    if ($ziputil->open($zipfile_path) == false) {
        // failed to open zip file
        return false;
    }
    // write zipfile
    $ziputil->add($file_path, $file_name);
    $ziputil->add($metafile_path, 'metainfo.txt');
    // close zipfile
    $ziputil->close();
    return $zipfile_path;
}
 function _get_item_log()
 {
     $log = '';
     $item_type_handler =& xoonips_getormhandler('xoonips', 'item_type');
     foreach ($this->_params['import_items'] as $item) {
         $basic =& $item->getVar('basic');
         $itemtype =& $item_type_handler->get($basic->get('item_type_id'));
         $handler =& xoonips_gethandler($itemtype->get('name'), 'import_item');
         $log .= "\n\n[item]\n" . $handler->getImportLog($item);
         foreach ($item->getErrors() as $e) {
             $log .= "\nerror {$e}";
         }
         foreach (array_merge($item->getDuplicateUnupdatableItemId(), $item->getDuplicateUpdatableItemId(), $item->getDuplicateLockedItemId()) as $item_id) {
             $log .= "\nwarning conflict with " . xnpGetItemDetailURL($item_id);
         }
     }
     return $log;
 }
 function _get_item_urls()
 {
     $result = array();
     $log = '';
     $item_type_handler =& xoonips_getormhandler('xoonips', 'item_type');
     foreach ($this->_params['import_items'] as $item) {
         //skip this item if don't import as new and update
         if (!$item->getImportAsNewFlag() && !$item->getUpdateFlag()) {
             continue;
         }
         $handler =& xoonips_getormhandler('xoonips', 'item_basic');
         if ($item->getUpdateFlag()) {
             $basic =& $handler->get($item->getUpdateItemId());
         } else {
             $basic =& $item->getVar('basic');
         }
         $result[] = array('pseudo_id' => $item->getPseudoId(), 'url' => xnpGetItemDetailURL($basic->get('item_id')));
     }
     return $result;
 }
        $item_basic_handler =& xoonips_getormhandler('xoonips', 'item_basic');
        $index_handler =& xoonips_getormhandler('xoonips', 'index');
        $index_item_link_handler =& xoonips_getormhandler('xoonips', 'index_item_link');
        $index_item_links =& $index_item_link_handler->getObjects(new Criteria('item_id', $item_id));
        $certify_required = false;
        foreach ($index_item_links as $index_item_link) {
            if ($index_item_link->get('certify_state') == CERTIFY_REQUIRED) {
                $index_id = $index_item_link->get('index_id');
                $index = $index_handler->get($index_id);
                if ($index->get('open_level') == OL_PUBLIC || $index->get('open_level') == OL_GROUP_ONLY) {
                    $item_basic_handler->lockItemAndIndexes($item_id, $index_id);
                    $certify_required = true;
                }
            }
        }
        $detail_url = xnpGetItemDetailURL($item_id, $doi);
        if ($certify_required) {
            redirect_header($detail_url, 5, "Succeed\n<br />" . _MD_XOONIPS_ITEM_NEED_TO_BE_CERTIFIED);
        } else {
            redirect_header($detail_url, 3, "Succeed");
        }
    }
    exit;
} else {
    if (!$param_check_result) {
        if (function_exists($modname . "CorrectEditParameters")) {
            eval($modname . "CorrectEditParameters();");
        }
        $msg = "";
        eval("\$param_check_result = " . $modname . "CheckEditParameters( \$msg );");
        $system_message = $system_message . $msg;
    xoonips_delete_item($item_id);
}
if ($op == 'print') {
    require_once XOOPS_ROOT_PATH . '/class/template.php';
    $xoopsTpl = new XoopsTpl();
    xoops_header(false);
    $xoopsTpl->assign('meta_copyright', $myxoopsConfigMetaFooter['meta_copyright']);
    $xoopsTpl->assign('meta_author', $myxoopsConfigMetaFooter['meta_author']);
    $xoopsTpl->assign('sitename', $myxoopsConfig['sitename']);
    include_once XOOPS_ROOT_PATH . '/modules/' . $itemtype['viewphp'];
    eval("\$body = " . $modname . "GetPrinterFriendlyDetailBlock( \$item_id );");
    echo "</head><body onload='window.print();'>\n";
    $val = "";
    xnp_get_config_value('printer_friendly_header', $val);
    $xoopsTpl->assign('printer_friendly_header', $val);
    $xoopsTpl->assign('item_url', xnpGetItemDetailURL($item_id, $doi));
    $xoopsTpl->assign('body', $body);
    $xoopsTpl->display("db:xoonips_detail_print.html");
    xoops_footer();
    exit;
}
$xoopsOption['template_main'] = 'xoonips_detail.html';
include XOOPS_ROOT_PATH . '/header.php';
$item_lock_handler =& xoonips_getormhandler('xoonips', 'item_lock');
if ($item_lock_handler->isLocked($item_id)) {
    $xoopsTpl->assign('locked_message', sprintf(_MD_XOONIPS_WARNING_CANNOT_EDIT_LOCKED_ITEM, xoonips_get_lock_type_string($item_lock_handler->getLockType($item_id))));
} else {
    $xoopsTpl->assign('locked_message', false);
}
if ($item_compo_handler->getPerm($item_id, $uid, 'delete') && $op != 'print') {
    $xoopsTpl->assign('delete_button_visible', '1');
/**
 * return url of child items of a binder
 *
 * @param integer $item_id item id of binder
 * @reutrn array string of URL of child items
 */
function xnpbidner_get_child_item_urls($binder_item_id)
{
    include_once dirname(dirname(dirname(__FILE__))) . '/xoonips/include/lib.php';
    $binder_item_link_handler =& xoonips_getormhandler('xnpbinder', 'binder_item_link');
    $criteria = new Criteria('binder_id', $binder_item_id);
    $links =& $binder_item_link_handler->getObjects($criteria);
    if (!$links) {
        return array();
    }
    $result = array();
    foreach ($links as $child) {
        $basic_handler =& xoonips_getormhandler('xoonips', 'item_basic');
        $basic =& $basic_handler->get($child->get('item_id'));
        $doi = $basic->get('doi');
        $result[] = xnpGetItemDetailURL($basic->get('item_id'));
    }
    return $result;
}
function xnpGetBasicInformationMetadata($metadataPrefix, $item_id)
{
    $textutil =& xoonips_getutility('text');
    $xconfig_handler =& xoonips_getormhandler('xoonips', 'config');
    $myxoopsConfigMetaFooter =& xoonips_get_xoops_configs(XOOPS_CONF_METAFOOTER);
    $basic = array();
    xnp_get_item($_SESSION['XNPSID'], $item_id, $basic);
    $tmparray = array();
    if (xnp_get_item_types($tmparray) == RES_OK) {
        foreach ($tmparray as $i) {
            if ($i['item_type_id'] == $basic['item_type_id']) {
                $itemtype = $i;
                break;
            }
        }
    }
    $nijc_code = $xconfig_handler->getValue('repository_nijc_code');
    if ($basic['doi'] == "") {
        $identifier = $nijc_code . '/' . $basic['item_type_id'] . '.' . $basic['item_id'];
    } else {
        $identifier = $nijc_code . ':' . XNP_CONFIG_DOI_FIELD_PARAM_NAME . '/' . $basic['doi'];
    }
    if ($metadataPrefix == 'junii' || $metadataPrefix == 'junii2') {
        $lines = array();
        $publisher = $xconfig_handler->getValue('repository_publisher');
        $institution = $xconfig_handler->getValue('repository_institution');
        $meta_author = $myxoopsConfigMetaFooter['meta_author'];
        if (strcasecmp($publisher, 'meta_author') == 0) {
            $publisher = $meta_author;
        } else {
            if (strcasecmp($publisher, 'creator') == 0) {
                $publisher = _MD_XOONIPS_ITEM_CONTRIBUTOR_LABEL;
            } else {
                if (strcasecmp($publisher, 'none') == 0) {
                    $publisher = null;
                }
            }
        }
        if (strcasecmp($institution, 'meta_author') == 0) {
            $institution = $meta_author;
        } else {
            if (strcasecmp($institution, 'creator') == 0) {
                $institution = _MD_XOONIPS_ITEM_CONTRIBUTOR_LABEL;
            } else {
                if (strcasecmp($institution, 'none') == 0) {
                    $institution = null;
                }
            }
        }
        $lines[] = "<title>" . $textutil->xml_special_chars(reset($basic['titles'])) . "</title>";
        while (next($basic['titles'])) {
            $lines[] = "<title>" . $textutil->xml_special_chars(current($basic['titles'])) . "</title>";
        }
        $lines[] = "<identifier>" . $textutil->xml_special_chars($identifier) . "</identifier>";
        $lines[] = "<identifier xsi:type=\"URL\">" . $textutil->xml_special_chars(xnpGetItemDetailURL($basic['item_id'], $basic['doi'])) . "</identifier>";
        $lines[] = "<type>itemType:" . $textutil->xml_special_chars($itemtype['name']) . "</type>";
        $lines[] = "<language xsi:type=\"ISO639-2\">" . $textutil->xml_special_chars($basic['lang']) . "</language>";
        if ($institution != null) {
            $lines[] = "<institution>" . $textutil->xml_special_chars($institution) . "</institution>";
        }
        if ($publisher != null) {
            $lines[] = "<publisher>" . $textutil->xml_special_chars($publisher) . "</publisher>";
        }
        $subject = array();
        $index_ids = array();
        $res = xnp_get_index_id_by_item_id($_SESSION['XNPSID'], $item_id, $index_ids);
        if ($res == RES_OK) {
            foreach ($index_ids as $xid) {
                if ($xid > 0) {
                    $index = array();
                    $result = xnp_get_index($_SESSION['XNPSID'], $xid, $index);
                    if ($result == 0) {
                        $str = xnpGetIndexPathServerString($_SESSION['XNPSID'], $xid);
                        $subject[] = "{$str}";
                    }
                }
            }
        }
        if (!empty($basic['keywords'])) {
            $subject = array_merge($subject, $basic['keywords']);
        }
        $lines[] = "<subject>" . $textutil->xml_special_chars(implode(', ', $subject)) . "</subject>";
        $lines[] = "<description>comment:" . $textutil->xml_special_chars($basic['description']) . "</description>";
        return implode("\n", $lines);
    } else {
        if ($metadataPrefix == 'oai_dc') {
            /* title, identifier, type, language, subject, description */
            $lines = array();
            $publisher = $xconfig_handler->getValue('repository_publisher');
            $meta_author = $myxoopsConfigMetaFooter['meta_author'];
            if (strcasecmp($publisher, 'meta_author') == 0) {
                $publisher = $meta_author;
            } else {
                if (strcasecmp($publisher, 'creator') == 0) {
                    $publisher = _MD_XOONIPS_ITEM_CONTRIBUTOR_LABEL;
                } else {
                    if (strcasecmp($publisher, 'none') == 0) {
                        $publisher = null;
                    }
                }
            }
            $lines[] = "<dc:title>" . $textutil->xml_special_chars($basic['title']) . "</dc:title>";
            $lines[] = "<dc:identifier>" . $textutil->xml_special_chars($identifier) . "</dc:identifier>";
            $lines[] = "<dc:identifier>" . $textutil->xml_special_chars(xnpGetItemDetailURL($basic['item_id'], $basic['doi'])) . "</dc:identifier>";
            $lines[] = "<dc:type>itemType:" . $textutil->xml_special_chars($itemtype['name']) . "</dc:type>";
            $lines[] = "<dc:language>" . $textutil->xml_special_chars($basic['lang']) . "</dc:language>";
            if ($publisher != null) {
                $lines[] = "<dc:publisher>" . $textutil->xml_special_chars($publisher) . "</dc:publisher>";
            }
            $subject = array();
            $index_ids = array();
            $res = xnp_get_index_id_by_item_id($_SESSION['XNPSID'], $item_id, $index_ids);
            if ($res == RES_OK) {
                foreach ($index_ids as $xid) {
                    if ($xid > 0) {
                        $index = array();
                        $result = xnp_get_index($_SESSION['XNPSID'], $xid, $index);
                        if ($result == 0) {
                            $str = xnpGetIndexPathServerString($_SESSION['XNPSID'], $xid);
                            $subject[] = "{$str}";
                        }
                    }
                }
            }
            if (!empty($basic['keywords'])) {
                $subject = array_merge($subject, $basic['keywords']);
            }
            foreach ($subject as $str) {
                $lines[] = "<dc:subject>" . $textutil->xml_special_chars($str) . "</dc:subject>";
            }
            $lines[] = "<dc:description>comment:" . $textutil->xml_special_chars($basic['description']) . "</dc:description>";
            return implode("\n", $lines) . "\n";
        }
    }
    return false;
}