コード例 #1
0
 /**
  * execute getIndex
  *
  * @param[in]  $vars[0] session ID
  * @param[in]  $vars[1] index ID
  * @param[out] $response->result true:success, false:failed
  * @param[out] $response->error  error information
  * @param[out] $response->success XooNIpsIndexCompo index information
  */
 function execute(&$vars, &$response)
 {
     // parameter check
     $error =& $response->getError();
     if (count($vars) > 2) {
         $error->add(XNPERR_EXTRA_PARAM);
     } else {
         if (count($vars) < 2) {
             $error->add(XNPERR_MISSING_PARAM);
         } else {
             if (isset($vars[0]) && strlen($vars[0]) > 32) {
                 $error->add(XNPERR_INVALID_PARAM, 'too long parameter 1');
             }
             if (!is_int($vars[1]) && !ctype_digit($vars[1])) {
                 $error->add(XNPERR_INVALID_PARAM, 'not integer parameter 2');
             }
         }
     }
     if ($error->get(0)) {
         // return if parameter error
         $response->setResult(false);
         return;
     } else {
         $sessionid = $vars[0];
         $index_id = $vars[1];
     }
     list($result, $uid, $session) = $this->restoreSession($sessionid);
     if (!$result) {
         $response->setResult(false);
         $error->add(XNPERR_INVALID_SESSION);
         return false;
     }
     // get index from index_id
     $index_compo_handler =& xoonips_getormcompohandler('xoonips', 'index');
     $index = $index_compo_handler->get($index_id);
     if ($index == false) {
         $response->setResult(false);
         $response->error->add(XNPERR_NOT_FOUND, "cannot get index");
         return false;
     }
     // check permission
     $index_handler =& xoonips_getormhandler('xoonips', 'index');
     if (!$index_handler->getPerm($index_id, $uid, 'read')) {
         $response->setResult(false);
         $response->error->add(XNPERR_ACCESS_FORBIDDEN, "no permission");
         return false;
     }
     $response->setSuccess($index);
     $response->setResult(true);
     return true;
 }
コード例 #2
0
 function execute(&$vars, &$response)
 {
     global $xoopsUser;
     $success = array();
     $error = false;
     $transaction = XooNIpsTransaction::getInstance();
     $transaction->start();
     $itemtype_handler =& xoonips_getormhandler('xoonips', 'item_type');
     foreach (array_keys($vars[0]) as $key) {
         assert(!($vars[0][$key]->getImportAsNewFlag() && $vars[0][$key]->getUpdateFlag()));
         //skip this item if don't import as new and update
         if (!$vars[0][$key]->getImportAsNewFlag() && !$vars[0][$key]->getUpdateFlag()) {
             continue;
         }
         $item_handler =& xoonips_getormcompohandler('xoonips', 'item');
         if ($vars[0][$key]->getUpdateFlag() && !$item_handler->getPerm($vars[0][$key]->getUpdateItemId(), $xoopsUser->getVar('uid'), 'write')) {
             //no write permission to updating exist item -> error
             $vars[0][$key]->setErrors(E_XOONIPS_UPDATE_CERTIFY_REQUEST_LOCKED, "can't update locked item(" . $vars[0][$key]->getUpdateItemId() . ")");
             $error = true;
             break;
         }
         $basic =& $vars[0][$key]->getVar('basic');
         $itemtype =& $itemtype_handler->get($basic->get('item_type_id'));
         $handler =& xoonips_gethandler($itemtype->get('name'), 'import_item');
         $handler->import($vars[0][$key]);
         $error = $error || count($vars[0][$key]->getErrors()) > 0;
     }
     if ($error) {
         $transaction->rollback();
     } else {
         foreach (array_keys($vars[0]) as $key) {
             $basic =& $vars[0][$key]->getVar('basic');
             $itemtype =& $itemtype_handler->get($basic->get('item_type_id'));
             $handler =& xoonips_gethandler($itemtype->get('name'), 'import_item');
             $handler->onImportFinished($vars[0][$key], $vars[0]);
             $error = $error || count($vars[0][$key]->getErrors()) > 0;
         }
         $transaction->commit();
         $this->_remove_files();
     }
     $success['import_items'] =& $vars[0];
     $response->setResult(!$error);
     $response->setSuccess($success);
 }
コード例 #3
0
 function onDelete($item_id)
 {
     //trigger_error( "Binder onDelete( $item_id )" );
     $bilink_handler =& xoonips_getormhandler('xnpbinder', 'binder_item_link');
     $criteria = new Criteria('item_id', $item_id);
     $bilinks =& $bilink_handler->getObjects($criteria);
     if (!$bilinks) {
         return;
     }
     foreach ($bilinks as $bilink) {
         $child_items =& $bilink_handler->getObjects(new Criteria('binder_id', $bilink->get('binder_id')));
         if (!$child_items) {
             continue;
         }
         $index_item_link_handler =& xoonips_getormhandler('xoonips', 'index_item_link');
         $join = new XooNIpsJoinCriteria('xoonips_index', 'index_id', 'index_id');
         $criteria = new CriteriaCompo(new Criteria('open_level', OL_PUBLIC));
         $criteria->add(new Criteria('certify_state', CERTIFIED));
         $criteria->add(new Criteria('item_id', $bilink->get('binder_id')));
         $index_item_links =& $index_item_link_handler->getObjects($criteria, false, '', false, $join);
         if (empty($index_item_links)) {
             continue;
         }
         if (count($child_items) == 1) {
             $item_handler =& xoonips_getormcompohandler('xnpbinder', 'item');
             $binder = $item_handler->get($bilink->get('binder_id'));
             $basic = $binder->getVar('basic');
             // define tags here for notification message
             $tags = xoonips_notification_get_item_tags($basic->get('item_id'));
             $mhandler =& xoops_gethandler('module');
             $module = $mhandler->getByDirName('xnpbinder');
             $nhandler =& xoonips_gethandler('xoonips', 'notification');
             $nhandler->triggerEvent2('user', 0, 'item_updated', _MD_XNPBINDER_USER_CONTENT_EMPTY_NOTIFYSBJ, $nhandler->getTemplateDirByMid($module->mid()), 'user_content_empty_notify', $tags, array($basic->get('uid')));
         }
         if (!$bilink_handler->delete($bilink)) {
             die('cannnot remove a deleted item from a binder.');
         }
     }
 }
 function doAction()
 {
     global $xoopsUser;
     // get item_id
     $item_id = $this->_formdata->getValue('get', 'item_id', 'i', false);
     // permission check
     $item_compo_handler =& xoonips_getormcompohandler('xoonips', 'item');
     if (!$item_compo_handler->getPerm($item_id, $xoopsUser->getVar('uid'), 'read')) {
         $this->show_no_permission_error_page();
     }
     // get item_info_compo of $item_id
     $item_basic_handler =& xoonips_getormhandler('xoonips', 'item_basic');
     $item_basic = $item_basic_handler->get($item_id);
     $item_type_handler =& xoonips_getormhandler('xoonips', 'item_type');
     $item_type = $item_type_handler->get($item_basic->get('item_type_id'));
     $info_compo_handler =& xoonips_getormcompohandler($item_type->get('name'), 'item');
     $info_compo = $info_compo_handler->get($item_id);
     // read language file of item
     $langman =& xoonips_getutility('languagemanager');
     $langman->read('main.php', $item_type->get('name'));
     // set params
     $this->_view_params['template_file_name'] = $info_compo_handler->getTemplateFileName(XOONIPS_TEMPLATE_TYPE_TRANSFER_ITEM_DETAIL);
     $this->_view_params['template_vars'] = $info_compo_handler->getTemplateVar(XOONIPS_TEMPLATE_TYPE_TRANSFER_ITEM_DETAIL, $item_id, $xoopsUser->getVar('uid'));
 }
 /**
  * get array of item for template vars
  * @param integer $item_id
  */
 function get_item_template_vars($item_id)
 {
     $item_handler =& xoonips_getormcompohandler('xoonips', 'item');
     $item_type_handler =& xoonips_getormhandler('xoonips', 'item_type');
     $item =& $item_handler->get($item_id);
     $basic =& $item->getVar('basic');
     $itemtype =& $item_type_handler->get($basic->get('item_type_id'));
     return array('item_id' => $item_id, 'item_type_name' => $itemtype->getVar('display_name', 's'), 'title' => $this->concatenate_titles($item->getVar('titles')));
 }
コード例 #6
0
/**
 *
 * アイテム情報取得.
 *
 * @param sid セッションID
 * @param iids 取得したいアイテムのIDの配列
 * @param criteria 結果の範囲指定,ソート条件指定
 * @param items 検索結果のを書き込む配列
 * @return RES_OK
 * @return RES_DB_NOT_INITIALIZED
 * @return RES_NO_SUCH_SESSION
 * @return RES_DB_QUERY_ERROR
 *
 */
function xnp_get_items($sess_id, $iids, $criteria, &$items)
{
    global $xoopsDB;
    $items = array();
    if (!xnp_is_valid_session_id($sess_id)) {
        return RES_NO_SUCH_SESSION;
    }
    $ret = _xnpal_sessionID2UID($sess_id, $uid);
    if ($ret != RES_OK) {
        return $ret;
    }
    $items = array();
    if (!isset($iids) || count($iids) == 0) {
        return RES_OK;
    }
    $sql = "SELECT DISTINCT ti.item_id as item_id, item_type_id, tt.title as title, description, doi, ti.uid as uid, creation_date, last_update_date, publication_year, publication_month, publication_mday, lang ";
    $sql .= " FROM ";
    $sql .= $xoopsDB->prefix("xoonips_index_item_link") . " AS tlink";
    $sql .= " LEFT JOIN " . $xoopsDB->prefix("xoonips_index") . " AS tx ON tlink.index_id = tx.index_id";
    $sql .= " LEFT JOIN " . $xoopsDB->prefix("xoonips_item_basic") . " AS ti ON tlink.item_id = ti.item_id";
    $sql .= " LEFT JOIN " . $xoopsDB->prefix("xoonips_item_title") . " AS tt ON tt.item_id=ti.item_id";
    $sql .= " LEFT JOIN " . $xoopsDB->prefix("xoonips_groups_users_link") . " as tgulink ON tx.gid=tgulink.gid";
    $sql .= " WHERE tlink.item_id IN ( " . _xnpal_getCsvStr($iids) . " )";
    $sql .= " AND title_id=" . DEFAULT_ORDER_TITLE_OFFSET;
    $sql .= xnp_criteria2str($criteria);
    $result = $xoopsDB->query($sql);
    if (!$result) {
        _xnpal_setLastErrorString("error in xnp_get_items " . $xoopsDB->error());
        return RES_DB_QUERY_ERROR;
    }
    $items_buf = array();
    $ordered_ids = array();
    //array of sorted item_id(s) to sort $items_buf in the end of this function
    $item_compo_handler =& xoonips_getormcompohandler('xoonips', 'item');
    while ($row = $xoopsDB->fetchArray($result)) {
        if (!$item_compo_handler->getPerm($row['item_id'], $uid, 'read')) {
            continue;
        }
        $items_buf[$row['item_id']] = $row;
        $items_buf[$row['item_id']]['titles'] = array();
        $items_buf[$row['item_id']]['keywords'] = array();
        $ordered_ids[] = $row['item_id'];
    }
    //get titles of selected item
    if (count($items_buf) > 0) {
        $sql = "SELECT item_id, title FROM " . $xoopsDB->prefix("xoonips_item_title") . " WHERE item_id IN ( " . implode(",", array_keys($items_buf)) . " ) ORDER BY item_id ASC, title_id ASC";
        $result = $xoopsDB->query($sql);
        if (!$result) {
            _xnpal_setLastErrorString("error in xnp_get_items " . $xoopsDB->error() . " sql={$sql}" . " at " . __LINE__ . " in " . __FILE__ . "\n" . xnp_get_last_error_string());
            return RES_DB_QUERY_ERROR;
        }
        while ($row = $xoopsDB->fetchArray($result)) {
            $items_buf[$row['item_id']]['titles'][] = $row['title'];
        }
        //get keywords of selected item
        $sql = "SELECT item_id, keyword FROM " . $xoopsDB->prefix("xoonips_item_keyword") . " WHERE item_id IN ( " . implode(",", array_keys($items_buf)) . " ) ORDER BY item_id ASC, keyword_id ASC";
        $result = $xoopsDB->query($sql);
        if (!$result) {
            _xnpal_setLastErrorString("error in xnp_get_items " . $xoopsDB->error() . " sql={$sql}" . " at " . __LINE__ . " in " . __FILE__ . "\n" . xnp_get_last_error_string());
            return RES_DB_QUERY_ERROR;
        }
        while ($row = $xoopsDB->fetchArray($result)) {
            $items_buf[$row['item_id']]['keywords'][] = $row['keyword'];
        }
    }
    // convert the associative array(index_buf) to the array(indexes) (keep order specified by criteriaString)
    foreach ($ordered_ids as $id) {
        $items[] = $items_buf[$id];
    }
    _xnpal_setLastErrorString("");
    return RES_OK;
}
コード例 #7
0
 /**
  * execute getItemPermission
  *
  * @param[in] $vars[0] sessionid
  * @param[in] $vars[1] id
  * @param[in] $vars[2] id_type
  * @param[out] $response->result true:success, false:failed
  * @param[out] $response->error  error information
  * @param[out] $response->success array item permission structure
  * @return false if fault
  */
 function execute(&$vars, &$response)
 {
     // parameter check
     $error =& $response->getError();
     if (count($vars) > 3) {
         $error->add(XNPERR_EXTRA_PARAM);
     } else {
         if (count($vars) < 3) {
             $error->add(XNPERR_MISSING_PARAM);
         } else {
             if (isset($vars[0]) && strlen($vars[0]) > 32) {
                 $error->add(XNPERR_INVALID_PARAM, 'too long parameter 1');
             }
             if ($vars[2] != 'item_id' && $vars[2] != 'ext_id') {
                 $error->add(XNPERR_INVALID_PARAM, 'invalid parameter 3');
             }
             if ($vars[2] == 'item_id') {
                 if (!is_int($vars[1]) && !ctype_digit($vars[1])) {
                     $error->add(XNPERR_INVALID_PARAM, 'not integer parameter 2');
                 }
                 if (strlen($vars[1]) > 10) {
                     $error->add(XNPERR_INVALID_PARAM, 'too long parameter 2');
                 }
             }
         }
     }
     if ($error->get(0)) {
         // return if parameter error
         $response->setResult(false);
         return false;
     } else {
         $sessionid = $vars[0];
         $id = $vars[1];
         $id_type = $vars[2];
         if ($id_type == 'item_id') {
             $id = intval($id);
         }
     }
     // validate session
     list($result, $uid, $session) = $this->restoreSession($sessionid);
     if (!$result) {
         // error invalid session
         $error->add(XNPERR_INVALID_SESSION);
         $response->setResult(false);
         return false;
     }
     // ext_id to item_id
     $item_compo_handler =& xoonips_getormcompohandler('xoonips', 'item');
     if ($id_type == 'ext_id') {
         $item_compo = $item_compo_handler->getByExtId($id);
     } else {
         if ($id_type == 'item_id') {
             $item_compo = $item_compo_handler->get($id);
         } else {
             $error->add(XNPERR_INVALID_PARAM, "invalid id_type({$id_type})");
             $response->setResult(false);
             return false;
         }
     }
     if ($item_compo == false) {
         $error->add(XNPERR_NOT_FOUND);
         $response->setResult(false);
         return false;
     }
     $item_basic = $item_compo->getVar('basic');
     $item_id = $item_basic->get('item_id');
     // get permission
     $result = array('read' => $item_compo_handler->getPerm($item_id, $uid, 'read'), 'write' => $item_compo_handler->getPerm($item_id, $uid, 'write'), 'delete' => $item_compo_handler->getPerm($item_id, $uid, 'delete'));
     $response->setSuccess($result);
     $response->setResult(true);
     return true;
 }
コード例 #8
0
function xnpmodelGetMetaInformation($item_id)
{
    $ret = array();
    $creator_array = array();
    $basic = xnpGetBasicInformationArray($item_id);
    $detail = xnpmodelGetDetailInformation($item_id);
    if (!empty($basic)) {
        $ret[_MD_XOONIPS_ITEM_TITLE_LABEL] = implode("\n", $basic['titles']);
        $ret[_MD_XOONIPS_ITEM_CONTRIBUTOR_LABEL] = $basic['contributor'];
        $ret[_MD_XOONIPS_ITEM_KEYWORDS_LABEL] = implode("\n", $basic['keywords']);
        $ret[_MD_XOONIPS_ITEM_DESCRIPTION_LABEL] = $basic['description'];
        $ret[_MD_XOONIPS_ITEM_DOI_LABEL] = $basic['doi'];
        $ret[_MD_XOONIPS_ITEM_LAST_UPDATE_DATE_LABEL] = $basic['last_update_date'];
        $ret[_MD_XOONIPS_ITEM_CREATION_DATE_LABEL] = $basic['creation_date'];
    }
    if (!empty($detail)) {
        $ret[_MD_XNPMODEL_MODEL_TYPE_LABEL] = $detail['model_type']['display_value'];
    }
    $xnpmodel_handler =& xoonips_getormcompohandler('xnpmodel', 'item');
    $xnpmodel =& $xnpmodel_handler->get($item_id);
    foreach ($xnpmodel->getVar('creator') as $creator) {
        $creator_array[] = $creator->getVar('creator', 'n');
    }
    $ret[_MD_XNPMODEL_CREATOR_LABEL] = implode("\n", $creator_array);
    return $ret;
}
コード例 #9
0
function xoonips_transfer_get_index_tree_for_dropdown($index_id, &$result, $depth)
{
    $index_compo_handler =& xoonips_getormcompohandler('xoonips', 'index');
    $index_compo = $index_compo_handler->get($index_id);
    if ($index_compo === false) {
        return;
        // bad index_id
    }
    $titles = $index_compo->getVar('titles');
    $index_item_link_handler =& xoonips_getormhandler('xoonips', 'index_item_link');
    $result[] = array('index_id' => $index_id, 'title' => $titles[DEFAULT_INDEX_TITLE_OFFSET]->get('title'), 'depth' => $depth, 'item_count' => $index_item_link_handler->getCount(new Criteria('index_id', $index_id)));
    $index_handler =& xoonips_getormhandler('xoonips', 'index');
    $index = $index_compo->getVar('index');
    $criteria = new Criteria('parent_index_id', $index_id);
    $criteria->setOrder('asc');
    $criteria->setSort('sort_number');
    $indexes =& $index_handler->getObjects($criteria);
    if ($indexes !== false) {
        foreach ($indexes as $index) {
            xoonips_transfer_get_index_tree_for_dropdown($index->get('index_id'), $result, $depth + 1);
        }
    }
}
コード例 #10
0
            break;
        }
        $dirArrayR[] = $index;
    }
    $ct = count($dirArrayR);
    $dirArray = array();
    for ($i = 0; $i < $ct; $i++) {
        $dirArray[] = $dirArrayR[$ct - $i - 1];
    }
    return $dirArray;
}
$dirArray = xoonipsGetPathArray($xnpsid, $xid);
// get Children
// -> childIndexes
$childIndexes = array();
$index_compo_handler =& xoonips_getormcompohandler('xoonips', 'index');
$join = new XooNIpsJoinCriteria('xoonips_index', 'item_id', 'index_id');
$criteria2 =& new Criteria('parent_index_id', $xid);
$criteria2->setSort('sort_number');
foreach ($index_compo_handler->getObjects($criteria2, true, '', false, $join) as $index_id => $childindex) {
    $item_lock_handler =& xoonips_getormhandler('xoonips', 'item_lock');
    $index_group_index_link_handler =& xoonips_getormhandler('xoonips', 'index_group_index_link');
    $titles =& $childindex->getVar('titles');
    $childIndexes[$index_id] = array('isLocked' => $item_lock_handler->isLocked($index_id), 'titles' => array($titles[0]->getVar('title', 's')), 'item_id' => $index_id, 'lockTypeString' => $textutil->html_special_chars(get_lock_type_string($index_id)), 'write_permission' => $index_handler->getPerm($index_id, @$_SESSION['xoopsUserId'], 'write'), 'public_index_string' => '', 'public_index_pending_string' => '');
    foreach ($index_group_index_link_handler->getByGroupIndexId($index_id, @$_SESSION['xoopsUserId']) as $link) {
        $childIndexes[$index_id]['public_index_string'] .= xnpGetIndexPathString($xnpsid, $link->get('index_id')) . "<br />";
        $childIndexes[$index_id]['public_index_pending_string'] .= _MD_XOONIPS_ITEM_PENDING_NOW . "<br />";
    }
}
// prev_idnex_id, next_index_id are set
reset($childIndexes);
コード例 #11
0
/**
 * return number of items of the item search cache
 * 
 * @param $search_cache_id integer cache id
 * @return integer number of items
 */
function xoonips_get_item_count_from_search_cache($search_cache_id)
{
    global $xoopsDB, $xoopsUser;
    $search_cache_item_handler =& xoonips_getormhandler('xoonips', 'search_cache_item');
    $join = new XooNIpsJoinCriteria('xoonips_item_basic', 'item_id', 'item_id', 'INNER', 'tb');
    $search_cache_item =& $search_cache_item_handler->getObjects(new Criteria('search_cache_id', $search_cache_id), false, '', false, $join);
    if (count($search_cache_item) == 0) {
        return 0;
    }
    $c = 0;
    $item_handler =& xoonips_getormcompohandler('xoonips', 'item');
    foreach ($search_cache_item as $item) {
        if ($item_handler->getPerm($item->get('item_id'), $xoopsUser ? $xoopsUser->getVar('uid') : UID_GUEST, 'read')) {
            $c++;
        }
    }
    return $c;
    /*
        $search_cache_item =& $search_cache_item_handler->getObjects( new Criteria( 'search_cache_id', $search_cache_id ), false, 'count(tb.item_id)', false, $join );
        if( count( $search_cache_item ) == 0 ) return 0;
        var_dump( $search_cache_item[0] -> getExtraVar( 'count(tb.item_id)' ) );
        return $search_cache_item[0] -> getExtraVar( 'count(tb.item_id)' );
    */
}
コード例 #12
0
 /**
  * execute updateFile
  *
  * @param[in]  $vars[0] session ID
  * @param[in]  $vars[1] item ID
  * @param[in]  $vars[2] identifier type of $vars[1] parameter('item_id'|'ext_id')
  * @param[in]  $vars[3] field name to add/update file
  * @param[in]  $vars[4] XooNIpsFile file information
  * @param[out] $response->result true:success, false:failed
  * @param[out] $response->error  error information
  * @param[out] $response->success new file id
  */
 function execute(&$vars, &$response)
 {
     /*
     check permission
     check field name
     check filesize <= upload_max_filesize
     get XooNIpsFile if file_id exist ($oldfile)
     create XooNIpsFile from item_id and file information ($newfile)
     start transaction
     insert $newfile
     create search_text and update xoonips_file table
     if oldfile exists, set is_deleted of oldfile to 1
     update certify_state, notify certify_required, auto_certify, update item_status, udpate RSS
     commit
     delete oldfile
     */
     // parameter check
     $error =& $response->getError();
     if (count($vars) > 5) {
         $error->add(XNPERR_EXTRA_PARAM);
     } else {
         if (count($vars) < 5) {
             $error->add(XNPERR_MISSING_PARAM);
         } else {
             if (isset($vars[0]) && strlen($vars[0]) > 32) {
                 $error->add(XNPERR_INVALID_PARAM, 'too long parameter 1');
             }
             if ($vars[2] != 'item_id' && $vars[2] != 'ext_id') {
                 $error->add(XNPERR_INVALID_PARAM, 'invalid parameter 3');
             }
             if ($vars[2] == 'item_id' && !is_int($vars[1]) && !ctype_digit($vars[1])) {
                 $error->add(XNPERR_INVALID_PARAM, 'not integer parameter 2');
             }
             if ($vars[2] == 'item_id' && strlen($vars[1]) > 10) {
                 $error->add(XNPERR_INVALID_PARAM, 'too long parameter 2');
             }
             // file size check
             $upload_max_filesize = $this->returnBytes(ini_get('upload_max_filesize'));
             if (filesize($vars[4]->getFilepath()) > $upload_max_filesize) {
                 $error->add(XNPERR_INVALID_PARAM, 'too large file');
             }
             $vars[4]->set('file_size', filesize($vars[4]->getFilepath()));
         }
     }
     if ($error->get(0)) {
         // return if parameter error
         $response->setResult(false);
         return false;
     } else {
         $sessionid = $vars[0];
         $id = $vars[1];
         $id_type = $vars[2];
         $field_name = $vars[3];
         $file = $vars[4];
     }
     list($result, $uid, $session) = $this->restoreSession($sessionid);
     if (!$result) {
         $response->setResult(false);
         $error->add(XNPERR_INVALID_SESSION);
         return false;
     }
     // get item and item_id
     $item_handler =& xoonips_getormcompohandler('xoonips', 'item');
     $item_basic_handler =& xoonips_getormhandler('xoonips', 'item_basic');
     if ($id_type == 'item_id') {
         $item = $item_handler->get($id);
     } else {
         if ($id_type == 'ext_id') {
             if (strlen($id) == 0) {
                 $response->setResult(false);
                 $error->add(XNPERR_INVALID_PARAM, "ext_id is empty");
                 return false;
             } else {
                 $basics =& $item_basic_handler->getObjects(new Criteria('doi', addslashes($id)));
                 if (false === $basics) {
                     $response->setResult(false);
                     $error->add(XNPERR_SERVER_ERROR, "cannot get basic information");
                     return false;
                 } else {
                     if (count($basics) >= 2) {
                         $response->setResult(false);
                         $error->add(XNPERR_SERVER_ERROR, "ext_id is duplicated");
                         return false;
                     } else {
                         if (count($basics) == 1) {
                             $item = $item_handler->get($basics[0]->get('item_id'));
                         } else {
                             $item = false;
                         }
                     }
                 }
             }
         }
     }
     if (!$item) {
         $response->setResult(false);
         $error->add(XNPERR_NOT_FOUND, "id={$id}");
         return false;
     }
     $basic = $item->getVar('basic');
     $item_id = $basic->get('item_id');
     // can modify?
     if (!$item_handler->getPerm($item_id, $uid, 'write')) {
         $item_lock_handler =& xoonips_getormhandler('xoonips', 'item_lock');
         $response->setResult(false);
         if ($item_lock_handler->isLocked($item_id)) {
             $error->add(XNPERR_ACCESS_FORBIDDEN, "cannot update file because item is " . $this->getLockTypeString($item_lock_handler->getLockType($item_id)));
         } else {
             $error->add(XNPERR_ACCESS_FORBIDDEN);
         }
         return false;
     }
     // item -> itemtype, detail_item_type
     $item_type_handler =& xoonips_getormhandler('xoonips', 'item_type');
     $item_type = $item_type_handler->get($basic->get('item_type_id'));
     if (!$item_type) {
         $response->setResult(false);
         $error->add(XNPERR_SERVER_ERROR, "cannot get itemtype of that item");
         return false;
     }
     $detail_item_type_handler =& xoonips_getormhandler($item_type->getVar('name'), 'item_type');
     $detail_item_type = $detail_item_type_handler->get($item_type->getVar('item_type_id'));
     if (!$detail_item_type) {
         $response->setResult(false);
         $error->add(XNPERR_SERVER_ERROR, "cannot get detail itemtype of that item");
         return false;
     }
     // is file_type_id proper?
     $file_type_handler =& xoonips_getormhandler('xoonips', 'file_type');
     $file_type_id = $file->getVar('file_type_id');
     $file_type = $file_type_handler->get($file_type_id);
     if (!$file_type) {
         $response->setResult(false);
         $error->add(XNPERR_SERVER_ERROR, "bad filetype({$file_type_id})");
         return false;
     }
     $file_type_name = $file_type->getVar('name');
     if (!in_array($file_type_name, $detail_item_type->getFileTypeNames())) {
         $response->setResult(false);
         $error->add(XNPERR_INVALID_PARAM, "bad filetype({$file_type_name})");
         return false;
     }
     // add file to non-multiple field?
     $file_handler =& xoonips_getormhandler('xoonips', 'file');
     if (!$detail_item_type->getMultiple($file_type_name) && !$file->getVar('file_id')) {
         $c = new CriteriaCompo();
         $c->add(new Criteria('item_id', $item_id));
         $c->add(new Criteria('file_type_id', $file_type_id));
         $c->add(new Criteria('is_deleted', 0));
         $same_file_num = $file_handler->getCount($c);
         if ($same_file_num > 0) {
             // already file exists
             $response->setResult(false);
             $error->add(XNPERR_INVALID_PARAM, "multiple file not allowed for {$file_type_name}");
             return false;
         }
     }
     // get oldfile from oldfile_id
     $oldfile_id = $file->getVar('file_id');
     if ($oldfile_id) {
         $oldfile = $file_handler->get($oldfile_id);
         if ($oldfile->getVar('is_deleted')) {
             $response->setResult(false);
             $error->add(XNPERR_INVALID_PARAM, "cannot update deleted file(file_id={$oldfile_id})");
             return false;
         } else {
             if ($oldfile->getVar('item_id') != $item_id) {
                 $response->setResult(false);
                 $error->add(XNPERR_INVALID_PARAM, "item(item_id={$item_id}) does not have that file(file_id={$oldfile_id})");
                 return false;
             }
             // check if $oldfile.item_type_id == $file.item_type_id
             $file_type_handler =& xoonips_getormhandler('xoonips', 'file_type');
             $file_type = $file_type_handler->get($oldfile->getVar('file_type_id'));
             if (!$file_type) {
                 $response->setResult(false);
                 $error->add(XNPERR_SERVER_ERROR, "old file has unknown file type id");
                 return false;
             }
             if ($file_type->getVar('name') != $file_type_name) {
                 $response->setResult(false);
                 $error->add(XNPERR_INVALID_PARAM, "cannot change filetype");
                 return false;
             }
         }
     } else {
         $oldfile = false;
     }
     // check item storage limit(private/group)
     $old_size = $this->getSizeOfItem($item);
     if ($oldfile) {
         $new_size = $old_size - $oldfile->getVar('file_size') + $file->getVar('file_size');
     } else {
         $new_size = $old_size + $file->getVar('file_size');
     }
     if (!$this->isEnoughSpace($error, $uid, $new_size, $item->getVar('indexes'), $old_size, $item->getVar('indexes'))) {
         $response->setResult(false);
         //$error->add(XNPERR_SERVER_ERROR, "not enough disk space"); // isEnoughSpace() adds errors.
         return false;
     }
     // set mime-type, thumbnail
     $file->setVar('mime_type', $this->guessMimeType($file));
     if ($detail_item_type->getPreviewFileName() == $file_type_name) {
         if (!$this->createThumbnail($error, $file)) {
             $response->setResult(false);
             return false;
         }
     }
     $data = file_get_contents($file->getFilepath());
     if ($data === false) {
         $response->setResult(false);
         $error->add(XNPERR_SERVER_ERROR, "cannot get file content");
         return false;
     }
     $file->setVar('file_id', null);
     $file->setVar('item_id', $item_id);
     $file->setNew();
     // start transaction
     $transaction = XooNIpsTransaction::getInstance();
     $transaction->start();
     // insert $file
     if (!$file_handler->insert($file)) {
         $response->setResult(false);
         $error->add(XNPERR_SERVER_ERROR, "cannot insert file");
         return false;
     }
     // create file search_text
     $admin_file_handler =& xoonips_gethandler('xoonips', 'admin_file');
     $admin_file_handler->updateFileSearchText($file->get('file_id'), true);
     if ($oldfile) {
         // set oldfile.is_deleted = 1;
         $oldfile->setVar('is_deleted', 1);
         if (!$file_handler->insert($oldfile)) {
             $transaction->rollback();
             $response->setResult(false);
             $error->add(XNPERR_SERVER_ERROR, "cannot update old file");
             return false;
         }
         // delete search_text of old file
         $search_text_handler =& xoonips_getormhandler('xoonips', 'search_text');
         $search_text = $search_text_handler->get($oldfile->get('file_id'));
         if ($search_text && !$search_text_handler->delete($search_text)) {
             $transaction->rollback();
             $response->setResult(false);
             $error->add(XNPERR_INVALID_PARAM, "cannot remove search text");
             return false;
         }
     }
     // event log ( update item )
     $eventlog_handler =& xoonips_getormhandler('xoonips', 'event_log');
     if (!$eventlog_handler->recordUpdateItemEvent($item_id)) {
         $error->add(XNPERR_SERVER_ERROR, "cannot insert event");
         $response->setResult(false);
         return false;
     }
     // item insert/update/certify_required/certified event, change certify_state, send notification, update RSS, update item_status.
     if (!$this->touchItem($error, $item, true)) {
         $transaction->rollback();
         $response->setResult(false);
         return false;
     }
     // commit
     $transaction->commit();
     // unlink old file
     if ($oldfile) {
         $file_handler->deleteFile($oldfile);
     }
     // return
     $response->setSuccess($file->getVar('file_id'));
     $response->setResult(true);
     return true;
 }
コード例 #13
0
 /**
  * execute putItem
  *
  * @param[in]  $vars[0] session ID
  * @param[in]  $vars[1] XooNIpsItemCompo item information
  * @param[in]  array $vars[2] XooNIpsFile[] meta information of attachment files
  * @param[out] $response->result true:success, false:failed
  * @param[out] $response->error  error information
  * @param[out] $response$response->success item id of registered item
  */
 function execute(&$vars, &$response)
 {
     // parameter check
     $error =& $response->getError();
     if (count($vars) > 3) {
         $error->add(XNPERR_EXTRA_PARAM);
     } else {
         if (count($vars) < 3) {
             $error->add(XNPERR_MISSING_PARAM);
         } else {
             if (isset($vars[0]) && strlen($vars[0]) > 32) {
                 $error->add(XNPERR_INVALID_PARAM, 'too long parameter 1');
             }
             // file size check
             if (is_array($vars[2])) {
                 $upload_max_filesize = $this->returnBytes(ini_get('upload_max_filesize'));
                 for ($i = 0; $i < count($vars[2]); $i++) {
                     if (filesize($vars[2][$i]->getFilepath()) > $upload_max_filesize) {
                         $error->add(XNPERR_INVALID_PARAM, 'too large file(file_id=' . $vars[2][$i]->get('file_id') . ')');
                     }
                     $vars[2][$i]->set('file_size', filesize($vars[2][$i]->getFilepath()));
                 }
             }
         }
     }
     if ($error->get(0)) {
         // return if parameter error
         $response->setResult(false);
         return;
     } else {
         $response->setResult(false);
         $sessionid = $vars[0];
         $item = $vars[1];
         $files = $vars[2];
     }
     list($result, $uid, $session) = $this->restoreSession($sessionid);
     if (!$result) {
         $response->setResult(false);
         $error->add(XNPERR_INVALID_SESSION);
         return false;
     }
     if ($uid == UID_GUEST) {
         $response->setResult(false);
         $error->add(XNPERR_ACCESS_FORBIDDEN, "guest user cannot putItem");
         // test E4
         return false;
     }
     // start transaction
     $transaction = XooNIpsTransaction::getInstance();
     $transaction->start();
     // set uid, title_id, keyword_id, creation_date, last_update_date
     $now = time();
     $basic = $item->getVar('basic');
     $basic->setVar('uid', $uid, true);
     $basic->setVar('creation_date', $now, true);
     $basic->setVar('last_update_date', $now, true);
     $item->setVar('basic', $basic);
     $titles = $item->getVar('titles');
     for ($i = 0; $i < count($titles); $i++) {
         $titles[$i]->setVar('title_id', $i, true);
     }
     $item->setVar('titles', $titles);
     $keywords = $item->getVar('keywords');
     for ($i = 0; $i < count($keywords); $i++) {
         $keywords[$i]->setVar('keyword_id', $i, true);
     }
     $item->setVar('keywords', $keywords);
     // ext_id duplicated?
     $item_basic_handler =& xoonips_getormhandler('xoonips', 'item_basic');
     $ext_id = $basic->get('doi');
     if (strlen($ext_id)) {
         $basics =& $item_basic_handler->getObjects(new Criteria('doi', addslashes($ext_id)));
         if (count($basics)) {
             $transaction->rollback();
             $response->setResult(false);
             $error->add(XNPERR_INCOMPLETE_PARAM, "{$ext_id} is duplicated");
             return false;
         }
     }
     //          // filled?
     //          $missing = array();
     //          if (!$item->isFilledRequired($missing)) {
     //              $response->setResult(false);
     //              $error->add(XNPERR_INCOMPLETE_PARAM); // test E3
     //              return false;
     //          }
     // can access that indexes? calculate get add_to_private, add_to_gids, add_to_public
     $index_handler =& xoonips_getormhandler('xoonips', 'index');
     $index_item_link_handler =& xoonips_getormhandler('xoonips', 'index_item_link');
     $index_item_links = $item->getVar('indexes');
     $add_to_private = false;
     $add_to_gids = array();
     $add_to_public = false;
     foreach ($index_item_links as $index_item_link) {
         $index_id = $index_item_link->get('index_id');
         $index = $index_handler->get($index_id);
         if (!$index) {
             $error->add(XNPERR_INVALID_PARAM, "no such index(index_id={$index_id})");
             // test e5
         } else {
             if (!$index_handler->getPerm($index_id, $uid, 'read')) {
                 $error->add(XNPERR_ACCESS_FORBIDDEN, "cannot access index(index_id={$index_id})");
                 // test e5
             } else {
                 $open_level = $index->get('open_level');
                 if ($open_level == OL_PRIVATE) {
                     $add_to_private = true;
                 } else {
                     if ($open_level == OL_GROUP_ONLY) {
                         $add_to_gids[$index->get('gid')] = true;
                     } else {
                         if ($open_level == OL_PUBLIC) {
                             $add_to_public = true;
                         }
                     }
                 }
             }
         }
     }
     $add_to_gids = array_keys($add_to_gids);
     // error if no private index is selected.
     if (!$add_to_private) {
         $error->add(XNPERR_INVALID_PARAM, "select at least 1 private index");
         // test e5
     }
     // item_type_id -> item_type_name, detail_item_type_handler, detail_item_type, detail_item_handler
     $item_type_handler =& xoonips_getormhandler('xoonips', 'item_type');
     $basic = $item->getVar('basic');
     $item_type_id = $basic->get('item_type_id');
     $item_type = $item_type_handler->get($item_type_id);
     if (!$item_type) {
         $response->setResult(false);
         $transaction->rollback();
         $error->add(XNPERR_INVALID_PARAM, "bad itemtype(item_type_id={$item_type_id})");
         // test E6*
         return false;
     }
     $item_type_name = $item_type->get('name');
     $detail_item_type_handler =& xoonips_getormhandler($item_type_name, 'item_type');
     if (!$detail_item_type_handler) {
         $response->setResult(false);
         $transaction->rollback();
         $error->add(XNPERR_SERVER_ERROR, "cannot get item type handler(item_type_id={$item_type_id})");
         // test E7*
         return false;
     }
     $detail_item_type = $detail_item_type_handler->get($item_type_id);
     if (!$detail_item_type) {
         $response->setResult(false);
         $transaction->rollback();
         $error->add(XNPERR_SERVER_ERROR, "cannot get item type(item_type_id={$item_type_id})");
         // test E8*
         return false;
     }
     $detail_item_handler =& xoonips_getormcompohandler($item_type_name, 'item');
     // can access that related_tos?
     $related_tos = $item->getVar('related_tos');
     foreach ($related_tos as $related_to) {
         $item_id = $related_to->get('item_id');
         $item_basic = $item_basic_handler->get($item_id);
         if (!$item_basic) {
             $error->add(XNPERR_INVALID_PARAM, "no such related_to(item_id={$item_id})");
             // test e5
         } else {
             if (!$detail_item_handler->getPerm($item_id, $uid, 'read')) {
                 $error->add(XNPERR_ACCESS_FORBIDDEN, "cannot access related_tos(item_id={$item_id})");
                 // test e5
             }
         }
     }
     if ($error->get()) {
         $transaction->rollback();
         $response->setResult(false);
         return false;
     }
     // error if add to public/group and no rights/readme input
     if ($add_to_public || count($add_to_gids)) {
         if (!$detail_item_handler->isValidForPubicOrGroupShared($item)) {
             $response->setResult(false);
             $error->add(XNPERR_INCOMPLETE_PARAM, "item cannot be public nor group-shared");
             return false;
         }
     }
     if (!$this->isPublicationDateValid($response, $basic->get('publication_year'), $basic->get('publication_month'), $basic->get('publication_mday'), $detail_item_type->getRequired('publication_year'), $detail_item_type->getRequired('publication_month'), $detail_item_type->getRequired('publication_mday'))) {
         $response->setResult(false);
         return false;
     }
     // item number/storage limit check
     $size = 0;
     foreach ($files as $file) {
         $size += $file->get('file_size');
     }
     if (!$this->isEnoughSpace($error, $uid, $size, $item->getVar('indexes'))) {
         $transaction->rollback();
         $response->setResult(false);
         // test E11
         return false;
     }
     // get filetypes
     $file_type_handler =& xoonips_getormhandler('xoonips', 'file_type');
     $file_types =& $file_type_handler->getObjects(null, true);
     // $item->setVar( '...', $files[...] ) // check exactly 1:1 ? correct filetype ? multiple files for non-multiple field?
     $pseudo2files = array();
     for ($i = 0; $i < count($files); $i++) {
         $pseudo_file_id = $files[$i]->get('file_id');
         if (isset($pseudo2files[$pseudo_file_id])) {
             $error->add(XNPERR_INVALID_PARAM, "pseudo file_id conflicts(pseudo file_id={$pseudo_file_id})");
             // test e12
         } else {
             $pseudo2files[$pseudo_file_id] = array('used' => false, 'file' => $files[$i]);
         }
     }
     foreach ($detail_item_type->getFileTypeNames() as $field_name) {
         $detail_files = $item->getVar($field_name);
         if (!$detail_item_type->getMultiple($field_name)) {
             $detail_file = $detail_files;
             if ($detail_file->get('file_id') == 0) {
                 $item->setVar($field_name, false);
                 continue;
                 // this filetype maybe optional and omitted.
             }
             $detail_files = array($detail_file);
         }
         for ($i = 0; $i < count($detail_files); $i++) {
             $pseudo_id = $detail_files[$i]->get('file_id');
             if ($pseudo_id == 0) {
                 unset($detail_files[$i]);
                 continue;
             }
             if (!isset($pseudo_id) || !isset($pseudo2files[$pseudo_id])) {
                 $error->add(XNPERR_INVALID_PARAM, "unknown pseudo file_id in {$field_name}(pseudo file_id={$pseudo_id})");
                 // test e12
             } else {
                 if ($pseudo2files[$pseudo_id]['used']) {
                     $error->add(XNPERR_INVALID_PARAM, "file referred twice(pseudo file_id={$pseudo_id})");
                     // test e12
                 } else {
                     $pseudo2files[$pseudo_id]['used'] = true;
                     $file_type_id = $pseudo2files[$pseudo_id]['file']->get('file_type_id');
                     if (!isset($file_types[$file_type_id])) {
                         $error->add(XNPERR_INVALID_PARAM, "bad filetype(file_type_id={$file_type_id} pseudo file_id={$pseudo_id})");
                         // test e12
                     } else {
                         if ($file_types[$file_type_id]->get('name') != $field_name) {
                             $error->add(XNPERR_INVALID_PARAM, "filetype not match(pseudo file_id={$pseudo_id})");
                             // test e12
                         } else {
                             $detail_files[$i] = $pseudo2files[$pseudo_id]['file'];
                             $detail_files[$i]->setVar('mime_type', $this->guessMimeType($detail_files[$i]), true);
                             if ($field_name == $detail_item_type->getPreviewFileName()) {
                                 $this->createThumbnail($error, $detail_files[$i]);
                             }
                         }
                     }
                 }
             }
         }
         if ($detail_item_type->getMultiple($field_name)) {
             $item->setVar($field_name, $detail_files);
         } else {
             if (count($detail_files)) {
                 if (count($detail_files) >= 2) {
                     $error->add(XNPERR_INVALID_PARAM, "too many files for {$field_name}");
                     // test e12
                 }
                 $item->setVar($field_name, $detail_files[0]);
             }
         }
     }
     if (count($pseudo2files) != 0) {
         foreach ($pseudo2files as $pseudo_id => $info) {
             if ($info['used'] == false) {
                 $error->add(XNPERR_INVALID_PARAM, "redundant file(pseudo file_id={$pseudo_id})");
                 // test e12
             }
         }
     }
     if ($error->get()) {
         $transaction->rollback();
         $response->setResult(false);
         return false;
     }
     // insert item
     $detail_item_handler->setNew($item);
     $detail_item_handler->setDirty($item);
     if (!$detail_item_handler->insert($item)) {
         $error->add(XNPERR_SERVER_ERROR, "cannot insert item");
         // test E13
         $transaction->rollback();
         $response->setResult(false);
         return false;
     }
     $detail_item_handler->unsetNew($item);
     $basic = $item->getVar('basic');
     $item_id = $basic->get('item_id');
     // event log ( insert item )
     $eventlog_handler =& xoonips_getormhandler('xoonips', 'event_log');
     if (!$eventlog_handler->recordInsertItemEvent($item_id)) {
         $transaction->rollback();
         $error->add(XNPERR_SERVER_ERROR, "cannot insert event");
         // test E14
         return false;
     }
     // item insert/update/certify_required/certified event, change certify_state, update item_status.
     if (!$this->touchItem1($error, $item, $uid)) {
         $transaction->rollback();
         $response->setResult(false);
         // test E16
         return false;
     }
     // commit
     $transaction->commit();
     // update search_text
     $file_handler =& xoonips_getormhandler('xoonips', 'file');
     $files =& $file_handler->getObjects(new Criteria('item_id', $item_id));
     if (false === $files) {
         $transaction->rollback();
         $error->add(XNPERR_SERVER_ERROR, "cannot get file");
         return false;
     } else {
         $admin_file_handler =& xoonips_gethandler('xoonips', 'admin_file');
         foreach ($files as $file) {
             $admin_file_handler->updateFileSearchText($file->get('file_id'), true);
         }
     }
     // notification and rss
     $this->touchItem2($error, $item, $uid);
     $response->setSuccess($item_id);
     $response->setResult(true);
     return true;
 }
コード例 #14
0
 /**
  * execute getSimpleItems
  *
  * @param[in] $vars[0] sessionid
  * @param[in] $vars[1] array of id
  * @param[in] $vars[2] id_type
  * @param[out] $response->result true:success, false:failed
  * @param[out] $response->error  error information
  * @param[out] $response->success XooNIpsItem retrieved item object
  * @return false if fault
  */
 function execute(&$vars, &$response)
 {
     $error =& $response->getError();
     $response->setResult(false);
     //
     // parameter check
     if (count($vars) > 3) {
         $error->add(XNPERR_EXTRA_PARAM);
     } else {
         if (count($vars) < 3) {
             $error->add(XNPERR_MISSING_PARAM);
         } else {
             if (isset($vars[0]) && strlen($vars[0]) > 32) {
                 $error->add(XNPERR_INVALID_PARAM, 'too long parameter 1');
             }
             if ($vars[2] != 'item_id' && $vars[2] != 'ext_id') {
                 $error->add(XNPERR_INVALID_PARAM, 'invalid parameter 3');
             }
         }
     }
     //
     if ($error->get(0)) {
         // return if parameter error
         $response->setResult(false);
         return false;
     } else {
         $sessionid = $vars[0];
         $ids = $vars[1];
         $id_type = $vars[2];
     }
     //
     // validate session
     list($result, $uid, $session) = $this->restoreSession($sessionid);
     if (!$result) {
         $error->add(XNPERR_INVALID_SESSION);
     }
     //
     if ($error->get(0)) {
         // return if parameter error
         $response->setResult(false);
         return;
     } else {
         $response->setResult(false);
         $sessionid = $vars[0];
         $item = $vars[1];
         $files = $vars[2];
     }
     //
     // escape each id
     $esc_ids = array();
     foreach ($ids as $id) {
         if ($id_type == 'item_id') {
             $esc_ids[] = intval($id);
         } else {
             if ($id_type == 'ext_id') {
                 $esc_ids[] = $GLOBALS['xoopsDB']->quoteString($id);
             }
         }
     }
     //
     //
     if ($id_type == 'item_id') {
         $criteria = new Criteria('item_id', '(' . implode(', ', $esc_ids) . ')', 'IN');
     } else {
         if ($id_type == 'ext_id') {
             $criteria = new Criteria('doi', '(' . implode(', ', $esc_ids) . ')', 'IN');
         }
     }
     // retrieve each item
     $xoonipsitem_handler =& xoonips_getormcompohandler('xoonips', 'item');
     $items =& $xoonipsitem_handler->getObjects($criteria);
     //
     $ret = array();
     // return array of items
     if ($items) {
         //
         // creat mapping of ext_id or item_id => item object
         $map = array();
         for ($i = 0; $i < count($items); $i++) {
             $basic = $items[$i]->getVar('basic');
             if ($id_type == 'item_id') {
                 $map[$basic->get('item_id')] = $items[$i];
             } else {
                 if ($id_type == 'ext_id') {
                     $map[$basic->get('doi')] = $items[$i];
                 }
             }
         }
         //
         $itemtype_handler =& xoonips_getormhandler('xoonips', 'item_type');
         foreach ($ids as $id) {
             if (!isset($map[$id])) {
                 continue;
             }
             // can't retrieve an item that is identified by $id.
             // check access permission
             $item = $map[$id];
             $basic = $item->getVar('basic');
             $perm = $xoonipsitem_handler->getPerm($basic->get('item_id'), $uid, 'read');
             if (!$perm) {
                 continue;
             }
             // skip access forbidden item
             $itemtype =& $itemtype_handler->get($basic->get('item_type_id'));
             if (!$itemtype) {
                 continue;
             }
             //
             //
             // retrieve item
             $item_handler =& xoonips_getormcompohandler($itemtype->get('name'), 'item');
             if ($item_handler) {
                 $i =& $item_handler->get($basic->get('item_id'));
                 if (is_object($i)) {
                     $ret[] = $i;
                 }
             }
         }
     }
     $response->setSuccess($ret);
     $response->setResult(true);
     return true;
 }
コード例 #15
0
 /**
  * execute getFile
  *
  * @param[in]  $vars[0] session ID
  * @param[in]  $vars[1] file ID
  * @param[out] $response->result true:success, false:failed
  * @param[out] $response->error  error information
  * @param[out] $response->success file metadata
  */
 function execute(&$vars, &$response)
 {
     // parameter check
     $error =& $response->getError();
     if (count($vars) > 2) {
         $error->add(XNPERR_EXTRA_PARAM);
     }
     if (count($vars) < 2) {
         $error->add(XNPERR_MISSING_PARAM);
     }
     //
     if (isset($vars[0]) && strlen($vars[0]) > 32) {
         $error->add(XNPERR_INVALID_PARAM, 'too long parameter 1');
     }
     if (!is_int($vars[1]) && !ctype_digit($vars[1])) {
         $error->add(XNPERR_INVALID_PARAM, 'not integer parameter 2');
     }
     //
     if ($error->get(0)) {
         // return if parameter error
         $response->setResult(false);
         return false;
     } else {
         $sessionid = $vars[0];
         $file_id = intval($vars[1]);
     }
     list($result, $uid, $session) = $this->restoreSession($sessionid);
     if (!$result) {
         $response->setResult(false);
         $error->add(XNPERR_INVALID_SESSION);
         return false;
     }
     // file_id -> file, item_id
     $file_handler =& xoonips_getormhandler('xoonips', 'file');
     $file = $file_handler->get($file_id);
     if (!$file) {
         $response->setResult(false);
         $error->add(XNPERR_NOT_FOUND);
         return false;
     }
     $item_id = $file->get('item_id');
     if (empty($item_id)) {
         $response->setResult(false);
         $error->add(XNPERR_NOT_FOUND);
         // maybe belong to other session
         return false;
     }
     // can user access that item?
     $item_handler =& xoonips_getormcompohandler('xoonips', 'item');
     if (!$item_handler->getPerm($item_id, $uid, 'read')) {
         $response->setResult(false);
         $error->add(XNPERR_ACCESS_FORBIDDEN);
         return false;
     }
     // already deleted?
     if ($file->get('is_deleted')) {
         $response->setResult(false);
         $error->add(XNPERR_NOT_FOUND, "already deleted or replaced");
         return false;
     }
     // item_id -> item, itemtype
     $item_basic_handler =& xoonips_getormhandler('xoonips', 'item_basic');
     $basic = $item_basic_handler->get($item_id);
     if (!$basic) {
         $response->setResult(false);
         $error->add(XNPERR_SERVER_ERROR, "cannot get item_basic");
         return false;
     }
     $item_type_handler =& xoonips_getormhandler('xoonips', 'item_type');
     $item_type = $item_type_handler->get($basic->get('item_type_id'));
     if (!$item_type) {
         $response->setResult(false);
         $error->add(XNPERR_SERVER_ERROR, "cannot get itemtype of that item");
         return false;
     }
     // item_type, item_id -> detail
     $detail_item_handler =& xoonips_getormcompohandler($item_type->get('name'), 'item');
     $detail_item = $detail_item_handler->get($item_id);
     if (!$detail_item) {
         $response->setResult(false);
         $error->add(XNPERR_SERVER_ERROR, "cannot get item");
         return false;
     }
     if (!$detail_item_handler->hasDownloadPermission($uid, $file_id)) {
         $response->setResult(false);
         $error->add(XNPERR_ACCESS_FORBIDDEN);
         return false;
     }
     $file_type_handler =& xoonips_getormhandler('xoonips', 'file_type');
     $file_type = $file_type_handler->get($file->get('file_type_id'));
     if ($file_type === false) {
         $response->setResult(false);
         $error->add(XNPERR_SERVER_ERROR, "unknown file type");
         return false;
     }
     $iteminfo = $detail_item_handler->getItemInfo();
     if ($iteminfo['files']['main'] == $file_type->get('name')) {
         $download_count = $file->get('download_count');
         $download_count_sum = $file_handler->getTotalDownloadCount($item_id, $file_type->get('name'));
     } else {
         $download_count = 0;
         $download_count_sum = 0;
     }
     if ($iteminfo['files']['preview'] == $file_type->get('name')) {
         $caption = $file->get('caption');
         $thumbnail = $file->get('thumbnail_file');
     } else {
         $caption = '';
         $thumbnail = '';
     }
     $result = array('id' => $file_id, 'filetype' => $file_type->get('name'), 'originalname' => $file->get('original_file_name'), 'size' => $file->get('file_size'), 'mimetype' => $file->get('mime_type'), 'caption' => $caption, 'thumbnail' => $thumbnail, 'registration_date' => $basic->get('creation_date'), 'last_modified_date' => $file->get('timestamp'), 'download_count' => $download_count, 'download_count_sum' => $download_count_sum);
     $response->setSuccess($result);
     $response->setResult(true);
     return true;
 }
コード例 #16
0
function xnpconferenceGetPrinterFriendlyDetailBlock($item_id)
{
    // get uid
    global $xoopsUser;
    $myuid = is_object($xoopsUser) ? $xoopsUser->getVar('uid', 'n') : UID_GUEST;
    // set to template
    global $xoopsTpl;
    $tpl = new XoopsTpl();
    $tpl->assign($xoopsTpl->get_template_vars());
    // copy variables in $xoopsTpl to $tpl
    $tpl->assign('editable', false);
    $tpl->assign('basic', xnpGetBasicInformationPrinterFriendlyBlock($item_id));
    $tpl->assign('index', xnpGetIndexPrinterFriendlyBlock($item_id));
    $tpl->assign('presentation_file', xnpGetAttachmentPrinterFriendlyBlock($item_id, 'conference_file'));
    $tpl->assign('conference_paper', xnpGetAttachmentPrinterFriendlyBlock($item_id, 'conference_paper'));
    $tpl->assign('dl_flag', (int) xnpconferenceGetAttachmentDownloadLimitOption($item_id));
    $xnpconference_handler =& xoonips_getormcompohandler('xnpconference', 'item');
    $tpl->assign('xoonips_item', $xnpconference_handler->getTemplateVar(XOONIPS_TEMPLATE_TYPE_ITEM_DETAIL, $item_id, $myuid));
    // return as HTML
    return $tpl->fetch('db:xnpconference_detail_block.html');
}
コード例 #17
0
/**
 * xoopsUser has item export permission or not.
 * @param integer $item_id id of item to check
 * @return boolean true(permitted), false(forbidden)
 */
function export_item_enable($item_id)
{
    global $xoopsUser;
    $handler =& xoonips_getormcompohandler('xoonips', 'item');
    return $handler->getPerm($item_id, $xoopsUser ? $xoopsUser->getVar('uid') : UID_GUEST, 'export');
}
コード例 #18
0
function xnppaperGetPrinterFriendlyDetailBlock($item_id)
{
    // get uid
    global $xoopsUser;
    $myuid = is_object($xoopsUser) ? $xoopsUser->getVar('uid', 'n') : UID_GUEST;
    global $xoopsTpl;
    $mhandler =& xoops_gethandler('module');
    $chandler =& xoops_gethandler('config');
    $module = $mhandler->getByDirname('xnppaper');
    $assoc = $chandler->getConfigsByCat(false, $module->mid());
    // set to template
    $tpl = new XoopsTpl();
    // copy variables in $xoopsTpl to $tpl
    $tpl->assign($xoopsTpl->get_template_vars());
    $tpl->assign('editable', xnp_get_item_permission($_SESSION['XNPSID'], $item_id, OP_MODIFY));
    $tpl->assign('basic', xnpGetBasicInformationPrinterFriendlyBlock($item_id));
    $tpl->assign('index', xnpGetIndexPrinterFriendlyBlock($item_id));
    $tpl->assign('paper_pdf_reprint', xnpGetAttachmentPrinterFriendlyBlock($item_id, 'paper_pdf_reprint'));
    // Make sure that this user access to item_id is permitted or not
    $tpl->assign('show_pdf', $assoc['pdf_access_rights'] <= xnpGetAccessRights($item_id));
    $tpl->assign('show_abstract', $assoc['abstract_access_rights'] <= xnpGetAccessRights($item_id));
    $xnppaper_handler =& xoonips_getormcompohandler('xnppaper', 'item');
    $tpl->assign('xoonips_item', $xnppaper_handler->getTemplateVar(XOONIPS_TEMPLATE_TYPE_ITEM_DETAIL, $item_id, $myuid));
    // return as HTML
    return $tpl->fetch('db:xnppaper_detail_block.html');
}
コード例 #19
0
 /**
  * delete user account and related data
  * - delete user account
  * - delete user's items
  * - delete user's private indexes
  * - remove user from groups
  * - remove user from xoonips groups
  * - remove user from notifications
  * @access public
  * @param int $uid uid to be deleted
  * 
  */
 function deleteAccount($uid)
 {
     $criteria = new Criteria('uid', intval($uid));
     //delete user's item
     $item_type_handler =& xoonips_getormhandler('xoonips', 'item_type');
     foreach ($item_type_handler->getObjects() as $itemtype) {
         if ($itemtype->get('item_type_id') == ITID_INDEX) {
             continue;
         }
         $item_handler =& xoonips_getormcompohandler($itemtype->get('name'), 'item');
         if (!$item_handler) {
             continue;
         }
         foreach ($item_handler->getObjects($criteria) as $item) {
             $item_handler->delete($item);
         }
     }
     //remove user from groups
     $member_handler =& xoops_gethandler('member');
     if ($member_handler->getUser($uid)) {
         $member_handler->deleteUser($member_handler->getUser($uid));
     }
     //remove user from xoonips groups
     $xgroups_users_link_handler =& xoonips_getormhandler('xoonips', 'groups_users_link');
     $xgroups_users_link_handler->deleteAll($criteria);
     //delete index
     $index_compo_handler =& xoonips_getormcompohandler('xoonips', 'index');
     foreach ($index_compo_handler->getObjects($criteria) as $index) {
         $index_compo_handler->delete($index);
     }
     //remove user from notifications
     $notification_handler =& xoops_gethandler('notification');
     $notification_handler->deleteAll(new Criteria('not_uid', intval($uid)));
     //delete xoonips user
     $xu_handler =& xoonips_getormhandler('xoonips', 'users');
     $xu_handler->deleteAll($criteria);
     return true;
 }
コード例 #20
0
 function convertIndexObjectToIndexStructure($index_compo, &$response)
 {
     $index = $index_compo->getVar('index');
     //
     $titles = $index_compo->getVar('titles');
     $title = $titles[0]->get('title');
     //
     switch ($index->get('open_level')) {
         case 1:
             //public
             $open_level = 'public';
             break;
         case 2:
             //group
             $groups_handler =& xoonips_getormhandler('xoonips', 'groups');
             $group = $groups_handler->get($index->get('gid'));
             if ($group) {
                 $open_level = $group->get('gname');
             } else {
                 $response->addError(XNPERR_SERVER_ERROR, 'group of index is not found. index_id:' . $index->get('index_id'));
                 return false;
             }
             break;
         case 3:
             //private
             $open_level = 'private';
             if ($index->get('parent_index_id') == IID_ROOT && $index->get('uid') == $_SESSION['xoopsUserId']) {
                 $title = XNP_PRIVATE_INDEX_TITLE;
                 // title of /Private is not username but "Private"
             }
             break;
         default:
             $response->addError(XNPERR_SERVER_ERROR, 'unknown open level:' . $index->get('open_level'));
             return false;
     }
     $index_compo_handler =& xoonips_getormcompohandler('xoonips', 'index');
     $user_handler =& xoonips_getormhandler('xoonips', 'users');
     $user = $user_handler->get($_SESSION['xoopsUserId']);
     $paths = $index_compo_handler->getIndexPathNames($index->get('index_id'), $user ? $user->get('private_index_id') : false);
     return array('id' => $index->get('index_id'), 'name' => $title, 'parent' => $index->get('parent_index_id'), 'open_level' => $open_level, 'path' => '/' . implode('/', $paths));
 }
コード例 #21
0
     redirect_header(XOOPS_URL . '/modules/xoonips/certifyuser.php', 3, _TAKINGBACK);
     exit;
 }
 // check token ticket
 if (!$xoopsGTicket->check(true, 'xoonips_certify_user_uncertfy')) {
     exit;
 }
 $comment = isset($_POST['comment']) ? $_POST['comment'] : '';
 $user = array();
 $result_get_account = xnp_get_account($xnpsid, $certify_uid, $user);
 if ($result_get_account != RES_OK) {
     redirect_header('certifyuser.php', 3, _MD_XOONIPS_ACCOUNT_CANNOT_ACQUIRE_USER_INFO . "(in xnp_get_account result={$result_get_account})");
     exit;
 }
 xoonips_notification_account_rejected($certify_uid, $comment);
 $user_compo_handler =& xoonips_getormcompohandler('xoonips', 'user');
 $user_compo_handler->deleteAccount($certify_uid);
 $event_handler =& xoonips_getormhandler('xoonips', 'event_log');
 $event_handler->recordDeleteAccountEvent($certify_uid);
 $event_handler->recordUncertifyAccountEvent($certify_uid, $comment);
 //
 // notify a uncertified to the user by e-mail
 //
 $langman =& xoonips_getutility('languagemanager');
 $xoopsMailer =& getMailer();
 $xoopsMailer->useMail();
 $xoopsMailer->setTemplateDir($langman->mail_template_dir());
 $xoopsMailer->setTemplate('xoonips_account_uncertified.tpl');
 $xoopsMailer->assign('X_UNAME', $user['uname']);
 $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
 $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
 function get_xoonips_item_detail_template_vars()
 {
     $basic =& $this->_params['item']->getVar('basic');
     $handler =& xoonips_getormcompohandler($this->_params['item_type']->get('name'), 'item');
     return $handler->getTemplateVar(XOONIPS_TEMPLATE_TYPE_TRANSFER_ITEM_DETAIL, $basic->get('item_id'));
 }
コード例 #23
0
/**
 * @access private
 */
function _xoonips_notification_get_item_list($transfer_uid, $item_ids)
{
    $item_list = array();
    $handler =& xoonips_getormcompohandler('xoonips', 'item');
    foreach ($item_ids as $item_id) {
        $item_titles = _xoonips_notification_get_title_of_items(array($item_id));
        $item_urls = _xoonips_notification_get_detail_urls(array($item_id));
        $item_list[] = _MD_XOONIPS_TRANSFER_NOTIFICATION_ITEM_TITLE . $item_titles[0] . "\n" . _MD_XOONIPS_TRANSFER_NOTIFICATION_ITEM_DETAIL . ($handler->getPerm($item_id, $transfer_uid, 'read') ? $item_urls[0] : _MD_XOONIPS_TRANSFER_NOTIFICATION_ITEM_DETAIL_FORBIDDEN);
    }
    return implode("\n\n", $item_list);
}
 /**
  * get index summary string like '/FOO/BAR(999)'
  * - index path
  * - number of item in its index
  * @access private
  * @param array $index_ids array of integer of index id to get sumary
  * @return array summary strings
  *
  */
 function get_index_summaries($index_ids)
 {
     $index_compo_handler =& xoonips_getormcompohandler('xoonips', 'index');
     $index_item_link_handler =& xoonips_getormhandler('xoonips', 'index_item_link');
     $result = array();
     foreach ($index_ids as $index_id) {
         // store for notification
         $rows =& $index_item_link_handler->getObjects(new Criteria('index_id', $index_id), false, 'count(*)');
         if ($rows && $rows[0]->getExtraVar('count(*)') > 0) {
             $result[] = sprintf('%s(%d)', '/' . join('/', $index_compo_handler->getIndexPathNames($index_id)), $rows[0]->getExtraVar('count(*)'));
         } else {
             $result[] = sprintf('%s', '/' . join('/', $index_compo_handler->getIndexPathNames($index_id)));
         }
     }
     return $result;
 }
コード例 #25
0
function xnppresentationGetPrinterFriendlyDetailBlock($item_id)
{
    // get uid
    global $xoopsUser;
    $myuid = is_object($xoopsUser) ? $xoopsUser->getVar('uid', 'n') : UID_GUEST;
    global $xoopsTpl;
    // get DetailInformation
    $detail_handler =& xoonips_getormhandler('xnppresentation', 'item_detail');
    $detail_orm =& $detail_handler->get($item_id);
    if (!$detail_orm) {
        return '';
    }
    // set to template
    $tpl = new XoopsTpl();
    // copy variables in $xoopsTpl to $tpl
    $tpl->assign($xoopsTpl->get_template_vars());
    $tpl->assign('editable', xnp_get_item_permission($_SESSION['XNPSID'], $item_id, OP_MODIFY));
    $tpl->assign('basic', xnpGetBasicInformationPrinterFriendlyBlock($item_id));
    $tpl->assign('index', xnpGetIndexPrinterFriendlyBlock($item_id));
    $tpl->assign('preview', xnpGetPreviewPrinterFriendlyBlock($item_id));
    $tpl->assign('presentation_file', xnpGetAttachmentPrinterFriendlyBlock($item_id, 'presentation_file'));
    $tpl->assign('readme', xnpGetTextFilePrinterFriendlyBlock($item_id, 'readme', $detail_orm->getVar('readme', 'n')));
    $tpl->assign('rights', xnpGetRightsPrinterFriendlyBlock($item_id, $detail_orm->getVar('use_cc', 'n'), $detail_orm->getVar('rights', 'n'), $detail_orm->getVar('cc_commercial_use', 'n'), $detail_orm->getVar('cc_modification', 'n')));
    $xnppresentation_handler =& xoonips_getormcompohandler('xnppresentation', 'item');
    $tpl->assign('xoonips_item', $xnppresentation_handler->getTemplateVar(XOONIPS_TEMPLATE_TYPE_ITEM_DETAIL, $item_id, $myuid));
    // return as HTML
    return $tpl->fetch('db:xnppresentation_detail_block.html');
}
コード例 #26
0
function xnpfilesGetPrinterFriendlyDetailBlock($item_id)
{
    // get uid
    global $xoopsUser;
    $myuid = is_object($xoopsUser) ? $xoopsUser->getVar('uid', 'n') : UID_GUEST;
    // set to template
    global $xoopsTpl;
    $tpl = new XoopsTpl();
    $tpl->assign($xoopsTpl->get_template_vars());
    // copy variables in $xoopsTpl to $tpl
    $tpl->assign('editable', xnp_get_item_permission($_SESSION['XNPSID'], $item_id, OP_MODIFY));
    $tpl->assign('basic', xnpGetBasicInformationPrinterFriendlyBlock($item_id));
    $tpl->assign('index', xnpGetIndexPrinterFriendlyBlock($item_id));
    $tpl->assign('files_file', xnpGetAttachmentPrinterFriendlyBlock($item_id, 'files_file'));
    $xnpfiles_handler =& xoonips_getormcompohandler('xnpfiles', 'item');
    $tpl->assign('xoonips_item', $xnpfiles_handler->getTemplateVar(XOONIPS_TEMPLATE_TYPE_ITEM_DETAIL, $item_id, $myuid));
    // return as HTML
    return $tpl->fetch('db:xnpfiles_detail_block.html');
}
コード例 #27
0
function xnpbookGetMetaInformation($item_id)
{
    $ret = array();
    $author_array = array();
    $basic = xnpGetBasicInformationArray($item_id);
    $detail = xnpbookGetDetailInformation($item_id);
    if (!empty($basic)) {
        $ret[_MD_XOONIPS_ITEM_TITLE_LABEL] = implode("\n", $basic['titles']);
        $ret[_MD_XOONIPS_ITEM_CONTRIBUTOR_LABEL] = $basic['contributor'];
        $ret[_MD_XOONIPS_ITEM_KEYWORDS_LABEL] = implode("\n", $basic['keywords']);
        $ret[_MD_XOONIPS_ITEM_DESCRIPTION_LABEL] = $basic['description'];
        $ret[_MD_XOONIPS_ITEM_DOI_LABEL] = $basic['doi'];
        $ret[_MD_XOONIPS_ITEM_LAST_UPDATE_DATE_LABEL] = $basic['last_update_date'];
        $ret[_MD_XOONIPS_ITEM_CREATION_DATE_LABEL] = $basic['creation_date'];
    }
    if (!empty($detail)) {
        $ret[_MD_XNPBOOK_EDITOR_LABEL] = $detail['editor']['value'];
        $ret[_MD_XNPBOOK_PUBLISHER_LABEL] = $detail['publisher']['value'];
        $ret[_MD_XNPBOOK_YEAR_LABEL] = $basic['publication_year'];
        $ret[_MD_XNPBOOK_URL_LABEL] = $detail['url']['value'];
        $ret[_MD_XNPBOOK_ISBN_LABEL] = $detail['isbn']['value'];
    }
    $xnpbook_handler =& xoonips_getormcompohandler('xnpbook', 'item');
    $xnpbook =& $xnpbook_handler->get($item_id);
    foreach ($xnpbook->getVar('author') as $author) {
        $author_array[] = $author->getVar('author', 'n');
    }
    $ret[_MD_XNPBOOK_AUTHOR_LABEL] = implode("\n", $author_array);
    return $ret;
}
コード例 #28
0
 /**
  * delete all of descendents
  * @param integer $index_id index id 
  * @return bool 
  */
 function deleteAllDescendents($index_id)
 {
     $index_compo_handler =& xoonips_getormcompohandler('xoonips', 'index');
     $index_handler =& xoonips_getormhandler('xoonips', 'index');
     foreach ($index_handler->getAllDescendents($index_id) as $descendent) {
         if (!$index_compo_handler->deleteByKey($descendent->get('index_id'))) {
             return false;
         }
     }
     return true;
 }
コード例 #29
0
 function unsetDirty(&$item)
 {
     $handler =& xoonips_getormcompohandler('xnpmodel', 'item');
     return $handler->unsetDirty($item);
 }
コード例 #30
0
    $xoopsTpl->assign('modify_button_visible', '1');
} else {
    $xoopsTpl->assign('modify_button_visible', '0');
}
if ($op != 'print') {
    $xoopsTpl->assign('print_button_visible', '1');
} else {
    $xoopsTpl->assign('print_button_visible', '0');
}
$xoopsTpl->assign('item_id', $item_id);
if ($doi != '') {
    $xoopsTpl->assign('doi', $textutil->html_special_chars($doi));
    $xoopsTpl->assign('doi_column_name', $textutil->html_special_chars($doi_column_name));
}
if (xoonips_is_user_export_enabled()) {
    $handler =& xoonips_getormcompohandler('xoonips', 'item');
    $xoopsTpl->assign('export_enabled', $handler->getPerm($item_id, $xoopsUser ? $xoopsUser->getVar('uid') : UID_GUEST, 'export'));
}
function genSelectLabels(&$index)
{
    $textutil =& xoonips_getutility('text');
    $title = $index['titles'][DEFAULT_INDEX_TITLE_OFFSET];
    $indent_html = str_repeat('&nbsp;&nbsp;', (int) $index['depth']);
    if (isset($index['child_count']) && $index['child_count'] != 0) {
        $select_label = sprintf(' %s ( %u )', $title, $index['child_count']);
    } else {
        $select_label = sprintf(' %s ', $title);
    }
    $index['indent_html'] = $indent_html;
    $index['select_label'] = $textutil->html_special_chars($select_label);
}