/**
  *
  * @brief return XoopsXmlRpcTag that has response of this request
  *
  * @return XoopsXmlRpcTag
  */
 function render()
 {
     $unicode =& xoonips_getutility('unicode');
     $index = $this->response->getSuccess();
     $struct = new XoopsXmlRpcStruct();
     $struct->add('id', new XoopsXmlRpcInt($index['id']));
     $struct->add('name', new XoopsXmlRpcString(htmlspecialchars($unicode->encode_utf8($index['name'], xoonips_get_server_charset()), ENT_QUOTES, 'UTF-8')));
     $struct->add('parent', new XoopsXmlRpcInt($index['parent']));
     $struct->add('open_level', new XoopsXmlRpcString(htmlspecialchars($unicode->encode_utf8($index['open_level'], xoonips_get_server_charset()), ENT_QUOTES, 'UTF-8')));
     $struct->add('path', new XoopsXmlRpcString(htmlspecialchars($unicode->encode_utf8($index['path'], xoonips_get_server_charset()), ENT_QUOTES, 'UTF-8')));
     return $struct;
 }
 /**
  *
  * @brief return XoopsXmlRpcTag that has response of this request
  *
  * @return XoopsXmlRpcTag
  */
 function render()
 {
     $metadata = $this->response->getSuccess();
     $resp = new XoopsXmlRpcStruct();
     $unicode =& xoonips_getutility('unicode');
     $resp->add('id', new XoopsXmlRpcInt($metadata['id']));
     $resp->add('filetype', new XoopsXmlRpcString($metadata['filetype']));
     $resp->add('originalname', new XoopsXmlRpcString(htmlspecialchars($unicode->encode_utf8($metadata['originalname'], xoonips_get_server_charset()), ENT_QUOTES, 'UTF-8')));
     $resp->add('size', new XoopsXmlRpcInt($metadata['size']));
     $resp->add('mimetype', new XoopsXmlRpcString($metadata['mimetype']));
     $resp->add('caption', new XoopsXmlRpcString(htmlspecialchars($unicode->encode_utf8($metadata['caption'], xoonips_get_server_charset()), ENT_QUOTES, 'UTF-8')));
     $resp->add('thumbnail', new XoopsXmlRpcBase64($metadata['thumbnail']));
     $resp->add('registration_date', new XoopsXmlRpcDatetime($metadata['registration_date']));
     $resp->add('last_modified_date', new XoopsXmlRpcDatetime($metadata['last_modified_date']));
     $resp->add('download_count', new XoopsXmlRpcInt($metadata['download_count']));
     $resp->add('download_count_sum', new XoopsXmlRpcInt($metadata['download_count_sum']));
     return $resp;
 }
 /**
  * load and execute xoonips logic.
  *
  * @param[in] XooNIpsXmlRpcRequest $request
  * @param[out] XooNIpsXmlRpcResponse $response
  *  result of logic(success/fault, response, error)
  */
 function execute(&$request, &$response)
 {
     // load logic instance
     $factory =& XooNIpsLogicFactory::getInstance();
     $logic =& $factory->create($request->getMethodName());
     if (!is_object($logic)) {
         $response->setResult(false);
         $error =& $response->getError();
         $logic = $request->getMethodName();
         $error->add(XNPERR_SERVER_ERROR, "can't create a logic of {$logic}");
         return;
     }
     // execute logic
     $params =& $request->getParams();
     $xoonips_response = new XooNIpsResponse();
     if (count($params) < 3) {
         $response->setResult(false);
         $error =& $response->getError();
         $error->add(XNPERR_MISSING_PARAM);
         return false;
     } else {
         if (count($params) > 3) {
             $response->setResult(false);
             $error =& $response->getError();
             $error->add(XNPERR_EXTRA_PARAM);
             return false;
         }
     }
     $vars = array();
     $vars[0] = $params[0];
     $unicode =& xoonips_getutility('unicode');
     $vars[1] = array();
     foreach ($params[1] as $key => $val) {
         $vars[1][$key] = $unicode->decode_utf8($val, xoonips_get_server_charset(), 'h');
     }
     $vars[2] = $params[2];
     $logic->execute($vars, $xoonips_response);
     //
     $response->setResult($xoonips_response->getResult());
     $response->setError($xoonips_response->getError());
     $response->setSuccess($xoonips_response->getSuccess());
 }
 /**
  * 
  * @param
  * @return void
  */
 function xmlEndElementHandler($parser, $name)
 {
     global $xoopsDB;
     $binder_item_links =& $this->_import_item->getVar('binder_item_links');
     $unicode =& xoonips_getutility('unicode');
     switch (implode('/', $this->_tag_stack)) {
         case "ITEM/DETAIL":
             if (count($binder_item_links) == 0) {
                 $this->_import_item->setErrors(E_XOONIPS_TAG_NOT_FOUND, " no binder_item_link" . $this->_get_parser_error_at());
             }
             break;
         case "ITEM/DETAIL/BINDER_ITEM_LINK":
             $handler =& xoonips_getormhandler('xnpbinder', 'binder_item_link');
             $link =& $handler->create();
             $link->set('item_id', intval($unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h')));
             $binder_item_links[] =& $link;
             break;
     }
     parent::xmlEndElementHandler($parser, $name);
 }
 function harvest()
 {
     global $xoopsDB;
     $handler =& xoonips_getormhandler('xoonips', 'oaipmh_repositories');
     $ts =& MyTextSanitizer::getInstance();
     $criteria = new Criteria('URL', $this->_baseUrl);
     $repository =& $handler->getObjects($criteria);
     if (!$repository) {
         return false;
     }
     $repository[0]->set('last_access_date', time());
     $repository[0]->set('last_access_result', null);
     if ($handler->insert($repository[0], true)) {
         if ($this->Identify()) {
             $unicode =& xoonips_getutility('unicode');
             $repository[0]->set('repository_name', $unicode->decode_utf8($this->_repositoryName, xoonips_get_server_charset(), 'h'));
             $handler->insert($repository[0], true);
             if ($this->ListMetadataFormats()) {
                 $args = array('metadataPrefix' => $this->_metadataPrefix);
                 if ('' == $repository[0]->get('last_success_date')) {
                     $args['from'] = gmdate($this->_dateFormat, $this->_earliestDatestamp);
                 } else {
                     $args['from'] = gmdate($this->_dateFormat, $repository[0]->get('last_success_date'));
                 }
                 if ($this->ListRecords($args)) {
                     //update repositories table
                     $repository[0]->set('last_access_result', $this->_lastStatus);
                     $repository[0]->set('last_success_date', time());
                     $repository[0]->set('metadata_count', $this->getMetadataCount($repository[0]->get('repository_id')));
                     return $handler->insert($repository[0], true);
                 }
             }
         }
     } else {
         $this->_lastError = $xoopsDB->error();
     }
     //update repositories table(last_access_result)
     $repository[0]->set('last_access_result', $this->_lastError);
     $handler->insert($repository[0], true);
     return false;
 }
 /**
  *
  * @brief return XoopsXmlRpcTag that has response of this request
  *
  * @return XoopsXmlRpcTag
  */
 function render()
 {
     $file = $this->response->getSuccess();
     $filetype_handler =& xoonips_getormhandler('xoonips', 'file_type');
     $filetype = $filetype_handler->get($file->get('file_type_id'));
     if (!$filetype) {
         return new XooNIpsXmlRpcFault(106, 'file_type not found: id=' . $file->get('file_type_id'));
     }
     if (!file_exists($file->getFilepath())) {
         return new XooNIpsXmlRpcFault(106, 'file not found: id=' . $file->get('file_type_id'));
     }
     $resp = new XoopsXmlRpcStruct();
     $resp->add('id', new XoopsXmlRpcInt($file->get('file_id')));
     $resp->add('filetype', new XoopsXmlRpcString($filetype->get('name')));
     $unicode =& xoonips_getutility('unicode');
     $resp->add('originalname', new XoopsXmlRpcString(htmlspecialchars($unicode->encode_utf8($file->get('original_file_name'), xoonips_get_server_charset()), ENT_QUOTES, 'UTF-8')));
     $resp->add('size', new XoopsXmlRpcInt($file->get('file_size')));
     $resp->add('mimetype', new XoopsXmlRpcString($file->get('mime_type')));
     $resp->add('caption', new XoopsXmlRpcString(htmlspecialchars($unicode->encode_utf8($file->get('caption'), xoonips_get_server_charset()), ENT_QUOTES, 'UTF-8')));
     $resp->add('thumbnail', new XoopsXmlRpcBase64($file->get('thumbnail_file')));
     $resp->add('data', new XoopsXmlRpcBase64(file_get_contents($file->getFilepath())));
     return $resp;
 }
 function getObject($array)
 {
     $obj = new XooNIpsOrmFile();
     //$file_handler=&xoonips_getormhandler('xoonips', 'file');
     //$obj=&$file_handler->create();
     //
     // filetype to file_type_id
     $file_type_handler =& xoonips_getormhandler('xoonips', 'file_type');
     $filetypes =& $file_type_handler->getObjects(new Criteria('name', $array['filetype']));
     if (!$filetypes || count($filetypes) != 1) {
         return false;
     }
     //
     //
     $unicode =& xoonips_getutility('unicode');
     $obj->assignVar('file_id', $array['id']);
     $obj->assignVar('file_type_id', $filetypes[0]->get('file_type_id'));
     $obj->assignVar('original_file_name', $unicode->decode_utf8($array['originalname'], xoonips_get_server_charset(), 'h'));
     $obj->assignVar('file_size', intval($array['size']));
     $obj->assignVar('mime_type', $array['mimetype']);
     $obj->assignVar('caption', $unicode->decode_utf8($array['caption'], xoonips_get_server_charset(), 'h'));
     $obj->assignVar('thumbnail_file', $array['thumbnail']);
     return $obj;
 }
 /**
  *
  * @brief return XoopsXmlRpcTag that has response of this request
  *
  * @return XoopsXmlRpcTag
  */
 function render()
 {
     $resp = new XoopsXmlRpcStruct();
     $itemtype = $this->response->getSuccess();
     $resp->add('id', new XoopsXmlRpcInt($itemtype->get('item_type_id')));
     $resp->add('name', new XoopsXmlRpcString($itemtype->get('name')));
     $resp->add('title', new XoopsXmlRpcString($itemtype->get('display_name')));
     $resp->add('description', new XoopsXmlRpcString($itemtype->getDescription()));
     $fields = new XoopsXmlRpcArray();
     $iteminfo = $itemtype->getIteminfo();
     // include language file of itemtype
     $langman =& xoonips_getutility('languagemanager');
     $modulename = $iteminfo['ormcompo']['module'];
     $langman->read('main.php', $modulename);
     $unicode =& xoonips_getutility('unicode');
     foreach ($iteminfo['io']['xmlrpc']['item'] as $i) {
         // data_type mapping
         switch ($i['xmlrpc']['type']) {
             case 'dateTime.iso8601':
                 $datatype = 'calendar';
                 break;
             case 'boolean':
                 $datatype = 'int';
                 break;
             default:
                 $datatype = $i['xmlrpc']['type'];
                 break;
         }
         $field = new XoopsXmlRpcStruct();
         $field->add('name', new XoopsXmlRpcString(implode('.', $i['xmlrpc']['field'])));
         $field->add('display_name', new XoopsXmlRpcString($unicode->encode_utf8(constant($i['xmlrpc']['display_name']), xoonips_get_server_charset())));
         $field->add('type', new XoopsXmlRpcString($datatype));
         if (isset($i['xmlrpc']['options'])) {
             $options = new XoopsXmlRpcArray();
             foreach ($i['xmlrpc']['options'] as $option_key => $option_val) {
                 $option = new XoopsXmlRpcStruct();
                 $option->add('option', new XoopsXmlRpcString($option_val['option']));
                 $option->add('display_name', new XoopsXmlRpcString($unicode->encode_utf8(constant($option_val['display_name']), xoonips_get_server_charset())));
                 $options->add($option);
                 unset($option);
             }
             $field->add('options', $options);
             unset($options);
         } else {
             $options = new XoopsXmlRpcArray();
             $field->add('options', $options);
             unset($options);
         }
         $field->add('required', new XoopsXmlRpcBoolean(isset($i['xmlrpc']['required']) ? $i['xmlrpc']['required'] : false));
         $field->add('multiple', new XoopsXmlRpcBoolean(isset($i['xmlrpc']['multiple']) ? $i['xmlrpc']['multiple'] : false));
         $field->add('readonly', new XoopsXmlRpcBoolean(isset($i['xmlrpc']['readonly']) ? $i['xmlrpc']['readonly'] : false));
         $fields->add($field);
         unset($field);
     }
     $resp->add('fields', $fields);
     if (strlen($itemtype->getMainFileName()) == 0) {
         $resp->add('mainfile', new XoopsXmlRpcString(''));
     } else {
         $iteminfo = $itemtype->getIteminfo();
         foreach ($iteminfo['io']['xmlrpc']['item'] as $f) {
             if ($f['orm']['field'][0]['orm'] == $itemtype->getMainFileName()) {
                 $resp->add('mainfile', new XoopsXmlRpcString(implode('.', $f['xmlrpc']['field'])));
                 break;
             }
         }
     }
     if (strlen($itemtype->getPreviewFileName()) == 0) {
         $resp->add('previewfile', new XoopsXmlRpcString(''));
     } else {
         $iteminfo = $itemtype->getIteminfo();
         foreach ($iteminfo['io']['xmlrpc']['item'] as $f) {
             if ($f['orm']['field'][0]['orm'] == $itemtype->getPreviewFileName()) {
                 $resp->add('previewfile', new XoopsXmlRpcString(implode('.', $f['xmlrpc']['field'])));
                 break;
             }
         }
     }
     return $resp;
 }
 /**
  * 
  * @param
  * @return void
  */
 function xmlEndElementHandler($parser, $name)
 {
     global $xoopsDB;
     $detail =& $this->_import_item->getVar('detail');
     $unicode =& xoonips_getutility('unicode');
     switch (implode('/', $this->_tag_stack)) {
         case "ITEM/DETAIL":
             foreach (array('editor', 'publisher', 'isbn', 'url') as $key) {
                 if (is_null($detail->get($key, 'n'))) {
                     $this->_import_item->setErrors(E_XOONIPS_TAG_NOT_FOUND, " no {$key}" . $this->_get_parser_error_at());
                 }
             }
             if (is_null($detail->get('attachment_dl_limit'))) {
                 if ($this->_detail_version == '1.00') {
                     //
                     // set zero to attachment_dl_limit
                     // if it is not declared in xml
                     //
                     $detail->set('attachment_dl_limit', 0);
                 } else {
                     $this->_import_item->setErrors(E_XOONIPS_TAG_NOT_FOUND, " no attachment_dl_limit tag " . $this->_get_parser_error_at());
                 }
             }
             if (is_null($detail->get('attachment_dl_notify'))) {
                 if ($this->_detail_version == '1.00' || $this->_detail_version == '1.01') {
                     $detail->set('attachment_dl_notify', 0);
                 } else {
                     $this->_import_item->setErrors(E_XOONIPS_TAG_NOT_FOUND, " no attachment_dl_notify tag " . $this->_get_parser_error_at());
                 }
             }
             break;
         case 'ITEM/DETAIL/AUTHOR':
             if ($this->_detail_version != '1.00' && $this->_detail_version != '1.01' && $this->_detail_version != '1.02') {
                 //<author> is only for 1.00, 1.01 and 1.02
                 break;
             }
             $cdata = $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h');
             if (trim($cdata) == '') {
                 break;
             }
             $author_handler =& xoonips_getormhandler('xnpbook', 'author');
             $authors =& $this->_import_item->getVar('author');
             $author =& $author_handler->create();
             $author->set('author', $cdata);
             $author->set('author_order', 0);
             $authors[0] = $author;
             break;
         case 'ITEM/DETAIL/AUTHORS/AUTHOR':
             if ($this->_detail_version != '1.03') {
                 break;
             }
             $cdata = $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h');
             if (trim($cdata) == '') {
                 break;
             }
             $authors =& $this->_import_item->getVar('author');
             $author_handler =& xoonips_getormhandler('xnpbook', 'author');
             $author =& $author_handler->create();
             $author->set('author', $cdata);
             $author->set('author_order', count($authors));
             $authors[] = $author;
             break;
         case "ITEM/DETAIL/EDITOR":
             $detail->set('editor', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'), true);
             break;
         case "ITEM/DETAIL/PUBLISHER":
             $detail->set('publisher', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'), true);
             break;
         case "ITEM/DETAIL/ISBN":
             $detail->set('isbn', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'), true);
             break;
         case "ITEM/DETAIL/URL":
             $detail->set('url', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'), true);
             break;
         case "ITEM/DETAIL/ATTACHMENT_DL_LIMIT":
             if ($this->_attachment_dl_limit_flag) {
                 $this->_import_item->setErrors(E_XOONIPS_TAG_REDUNDANT, "attachment_dl_limit is redundant" . $this->_get_parser_error_at());
             } else {
                 if (ctype_digit($this->_cdata)) {
                     $detail->set('attachment_dl_limit', intval($this->_cdata));
                     $this->_attachment_dl_limit_flag = true;
                 } else {
                     $this->_import_item->setErrors(E_XOONIPS_INVALID_VALUE, "invalid value(" . $this->_cdata . ") of attachment_dl_limit" . $this->_get_parser_error_at());
                 }
             }
             break;
         case "ITEM/DETAIL/ATTACHMENT_DL_NOTIFY":
             if ($this->_attachment_dl_notify_limit_flag) {
                 $this->_import_item->setErrors(E_XOONIPS_TAG_REDUNDANT, "attachment_dl_notify is redundant" . $this->_get_parser_error_at());
             } else {
                 if (ctype_digit($this->_cdata)) {
                     $detail->set('attachment_dl_notify', intval($this->_cdata));
                     $this->_attachment_dl_notify_limit_flag = true;
                 } else {
                     $this->_import_item->setErrors(E_XOONIPS_INVALID_VALUE, "invalid value(" . $this->_cdata . ") of attachment_dl_notify" . $this->_get_parser_error_at());
                 }
             }
             break;
         case "ITEM/DETAIL/FILE":
             $this->_book_pdf_file_flag = true;
             $file_handler =& xoonips_getormhandler('xoonips', 'file');
             if (!$file_handler->insert($this->_book_pdf_file)) {
                 $this->_import_item->setErrors(E_XOONIPS_DB_QUERY, "can't insert attachment file:" . $this->_book_pdf_file->get('original_file_name') . $this->_get_parser_error_at());
             }
             $this->_book_pdf_file = $file_handler->get($this->_book_pdf_file->get('file_id'));
             $this->_import_item->setVar('book_pdf', $this->_book_pdf_file);
             $this->_import_item->setHasBookPdf();
             break;
         case 'ITEM/DETAIL/FILE/CAPTION':
             $unicode =& xoonips_getutility('unicode');
             $this->_book_pdf_file->set('caption', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'));
             break;
         case 'ITEM/DETAIL/FILE/THUMBNAIL':
             $this->_book_pdf_file->set('thumbnail_file', base64_decode($this->_cdata));
             break;
     }
     parent::xmlEndElementHandler($parser, $name);
 }
示例#10
0
function xoonips_get_download_filename($file_id)
{
    $file_handler =& xoonips_getormhandler('xoonips', 'file');
    $file = $file_handler->get($file_id);
    if ($file == NULL) {
        return NULL;
    }
    $item_basic_handler =& xoonips_getormhandler('xoonips', 'item_basic');
    $item_basic = $item_basic_handler->get($file->get('item_id'));
    if ($item_basic == NULL) {
        return NULL;
    }
    $item_type_handler =& xoonips_getormhandler('xoonips', 'item_type');
    $item_type = $item_type_handler->get($item_basic->get('item_type_id'));
    if ($item_type == NULL) {
        return NULL;
    }
    $xconfig_handler =& xoonips_getormhandler('xoonips', 'config');
    $download_file_compression = $xconfig_handler->getValue('download_file_compression');
    if (is_null($download_file_compression)) {
        return NULL;
    }
    if ($download_file_compression == 'on') {
        return $item_type->get('display_name') . '_' . $file->get('file_id') . '.zip';
    } else {
        $unicode =& xoonips_getutility('unicode');
        return mb_decode_numericentity($unicode->encode_utf8($file->get('original_file_name'), xoonips_get_server_charset()), xoonips_get_conversion_map(), 'UTF-8');
    }
}
 /**
  * 
  * get index_id of given an array of index hierarchy
  * (ex: index_array2index_id <id of root index>, array( 'foo', 'bar' ),
  *  'group' ); you can get group index id of /foo/bar )
  * 
  * @param index_id parent index id
  * @param indexes array of index hierarchy
  * @param open_level open_level of index of target index
  *  (public|group|private)
  * @return index id or false if index is not found.
  * 
  */
 function index_array2index_id($index_id, $indexes, $open_level = 'private')
 {
     global $xoopsDB;
     switch ($open_level) {
         case 'public':
             $open_level_val = OL_PUBLIC;
             break;
         case 'group':
             $open_level_val = OL_GROUP_ONLY;
             break;
         case 'private':
         default:
             $open_level_val = OL_PRIVATE;
             break;
     }
     $unicode =& xoonips_getutility('unicode');
     $sql = "SELECT i.item_id FROM " . $xoopsDB->prefix("xoonips_item_basic") . " AS i, " . $xoopsDB->prefix("xoonips_item_title") . " AS t, " . $xoopsDB->prefix("xoonips_index") . " AS x " . "WHERE title_id = 0 AND x.parent_index_id = {$index_id}" . " AND x.index_id = t.item_id AND t.item_id = i.item_id" . " AND t.title = " . $xoopsDB->quoteString($unicode->decode_utf8(reset($indexes), xoonips_get_server_charset(), 'h')) . " AND open_level = {$open_level_val}";
     $result = $xoopsDB->query($sql);
     if (!$result) {
         return false;
     } else {
         if ($xoopsDB->getRowsNum($result) == 0) {
             return false;
         }
     }
     list($next_index_id) = $xoopsDB->fetchRow($result);
     array_shift($indexes);
     if (count($indexes) >= 1) {
         return $this->index_array2index_id($next_index_id, $indexes, $open_level);
     } else {
         return $next_index_id;
     }
 }
/**
 * 
 * convert file encoding
 * 
 * @param $infile input file path(any encoindg)
 * @param $outfile output file path(UTF-8)
 * @return bool true(succeed) or false(failed)
 * 
 */
function xoonips_convert_file_encoding_to_utf8($tmpfile, $filename)
{
    $fp_r = fopen($tmpfile, "r");
    $fp_w = fopen($filename, "w");
    if (!$fp_r || !$fp_w) {
        unlink($filename);
        if ($fp_r) {
            fclose($fp_r);
        }
        if ($fp_w) {
            fclose($fp_w);
        }
        return false;
    }
    while (!feof($fp_r)) {
        $unicode =& xoonips_getutility('unicode');
        fputs($fp_w, $unicode->encode_utf8(fgets($fp_r, 131072), xoonips_get_server_charset()));
    }
    fclose($fp_r);
    fclose($fp_w);
    return true;
}
function xoops_module_update_xnpbook($xoopsMod, $oldversion)
{
    global $xoopsDB;
    switch ($oldversion) {
        // remember that version is multiplied with 100 to get an integer
        case 100:
            // perform actions to upgrade from version 1.00
            //    global $xoopsDB;
            $sql = sprintf('ALTER TABLE %s ADD attachment_dl_limit int(1) unsigned default 0', $xoopsDB->prefix('xnpbook_item_detail'));
            $result = $xoopsDB->query($sql);
            if (!$result) {
                echo 'ERROR: ' . $xoopsDB->error();
                return false;
            }
            return true;
        case 101:
        case 102:
            // correction different encoding data in DB caused by no-converting ISBN information from 'UTF-8' to specified encoding at registration.
            if (_CHARSET != 'UTF-8') {
                $table1 = $xoopsDB->prefix('xnpbook_item_detail');
                $table2 = $xoopsDB->prefix('xoonips_item_basic');
                $items = array();
                $sql1 = "SELECT book_id, author, publisher FROM {$table1}";
                $result1 = $xoopsDB->query($sql1);
                if (!$result1) {
                    echo 'ERROR: ' . $xoopsDB->error();
                    return false;
                }
                $i = 0;
                while (list($book_id, $author, $publisher) = $xoopsDB->fetchRow($result1)) {
                    $unicode =& xoonips_getutility('unicode');
                    if (_CHARSET == 'EUC-JP') {
                        $author = $unicode->encode_utf8($author, xoonips_get_server_charset());
                        $publisher = $unicode->encode_utf8($publisher, xoonips_get_server_charset());
                    }
                    $author = $unicode->decode_utf8($author, xoonips_get_server_charset(), 'h');
                    $author = addslashes($author);
                    $publisher = $unicode->decode_utf8($publisher, xoonips_get_server_charset(), 'h');
                    $publisher = addslashes($publisher);
                    $sql2 = "SELECT title FROM {$table2} where item_id={$book_id}";
                    $result2 = $xoopsDB->query($sql2);
                    if (!$result2) {
                        echo 'ERROR: ' . $xoopsDB->error();
                        return false;
                    }
                    list($title) = $xoopsDB->fetchRow($result2);
                    if (_CHARSET == 'EUC-JP') {
                        $title = $unicode->encode_utf8($title, xoonips_get_server_charset());
                    }
                    $title = $unicode->decode_utf8($title, xoonips_get_server_charset(), 'h');
                    $title = addslashes($title);
                    $sql3 = "UPDATE {$table2} SET title='{$title}' where item_id={$book_id}";
                    $result3 = $xoopsDB->query($sql3);
                    if (!$result3) {
                        echo 'ERROR: ' . $xoopsDB->error();
                        return false;
                    }
                    $sql4 = "UPDATE {$table1} SET author='{$author}', publisher='{$publisher}' where book_id={$book_id}";
                    $result4 = $xoopsDB->query($sql4);
                    if (!$result4) {
                        echo 'ERROR: ' . $xoopsDB->error();
                        return false;
                    }
                }
            }
        case 110:
            // 110->111: author varchar -> text
            $result = $xoopsDB->query('ALTER TABLE ' . $xoopsDB->prefix('xnpbook_item_detail') . ' CHANGE COLUMN author author TEXT NOT NULL');
            if (!$result) {
                echo 'ERROR: ' . $xoopsDB->error();
                return false;
            }
        case 111:
        case 200:
        case 300:
        case 310:
            $sql = 'ALTER TABLE ' . $xoopsDB->prefix('xnpbook_item_detail') . ' TYPE = innodb';
            $result = $xoopsDB->query($sql);
            if (!$result) {
                echo 'ERROR: line=' . __LINE__ . " sql={$sql} " . $xoopsDB->error();
            }
        case 311:
            $sql = 'ALTER TABLE ' . $xoopsDB->prefix('xnpbook_item_detail') . ' ADD COLUMN attachment_dl_notify int(1) unsigned default 0 ';
            $result = $xoopsDB->query($sql);
            if (!$result) {
                echo 'ERROR: line=' . __LINE__ . " sql={$sql} " . $xoopsDB->error();
            }
        case 330:
        case 331:
        case 332:
        case 333:
        case 334:
        case 335:
        case 336:
        case 337:
        case 338:
        case 339:
            // support for ISBN13
            $sql = sprintf('ALTER TABLE `%s` MODIFY `isbn` char(13) default NULL', $xoopsDB->prefix('xnpbook_item_detail'));
            $result = $xoopsDB->query($sql);
            if (!$result) {
                echo 'ERROR: line=' . __LINE__ . " sql={$sql} " . $xoopsDB->error();
            }
            // support authors
            $key_name = 'book_id';
            $table_detail = 'xnpbook_item_detail';
            $table_author = 'xnpbook_author';
            $sql = 'CREATE TABLE ' . $xoopsDB->prefix($table_author) . ' (';
            $sql .= '`book_author_id` int(10) unsigned NOT NULL auto_increment,';
            $sql .= '`book_id` int(10) unsigned NOT NULL,';
            $sql .= '`author` varchar(255) NOT NULL,';
            $sql .= '`author_order` int(10) unsigned NOT NULL default \'0\',';
            $sql .= '  PRIMARY KEY  (`book_author_id`)';
            $sql .= ') TYPE=InnoDB';
            $result = $xoopsDB->query($sql);
            if (!$result) {
                echo '&nbsp;&nbsp;' . $xoopsDB->error() . '<br />';
                return false;
            }
            $result = $xoopsDB->query('select ' . $key_name . ',author from ' . $xoopsDB->prefix($table_detail) . ' where author!=\'\'');
            while (list($id, $author) = $xoopsDB->fetchRow($result)) {
                $author_array = array_map('trim', explode(',', $author));
                $i = 0;
                foreach ($author_array as $author) {
                    if (empty($author)) {
                        continue;
                    }
                    $sql = 'insert into ' . $xoopsDB->prefix($table_author);
                    $sql .= '(' . $key_name . ',author,author_order) values (';
                    $sql .= $id . ',' . $xoopsDB->quoteString($author) . ',' . $i . ')';
                    if ($xoopsDB->queryF($sql) == false) {
                        echo '&nbsp;&nbsp;' . $xoopsDB->error() . '<br />';
                        return false;
                    }
                    $i++;
                }
            }
            $sql = 'ALTER TABLE ' . $xoopsDB->prefix($table_detail) . ' DROP COLUMN `author`';
            $result = $xoopsDB->query($sql);
            if (!$result) {
                echo '&nbsp;&nbsp;' . $xoopsDB->error() . '<br />';
                return false;
            }
        case 340:
        case 341:
        case 342:
        case 343:
        case 344:
        case 345:
        case 346:
            // drop year field from datail table
            $sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnpbook_item_detail') . '` DROP COLUMN `year`';
            $result = $xoopsDB->query($sql);
            if (!$result) {
                echo '&nbsp;&nbsp;' . $xoopsDB->error() . '<br />';
                return false;
            }
        case 347:
        default:
    }
    return true;
}
    /**
     * 
     * @param $uploadfile string import file path
     * @pram $error_check_only string 'on' or else
     * 
     */
    function _read_index_tree($uploadfile, $error_check_only, $import_index_ids = array())
    {
        global $xoopsDB, $xoopsConfig, $xoopsUser, $xoopsLogger, $xoopsUserIsAdmin;
        //
        // Import index tree if uploaded file has index.xml.
        // In this case, other files are ignored.
        //
        $unzip =& xoonips_getutility('unzip');
        if (!$unzip->open($uploadfile)) {
            redirect_header('import.php?action=default', 3, _MD_XOONIPS_IMPORT_FILE_NOT_FOUND);
            exit;
        }
        $fnames = $unzip->get_file_list();
        foreach ($fnames as $fname) {
            if (strtolower($fname) != 'index.xml') {
                continue;
            }
            //
            // start transaction
            //
            $xoopsDB->query('START TRANSACTION');
            //
            // check index tree structures
            // and show the structures
            //
            $xml = $unzip->get_data($fname);
            $indexes = array();
            xnpImportIndexCheck($xml, $indexes);
            // To construct tree structure from given indexes by $indexes
            $c2p = array();
            //associative array (child ID -> parent ID)
            $p2c = array();
            //associative array (parent ID -> array of child ID)
            $index_by_id = array();
            // $index_by_id[ index_id ] => index array;
            foreach ($indexes as $i) {
                if (empty($i)) {
                    continue;
                }
                $c2p[$i['index_id']] = $i['parent_id'];
                if (!isset($p2c[$i['parent_id']])) {
                    $p2c[$i['parent_id']] = array();
                }
                $p2c[$i['parent_id']][] = $i['index_id'];
                $index_by_id[$i['index_id']] = $i;
            }
            $str_indexes = '';
            $error = false;
            //true if cyclic reference
            foreach ($index_by_id as $index_id => $index) {
                if ($index['index_id'] == $index['parent_id']) {
                    //
                    // cyclic reference detected( refers itself )
                    //
                    $error = true;
                    continue;
                }
                if (isset($p2c[$index['index_id']])) {
                    continue;
                }
                //index_id already visited(to detect cyclic reference)
                $visited = array($index['index_id']);
                // $index is not parent of all indexes
                $path = array();
                array_push($path, $index['titles'][0]);
                while (isset($index_by_id[$index['parent_id']])) {
                    $parent = $index_by_id[$index['parent_id']];
                    if (in_array($parent['index_id'], $visited)) {
                        // cyclic reference detecetd( $index refers
                        // already visited index )
                        //
                        $error = true;
                        break;
                    }
                    $visited[] = $parent['index_id'];
                    $unicode =& xoonips_getutility('unicode');
                    array_push($path, $unicode->decode_utf8($parent['titles'][0], xoonips_get_server_charset(), 'h'));
                    $index = $parent;
                }
                $str_indexes .= htmlspecialchars(implode('/', array_reverse($path)), ENT_QUOTES) . "<br />\n";
            }
            $unzip->close();
            include XOOPS_ROOT_PATH . '/header.php';
            if ($error) {
                $submit = _MD_XOONIPS_ITEM_BACK_BUTTON_LABEL;
                $message = _MD_XOONIPS_IMPORT_CIRCULAR_INDEX;
                echo <<<EOT
                    <p>
                    {$message} <br />
                    </p>
                    <form id='form_submit_back' action='import.php?action=default'
                     method='post'>
                    <input class="formButton" id='submit_back' type='submit'
                    value='{$submit}'/>
                    </form>
EOT;
                unlink($uploadfile);
            } else {
                if ($error_check_only == 'on') {
                    $submit = _MD_XOONIPS_ITEM_BACK_BUTTON_LABEL;
                    $message = _MD_XOONIPS_IMPORT_ERROR_CKECK_DONE . "<br />\n" . _MD_XOONIPS_IMPORT_FOLLOWING_INDEX_TEST;
                    echo <<<EOT
                    <p>
                    {$message}
                    </p>
                    <p>
                    {$str_indexes}
                    </p>
                    <form id='form_submit_back' action='import.php?action=default'
                    method='post'>
                    <input class="formButton" id='submit_back' type='submit' 
                    value='{$submit}'/>
                    </form>
EOT;
                    unlink($uploadfile);
                } else {
                    $_SESSION['xoonips_import_file_path'] = $uploadfile;
                    $_SESSION['xoonips_import_index_ids'] = serialize($import_index_ids);
                    $submit = _MD_XOONIPS_IMPORT_UPLOAD_SUBMIT;
                    $message = _MD_XOONIPS_IMPORT_FOLLOWING_INDEX;
                    $xoonipsCheckedXID = implode(',', $import_index_ids);
                    echo <<<EOT
                    <p>
                    {$message}
                    </p>
                    <p>
                    {$str_indexes}
                    </p>
                    <form id='form_import_index'
                    action='import.php?action=import_index_tree'
                    method='post'>
                    <input class="formButton" id='submit_import_index'
                    type='submit' value='{$submit}'/>
                    </form>
EOT;
                }
            }
            include XOOPS_ROOT_PATH . '/footer.php';
            exit;
        }
    }
 /**
  *
  * get orm composer object( subclass of XooNIpsItemCompo ) from associative array
  * see also {@link $this -> iteminfo}
  *
  * @param array associative array of XML-RPC argument
  * @return XooNIpsTableObject reference of subclass of XooNIpsTableObject
  */
 function getObject($in_array)
 {
     $handler =& xoonips_getormcompohandler($this->iteminfo['ormcompo']['module'], $this->iteminfo['ormcompo']['name']);
     $this->iteminfo = $handler->getIteminfo();
     //
     // get primary key
     $primary_id = false;
     foreach ($this->iteminfo['io']['xmlrpc']['item'] as $input) {
         if ($input['orm']['field'][0]['orm'] == $this->iteminfo['ormcompo']['primary_orm'] && $input['orm']['field'][0]['field'] == $this->iteminfo['ormcompo']['primary_key']) {
             $primary_id = isset($in_array[$input['xmlrpc']['field'][0]]) ? $in_array[$input['xmlrpc']['field'][0]] : false;
             break;
         }
     }
     if (false == $primary_id) {
         // create ormcompo
         $obj = $handler->create();
     } else {
         // get object from database
         $obj = $handler->get($primary_id);
         //var_dump('obj=get(primary_id):', $obj);
         if (!$obj) {
             $obj = $handler->create();
         }
     }
     $primary_orm = $obj->getVar($this->iteminfo['ormcompo']['primary_orm']);
     //
     // apply all input rule in iteminfo
     $unicode =& xoonips_getutility('unicode');
     foreach ($this->iteminfo['io']['xmlrpc']['item'] as $input) {
         $in_field = null;
         $in_var = array();
         $out_var = array();
         //
         // get reference of orm's information corresnponds to $input
         $orminfo = null;
         foreach ($this->iteminfo['orm'] as $orm) {
             if ($orm['field'] == $input['orm']['field'][0]['orm']) {
                 $orminfo = $orm;
                 break;
             }
         }
         //
         // get variable in $in_var according to $this -> iteminfo['input'] rule
         $is_multiple = isset($input['xmlrpc']['multiple']) ? $input['xmlrpc']['multiple'] : false;
         if ($input['xmlrpc']['field'][0] == 'detail_field') {
             if ($is_multiple) {
                 $in_field = array();
             }
             foreach ($in_array['detail_field'] as $field) {
                 if (trim($field['name']) == $input['xmlrpc']['field'][1]) {
                     if (isset($in_field) && !is_array($in_field)) {
                         $in_field = array($in_field);
                     }
                     if (is_array($in_field)) {
                         $in_field[] = $field['value'];
                     } else {
                         $in_field = trim($field['value']);
                     }
                 }
             }
         } else {
             $in_field = $in_array;
             foreach ($input['xmlrpc']['field'] as $field) {
                 if (array_key_exists($field, $in_field)) {
                     $in_field = $in_field[$field];
                 } else {
                     // set empty array if $field is not given in $in_array
                     $in_field = array();
                     break;
                 }
             }
         }
         //
         // set value to orm variable
         if ($orminfo['multiple']) {
             //
             // get handler of orm to set variable
             $handler =& $this->handlers[$input['orm']['field'][0]['orm']];
             // prepare orm array
             $foreign_key = $orminfo['foreign_key'];
             $cri = new CriteriaCompo(new Criteria($foreign_key, $primary_orm->get($this->iteminfo['ormcompo']['primary_key'])));
             $var_objs =& $handler->getObjects($cri);
             array_splice($var_objs, count($in_field));
             //delete redundant element
             while (count($var_objs) < count($in_field)) {
                 $var_objs[] = $handler->create();
             }
             //
             $pos = 0;
             $array = array();
             foreach ($in_field as $v) {
                 if (isset($array[$pos])) {
                     $var_obj = $array[$pos];
                 } else {
                     $var_obj = $handler->create();
                 }
                 // convert to numeric reference
                 if (is_string($v)) {
                     $in = $v;
                     $v = $unicode->decode_utf8($v, xoonips_get_server_charset(), 'h');
                 }
                 // evaluate
                 $in_var = array($v);
                 $out_var = array();
                 $context = array('position' => $pos);
                 eval(isset($input['eval']['xmlrpc2orm']) ? $input['eval']['xmlrpc2orm'] : '$out_var[0] = $in_var[0];');
                 //
                 for ($i = 0; $i < count($input['orm']['field']); $i++) {
                     if (isset($out_var[$i])) {
                         $var_objs[$pos]->setVar($input['orm']['field'][$i]['field'], $out_var[$i], true);
                     } else {
                         $var_objs[$pos]->setDefault($input['orm']['field'][$i]['field']);
                     }
                 }
                 $array[$pos] = $var_objs[$pos];
                 $pos++;
             }
             $obj->setVar($input['orm']['field'][0]['orm'], $array);
         } else {
             // convert to numeric reference
             if (is_string($in_field)) {
                 $in_field = $unicode->decode_utf8($in_field, xoonips_get_server_charset(), 'h');
             }
             //
             // evaluate
             $in_var = array($in_field);
             $out_var = array();
             eval(isset($input['eval']['xmlrpc2orm']) ? $input['eval']['xmlrpc2orm'] : '$out_var[0] = $in_var[0];');
             $i = 0;
             foreach ($input['orm']['field'] as $field) {
                 $orm = $obj->getVar($field['orm']);
                 if (!isset($out_var[$i])) {
                     //this field musn't be transformed XML to ORM
                     continue;
                 } else {
                     if (strlen($out_var[$i]) == 0) {
                         $orm->setDefault($field['field']);
                     } else {
                         $orm->setVar($field['field'], $out_var[$i], true);
                     }
                 }
                 $obj->setVar($field['orm'], $orm);
                 $i++;
             }
         }
     }
     return $obj;
 }
 /**
  * insert metadata fields
  * @access private
  * @param integer metadata id of metadata fields
  */
 function insertMetadataFeilds($metadata_id)
 {
     $unicode =& xoonips_getutility('unicode');
     $handler =& xoonips_getormhandler('xoonips', 'oaipmh_metadata_field');
     $this->deleteMetadataFields($metadata_id);
     foreach ($this->_metadata as $key => $field) {
         $orm =& $handler->create();
         $orm->set('name', $field['name']);
         $orm->set('metadata_id', $metadata_id);
         $orm->set('format', $this->metadataPrefix);
         $orm->set('category_name', $field['category_name']);
         $orm->set('value', $unicode->decode_utf8($field['value'], xoonips_get_server_charset(), 'h'));
         $orm->set('ordernum', intval($key) + 1);
         $orm->set('namespace', $field['namespace']);
         $orm->set('namespace_uri', $field['namespace_uri']);
         $result = $handler->insert($orm, true);
     }
 }
/**
 * 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);
        }
    }
}
 /**
  *
  * @param[in] XooNIpsXmlRpcRequest $request
  * @param[out] XooNIpsXmlRpcResponse $response result of logic(success/fault, response, error)
  */
 function execute(&$request, &$response)
 {
     $error =& $response->getError();
     // load logic instance
     $factory =& XooNIpsLogicFactory::getInstance();
     $logic =& $factory->create($request->getMethodName());
     if (!is_object($logic)) {
         $response->setResult(false);
         $error =& $response->getError();
         $logic = $request->getMethodName();
         $error->add(XNPERR_SERVER_ERROR, "can't create a logic of {$logic}");
         return false;
     }
     //
     $params =& $request->getParams();
     $vars = array();
     if (count($params) < 5) {
         $response->setResult(false);
         $error->add(XNPERR_MISSING_PARAM);
         return false;
     } else {
         if (count($params) > 5) {
             $response->setResult(false);
             $error->add(XNPERR_EXTRA_PARAM);
             return false;
         }
     }
     //
     // parameter 1(sessionid)
     $vars[0] = $params[0];
     //
     // parameter 2(itemid)
     $unicode =& xoonips_getutility('unicode');
     $vars[1] = $unicode->decode_utf8($params[1], xoonips_get_server_charset(), 'h');
     //
     // parameter 3(id_type)
     $vars[2] = $params[2];
     //
     // parameter 4(fieldName)
     $vars[3] = $params[3];
     //
     //
     // transform array to object
     // parameter 5(file structure) to XooNIpsFile object
     // using XooNIpsTransformFile
     // and write file data to temporary file
     $factory =& XooNIpsXmlRpcTransformFactory::getInstance();
     $trans =& $factory->create('xoonips', 'file');
     $fileobj = $trans->getObject($params[4]);
     if (!$fileobj) {
         $response->setResult(false);
         $error->add(XNPERR_INVALID_PARAM, 'can not get file from parameter #5');
         return false;
     }
     $tmpfile = tempnam("/tmp", "FOO");
     $h = fopen($tmpfile, "wb");
     if ($h) {
         $len = fwrite($h, $params[4]['data']);
         fclose($h);
     }
     if (!$h || $len != strlen($params[4]['data'])) {
         $response->setResult(false);
         $error->add(XNPERR_SERVER_ERROR, "can't write to file {$tmpfile}");
         return false;
     }
     $fileobj->setFilepath($tmpfile);
     $vars[4] = $fileobj;
     // execute logic
     $xoonips_response = new XooNIpsResponse();
     $logic->execute($vars, $xoonips_response);
     //
     $response->setResult($xoonips_response->getResult());
     $response->setError($xoonips_response->getError());
     $response->setSuccess($xoonips_response->getSuccess());
 }
 /**
  * 
  * @param
  * @return void
  */
 function xmlEndElementHandler($parser, $name)
 {
     global $xoopsDB;
     $detail =& $this->_import_item->getVar('detail');
     $unicode =& xoonips_getutility('unicode');
     switch (implode('/', $this->_tag_stack)) {
         case "ITEM/DETAIL":
             if (is_null($detail->get('url', 'n'))) {
                 $this->_import_item->setErrors(E_XOONIPS_TAG_NOT_FOUND, " no item_link" . $this->_get_parser_error_at());
             }
             break;
         case "ITEM/DETAIL/URL":
             $detail->set('url', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'), true);
             break;
         case "ITEM/DETAIL/FILE":
             $this->_url_banner_file_flag = true;
             $file_handler =& xoonips_getormhandler('xoonips', 'file');
             if (!$file_handler->insert($this->_url_banner_file)) {
                 $this->_import_item->setErrors(E_XOONIPS_DB_QUERY, "can't insert attachment file:" . $this->_url_banner_file->get('original_file_name') . $this->_get_parser_error_at());
             }
             $this->_url_banner_file = $file_handler->get($this->_url_banner_file->get('file_id'));
             $this->_import_item->setVar('url_banner_file', $this->_url_banner_file);
             $this->_import_item->setHasUrlBannerFile();
             break;
         case 'ITEM/DETAIL/FILE/CAPTION':
             $this->_url_banner_file->set('caption', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'));
             break;
         case 'ITEM/DETAIL/FILE/THUMBNAIL':
             $this->_url_banner_file->set('thumbnail_file', base64_decode($this->_cdata));
             break;
     }
     parent::xmlEndElementHandler($parser, $name);
 }
 /**
  * 
  * @param
  * @return void
  */
 function xmlEndElementHandler($parser, $name)
 {
     global $xoopsDB;
     $detail =& $this->_import_item->getVar('detail');
     $unicode =& xoonips_getutility('unicode');
     switch (implode('/', $this->_tag_stack)) {
         case "ITEM/DETAIL":
             foreach (array('journal', 'volume', 'number', 'page', 'abstract', 'pubmed_id') as $key) {
                 if (is_null($detail->get($key, 'n'))) {
                     $this->_import_item->setErrors(E_XOONIPS_TAG_NOT_FOUND, " no {$key}" . $this->_get_parser_error_at());
                 }
             }
             //error is no authors
             if (count($this->_import_item->getVar('author')) == 0) {
                 $this->_import_item->setErrors(E_XOONIPS_TAG_NOT_FOUND, " no author" . $this->_get_parser_error_at());
             }
             break;
         case "ITEM/DETAIL/AUTHORS/AUTHOR":
             $authors =& $this->_import_item->getVar('author');
             $author_handler =& xoonips_getormhandler('xnppaper', 'author');
             $author =& $author_handler->create();
             $author->set('author', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'));
             $author->set('author_order', count($authors));
             $authors[] = $author;
             break;
         case "ITEM/DETAIL/JOURNAL":
         case "ITEM/DETAIL/VOLUME":
         case "ITEM/DETAIL/NUMBER":
         case "ITEM/DETAIL/PAGE":
         case "ITEM/DETAIL/ABSTRACT":
         case "ITEM/DETAIL/PUBMED_ID":
             $detail->set(strtolower(end($this->_tag_stack)), $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'), true);
             break;
         case "ITEM/DETAIL/FILE":
             $this->_paper_pdf_reprint_file_flag = true;
             $file_handler =& xoonips_getormhandler('xoonips', 'file');
             if (!$file_handler->insert($this->_paper_pdf_reprint_file)) {
                 $this->_import_item->setErrors(E_XOONIPS_DB_QUERY, "can't insert attachment file:" . $this->_paper_pdf_reprint_file->get('original_file_name') . $this->_get_parser_error_at());
             }
             $this->_paper_pdf_reprint_file = $file_handler->get($this->_paper_pdf_reprint_file->get('file_id'));
             $this->_import_item->setVar('paper_pdf_reprint', $this->_paper_pdf_reprint_file);
             $this->_import_item->setHasPaperPdfReprint();
             break;
         case 'ITEM/DETAIL/FILE/CAPTION':
             $this->_paper_pdf_reprint_file->set('caption', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'));
             break;
         case 'ITEM/DETAIL/FILE/THUMBNAIL':
             $this->_paper_pdf_reprint_file->set('thumbnail_file', base64_decode($this->_cdata));
             break;
     }
     parent::xmlEndElementHandler($parser, $name);
 }
 /**
  * 
  * @param
  * @return void
  */
 function xmlEndElementHandler($parser, $name)
 {
     global $xoopsDB;
     $detail =& $this->_import_item->getVar('detail');
     $unicode =& xoonips_getutility('unicode');
     switch (implode('/', $this->_tag_stack)) {
         case "ITEM/DETAIL":
             foreach (array('model_type', 'rights', 'readme', 'use_cc', 'cc_commercial_use', 'cc_modification') as $key) {
                 if (is_null($detail->get($key, 'n'))) {
                     $this->_import_item->setErrors(E_XOONIPS_TAG_NOT_FOUND, " no {$key}" . $this->_get_parser_error_at());
                 }
             }
             //error if no creators
             if (count($this->_import_item->getVar('creator')) == 0) {
                 $this->_import_item->setErrors(E_XOONIPS_TAG_NOT_FOUND, " no creator" . $this->_get_parser_error_at());
             }
             break;
         case "ITEM/DETAIL/MODEL_TYPE":
         case "ITEM/DETAIL/RIGHTS":
         case "ITEM/DETAIL/README":
         case "ITEM/DETAIL/USE_CC":
         case "ITEM/DETAIL/CC_MODIFICATION":
         case "ITEM/DETAIL/CC_COMMERCIAL_USE":
             $detail->set(strtolower(end($this->_tag_stack)), $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'), true);
             break;
         case 'ITEM/DETAIL/CREATORS/CREATOR':
             if ($this->_detail_version != '1.03') {
                 break;
             }
             $creators =& $this->_import_item->getVar('creator');
             $creator_handler =& xoonips_getormhandler('xnpmodel', 'creator');
             $creator =& $creator_handler->create();
             $creator->set('creator', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'));
             $creator->set('creator_order', count($creators));
             $creators[] = $creator;
             break;
         case "ITEM/DETAIL/CREATOR":
             if ($this->_detail_version != '1.00' && $this->_detail_version != '1.01' && $this->_detail_version != '1.02') {
                 //<creator> is only for 1.00, 1.01 and 1.02
                 break;
             }
             $creator_handler =& xoonips_getormhandler('xnpmodel', 'creator');
             $creators =& $this->_import_item->getVar('creator');
             $creator =& $creator_handler->create();
             $creator->set('creator', trim($unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h')));
             $creator->set('creator_order', 0);
             $creators[0] = $creator;
             break;
         case "ITEM/DETAIL/ATTACHMENT_DL_LIMIT":
             if ($this->_attachment_dl_limit_flag) {
                 $this->_import_item->setErrors(E_XOONIPS_TAG_REDUNDANT, "attachment_dl_limit is redundant" . $this->_get_parser_error_at());
             } else {
                 if (ctype_digit($this->_cdata)) {
                     $detail->set('attachment_dl_limit', intval($this->_cdata));
                     $this->_attachment_dl_limit_flag = true;
                 } else {
                     $this->_import_item->setErrors(E_XOONIPS_INVALID_VALUE, "invalid value(" . $this->_cdata . ") of attachment_dl_limit" . $this->_get_parser_error_at());
                 }
             }
             break;
         case "ITEM/DETAIL/ATTACHMENT_DL_NOTIFY":
             if ($this->_attachment_dl_notify_limit_flag) {
                 $this->_import_item->setErrors(E_XOONIPS_TAG_REDUNDANT, "attachment_dl_notify is redundant" . $this->_get_parser_error_at());
             } else {
                 if (ctype_digit($this->_cdata)) {
                     $detail->set('attachment_dl_notify', intval($this->_cdata));
                     $this->_attachment_dl_notify_limit_flag = true;
                 } else {
                     $this->_import_item->setErrors(E_XOONIPS_INVALID_VALUE, "invalid value(" . $this->_cdata . ") of attachment_dl_notify" . $this->_get_parser_error_at());
                 }
             }
             break;
         case "ITEM/DETAIL/FILE":
             $file_handler =& xoonips_getormhandler('xoonips', 'file');
             if ($this->_file_type_attribute == 'model_data') {
                 $this->_model_data_flag = true;
                 if (!$file_handler->insert($this->_model_data)) {
                     global $xoopsDB;
                     $this->_import_item->setErrors(E_XOONIPS_DB_QUERY, "can't insert attachment file:" . $this->_model_data->get('original_file_name') . $this->_get_parser_error_at());
                     trigger_error($xoopsDB->error());
                 }
                 $this->_model_data = $file_handler->get($this->_model_data->get('file_id'));
                 $this->_import_item->setVar('model_data', $this->_model_data);
                 $this->_import_item->setHasModelData();
                 $this->_file_type_attribute = null;
             } else {
                 if ($this->_file_type_attribute == 'preview') {
                     $this->_preview_flag = true;
                     if (!$file_handler->insert($this->_preview)) {
                         $this->_import_item->setErrors(E_XOONIPS_DB_QUERY, "can't insert attachment file:" . $this->_preview->get('original_file_name') . $this->_get_parser_error_at());
                     }
                     $this->_preview = $file_handler->get($this->_preview->get('file_id'));
                     $previews =& $this->_import_item->getVar('preview');
                     $previews[] = $this->_preview;
                     $this->_import_item->setHasPreview();
                     $this->_file_type_attribute = null;
                 } else {
                     die('unknown file type:' . $this->_file_type_attribute);
                 }
             }
             break;
         case 'ITEM/DETAIL/FILE/CAPTION':
             if ($this->_file_type_attribute == 'model_data') {
                 $this->_model_data->set('caption', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'));
             } else {
                 if ($this->_file_type_attribute == 'preview') {
                     $this->_preview->set('caption', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'));
                 }
             }
             break;
             break;
         case 'ITEM/DETAIL/FILE/THUMBNAIL':
             if ($this->_file_type_attribute == 'model_data') {
                 $this->_model_data->set('thumbnail_file', base64_decode($this->_cdata));
             } else {
                 if ($this->_file_type_attribute == 'preview') {
                     $this->_preview->set('thumbnail_file', base64_decode($this->_cdata));
                 }
             }
             break;
     }
     parent::xmlEndElementHandler($parser, $name);
 }
 /**
  * 
  * @param
  * @return void
  */
 function xmlEndElementHandler($parser, $name)
 {
     global $xoopsDB;
     $detail =& $this->_import_item->getVar('detail');
     $unicode =& xoonips_getutility('unicode');
     switch (implode('/', $this->_tag_stack)) {
         case "ITEM/DETAIL":
             if ($this->_detail_version == '1.00') {
             } else {
                 if ($this->_detail_version == '1.01') {
                     $keys[] = 'attachment_dl_limit';
                 } else {
                     $keys[] = 'attachment_dl_limit';
                     $keys[] = 'attachment_dl_notify';
                 }
             }
             foreach (array('presentation_type', 'conference_title', 'place', 'abstract', 'conference_from_year', 'conference_from_month', 'conference_from_mday', 'conference_to_year', 'conference_to_month', 'conference_to_mday') as $key) {
                 if (is_null($detail->get($key, 'n'))) {
                     $this->_import_item->setErrors(E_XOONIPS_TAG_NOT_FOUND, " no {$key}" . $this->_get_parser_error_at());
                 }
             }
             //error if no authors
             if (count($this->_import_item->getVar('author')) == 0) {
                 $this->_import_item->setErrors(E_XOONIPS_TAG_NOT_FOUND, " no author" . $this->_get_parser_error_at());
             }
             break;
         case "ITEM/DETAIL/AUTHORS/AUTHOR":
             if ($this->_detail_version != '1.01' && $this->_detail_version != '1.02') {
                 break;
             }
             $authors =& $this->_import_item->getVar('author');
             $author_handler =& xoonips_getormhandler('xnpconference', 'author');
             $author =& $author_handler->create();
             $author->set('author', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'));
             $author->set('author_order', count($authors));
             $authors[] = $author;
             break;
         case "ITEM/DETAIL/AUTHOR":
             // /item/detail/author is only available in ver 1.00
             if ($this->_detail_version != '1.00') {
                 break;
             }
             $authors =& $this->_import_item->getVar('author');
             $author_handler =& xoonips_getormhandler('xnpconference', 'author');
             $author =& $author_handler->create();
             $author->set('author', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'));
             $author->set('author_order', 0);
             $authors[0] = $author;
             break;
         case "ITEM/DETAIL/PRESENTATION_TYPE":
         case "ITEM/DETAIL/CONFERENCE_TITLE":
         case "ITEM/DETAIL/PLACE":
         case "ITEM/DETAIL/ABSTRACT":
         case "ITEM/DETAIL/CONFERENCE_FROM_YEAR":
         case "ITEM/DETAIL/CONFERENCE_FROM_MONTH":
         case "ITEM/DETAIL/CONFERENCE_FROM_MDAY":
         case "ITEM/DETAIL/CONFERENCE_TO_YEAR":
         case "ITEM/DETAIL/CONFERENCE_TO_MONTH":
         case "ITEM/DETAIL/CONFERENCE_TO_MDAY":
             $unicode =& xoonips_getutility('unicode');
             $detail->set(strtolower(end($this->_tag_stack)), $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'), true);
             break;
         case "ITEM/DETAIL/ATTACHMENT_DL_LIMIT":
             if ($this->_attachment_dl_limit_flag) {
                 $this->_import_item->setErrors(E_XOONIPS_TAG_REDUNDANT, "attachment_dl_limit is redundant" . $this->_get_parser_error_at());
             } else {
                 if (ctype_digit($this->_cdata)) {
                     $detail->set('attachment_dl_limit', intval($this->_cdata));
                     $this->_attachment_dl_limit_flag = true;
                 } else {
                     $this->_import_item->setErrors(E_XOONIPS_INVALID_VALUE, "invalid value(" . $this->_cdata . ") of attachment_dl_limit" . $this->_get_parser_error_at());
                 }
             }
             break;
         case "ITEM/DETAIL/ATTACHMENT_DL_NOTIFY":
             if ($this->_attachment_dl_notify_limit_flag) {
                 $this->_import_item->setErrors(E_XOONIPS_TAG_REDUNDANT, "attachment_dl_notify is redundant" . $this->_get_parser_error_at());
             } else {
                 if (ctype_digit($this->_cdata)) {
                     $detail->set('attachment_dl_notify', intval($this->_cdata));
                     $this->_attachment_dl_notify_limit_flag = true;
                 } else {
                     $this->_import_item->setErrors(E_XOONIPS_INVALID_VALUE, "invalid value(" . $this->_cdata . ") of attachment_dl_notify" . $this->_get_parser_error_at());
                 }
             }
             break;
         case "ITEM/DETAIL/FILE":
             $file_handler =& xoonips_getormhandler('xoonips', 'file');
             if ($this->_file_type_attribute == 'conference_file') {
                 $this->_conference_file_flag = true;
                 if (!$file_handler->insert($this->_conference_file)) {
                     $this->_import_item->setErrors(E_XOONIPS_DB_QUERY, "can't insert attachment file:" . $this->_conference_file->get('original_file_name') . $this->_get_parser_error_at());
                 }
                 $this->_conference_file = $file_handler->get($this->_conference_file->get('file_id'));
                 $this->_import_item->setVar('conference_file', $this->_conference_file);
                 $this->_import_item->setHasConferenceFile();
                 $this->_file_type_attribute = null;
             } else {
                 if ($this->_file_type_attribute == 'conference_paper') {
                     $this->_conference_paper_flag = true;
                     if (!$file_handler->insert($this->_conference_paper)) {
                         $this->_import_item->setErrors(E_XOONIPS_DB_QUERY, "can't insert attachment file:" . $this->_conference_paper->get('original_file_name') . $this->_get_parser_error_at());
                     }
                     $this->_conference_paper = $file_handler->get($this->_conference_paper->get('file_id'));
                     $this->_import_item->setVar('conference_paper', $this->_conference_paper);
                     $this->_import_item->setHasConferencePaper();
                     $this->_file_type_attribute = null;
                 } else {
                     die('unknown file type:' . $this->_file_type_attribute);
                 }
             }
             break;
         case 'ITEM/DETAIL/FILE/CAPTION':
             $unicode =& xoonips_getutility('unicode');
             if ($this->_file_type_attribute == 'conference_file') {
                 $this->_conference_file->set('caption', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'));
             } else {
                 if ($this->_file_type_attribute == 'conference_paper') {
                     $this->_conference_paper->set('caption', $unicode->decode_utf8($this->_cdata, xoonips_get_server_charset(), 'h'));
                 }
             }
             break;
         case 'ITEM/DETAIL/FILE/THUMBNAIL':
             if ($this->_file_type_attribute == 'conference_file') {
                 $this->_conference_file->set('thumbnail_file', base64_decode($this->_cdata));
             } else {
                 if ($this->_file_type_attribute == 'conference_paper') {
                     $this->_conference_paper->set('thumbnail_file', base64_decode($this->_cdata));
                 }
             }
             break;
     }
     parent::xmlEndElementHandler($parser, $name);
 }