| 22 |
* |
* |
| 23 |
* $Revision$ |
* $Revision$ |
| 24 |
* $Log$ |
* $Log$ |
| 25 |
* Revision 1.118.2.7 2006/10/04 09:25:21 tani |
* Revision 1.120 2006/04/11 10:31:27 tani |
| 26 |
* activate: accept only guest session or login user's session. |
* merge to main trunk (from REL20060213 to merge_to_20060411) |
| 27 |
* |
* REL20060213からmerge_to_20060411までのSTABLE_2の差分をCURRENTにマージ. |
|
* Revision 1.118.2.6 2006/10/04 08:31:05 tani |
|
|
* activate: don't valid session for activation by user. |
|
|
* |
|
|
* Revision 1.118.2.5 2006/08/24 09:59:20 aga4096 |
|
|
* ・[ #8723 ] STABLE2 のALでDB接続文字コード指定 のパッチをあてた. |
|
|
* |
|
|
* Revision 1.118.2.4 2006/06/30 02:46:02 aga4096 |
|
|
* ・MySQL5.0.22では certify.php で常に No items found. になる場合があるのを修正. |
|
|
* |
|
|
* Revision 1.118.2.3 2006/04/12 09:20:12 aga4096 |
|
|
* ・insert_index で item_type_id が0になる場合があるのを修正. |
|
| 28 |
* |
* |
| 29 |
* Revision 1.118.2.2 2006/02/28 04:49:17 aga4096 |
* Revision 1.118.2.2 2006/02/28 04:49:17 aga4096 |
| 30 |
* ・NIJC code, guestのon/offを書き換えたときに item_status をリセットする. |
* ・NIJC code, guestのon/offを書き換えたときに item_status をリセットする. |
| 32 |
* Revision 1.118.2.1 2006/02/14 05:13:17 aga4096 |
* Revision 1.118.2.1 2006/02/14 05:13:17 aga4096 |
| 33 |
* ・アイテムが private/index_a と public/index_b に登録された状態で、 private/index_aを削除するとおかしくなるのを修正. |
* ・アイテムが private/index_a と public/index_b に登録された状態で、 private/index_aを削除するとおかしくなるのを修正. |
| 34 |
* |
* |
| 35 |
|
* Revision 1.119 2006/04/07 08:19:51 tani |
| 36 |
|
* doiをDBから取得する時の型指定をBLOBにあわせて修正. |
| 37 |
|
* |
| 38 |
* Revision 1.118 2006/01/10 10:56:30 tani |
* Revision 1.118 2006/01/10 10:56:30 tani |
| 39 |
* selectiveHarvesting:stat.item_idでorder by(asc) |
* selectiveHarvesting:stat.item_idでorder by(asc) |
| 40 |
* |
* |
| 1166 |
return sql; |
return sql; |
| 1167 |
} |
} |
| 1168 |
|
|
|
/** |
|
|
* |
|
|
* Set the character code for database connection |
|
|
* |
|
|
* @param type DBTYPE_MYSQL or DBTYPE_SQLITE |
|
|
* @return RES_OK |
|
|
* @return RES_DB_INITIALIZE_ERROR |
|
|
* @see result_t |
|
|
*/ |
|
|
static result_t setCharset( dbtype_t type ) { |
|
|
SQLRETURN sqlcode; |
|
|
SQLHANDLE hstmt = NULL; |
|
|
string sql; |
|
|
result_t ret; |
|
|
ret = RES_OK; |
|
|
#ifdef USE_MYSQL_CHARSET |
|
|
if( type == DBTYPE_MYSQL ) { |
|
|
sql = "SET NAMES "; |
|
|
sql += MYSQL_CHARSET; |
|
|
if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) { |
|
|
if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) == SQL_SUCCESS ) ) { |
|
|
ret = RES_OK; |
|
|
syslog_printf( "setCharset succeed" ); |
|
|
} else { |
|
|
string s( "SQLExecDirect in setCharset "); |
|
|
s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode ); |
|
|
s += string( ", sql=" ) + string( sql ); |
|
|
setLastErrorString( s.c_str() ); |
|
|
ret = RES_DB_INITIALIZE_ERROR; |
|
|
} |
|
|
SQLFreeHandle( SQL_HANDLE_STMT, hstmt ); |
|
|
} else { |
|
|
string s( "SQLAllocHandle in setCharset "); |
|
|
s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode ); |
|
|
setLastErrorString( s.c_str() ); |
|
|
ret = RES_DB_INITIALIZE_ERROR; |
|
|
} |
|
|
} |
|
|
#endif |
|
|
return ret; |
|
|
} |
|
|
|
|
| 1169 |
|
|
| 1170 |
/** |
/** |
| 1171 |
* |
* |
| 1225 |
return RES_DB_CONNECT_ERROR; |
return RES_DB_CONNECT_ERROR; |
| 1226 |
} |
} |
| 1227 |
syslog_printf( "initializeDB succeed" ); |
syslog_printf( "initializeDB succeed" ); |
| 1228 |
return setCharset( dbtype ); |
return RES_OK; |
| 1229 |
} |
} |
| 1230 |
|
|
| 1231 |
/** |
/** |
| 1311 |
result_t activate( sessionid_t sid, userid_t uid, bool activate ) |
result_t activate( sessionid_t sid, userid_t uid, bool activate ) |
| 1312 |
{ |
{ |
| 1313 |
if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED; |
if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED; |
| 1314 |
if( sid != session_t::SID_GUEST |
if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION; |
|
&& !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION; |
|
| 1315 |
|
|
| 1316 |
string sql; |
string sql; |
| 1317 |
SQLHANDLE hstmt = NULL; |
SQLHANDLE hstmt = NULL; |
| 1925 |
if ( ret == RES_OK ){ |
if ( ret == RES_OK ){ |
| 1926 |
// private index作成 |
// private index作成 |
| 1927 |
index_t index; |
index_t index; |
| 1928 |
|
index.setItemTypeID(item::ITID_INDEX); |
| 1929 |
|
index.setContributorUID(*uid); |
| 1930 |
index.setParentIndexID(item::IID_ROOT); |
index.setParentIndexID(item::IID_ROOT); |
| 1931 |
index.setOwnerUID(*uid); |
index.setOwnerUID(*uid); |
| 1932 |
index.setOpenLevel(index::OL_PRIVATE); |
index.setOpenLevel(index::OL_PRIVATE); |
| 3006 |
userid_t uid; |
userid_t uid; |
| 3007 |
ret = sessionID2UID( sid, &uid ); |
ret = sessionID2UID( sid, &uid ); |
| 3008 |
if ( ret == RES_OK ){ |
if ( ret == RES_OK ){ |
| 3009 |
|
index.setItemTypeID(item::ITID_INDEX); |
| 3010 |
|
index.setContributorUID(uid); |
| 3011 |
index.setParentIndexID(item::IID_ROOT); |
index.setParentIndexID(item::IID_ROOT); |
| 3012 |
index.setOwnerGID(*gid); |
index.setOwnerGID(*gid); |
| 3013 |
index.setOpenLevel(index::OL_GROUP_ONLY); |
index.setOpenLevel(index::OL_GROUP_ONLY); |
| 3806 |
SQLBindParameter(hstmt, 11, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &publication_mday, 0, &cbPublication_mday ); |
SQLBindParameter(hstmt, 11, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &publication_mday, 0, &cbPublication_mday ); |
| 3807 |
SQLBindParameter(hstmt, 12, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ITEM_LANG_LEN, 0, lang, 0, &cbLang ); |
SQLBindParameter(hstmt, 12, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ITEM_LANG_LEN, 0, lang, 0, &cbLang ); |
| 3808 |
|
|
| 3809 |
|
//アイテム情報をitem構造体からSQL_CHAR配列へコピーする |
| 3810 |
strncpy2( (char*)title, item -> getTitle(), XNP_ITEM_TITLE_LEN ); |
strncpy2( (char*)title, item -> getTitle(), XNP_ITEM_TITLE_LEN ); |
| 3811 |
strncpy2( (char*)keywords, item -> getKeywords(), XNP_ITEM_KEYWORDS_LEN ); |
strncpy2( (char*)keywords, item -> getKeywords(), XNP_ITEM_KEYWORDS_LEN ); |
| 3812 |
strncpy2( (char*)description, item -> getDescription(), XNP_ITEM_DESCRIPTION_LEN ); |
strncpy2( (char*)description, item -> getDescription(), XNP_ITEM_DESCRIPTION_LEN ); |
| 4009 |
SQLBindCol( hstmt, 11, SQL_C_SLONG, &publication_month, 0, &cbPublication_month ); |
SQLBindCol( hstmt, 11, SQL_C_SLONG, &publication_month, 0, &cbPublication_month ); |
| 4010 |
SQLBindCol( hstmt, 12, SQL_C_SLONG, &publication_mday, 0, &cbPublication_mday ); |
SQLBindCol( hstmt, 12, SQL_C_SLONG, &publication_mday, 0, &cbPublication_mday ); |
| 4011 |
|
|
| 4012 |
|
//取得したアイテムの情報をitem構造体へコピーする |
| 4013 |
|
//DOIはBLOB型→char*型へ変換のため,引数でSQL_C_BINARYを明示する |
| 4014 |
*itemsLen = 0; |
*itemsLen = 0; |
| 4015 |
for( int i = 0; ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS && i < iidsLen ; i++ ){ |
for( int i = 0; ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS && i < iidsLen ; i++ ){ |
| 4016 |
dst[ i ].setItemID( item_id ); |
dst[ i ].setItemID( item_id ); |
| 4018 |
dst[ i ].setTitle( getResultCol( hstmt, 3 ).c_str() ); |
dst[ i ].setTitle( getResultCol( hstmt, 3 ).c_str() ); |
| 4019 |
dst[ i ].setKeywords( getResultCol( hstmt, 4 ).c_str() ); |
dst[ i ].setKeywords( getResultCol( hstmt, 4 ).c_str() ); |
| 4020 |
dst[ i ].setDescription( getResultCol( hstmt, 5 ).c_str() ); |
dst[ i ].setDescription( getResultCol( hstmt, 5 ).c_str() ); |
| 4021 |
dst[ i ].setDOI( getResultCol( hstmt, 6 ).c_str() ); |
dst[ i ].setDOI( getResultCol( hstmt, 6, SQL_C_BINARY ).c_str() ); |
| 4022 |
dst[ i ].setContributorUID( uid ); |
dst[ i ].setContributorUID( uid ); |
| 4023 |
dst[ i ].setCreationDate( creation_date ); |
dst[ i ].setCreationDate( creation_date ); |
| 4024 |
dst[ i ].setLastUpdateDate( last_update_date ); |
dst[ i ].setLastUpdateDate( last_update_date ); |
| 4286 |
SQLBindParameter(hstmt, 11, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ITEM_LANG_LEN, 0, lang, 0, &cbLang ); |
SQLBindParameter(hstmt, 11, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ITEM_LANG_LEN, 0, lang, 0, &cbLang ); |
| 4287 |
SQLBindParameter(hstmt, 12, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &item_id, 0, &cbItem_id ); |
SQLBindParameter(hstmt, 12, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &item_id, 0, &cbItem_id ); |
| 4288 |
|
|
| 4289 |
|
//DBから得られたカラムの値をitem構造体へコピーする |
| 4290 |
strncpy2( (char*)title, item -> getTitle(), XNP_ITEM_TITLE_LEN ); |
strncpy2( (char*)title, item -> getTitle(), XNP_ITEM_TITLE_LEN ); |
| 4291 |
strncpy2( (char*)keywords, item -> getKeywords(), XNP_ITEM_KEYWORDS_LEN ); |
strncpy2( (char*)keywords, item -> getKeywords(), XNP_ITEM_KEYWORDS_LEN ); |
| 4292 |
strncpy2( (char*)description, item -> getDescription(), XNP_ITEM_DESCRIPTION_LEN ); |
strncpy2( (char*)description, item -> getDescription(), XNP_ITEM_DESCRIPTION_LEN ); |
| 5798 |
} |
} |
| 5799 |
|
|
| 5800 |
/** インデックスを作成する。引数のチェックは行わない。 |
/** インデックスを作成する。引数のチェックは行わない。 |
|
* item_type_id, contributor_uid を上書きする。 |
|
| 5801 |
*/ |
*/ |
| 5802 |
static result_t insertIndexInternal( sessionid_t sid, index_t *index, indexid_t *xid ){ |
static result_t insertIndexInternal( sessionid_t sid, index_t *index, indexid_t *xid ){ |
| 5803 |
itemid_t iid; |
itemid_t iid; |
| 5804 |
|
|
|
index->setItemTypeID(item::ITID_INDEX); |
|
|
index->setContributorUID(0); |
|
| 5805 |
result_t result = insertItem( sid, index, &iid ); |
result_t result = insertItem( sid, index, &iid ); |
| 5806 |
if ( result == RES_OK ){ |
if ( result == RES_OK ){ |
| 5807 |
string nullString("NULL"); |
string nullString("NULL"); |
| 7578 |
SQLRETURN sqlcode; |
SQLRETURN sqlcode; |
| 7579 |
SQLLEN count = 0; |
SQLLEN count = 0; |
| 7580 |
userid_t sess_uid; |
userid_t sess_uid; |
|
|
|
|
bool is_moderator = false; |
|
| 7581 |
|
|
| 7582 |
if( ( ret = sessionID2UID( sid, &sess_uid ) ) != RES_OK ) return ret; |
if( ( ret = sessionID2UID( sid, &sess_uid ) ) != RES_OK ) return ret; |
| 7583 |
|
|
| 7584 |
sql = "SELECT DISTINCT tlink.index_id, tlink.item_id"; |
sql = "SELECT DISTINCT tlink.index_id, tlink.item_id"; |
| 7585 |
sql += " FROM " + dbprefix + "_xoonips_index_item_link AS tlink"; |
sql += " FROM " + dbprefix + "_xoonips_index_item_link AS tlink"; |
| 7586 |
sql += " LEFT JOIN " + dbprefix + "_xoonips_index AS tx ON tlink.index_id = tx.index_id"; |
sql += " LEFT JOIN " + dbprefix + "_xoonips_index AS tx ON tlink.index_id = tx.index_id"; |
| 7587 |
sql += " LEFT JOIN " + dbprefix + "_xoonips_item_basic AS ti ON tlink.item_id = ti.item_id"; |
sql += " LEFT JOIN " + dbprefix + "_xoonips_item_basic AS ti ON tlink.item_id = ti.item_id"; |
| 7588 |
|
sql += " LEFT JOIN " + dbprefix + "_xoonips_groups_users_link AS tgulink ON tgulink.gid = tx.gid"; |
| 7589 |
is_moderator = isModerator( sid, sess_uid ); |
sql += " WHERE open_level<=" + unsignedIntToString( index::OL_GROUP_ONLY ); |
|
if( ! is_moderator ) { |
|
|
sql += " LEFT JOIN " + dbprefix + "_xoonips_groups_users_link AS tgulink ON tgulink.gid = tx.gid"; |
|
|
} |
|
|
sql += " WHERE open_level<=" + unsignedIntToString( index::OL_GROUP_ONLY ); |
|
| 7590 |
sql += " AND certify_state=" + unsignedIntToString( index::CERTIFY_REQUIRED ); |
sql += " AND certify_state=" + unsignedIntToString( index::CERTIFY_REQUIRED ); |
| 7591 |
sql += " AND item_type_id !=" + unsignedIntToString( item::ITID_INDEX ); |
sql += " AND item_type_id !=" + unsignedIntToString( item::ITID_INDEX ); |
| 7592 |
|
sql += " AND ( is_admin=1 AND tgulink.uid=" + unsignedIntToString( sess_uid ); |
| 7593 |
if( ! is_moderator ) { |
sql += string( isModerator( sid, sess_uid ) ? " OR 1)" : " OR 0)" ); //モデレータならOR 1,それ以外は OR 0 |
|
sql += " AND is_admin=1 AND tgulink.uid=" + unsignedIntToString( sess_uid ); |
|
|
} |
|
|
|
|
| 7594 |
syslog_printf( "\nsql at %d=%s", __LINE__, sql.c_str() ); |
syslog_printf( "\nsql at %d=%s", __LINE__, sql.c_str() ); |
| 7595 |
|
|
| 7596 |
if( countResultRows( sql.c_str(), &count ) == RES_OK ){ |
if( countResultRows( sql.c_str(), &count ) == RES_OK ){ |