function xnppresentationGetConfirmBlock($item_id)
{
    $formdata =& xoonips_getutility('formdata');
    $creator_handler =& xoonips_getormhandler('xnppresentation', 'creator');
    $creator_objs =& $formdata->getObjectArray('post', $creator_handler->getTableName(), $creator_handler, false);
    // retrieve blocks of BasicInformation / Preview / index block
    $basic = xnpGetBasicInformationConfirmBlock($item_id);
    $preview = xnpGetPreviewConfirmBlock($item_id);
    $index = xnpGetIndexConfirmBlock($item_id);
    $presentation_file = xnpGetAttachmentConfirmBlock($item_id, 'presentation_file');
    $lengths = xnpGetColumnLengths('xnppresentation_item_detail');
    $readme = xnpGetTextFileConfirmBlock($item_id, 'readme', $lengths['readme']);
    $rights = xnpGetRightsConfirmBlock($item_id, $lengths['rights']);
    // retrieve detail information
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $detail = array('presentation_type' => array('value' => $formdata->getValue('post', 'presentation_type', 's', false)));
        xnpConfirmHtml($detail, 'xnppresentation_item_detail', array_keys($detail), _CHARSET);
        $types = xnppresentationGetTypes();
        $detail['presentation_type_str'] = array('value' => htmlspecialchars($types[$detail['presentation_type']['value']], ENT_QUOTES));
    } else {
        $detail = array();
    }
    // trim strings
    if (xnpHasWithout($basic) || xnpHasWithout($readme) || xnpHasWithout($rights) || xnpHasWithout($detail) || xnpHasWithout($preview) || xnpHasWithout($presentation_file) || xoonips_is_multiple_field_too_long($creator_objs, 'xnppresentation', 'creator')) {
        global $system_message;
        $system_message = $system_message . "\n<br /><font color='#ff0000'>" . _MD_XOONIPS_ITEM_WARNING_FIELD_TRIM . '</font><br />';
    }
    // 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', xnpGetDownloadLimitationOptionConfirmBlock('xnppresentation'));
    $tpl->assign('attachment_dl_notify', xnpGetDownloadNotificationOptionConfirmBlock('xnppresentation'));
    $tpl->assign('detail', $detail);
    $tpl->assign('readme', $readme);
    $tpl->assign('rights', $rights);
    $tpl->assign('xnppresentation_creator', xoonips_get_multiple_field_template_vars($creator_objs, 'xnppresentation', 'creator'));
    // return HTML content
    return $tpl->fetch('db:xnppresentation_confirm_block.html');
}
                 //echo "swap($updown_xid,$updown_xid2) result=$result";
                 if ($result != RES_OK) {
                     break;
                 }
             }
         }
     }
     header('Location: ' . XOOPS_URL . '/modules/xoonips/editindex.php?index_id=' . intval($xid));
 } else {
     if (($op == 'rename' || $op == 'delete' || $op == 'moveto') && isset($check)) {
         // check token ticket
         if (!$xoopsGTicket->check(true, 'xoonips_edit_index')) {
             exit;
         }
         $xoopsMailer =& getMailer();
         $lengths = xnpGetColumnLengths('xoonips_item_title');
         // error if checked index is locked.
         reset($check);
         while (list($key, $index_id) = each($check)) {
             xoonips_show_error_if_index_locked($index_id, $xid);
         }
         reset($check);
         while (list($key, $index_id) = each($check)) {
             $index_id = (int) $index_id;
             $index = array();
             $result = xnp_get_index($xnpsid, $index_id, $index);
             if ($result != RES_OK) {
                 redirect_header(XOOPS_URL . '/index.php', 3, "ERROR");
                 exit;
             }
             $oldPathString = xoonipsGetPathString($xnpsid, $index_id);
function xnpmodelGetConfirmBlock($item_id)
{
    $textutil =& xoonips_getutility('text');
    $formdata =& xoonips_getutility('formdata');
    $creator_handler =& xoonips_getormhandler('xnpmodel', 'creator');
    $creator_objs =& $formdata->getObjectArray('post', $creator_handler->getTableName(), $creator_handler, false);
    // retrive creator, model_type from GET/POST array
    foreach (array('model_type', 'creator', 'readme', 'rights') as $k) {
        $tmp = $formdata->getValue('both', $k, 's', false);
        if ($tmp !== NULL) {
            ${$k} = $tmp;
        } else {
            ${$k} = false;
        }
    }
    // get BasicInformation / Preview / index block
    $basic = xnpGetBasicInformationConfirmBlock($item_id);
    // TODO xnpConfirmHtml
    $model_types = xnpmodel_get_type_array();
    // reject if illegal model_type
    if (isset($model_types[$model_type])) {
        $detail['model_type'] = array('value' => $textutil->html_special_chars($model_type), 'display_value' => $textutil->html_special_chars($model_types[$model_type]));
    }
    $preview = xnpGetPreviewConfirmBlock($item_id);
    $attachment = xnpGetAttachmentConfirmBlock($item_id, 'model_data');
    $index = xnpGetIndexConfirmBlock($item_id);
    $lengths = xnpGetColumnLengths('xnpmodel_item_detail');
    $readme = xnpGetTextFileConfirmBlock($item_id, 'readme', $lengths['readme']);
    $rights = xnpGetRightsConfirmBlock($item_id, $lengths['rights']);
    if (xnpHasWithout($basic) || xnpHasWithout($readme) || xnpHasWithout($rights) || xnpHasWithout($detail) || xoonips_is_multiple_field_too_long($creator_objs, 'xnpmodel', 'creator')) {
        global $system_message;
        $system_message = $system_message . "\n" . '<br /><font color="#ff0000">' . _MD_XOONIPS_ITEM_WARNING_FIELD_TRIM . '</font><br />';
    }
    $detail['creator_str'] = array('value' => '');
    if (!empty($detail['creator'])) {
        $detail['creator_str']['value'] = "<table>\n";
        $creator = explode("\n", $detail['creator']['value']);
        $i = 0;
        foreach ($creator as $value) {
            $detail['creator_str']['value'] .= '<tr class="oddeven' . fmod($i, 2) . '"><td>' . $value . "</td></tr>\n";
            $i++;
        }
        $detail['creator_str']['value'] .= '</table>';
        $detail['creator_cnt'] = array('value' => strval(fmod(count($creator), 2)));
    }
    // 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', xnpGetDownloadLimitationOptionConfirmBlock('xnpmodel'));
    $tpl->assign('attachment_dl_notify', xnpGetDownloadNotificationOptionConfirmBlock('xnpmodel'));
    $tpl->assign('detail', $detail);
    $tpl->assign('readme', $readme);
    $tpl->assign('rights', $rights);
    $tpl->assign('model_type', $model_type);
    $tpl->assign('xnpmodel_creator', xoonips_get_multiple_field_template_vars($creator_objs, 'xnpmodel', 'creator'));
    // return as HTML
    return $tpl->fetch('db:xnpmodel_confirm_block.html');
}
function xnpsimulatorGetConfirmBlock($item_id)
{
    $textutil =& xoonips_getutility('text');
    $formdata =& xoonips_getutility('formdata');
    $developer_handler =& xoonips_getormhandler('xnpsimulator', 'developer');
    $developer_objs =& $formdata->getObjectArray('post', $developer_handler->getTableName(), $developer_handler, false);
    // retrive detail information
    $detail = array();
    $simulator_type = $formdata->getValue('post', 'simulator_type', 's', false);
    if ($simulator_type !== false) {
        $simulator_types = xnpsimulator_get_type_array();
        $detail['simulator_type'] = array('value' => $textutil->html_special_chars($simulator_type), 'display_value' => $textutil->html_special_chars($simulator_types[$simulator_type]));
    }
    // retrieve blocks of BasicInformation / Preview / index block
    $basic = xnpGetBasicInformationConfirmBlock($item_id);
    xnpConfirmHtml($detail, 'xnpsimulator_item_detail', array_keys($detail), _CHARSET);
    $preview = xnpGetPreviewConfirmBlock($item_id);
    $attachment = xnpGetAttachmentConfirmBlock($item_id, 'simulator_data');
    $index = xnpGetIndexConfirmBlock($item_id);
    $lengths = xnpGetColumnLengths('xnpsimulator_item_detail');
    $readme = xnpGetTextFileConfirmBlock($item_id, 'readme', $lengths['readme']);
    $rights = xnpGetRightsConfirmBlock($item_id, $lengths['rights']);
    if (xnpHasWithout($basic) || xnpHasWithout($detail) || xnpHasWithout($preview) || xnpHasWithout($attachment) || xnpHasWithout($readme) || xnpHasWithout($rights) || xoonips_is_multiple_field_too_long($developer_objs, 'xnpsimulator', 'developer')) {
        global $system_message;
        $system_message = $system_message . "\n<br /><font color='#ff0000'>" . _MD_XOONIPS_ITEM_WARNING_FIELD_TRIM . '</font><br />';
    }
    // 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', xnpGetDownloadLimitationOptionConfirmBlock('xnpsimulator'));
    $tpl->assign('attachment_dl_notify', xnpGetDownloadNotificationOptionConfirmBlock('xnpsimulator'));
    $tpl->assign('detail', $detail);
    $tpl->assign('readme', $readme);
    $tpl->assign('rights', $rights);
    if (isset($simulator_date)) {
        $tpl->assign('simulator_date', $simulator_date);
        if ($simulator_date['Date_Year']) {
            $tpl->assign('system_message', $tpl->get_template_vars('system_message') . '<br/><font color=\'#ff0000\'>' . _MD_XOONIPS_ITEM_TITLE_REQUIRED . '</font>');
        }
    }
    $tpl->assign('xnpsimulator_developer', xoonips_get_multiple_field_template_vars($developer_objs, 'xnpsimulator', 'developer'));
    // return HTML content
    return $tpl->fetch('db:xnpsimulator_confirm_block.html');
}
/**
 * Importing indexes to a index that is specified by $parent_index_id.
 * Associations of pseudo ID and Real index ID are sotred to $id_table.
 *
 * @param parent_index_id index_id that indexes is imported to.
 * @param $indexes array of index information to be imported.
 * $indexes = array(
 *                   array( 'titles' => array( TITLE1, TITLE2, ... )
 *                          'parent_id' => pseudo id of parent index
 *                          'item_id' => pseudo id of own index
 *                          'child' => array( [0] => array( 'titles' => ..., 'parent_id' => ..., 'child' => ....)
 *                                            [1] => array( same above ),
 *                                            ....
 *                           )
 *                         ),
 *                   array( 'titles' => array( TITLE1, TITLE2, ... )
 *                          same above ... ),
 *                   ...
 *                   );
 * @param id_table reference of associative array for output( [pseudo id] => [real index id] )
 * @return no return value.
 */
function _xoonips_import_index($parent_index_id, &$indexes, &$id_table)
{
    $xnpsid = $_SESSION['XNPSID'];
    $lengths = xnpGetColumnLengths('xoonips_item_title');
    $unicode =& xoonips_getutility('unicode');
    foreach ($indexes as $index) {
        foreach ($index['titles'] as $k => $title) {
            list($index['titles'][$k], $dummy) = xnpTrimString($unicode->decode_utf8($title, xoonips_get_server_charset(), 'h'), $lengths['title'], 'UTF-8');
        }
        $child = array();
        // numbers of same index name
        $cnt = 0;
        $index_id = 0;
        if (xnp_get_indexes($xnpsid, $parent_index_id, array(), $child) == RES_OK) {
            foreach ($child as $i) {
                $diff = array_diff($i['titles'], $index['titles']);
                if (empty($diff)) {
                    // true if $index have only same names of $i ( $i['titles'] == $index['titles'] )
                    $cnt++;
                    $index_id = $i['item_id'];
                }
            }
        }
        if ($cnt == 1) {
            $id_table[$index['index_id']] = $index_id;
        } else {
            $insert_index = array();
            $insert_index['titles'] = $index['titles'];
            $insert_index['parent_index_id'] = $parent_index_id;
            $result = xnp_insert_index($xnpsid, $insert_index, $index_id);
            if ($result != RES_OK) {
                break;
            }
            $id_table[$index['index_id']] = $index_id;
            // record event log
            $mydirname = basename(dirname(__DIR__));
            $event_handler =& xoonips_getormhandler('xoonips', 'event_log');
            $event_handler->recordInsertIndexEvent($index_id);
        }
        if (array_key_exists('child', $index)) {
            _xoonips_import_index($index_id, $index['child'], $id_table);
        }
    }
}
function xnpdataGetConfirmBlock($item_id)
{
    $formdata =& xoonips_getutility('formdata');
    $experimenter_handler =& xoonips_getormhandler('xnpdata', 'experimenter');
    $experimenter_objs =& $formdata->getObjectArray('post', $experimenter_handler->getTableName(), $experimenter_handler, false);
    $textutil =& xoonips_getutility('text');
    // get BasicInformation / Preview / index block
    $ar = array();
    $basic = xnpGetBasicInformationConfirmBlock($item_id);
    $preview = xnpGetPreviewConfirmBlock($item_id);
    $index = xnpGetIndexConfirmBlock($item_id);
    $data_file = xnpGetAttachmentConfirmBlock($item_id, 'data_file');
    $lengths = xnpGetColumnLengths('xnpdata_item_detail');
    $readme = xnpGetTextFileConfirmBlock($item_id, 'readme', $lengths['readme']);
    $rights = xnpGetRightsConfirmBlock($item_id, $lengths['rights']);
    $attachment_dl_limit = xnpGetDownloadLimitationOptionConfirmBlock('xnpdata');
    $attachment_dl_notify = xnpGetDownloadNotificationOptionConfirmBlock('xnpdata');
    // get DetailInformation
    $detail = array('data_type' => array('value' => $formdata->getValue('post', 'data_type', 's', false)));
    xnpConfirmHtml($detail, 'xnpdata_item_detail', array_keys($detail), _CHARSET);
    $types = xnpdataGetTypes();
    $detail['data_type_str'] = array('value' => $textutil->html_special_chars($types[$detail['data_type']['value']], ENT_QUOTES));
    if (xnpHasWithout($basic) || xnpHasWithout($readme) || xnpHasWithout($rights) || xnpHasWithout($detail) || xoonips_is_multiple_field_too_long($experimenter_objs, 'xnpdata', 'experimenter')) {
        global $system_message;
        $system_message = $system_message . "\n" . '<br /><font color="#ff0000">' . _MD_XOONIPS_ITEM_WARNING_FIELD_TRIM . '</font><br />';
    }
    // 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', $detail);
    $tpl->assign('readme', $readme);
    $tpl->assign('rights', $rights);
    $tpl->assign('xnpdata_experimenter', xoonips_get_multiple_field_template_vars($experimenter_objs, 'xnpdata', 'experimenter'));
    // return as HTML
    return $tpl->fetch('db:xnpdata_confirm_block.html');
}
/**
 * return template variables for 'xoonips_multiple_filed_confirm' template
 * @param XooNIpsTableObject[] orm to get template vars
 * @param string $field_name orm field name that is used as value to show.
 */
function xoonips_get_multiple_field_template_vars($ormObjects, $module, $name)
{
    $field_handler =& xoonips_getormhandler($module, $name);
    $lengths = xnpGetColumnLengths($field_handler->getTableName());
    $vars = array('table_name' => $field_handler->getTableName(), 'name' => array('primary_key' => $field_handler->getKeyName(), 'text' => $name, 'order' => $name . '_order'), 'objects' => array());
    foreach ($ormObjects as $orm) {
        list($within, $without) = xnpTrimString($orm->getVar($name, 's'), $lengths[$name], _CHARSET);
        $vars['objects'][] = array('primary_key' => array('name' => $field_handler->getKeyName(), 'value' => $orm->getVar($field_handler->getKeyName(), 's')), 'text' => array('name' => $name, 'within' => empty($within) ? '' : $within, 'without' => empty($without) ? '' : $without, 'value' => $orm->getVar($name, 's')), 'order' => array('name' => "{$name}_order", 'value' => $orm->get("{$name}_order")));
    }
    $vars['num'] = count($vars['objects']);
    return $vars;
}
/**
 * @param $assoc: 連想配列.
 *        array( column_name => array( 'value' => value ), ... )
 * @param $table_wo_prefix: prefixを除いたテーブル名
 * @param $names: チェックするカラム名.  array( 'readme', 'rights' ) など
 * $assoc に value, within, without, html_string を書く。
 *          array( column_name => array( 'value'=>value, 'within'=>within, 'without'=>without, 'html_string'=>html_string ), ... )
 */
function xnpConfirmHtml(&$assoc, $table_wo_prefix, $names = null, $enc = null)
{
    $textutil =& xoonips_getutility('text');
    $lengths = xnpGetColumnLengths($table_wo_prefix);
    if ($lengths == false) {
        return false;
    }
    foreach ($lengths as $name => $len) {
        //echo "xnpTrimColumn: name=$name len=$len type=$type <br />\n";
        if (isset($assoc[$name]) && (is_null($names) || in_array($name, $names))) {
            $assoc[$name]['html_string'] = $textutil->html_special_chars($assoc[$name]['value']);
            list($assoc[$name]['within'], $assoc[$name]['without']) = xnpTrimString($assoc[$name]['value'], $len, $enc);
            $assoc[$name]['value'] = xnpWithinWithoutHtml($assoc[$name]['within'], $assoc[$name]['without']);
        }
    }
}