function xnppresentationGetEditBlock($item_id)
{
    global $xoopsDB;
    $myts =& MyTextsanitizer::getInstance();
    $formdata =& xoonips_getutility('formdata');
    // get DetailInformation
    $result = $xoopsDB->query('select * from ' . $xoopsDB->prefix('xnppresentation_item_detail') . " where presentation_id={$item_id}");
    foreach ($model = $xoopsDB->fetchArray($result) as $k => $v) {
        ${$k} = $v;
    }
    // overwrite DetailInformation with POST/GET variables
    foreach (array('presentation_type', 'creator', 'readme', 'rights') as $k) {
        if (array_key_exists($k, $_GET)) {
            ${$k} = $myts->stripSlashesGPC($_GET[$k]);
        } else {
            if (array_key_exists($k, $_POST)) {
                ${$k} = $myts->stripSlashesGPC($_POST[$k]);
            }
        }
    }
    // retrieve blocks of BasicInformation / Preview / index block
    $basic = xnpGetBasicInformationEditBlock($item_id);
    $preview = xnpGetPreviewEditBlock($item_id);
    $index = xnpGetIndexEditBlock($item_id);
    $presentation_file = xnpGetAttachmentEditBlock($item_id, 'presentation_file');
    // retrieve detail information
    if (!is_null($formdata->getValue('get', 'post_id', 's', false))) {
        $myts =& MyTextSanitizer::getInstance();
        $detail = array('presentation_type' => $formdata->getValue('post', 'presentation_type', 's', true), 'readme' => '', 'rights' => '', 'use_cc' => '', 'cc_commercial_use' => '', 'cc_modification' => '');
    } else {
        if (!empty($item_id)) {
            $detail = xnppresentationGetDetailInformation($item_id);
        } else {
            $detail = array();
        }
    }
    $readme = xnpGetTextFileEditBlock($item_id, 'readme', isset($detail['readme']) ? $detail['readme'] : '');
    $rights = xnpGetRightsEditBlock($item_id, $detail['use_cc'], $detail['rights'], $detail['cc_commercial_use'], $detail['cc_modification']);
    // assign to template
    global $xoopsTpl;
    $tpl = new XoopsTpl();
    $tpl->assign($xoopsTpl->get_template_vars());
    // variables assigned to xoopsTpl are copied to tpl
    $tpl->assign('basic', $basic);
    $tpl->assign('preview', $preview);
    $tpl->assign('index', $index);
    $tpl->assign('presentation_file', $presentation_file);
    $tpl->assign('attachment_dl_limit', xnpGetDownloadLimitationOptionEditBlock('xnppresentation', xnppresentationGetAttachmentDownloadLimitOption($item_id)));
    $tpl->assign('attachment_dl_notify', xnpGetDownloadNotificationOptionEditBlock('xnppresentation', xnppresentationGetAttachmentDownloadNotifyOption($item_id)));
    $tpl->assign('detail', $detail);
    $tpl->assign('readme', $readme);
    $tpl->assign('rights', $rights);
    $tpl->assign('presentation_type', xnppresentationGetTypes());
    $tpl->assign('presentation_type_selected', $detail['presentation_type']);
    if (!$formdata->getValue('get', 'post_id', 's', false)) {
        $detail_handler =& xoonips_getormhandler('xnppresentation', 'item_detail');
        $detail_orm =& $detail_handler->get($item_id);
        $tpl->assign('xnppresentation_creator', xoonips_get_multiple_field_template_vars($detail_orm->getCreators(), 'xnppresentation', 'creator'));
    } else {
        $tpl->assign('xnppresentation_creator', xoonips_get_multiple_field_template_vars(xoonips_get_orm_from_post('xnppresentation', 'creator'), 'xnppresentation', 'creator'));
    }
    // return HTML content
    return $tpl->fetch('db:xnppresentation_register_block.html');
}
function xnpbookGetEditBlock($item_id)
{
    $textutil =& xoonips_getutility('text');
    $formdata =& xoonips_getutility('formdata');
    // get BasicInformation / Preview / index block
    $basic = xnpGetBasicInformationEditBlock($item_id);
    $index = xnpGetIndexEditBlock($item_id);
    $attachment = xnpGetAttachmentEditBlock($item_id, 'book_pdf');
    // get DetailInformation
    $detail = xnpbookGetDetailInformation($item_id);
    // override values if post form request
    foreach (_xnpbook_get_detail_request(true) as $key => $val) {
        if ($val !== null) {
            $detail[$key]['value'] = $val;
        }
    }
    // html special chars for each value
    foreach ($detail as $key => $val) {
        $detail[$key]['value'] = $textutil->html_special_chars($detail[$key]['value']);
    }
    // check amazon access key and secret access key
    $mydirname = basename(dirname(dirname(__FILE__)));
    $mhandler =& xoops_gethandler('module');
    $module =& $mhandler->getByDirname($mydirname);
    $chandler =& xoops_gethandler('config');
    $mconfig = $chandler->getConfigsByCat(false, $module->mid());
    $amazon_key_exist = true;
    if (empty($mconfig['AccessKey']) || empty($mconfig['SecretAccessKey']) || empty($mconfig['AssociateTag'])) {
        $amazon_key_exist = false;
    }
    // set to template
    global $xoopsTpl;
    $tpl = new XoopsTpl();
    // copy variables in $xoopsTpl to $tpl
    $tpl->assign($xoopsTpl->get_template_vars());
    $tpl->assign('basic', $basic);
    $tpl->assign('index', $index);
    $tpl->assign('attachment', $attachment);
    $tpl->assign('attachment_dl_limit', xnpGetDownloadLimitationOptionEditBlock('xnpbook', xnpbookGetAttachmentDownloadLimitOption($item_id)));
    $tpl->assign('attachment_dl_notify', xnpGetDownloadNotificationOptionEditBlock('xnpbook', xnpbookGetAttachmentDownloadNotifyOption($item_id)));
    $tpl->assign('detail', $detail);
    $tpl->assign('system_message', $tpl->get_template_vars('system_message'));
    $tpl->assign('is_register', false);
    $tpl->assign('myurl', XOOPS_URL . '/modules/xoonips/edit.php');
    $formdata =& xoonips_getutility('formdata');
    if (!$formdata->getValue('get', 'post_id', 's', false)) {
        $detail_handler =& xoonips_getormhandler('xnpbook', 'item_detail');
        $detail_orm =& $detail_handler->get($item_id);
        $tpl->assign('xnpbook_author', xoonips_get_multiple_field_template_vars($detail_orm->getAuthors(), 'xnpbook', 'author'));
    } else {
        $tpl->assign('xnpbook_author', xoonips_get_multiple_field_template_vars(xoonips_get_orm_from_post('xnpbook', 'author'), 'xnpbook', 'author'));
    }
    $tpl->assign('amazon_key_exist', $amazon_key_exist);
    // return as HTML
    return $tpl->fetch('db:xnpbook_register_block.html');
}
function xnpmodelGetEditBlock($item_id)
{
    global $xoopsDB;
    $textutil =& xoonips_getutility('text');
    $formdata =& xoonips_getutility('formdata');
    // get DetailInformation
    $result = $xoopsDB->query('select * from ' . $xoopsDB->prefix('xnpmodel_item_detail') . " where model_id={$item_id}");
    foreach ($model = $xoopsDB->fetchArray($result) as $k => $v) {
        ${$k} = $v;
    }
    // overwrite DetailInformation with POST/GET variables
    foreach (array('model_type', 'readme', 'rights') as $k) {
        $tmp = $formdata->getValue('both', $k, 's', false);
        if ($tmp !== NULL) {
            ${$k} = $tmp;
        }
    }
    // get BasicInformation / Preview / index block
    $basic = xnpGetBasicInformationEditBlock($item_id);
    $model_types = xnpmodel_get_type_array();
    $detail = xnpmodelGetDetailInformation($item_id);
    $detail['model_type']['value'] = $model_type;
    $detail['model_type']['display_value'] = $model_types[$model_type];
    $detail['model_type']['select'] = $model_types;
    $preview = xnpGetPreviewEditBlock($item_id);
    $index = xnpGetIndexEditBlock($item_id);
    $attachment = xnpGetAttachmentEditBlock($item_id, 'model_data');
    $readme = xnpGetTextFileEditBlock($item_id, 'readme', $textutil->html_special_chars($readme));
    $rights = xnpGetRightsEditBlock($item_id, $detail['use_cc']['value'], $detail['rights']['value'], $detail['cc_commercial_use']['value'], $detail['cc_modification']['value']);
    // set to template
    global $xoopsTpl;
    $tpl = new XoopsTpl();
    // copy variables in $xoopsTpl to $tpl
    $tpl->assign($xoopsTpl->get_template_vars());
    $tpl->assign('basic', $basic);
    $tpl->assign('preview', $preview);
    $tpl->assign('index', $index);
    $tpl->assign('attachment', $attachment);
    $tpl->assign('attachment_dl_limit', xnpGetDownloadLimitationOptionEditBlock('xnpmodel', xnpmodelGetAttachmentDownloadLimitOption($item_id)));
    $tpl->assign('attachment_dl_notify', xnpGetDownloadNotificationOptionEditBlock('xnpmodel', xnpmodelGetAttachmentDownloadNotifyOption($item_id)));
    $tpl->assign('detail', $detail);
    $tpl->assign('readme', $readme);
    $tpl->assign('rights', $rights);
    if (!$formdata->getValue('get', 'post_id', 's', false)) {
        $detail_handler =& xoonips_getormhandler('xnpmodel', 'item_detail');
        $detail_orm =& $detail_handler->get($item_id);
        $tpl->assign('xnpmodel_creator', xoonips_get_multiple_field_template_vars($detail_orm->getCreators(), 'xnpmodel', 'creator'));
    } else {
        $tpl->assign('xnpmodel_creator', xoonips_get_multiple_field_template_vars(xoonips_get_orm_from_post('xnpmodel', 'creator'), 'xnpmodel', 'creator'));
    }
    // return as HTML
    return $tpl->fetch('db:xnpmodel_register_block.html');
}
function xnpconferenceGetEditBlock($item_id)
{
    $textutil =& xoonips_getutility('text');
    $formdata =& xoonips_getutility('formdata');
    // get BasicInformation / Preview / index block
    $basic = xnpGetBasicInformationEditBlock($item_id);
    $index = xnpGetIndexEditBlock($item_id);
    $presentation_file = xnpGetAttachmentEditBlock($item_id, 'conference_file');
    $conference_paper = xnpGetAttachmentEditBlock($item_id, 'conference_paper');
    // get DetailInformation
    $presentation_type = $formdata->getValue('post', 'presentation_type', 's', false);
    if (isset($presentation_type)) {
        $detail = array('presentation_type' => $presentation_type, 'conference_title' => $formdata->getValue('post', 'conference_title', 's', false), 'place' => $formdata->getValue('post', 'place', 's', false), 'abstract' => $formdata->getValue('post', 'abstract', 's', false), 'conference_from_year' => $formdata->getValue('post', 'conferenceFromYear', 'i', false), 'conference_from_month' => $formdata->getValue('post', 'conferenceFromMonth', 'i', false), 'conference_from_mday' => $formdata->getValue('post', 'conferenceFromDay', 'i', false), 'conference_to_year' => $formdata->getValue('post', 'conferenceToYear', 'i', false), 'conference_to_month' => $formdata->getValue('post', 'conferenceToMonth', 'i', false), 'conference_to_mday' => $formdata->getValue('post', 'conferenceToDay', 'i', false));
        foreach ($detail as $key => $val) {
            ${$key} = $val;
        }
    } else {
        if (!empty($item_id)) {
            $detail = xnpconferenceGetDetailInformation($item_id);
        } else {
            $detail = array();
        }
    }
    $basic2 = xnpGetBasicInformationDetailBlock($item_id);
    $tpl = new XoopsTpl();
    if (!empty($detail['conference_from_year'])) {
        $tpl->assign('gmtimeFrom', mktime(0, 0, 0, $detail['conference_from_month'], $detail['conference_from_mday'], $detail['conference_from_year']));
        $tpl->assign('gmtimeTo', mktime(0, 0, 0, $detail['conference_to_month'], $detail['conference_to_mday'], $detail['conference_to_year']));
    } else {
        $tpl->assign('gmtimeFrom', mktime(0, 0, 0, $basic2['publication_month']['value'], $basic2['publication_mday']['value'], $basic2['publication_year']['value']));
        $tpl->assign('gmtimeTo', mktime(0, 0, 0, $basic2['publication_month']['value'], $basic2['publication_mday']['value'], $basic2['publication_year']['value']));
    }
    $detail = array_map(array($textutil, 'html_special_chars'), $detail);
    $detail['conference_date'] = array('name' => _MD_XOONIPS_ITEM_PUBLICATION_DATE_LABEL, 'value' => $tpl->fetch('db:xnpconference_date.html'));
    $attachment_dl_limit = xnpGetDownloadLimitationOptionEditBlock('xnpconference', xnpconferenceGetAttachmentDownloadLimitOption($item_id));
    $attachment_dl_notify = xnpGetDownloadNotificationOptionEditBlock('xnpconference', xnpconferenceGetAttachmentDownloadNotifyOption($item_id));
    // set to template
    global $xoopsTpl;
    $tpl = new XoopsTpl();
    // copy variables in $xoopsTpl to $tpl
    $tpl->assign($xoopsTpl->get_template_vars());
    $tpl->assign('basic', $basic);
    $tpl->assign('index', $index);
    $tpl->assign('presentation_file', $presentation_file);
    $tpl->assign('conference_paper', $conference_paper);
    $tpl->assign('attachment_dl_limit', $attachment_dl_limit);
    $tpl->assign('attachment_dl_notify', $attachment_dl_notify);
    $tpl->assign('detail', $detail);
    $tpl->assign('conference_date', $detail['conference_date']);
    $formdata =& xoonips_getutility('formdata');
    if (!$formdata->getValue('get', 'post_id', 's', false)) {
        $detail_handler =& xoonips_getormhandler('xnpconference', 'item_detail');
        $detail_orm =& $detail_handler->get($item_id);
        $tpl->assign('xnpconference_author', xoonips_get_multiple_field_template_vars($detail_orm->getAuthors(), 'xnpconference', 'author'));
    } else {
        $tpl->assign('xnpconference_author', xoonips_get_multiple_field_template_vars(xoonips_get_orm_from_post('xnpconference', 'author'), 'xnpconference', 'author'));
    }
    $tpl->assign('presentation_type', xnpconferenceGetTypes());
    $tpl->assign('presentation_type_selected', $detail['presentation_type']);
    // return as HTML
    return $tpl->fetch('db:xnpconference_register_block.html');
}
function xnppaperGetEditBlock($item_id)
{
    global $xoopsDB;
    $formdata =& xoonips_getutility('formdata');
    $textutil =& xoonips_getutility('text');
    // retrieve blocks of BasicInformation / index
    $basic = xnpGetBasicInformationEditBlock($item_id);
    $index = xnpGetIndexEditBlock($item_id);
    $paper_pdf_reprint = xnpGetAttachmentEditBlock($item_id, 'paper_pdf_reprint');
    // retrieve DetailInformation
    $title = $formdata->getValue('post', 'title', 's', false);
    if (isset($title)) {
        $detail = _xnppaper_get_form_request();
    } else {
        if (!empty($item_id)) {
            $detail = xnppaperGetDetailInformation($item_id);
            $item = array();
            $result = xnp_get_item($_SESSION['XNPSID'], $item_id, $item);
        } else {
            $detail = array();
        }
    }
    foreach ($detail as $key => $val) {
        $detail[$key] = $textutil->html_special_chars($detail[$key]);
    }
    // assign to template
    global $xoopsTpl;
    $tpl = new XoopsTpl();
    $tpl->assign($xoopsTpl->get_template_vars());
    // variables assigned to xoopsTpl are copied to $tpl
    $tpl->assign('basic', $basic);
    $tpl->assign('index', $index);
    $tpl->assign('paper_pdf_reprint', $paper_pdf_reprint);
    $tpl->assign('detail', $detail);
    if (!$formdata->getValue('get', 'post_id', 's', false)) {
        $detail_handler =& xoonips_getormhandler('xnppaper', 'item_detail');
        $detail_orm =& $detail_handler->get($item_id);
        $tpl->assign('xnppaper_author', xoonips_get_multiple_field_template_vars($detail_orm->getAuthors(), 'xnppaper', 'author'));
    } else {
        $tpl->assign('xnppaper_author', xoonips_get_multiple_field_template_vars(xoonips_get_orm_from_post('xnppaper', 'author'), 'xnppaper', 'author'));
    }
    // for pubmed fillin
    $tpl->assign('is_register', false);
    $tpl->assign('myurl', XOOPS_URL . '/modules/xoonips/edit.php');
    // return HTML
    return $tpl->fetch('db:xnppaper_register_block.html');
}
function xnpsimulatorGetEditBlock($item_id)
{
    $formdata =& xoonips_getutility('formdata');
    // retrieve detail information
    $detail = xnpsimulatorGetDetailInformation($item_id);
    $simulator_types = xnpsimulator_get_type_array();
    $post_id = $formdata->getValue('get', 'post_id', 's', false);
    if (!is_null($post_id)) {
        $simulator_type = $formdata->getValue('post', 'simulator_type', 's', false);
        if ($simulator_type == false) {
            list($simulator_type) = each($simulator_types);
        }
        $detail['simulator_type'] = array('value' => $simulator_type, 'display_value' => $simulator_types[$simulator_type], 'select' => $simulator_types);
    }
    // retrieve blocks of BasicInformation / Preview / index block
    $basic = xnpGetBasicInformationEditBlock($item_id);
    $preview = xnpGetPreviewEditBlock($item_id);
    $index = xnpGetIndexEditBlock($item_id);
    $attachment = xnpGetAttachmentEditBlock($item_id, 'simulator_data');
    $readme = xnpGetTextFileEditBlock($item_id, 'readme', $detail['readme']['value']);
    $rights = xnpGetRightsEditBlock($item_id, $detail['use_cc']['value'], $detail['rights']['value'], $detail['cc_commercial_use']['value'], $detail['cc_modification']['value']);
    // assign to template
    global $xoopsTpl;
    $tpl = new XoopsTpl();
    // variables assigned to xoopsTpl are copied to tpl
    $tpl->assign($xoopsTpl->get_template_vars());
    $tpl->assign('basic', $basic);
    $tpl->assign('preview', $preview);
    $tpl->assign('index', $index);
    $tpl->assign('attachment', $attachment);
    $tpl->assign('attachment_dl_limit', xnpGetDownloadLimitationOptionEditBlock('xnpsimulator', xnpsimulatorGetAttachmentDownloadLimitOption($item_id)));
    $tpl->assign('attachment_dl_notify', xnpGetDownloadNotificationOptionEditBlock('xnpsimulator', xnpsimulatorGetAttachmentDownloadNotifyOption($item_id)));
    $tpl->assign('detail', $detail);
    $tpl->assign('readme', $readme);
    $tpl->assign('rights', $rights);
    if (!$formdata->getValue('get', 'post_id', 's', false)) {
        $detail_handler =& xoonips_getormhandler('xnpsimulator', 'item_detail');
        $detail_orm =& $detail_handler->get($item_id);
        $tpl->assign('xnpsimulator_developer', xoonips_get_multiple_field_template_vars($detail_orm->getDevelopers(), 'xnpsimulator', 'developer'));
    } else {
        $tpl->assign('xnpsimulator_developer', xoonips_get_multiple_field_template_vars(xoonips_get_orm_from_post('xnpsimulator', 'developer'), 'xnpsimulator', 'developer'));
    }
    // return HTML content
    return $tpl->fetch('db:xnpsimulator_register_block.html');
}
function xnpdataGetEditBlock($item_id)
{
    $textutil =& xoonips_getutility('text');
    $formdata =& xoonips_getutility('formdata');
    // get BasicInformation / Preview / index block
    $basic = xnpGetBasicInformationEditBlock($item_id);
    $preview = xnpGetPreviewEditBlock($item_id);
    $index = xnpGetIndexEditBlock($item_id);
    $data_file = xnpGetAttachmentEditBlock($item_id, 'data_file');
    // get DetailInformation
    $data_type = $formdata->getValue('post', 'data_type', 's', false);
    if (isset($data_type)) {
        $detail = array('data_type' => $data_type, 'readme' => '', 'rights' => '', 'use_cc' => '', 'cc_commercial_use' => '', 'cc_modification' => '');
    } else {
        if (!empty($item_id)) {
            $detail = xnpdataGetDetailInformation($item_id);
        } else {
            $detail = array();
        }
    }
    $readme = xnpGetTextFileEditBlock($item_id, 'readme', $detail['readme']);
    $rights = xnpGetRightsEditBlock($item_id, $detail['use_cc'], $detail['rights'], $detail['cc_commercial_use'], $detail['cc_modification']);
    $attachment_dl_limit = xnpGetDownloadLimitationOptionEditBlock('xnpdata', xnpdataGetAttachmentDownloadLimitOption($item_id));
    $attachment_dl_notify = xnpGetDownloadNotificationOptionEditBlock('xnpdata', xnpdataGetAttachmentDownloadNotifyOption($item_id));
    // set to template
    global $xoopsTpl;
    $tpl = new XoopsTpl();
    // copy variables in $xoopsTpl to $tpl
    $tpl->assign($xoopsTpl->get_template_vars());
    $tpl->assign('basic', $basic);
    $tpl->assign('preview', $preview);
    $tpl->assign('index', $index);
    $tpl->assign('attachment_dl_limit', $attachment_dl_limit);
    $tpl->assign('attachment_dl_notify', $attachment_dl_notify);
    $tpl->assign('data_file', $data_file);
    $tpl->assign('detail', array_map(array($textutil, 'html_special_chars'), $detail));
    $tpl->assign('readme', $readme);
    $tpl->assign('rights', $rights);
    $tpl->assign('data_type', xnpdataGetTypes());
    $tpl->assign('data_type_selected', $detail['data_type']);
    if (!$formdata->getValue('get', 'post_id', 's', false)) {
        $detail_handler =& xoonips_getormhandler('xnpdata', 'item_detail');
        $detail_orm =& $detail_handler->get($item_id);
        $tpl->assign('xnpdata_experimenter', xoonips_get_multiple_field_template_vars($detail_orm->getExperimenters(), 'xnpdata', 'experimenter'));
    } else {
        $tpl->assign('xnpdata_experimenter', xoonips_get_multiple_field_template_vars(xoonips_get_orm_from_post('xnpdata', 'experimenter'), 'xnpdata', 'experimenter'));
    }
    // return as HTML
    return $tpl->fetch('db:xnpdata_register_block.html');
}