Develop and Download Open Source Software

Browse CVS Repository

Annotation of /xoonips/AL/commonal.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.69 - (hide annotations) (download) (as text)
Tue Feb 22 02:39:30 2005 UTC (19 years, 1 month ago) by tani
Branch: MAIN
Changes since 1.68: +64 -49 lines
File MIME type: text/x-c++src
public_item_target_user_all関数を追加.
SQL中のpublic_item_target_user_allの比較式をpublic_item_target_user_all関数に置換.
sessionテーブルのLEFT JOINの条件にsidのチェックを追加.
DB問合せ処理の高速化.

1 youi 1.1 /*
2     *
3 tani 1.69 * $Revision: 1.68 $
4 youi 1.2 * $Log: commonal.cc,v $
5 tani 1.69 * Revision 1.68 2005/02/21 05:46:18 tani
6     * getItemCount??菴遵??.
7     * dumpItemID, getItems?????????蕭?????.
8     *
9 tani 1.68 * Revision 1.67 2005/02/19 02:06:11 tani
10     * ?粋??倶????┤?????с?????????????菴遵??.
11     *
12 tani 1.67 * Revision 1.66 2005/02/16 10:03:13 youi
13     * publication_year/month/mday???綽?.
14     *
15 youi 1.66 * Revision 1.65 2005/02/16 07:37:17 youi
16     * insertItem, updateItem, getItems: publication_date???綽?.
17     *
18 youi 1.65 * Revision 1.64 2005/02/15 02:35:47 youi
19     * SQLINTEGER????SQLLEN?後??紊???
20     *
21 youi 1.64 * Revision 1.63 2005/02/10 02:33:16 aga
22     * ??ipCreate???潟?<?潟???≪?????????????????祉????.
23     *
24 aga 1.63 * Revision 1.62 2005/02/09 11:11:52 youi
25     * deleteItem???≪?ゃ???????≫????????潟?????????ゅ??????菴遵??.
26     *
27 youi 1.62 * Revision 1.61 2005/02/09 07:23:50 aga
28     * ??RL to My Personal Archive ??DB??L????羔?????.
29     *
30 aga 1.61 * Revision 1.60 2005/02/09 02:14:15 aga
31     * ??nitializeDB()??btype綣??違??菴遵??(SQLite??.
32     *
33 aga 1.60 * Revision 1.59 2005/02/08 07:15:02 youi
34     * pubmed???若?劫????:
35     *
36 youi 1.59 * Revision 1.58 2005/02/08 06:40:51 youi
37     * pubmedComplete:?吾?c?若????????????帥?ゃ????????緇?????ubmed_t???祉????.
38     *
39 youi 1.58 * Revision 1.57 2005/02/03 12:04:58 youi
40     * getOwnPublicItemID??絎?臂?
41     * binder_item_link?????若????????篆??.
42     *
43 youi 1.57 * Revision 1.56 2005/01/29 09:49:22 youi
44     * syslog_printf: ???????違?<???祉?若?後?阪???∽?違??絎?臂?????.
45     * getCertifyPermission: ???с????????ql??絎?臂?????.
46     * SQLINTEGER->SQLLEN?後????紊??眼????.
47     * getItemPermission: ?≪?????若?帥?с??????鐚????ゆ???>散??篆??.
48     *
49 youi 1.56 * Revision 1.55 2005/01/28 07:01:38 youi
50     * getItemIDByIndexID: 絲乗院???????≪?ゃ???????>散荀??眼??.
51     * SQLAllocHandle紊掩???????<???祉?若?吾??菴遵??.
52     *
53 youi 1.55 * Revision 1.54 2005/01/28 00:36:58 aga
54     * ??reeString?ц?純?<????????????????篆??.
55     *
56 aga 1.54 * Revision 1.53 2005/01/27 08:30:35 youi
57     * getIndexIDByItemID??絎?臂?????.
58     *
59 youi 1.53 * Revision 1.52 2005/01/25 06:46:50 aga
60     * ??inders??????index??eleteIndex筝???
61     * ??etItems???????若???冴????????????????篆??.
62     *
63 aga 1.52 * Revision 1.51 2005/01/24 10:50:29 youi
64     * freeItemType,getItemTypes?∽?違??菴遵??????.
65     *
66 youi 1.51 * Revision 1.50 2005/01/24 01:54:38 youi
67     * 綣??違????篆????紊???
68     * dumpItemID, getItemIDByBinderID, getItemIDByIndexID
69     * ?∽?域申??
70     * getPrivateItemID, getUncertifiedLink
71     *
72 youi 1.50 * Revision 1.49 2005/01/22 09:30:58 youi
73     * setLastErrorString???荐???菴遵??????.
74     *
75 youi 1.49 * Revision 1.48 2005/01/22 04:18:22 aga
76     * ??oginUser, insertAccount???с??d5()??茵??????????篆??.
77     *
78 aga 1.48 * Revision 1.47 2005/01/22 02:41:14 aga
79     * ??mazon茖?絎???篏???.
80     *
81 aga 1.47 * Revision 1.46 2005/01/21 01:36:11 youi
82     * pubmed茖?絎?罘??純??菴遵??????.
83     *
84 youi 1.46 * Revision 1.45 2005/01/19 10:07:53 aga
85     * ?祉?蚊?鴻?????若?九??????信罩?
86     *
87 aga 1.45 * Revision 1.44 2005/01/19 06:01:59 youi
88     * ?∽?域申??
89     * getConfigValue
90     * setConfigValue
91     * getChangeLogs
92     * insertChangeLog
93     * getItemIDByBinderID
94     * registerBinderItem
95     * unregisterBinderItem
96     * getIndexPermission
97     * freeString
98     * freeChangeLog
99     * 綣??違??riteria_t??菴遵??
100     * getItemIDByIndexID
101     * 綣??違????綺??紊???/span>
102     * getCertifyState
103     * setCertifyState
104     * getCertifyPermission
105     * sessionID2UID,querySimple,queryGetUnsignedInt??????/span>
106     * insertItem????????rivateIndex?悟?脂?蚊??茵?????
107     * getItems: getItemPermission??篏帥?c??茯??粋昭?炊┤?????с????
108     *
109 youi 1.44 * Revision 1.43 2005/01/19 01:42:15 aga
110     * ??_xnpaccount_index??id,uid??0??????????????篆??.
111     *
112 aga 1.43 * Revision 1.42 2005/01/19 00:51:29 aga
113     * ??nsertIndex??_xnpaccount_index.index_id??????????????篆??.
114     *
115 aga 1.42 * Revision 1.41 2005/01/19 00:06:51 aga
116     * ??pdateIndex?с??????????????綣???????????????腥冴?с?????????????若??????.
117     * ??reateSession?с??uid??Platform???若?吟?с??????activate?????????????????????若??????.
118     *
119 aga 1.41 * Revision 1.40 2005/01/17 00:15:05 aga
120     * ??eleteIndex, updateIndex??け????????????????????篆??.
121     *
122 aga 1.40 * Revision 1.39 2005/01/15 05:38:10 youi
123     * insertAccount: ??絖??????????<???泣?ゃ?肴??眼????
124     * updateAccount: ??絖??????????<???泣?ゃ?肴??眼????
125     * ?≪?ゃ????膊∞???∽?違??絎?臂?????.
126     * insertItem, getItem, getItems, dumpItemID, updateItem, deleteItem????
127     * freeGID, freeUID: 綣??違??????篆??.
128     *
129 youi 1.39 * Revision 1.38 2005/01/15 00:39:16 aga
130     * ??_xnpaccount_item_basic???????紊???
131     *
132 aga 1.38 * Revision 1.37 2005/01/14 10:36:59 aga
133     * ??ndex?≫?????????菴遵??.
134     * ??nsertAccount??rivate index??篏???????????篆??.
135     * ??nsertGroup??roup index ??篏???????????篆??.
136     *
137 aga 1.37 * Revision 1.36 2005/01/13 04:19:22 aga
138     * ??P??XNP?????.
139     *
140 aga 1.36 * Revision 1.35 2005/01/06 07:20:17 youi
141     * WIN32絎?臂??????ゃ?潟?????若????申??.
142     * MySQL API???≪?????????????<?ゃ????????
143     * deleteAccount: ??絮?????Platform?違???若???????????ゃ?????泣????.
144     * insertAccount: ???若?句?脂?蚊??????????????????Platform?違???若???悟?脂?蚊????.
145     * deleteMember: ??????????Platform?違???若???????????ゃ??胼?罩≪????.
146     * deleteMemberNoLimit???臂?
147     *
148 youi 1.35 * Revision 1.34 2004/12/28 04:38:14 aga
149     * ??ogoutUser()??信罩?
150     *
151 aga 1.34 * Revision 1.33 2004/12/27 05:56:23 youi
152     * odbcDiagString: STMT篁ュ?????潟??????????????????????眼????.
153     * syslog?<???祉?若?吾????????菴遵??????.
154     *
155 youi 1.33 * Revision 1.32 2004/12/25 09:46:47 youi
156     * MySQL+MyODBC?у??篏???????????信罩c????.
157     *
158 youi 1.32 * Revision 1.31 2004/12/21 11:42:59 youi
159     * ?潟?<?潟??????逸??祉???ゃ???????????菴遵??.
160     *
161 youi 1.31 * Revision 1.30 2004/12/18 10:24:54 youi
162     * IMPORT_MYSQLDLL??絎?臂?????????鐚?MYSQL??LL?????????潟?????????????帥?ゃ??絎h???
163     * ???鴻????????????信罩c????.
164     *
165 youi 1.30 * Revision 1.29 2004/12/18 01:12:29 youi
166     * freeResult???∽?医????free<???若?水??>????眼????.
167     *
168 youi 1.29 * Revision 1.28 2004/12/14 12:02:08 youi
169     * __WIN__??絎?臂???????????indows??ll篏??????荀?????????茵?????.
170     * USE_SYSLOG??絎?臂???????????yslogd?吾?<???祉?若?吾???阪??????.
171     * getAccounts: uidsLen??0??????????????菴遵??????.
172     *
173 youi 1.28 * Revision 1.27 2004/12/06 11:34:47 aga
174     * ??ninitializeDB()??菴遵??.
175     *
176 aga 1.27 * Revision 1.26 2004/12/06 10:17:36 youi
177     * mysql_use_result????腟?????罧??????????冴??????鐚?
178     * while( row = mysql_fetch_row(result) );???水?ワ?
179     *
180 youi 1.26 * Revision 1.25 2004/12/06 07:24:33 youi
181     * insertAccount, insertGroup:
182     * ?域?菴遵?????????宴???綽????????若??D鐚??違???若??ID??膃??綣??違???吾??莨若??.
183     *
184 youi 1.25 * Revision 1.24 2004/12/06 01:45:50 aga
185     * ?祉?潟?<?潟???ゃ??.
186     * ?脂???上???篆??.
187     *
188 aga 1.24 * Revision 1.23 2004/12/04 09:21:10 aga
189 aga 1.36 * ??np_config ?? xnpaccount_config.
190 aga 1.24 *
191 aga 1.23 * Revision 1.22 2004/12/03 07:17:21 youi
192     * isModerator?с?≪???祉?鴻???????若?帥???若?鴻???若????????篆??.
193     *
194 youi 1.22 * Revision 1.21 2004/12/01 10:28:58 youi
195     * DB????????????眼??軸??篆??
196     * institute -> division
197     * organizaion -> company_name
198     *
199 aga 1.61 * Revis1.20 2004/12/01 04:37:04 youi
200 youi 1.21 * freeResult: unsigned int* ?? int* ?娯信罩?
201     * ?潟?<?潟???????∽?違???????菴処?.
202     *
203 youi 1.20 * Revision 1.19 2004/11/30 06:40:11 youi
204     * ?∽?違??菴遵??(gidExists, uidExists)
205     * getGroupCount??絎?臂?
206     * getGroupsByUid??絎?臂?
207     * isGroupAdmin??篆??.
208     * dumpGroupAdmins??絎?臂?
209     * deleteMember??絎?臂?
210     * insertMember??絎?臂?
211     * getMembers??絎?臂?
212     * isModerator??絎?臂?
213     *
214 youi 1.19 * Revision 1.18 2004/11/30 05:46:32 aga
215     * ??ession????remoteHost??????
216     *
217 aga 1.18 * Revision 1.17 2004/11/27 09:35:49 youi
218     * isActivated??絎?臂?
219     * activate??絎?臂?
220     * dumpUid??絎?臂?
221     *
222 youi 1.17 * Revision 1.16 2004/11/27 06:29:29 youi
223     * getAccountCount??絎?臂?
224     * dumpGids??絎?臂?
225     * insertGroup, deleteGroup, updateGroup??絎?臂?
226     * getGroup, getGroups??絎?臂?
227     * ???若?帥???若?劫?????????弱?冴?????鐚?RES_DB_NOT_INITIALIZED??菴????????????∽?違??申??
228     * (???綽????∽?違??罧??c??????)
229     *
230 youi 1.16 * Revision 1.15 2004/11/27 02:22:22 aga
231     * ??nitializeDB????ddSlashes()???若?吟???純?<??????篆??.
232     *
233 aga 1.15 * Revision 1.14 2004/11/27 01:07:31 youi
234     * criteria2str: LIMIT??RDER BY?????????ャ???帥????.
235     *
236 youi 1.14 * Revision 1.13 2004/11/27 00:35:39 youi
237     * getAccounts??絎?臂?
238     * getAccount??篆??鐚???????etAccounts???若?喝?冴??.
239     * criteria2str??絎?臂?
240     *
241 youi 1.13 * Revision 1.12 2004/11/26 09:45:28 youi
242     * getAccount??絎?臂?
243     *
244 youi 1.12 * Revision 1.11 2004/11/26 08:16:26 aga
245     * ??etSession, loginUser, createSession, freeResult(const session_t*) 篆??.
246     *
247 aga 1.11 * Revision 1.10 2004/11/26 07:57:42 youi
248     * updateAccount, deleteAccount??絎?臂?
249     * mysql_query紊掩??????tderr?吾?????若?潟?若?????????若?<???祉?若?吾???阪??.
250     *
251 youi 1.10 * Revision 1.9 2004/11/26 07:38:02 aga
252     * ??AILUE -> FAILURE.
253     *
254 aga 1.9 * Revision 1.8 2004/11/26 06:36:55 aga
255     * ??reateSession, getSession ??篏???.
256     *
257 aga 1.8 * Revision 1.7 2004/11/26 04:51:47 youi
258     * dbprefix??絎?臂?????.
259     * insertAccount??絎?臂?????.
260     * isValidSessionID??絎?臂?????.
261     *
262 youi 1.7 * Revision 1.6 2004/11/26 04:35:55 aga
263     * ??oginUser(), logoutUser()??篏???.
264     *
265 aga 1.6 * Revision 1.5 2004/11/26 01:08:25 aga
266     * ??ddSlashes()篏???.
267     *
268 aga 1.5 * Revision 1.4 2004/11/25 12:14:29 youi
269     * getUid????????絎?臂?????.
270     *
271 youi 1.4 * Revision 1.3 2004/11/25 11:13:59 youi
272     * getLastErrorString/setLastErrorString??絎?臂?
273     *
274 youi 1.3 * Revision 1.2 2004/11/25 08:55:19 youi
275     * 綣??違??????篆??.
276     * freeResult??菴遵??.
277     *
278 youi 1.2 * Revision 1.1 2004/11/25 05:14:58 youi
279     * initial version
280     *
281 youi 1.1 *
282     */
283 youi 1.35 #ifdef WIN32
284     #include <windows.h>
285 youi 1.28 #endif
286    
287     #ifdef USE_SYSLOG
288     #include <syslog.h>
289     #endif
290    
291 youi 1.1 #include <stdio.h>
292 aga 1.6 #include <stdlib.h>
293 youi 1.1 #include <string.h>
294 youi 1.3 #include <string>
295 aga 1.27 #include <assert.h>
296 youi 1.32 #include <sql.h>
297     #include <sqlext.h>
298 youi 1.46 #include <libxml/xmlreader.h>
299    
300 youi 1.7 using namespace std;
301 youi 1.1
302     #include "common.h"
303     #include "account.h"
304     #include "group.h"
305     #include "session.h"
306 youi 1.39 #include "item.h"
307     #include "itemtype.h"
308 youi 1.1 #include "criteria.h"
309     #include "commonal.h"
310 aga 1.37 #include "item.h"
311     #include "index.h"
312 youi 1.44 #include "changelog.h"
313 youi 1.46 #include "pubmed.h"
314 aga 1.47 #include "amazonbook.h"
315 youi 1.1
316 youi 1.32 static string dbprefix; //!< XOOPS???若?帥???若?鴻???若??????REFIX
317 aga 1.60 static dbtype_t dbtype; //!< MySQL/SQLite
318 youi 1.32
319     static SQLHANDLE henv = NULL;
320     static SQLHANDLE hdbc = NULL;
321     static SQLHANDLE hstmt = NULL;
322    
323 youi 1.58 static bool processEsummary(xmlTextReaderPtr reader, pubmed_t* p);
324     static bool processEsearch(xmlTextReaderPtr reader, pubmed_t* p, int* DocID );
325 youi 1.46 static void processEfetch(xmlTextReaderPtr reader, pubmed_t* p);
326     static int streamPubmedFile(const char *filename, pubmed_t* p);
327 aga 1.37 static result_t insertIndexInternal( sessionid_t sid, index_t *index, indexid_t *xid );
328 youi 1.33 static string odbcDiagString( SQLSMALLINT HandleType, SQLHANDLE hstmt, SQLRETURN sqlcode );
329 youi 1.35 static result_t deleteMemberNoLimit( sessionid_t sid, groupid_t gid, userid_t uid );
330 youi 1.56 static result_t getXoopsModuleConfigValue( const char *module, const char *key, char **value );
331 youi 1.49 static void setLastErrorString( const char* str );
332 youi 1.32
333 youi 1.56 void syslog_printf( char* format, ... )
334     {
335     #ifdef USE_SYSLOG
336     va_list ap;
337     va_start(ap, format);
338     openlog( "commonal", LOG_ODELAY, LOG_USER );
339     vsyslog( LOG_DEBUG, format, ap );
340     closelog( );
341     #endif
342     }
343    
344 tani 1.69 /**
345     *
346     * public_item_target_user??┃絎??ゃ??'all'????true????????
347     * 荐???ゃ??????け???????翫??鐚?'all'篁ュ????翫????alse????????
348     *
349     */
350     static bool public_item_target_user_all( )
351     {
352     char* value = 0;
353     bool public_item_target_user_all = false;
354     if( getConfigValue( XNP_CONFIG_PUBLIC_ITEM_TARGET_USER_KEY, &value ) == RES_OK ){
355     public_item_target_user_all = ( strcmp( value, XNP_CONFIG_PUBLIC_ITEM_TARGET_USER_ALL ) == 0 );
356     freeString( value );
357     }
358     return public_item_target_user_all;
359     }
360    
361 youi 1.56 static result_t countResultRows( const char* sql, SQLLEN* count )
362 youi 1.32 {
363     result_t ret = RES_ERROR;
364     SQLRETURN sqlcode;
365     SQLHANDLE hstmt = NULL;
366     if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
367     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql, strlen( sql ) ) ) == SQL_SUCCESS ){
368     *count = 0;
369     while( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ) ( *count )++;
370     ret = RES_OK;
371     }else{
372     string s( "SQLExecDirect in countResultRows " );
373 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
374 youi 1.32 s += "sql=";
375     s += string( sql );
376     setLastErrorString( s.c_str( ) );
377     ret = RES_DB_QUERY_ERROR;
378     }
379     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
380     }
381     return ret;
382     }
383    
384 youi 1.44
385 youi 1.39 /**
386     *
387 youi 1.44 * ?ゃ?潟???????合?脂?駕??≪?ゃ?????贋?違??茵????c?????????粋??倶?????????ゃ??鐚?
388     * ?激?鴻????荐???????????c??????障??鐚?/span>
389     *
390 youi 1.39 */
391 youi 1.44 static certify_t getInitialCertifyStateFromConfig( )
392 youi 1.39 {
393 youi 1.44 char* certify_item_val;
394     certify_t ret = index::NOT_CERTIFIED;
395    
396     if( getConfigValue( XNP_CONFIG_CERTIFY_ITEM_KEY, &certify_item_val ) == RES_OK ){
397     if( strcmp( certify_item_val, XNP_CONFIG_CERTIFY_ITEM_AUTO ) == 0 ){
398     //certify automatic
399     ret = index::CERTIFIED;
400     }else if( strcmp( certify_item_val, XNP_CONFIG_CERTIFY_ITEM_ON ) == 0 ){
401     //certify by moderator or group admin
402     ret = index::CERTIFY_REQUIRED;
403     }
404     freeString( certify_item_val );
405 youi 1.39 }
406 youi 1.44 return ret;
407 youi 1.39 }
408    
409     /**
410     *
411     * ?祉???激?с?潟???綽?篁????????????若?吟??鐚?Platform???若?吟??????ctivate??
412     * ????????????菴???
413     *
414     * @param sid ?祉???激?с??D
415     * @return true Activate??????????
416     * @return false Activate??????????鐚??障??????????/span>
417     *
418     */
419     static bool isActivatedBySession( sessionid_t sid )
420     {
421     const session_t* session;
422     if( getSession( sid, &session ) == RES_OK ){
423     userid_t sess_uid = session -> getUID( );
424     freeSession( session );
425     return isActivated( sid, sess_uid );
426     }
427     return false;
428     }
429    
430     /**
431     *
432     * ?祉???激?с?潟???綽?篁????????????若?吟??鐚??≪?????若?帥?с??????鐚?
433     *
434     *
435     * @param sid ?祉???激?с??D
436     * @return true ?≪?????若??/span>
437     * @return false ?≪?????若?帥?с????鐚??障??????????/span>
438     *
439     */
440     static bool isModeratorBySession( sessionid_t sid )
441     {
442     const session_t* session;
443     if( getSession( sid, &session ) == RES_OK ){
444     userid_t sess_uid = session -> getUID( );
445     freeSession( session );
446     return isModerator( sid, sess_uid );
447     }
448     return false;
449     }
450    
451 aga 1.45
452    
453    
454 aga 1.37 /** SQL??絎?茵???????腟?????????????
455     * @param sql sql
456     * @return result_t
457     */
458     static result_t querySimple( const char *functionName, string &sql ){
459     result_t ret = RES_ERROR;
460     SQLRETURN sqlcode;
461     SQLHANDLE hstmt = NULL;
462     if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
463     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), strlen( sql.c_str() ) ) ) == SQL_SUCCESS ){
464     ret = RES_OK;
465     }else{
466     string s( "SQLExecDirect in querySimple " );
467     s += functionName;
468     s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
469     s += "sql=";
470     s += sql;
471     setLastErrorString( s.c_str( ) );
472     ret = RES_DB_QUERY_ERROR;
473     }
474     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
475     }
476     else {
477 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in querySimple " );
478     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
479     setLastErrorString( s.c_str( ) );
480 aga 1.37 ret = RES_ERROR;
481     }
482     return ret;
483     }
484    
485     /** SQL??絎?茵?????1茵????????????贋?医??NULL????0???帥????)???水?????????
486     * @param sql sql
487     * @param u ?贋?医?ゃ??????????紊??違??
488     * @return result_t
489     */
490     static result_t queryGetUnsignedInt( const char *functionName, string &sql, unsigned int *u ){
491     result_t ret = RES_ERROR;
492     SQLRETURN sqlcode;
493     SQLHANDLE hstmt = NULL;
494 youi 1.53
495 aga 1.37 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
496     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), strlen( sql.c_str() ) ) ) == SQL_SUCCESS ){
497     SQLUINTEGER sInt = 0;
498 youi 1.56 SQLLEN len = 0;
499 aga 1.37 SQLBindCol( hstmt, 1, SQL_C_ULONG, &sInt, 0, &len );
500     if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){
501     if ( len == SQL_NULL_DATA )
502     sInt = 0;
503     *u = sInt;
504     ret = RES_OK;
505     }else{
506     string s( "SQLFetch in queryGetUnsignedInt " );
507     s += functionName;
508 youi 1.44 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
509 aga 1.37 setLastErrorString( s.c_str( ) );
510     ret = RES_ERROR;
511     }
512     }else{
513     string s( "SQLExecDirect in queryGetUnsignedInt " );
514     s += functionName;
515     s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
516     s += "sql=";
517     s += sql;
518     setLastErrorString( s.c_str( ) );
519     ret = RES_DB_QUERY_ERROR;
520     }
521     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
522     }
523     else {
524 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in queryGetUnsignedInt " );
525     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
526     setLastErrorString( s.c_str( ) );
527 aga 1.37 ret = RES_ERROR;
528     }
529     return ret;
530     }
531    
532 youi 1.32 /**
533     *
534     * ??絖????潟???種?
535     * ??絎???絖??違???潟???若??鐚????????<????緇???NULL腟?腴?????鐚?/span>
536     * ( dst???泣?ゃ? >= len + 1 )?с????????/span>
537     *
538     */
539     static char* strncpy2( char* dst, const char* src, int len )
540     {
541     strncpy( dst, src, len );
542     dst[ len ] = '\0';
543 youi 1.56 syslog_printf( "\nstrncpy2 '%s'\n", dst );
544 youi 1.32 return dst;
545     }
546    
547     /**
548     *
549     * SQL???茵?腟????????????惹??絖?????????????
550     *
551     * @param hstmt SQL??????潟????/span>
552     * @param sqlcode SQLExecDirect,SQLExecute???祉????/span>
553     * @return ?????惹??絖???
554     */
555 youi 1.33 static string odbcDiagString( SQLSMALLINT HandleType, SQLHANDLE hstmt, SQLRETURN sqlcode )
556 youi 1.32 {
557     string s;
558     if( sqlcode == SQL_ERROR || sqlcode == SQL_SUCCESS_WITH_INFO ){
559     SQLCHAR SQLState[6];
560     SQLINTEGER NativeError;
561     SQLCHAR MessageText[ 1024 ];
562     SQLSMALLINT TextLength;
563 youi 1.33 SQLGetDiagRec( HandleType, hstmt, 1, SQLState, &NativeError, MessageText, 1024, &TextLength );
564 youi 1.32
565     s += string( (char*)MessageText );
566     s += " SQLSTATE=";
567     s += string( (char*)SQLState );
568    
569     }
570     s += " sqlcode=";
571     s += intToString( sqlcode );
572     return s;
573     }
574    
575     /**
576     *
577     * ??絎??????????ゃ???????冴??????????絖?????菴???
578     *
579     */
580     string getResultCol( SQLHANDLE hstmt, int col )
581     {
582     string s;
583 youi 1.64 SQLRETURN sqlcode;
584     SQLCHAR BinaryPtr[5000];
585     SQLLEN BinaryLenOrInd;
586     SQLINTEGER NumBytes;
587 youi 1.32
588     while ( ( sqlcode = SQLGetData(hstmt, col, SQL_C_CHAR, BinaryPtr, sizeof(BinaryPtr),
589     &BinaryLenOrInd)) != SQL_NO_DATA) {
590     NumBytes = (BinaryLenOrInd > 5000) || (BinaryLenOrInd == SQL_NO_TOTAL) ? 5000 : BinaryLenOrInd;
591 youi 1.33 if( NumBytes >= 0 ){
592     s += string( (char*)BinaryPtr, NumBytes );
593     }
594 youi 1.32 }
595 youi 1.33 #ifdef USE_SYSLOG
596     // openlog( "commonal", LOG_ODELAY, LOG_USER );
597     // syslog( LOG_DEBUG, "getResultCol col=%d ret='%s'\n", col, s.c_str());
598     // closelog( );
599     #endif
600 youi 1.32 return s;
601     }
602 youi 1.7
603 aga 1.5
604     /**
605     *
606 youi 1.32 * ?????若????????\荐??激?с???鴻?宴?若??????
607 aga 1.5 *
608 youi 1.32 * @param str addslashes???鴻????絖?????NULL??絎?筝?????
609     * @return 紊???緇?????絖???
610 aga 1.5 */
611     string addSlashes( const char *str )
612     {
613 youi 1.32 if ( hdbc == NULL ){
614 aga 1.15 string s;
615     return s;
616 youi 1.32 }else{
617     string s( str );
618     return s;
619     }
620    
621     int len = strlen(str) * 3;
622     char* dst = new char[ len ];
623     const char* from = str;
624     char* to = dst;
625     while( *from != '\0' ){
626     switch( *from ){
627     case '\'':
628     case '\"':
629     case ';':
630     *to = '\\'; to++;
631     break;
632     }
633     *to = *from; to++;
634     from++;
635     }
636     *to = '\0';
637     string s( dst );
638     delete[] dst;
639 aga 1.5 return s;
640     }
641    
642 aga 1.45 /** Xoops Module ??┃絎???茯帥?鴻??
643     * @param module ?≪?吾?ャ?若????irname
644     * @param key 荐????ey
645     * @param value 荐????菴???紊??違??
646     * @return
647     */
648     static result_t getXoopsModuleConfigValue( const char *module, const char *key, char **value ){
649     SQLRETURN sqlcode;
650     SQLHANDLE hstmt = NULL;
651     result_t result = RES_ERROR;
652    
653     if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
654     string sql = "SELECT conf_value "
655     " from " + dbprefix + "_config as tc, " + dbprefix + "_modules as tm "
656     " where tm.mid=tc.conf_modid and tm.dirname = ? and tc.conf_name = ? ";
657     sqlcode = SQLPrepare(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS);
658 youi 1.56 SQLLEN cbModule = SQL_NTS, cbKey = SQL_NTS;
659 aga 1.45 SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, strlen(module), 0, (SQLCHAR *)module, 0, &cbModule );
660     SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, strlen(key), 0, (SQLCHAR *)key, 0, &cbKey );
661     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), strlen( sql.c_str() ) ) ) == SQL_SUCCESS ){
662     if ( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){
663     string s = getResultCol( hstmt, 1 );
664     *value = new char[s.length()+1];
665     strcpy( *value, s.c_str() );
666     result = RES_OK;
667     }
668     else if ( sqlcode == SQL_NO_DATA ){
669 aga 1.54 *value = 0;
670 aga 1.45 result = RES_OK;
671     }
672     else {
673     string s( "SQLFetch in getXoopsModuleConfig " );
674     s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
675     s += "sql=";
676     s += sql;
677     setLastErrorString( s.c_str( ) );
678     result = RES_ERROR;
679     }
680     }else{
681     string s( "SQLExecDirect in getXoopsModuleConfig " );
682     s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
683     s += "sql=";
684     s += sql;
685     setLastErrorString( s.c_str( ) );
686     result = RES_DB_QUERY_ERROR;
687     }
688     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
689     }
690     else {
691 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getXoopsModuleConfig " );
692     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
693     setLastErrorString( s.c_str( ) );
694 aga 1.45 result = RES_ERROR;
695     }
696     return result;
697     }
698    
699     /** ?蚊?鴻?????若?吟??XooNiPs??ublic???≪?ゃ??????荀??????????с??????????????菴?????
700     */
701     static bool isGuestEnabled(){
702     char *value = 0;
703     result_t result = getXoopsModuleConfigValue( "xnpaccount", "public_item_target_user", &value );
704     if ( result != RES_OK )
705     return false;
706     if ( value == 0 )
707     return false;
708     bool enabled = ( strcmp( value, "all" ) == 0 );
709     freeString( value );
710     return enabled;
711     }
712    
713     /** sid????uid??緇?????
714     * @param sid session id
715     * @param uid uid??????????紊???/span>
716     * @return RES_OK
717     * sid?????鴻??essionid?с???????????翫??*uid???????鴻??id???ャ????
718     * ???????????????≪?ゃ????????XooNiPs???若?吟?????? ????id??session::SID_GUEST(=0)?с???????????翫????*uid????ccount::UID_GUEST(=0)???ャ????
719     * @return ????? ??????/span>
720     */
721     static result_t sessionID2UID( sessionid_t sid, userid_t *uid ){
722     if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
723    
724     if ( sid == session::SID_GUEST ){
725     if ( isGuestEnabled() ){
726     *uid = account::UID_GUEST;
727     return RES_OK;
728     }
729     return RES_NO_SUCH_SESSION;
730     }
731     else {
732     string sql = "SELECT uid FROM " + dbprefix + "_xnpaccount_session WHERE sid=" + unsignedIntToString(sid);
733     return queryGetUnsignedInt( "sessionID2UID", sql, uid );
734     }
735     }
736    
737    
738    
739 youi 1.13 /**
740     *
741 youi 1.19 * gid??????????с????
742     * DB???≪???祉?劫け????????false??????鐚?/span>
743     *
744     * @param gid ???с??????????GID
745     * @return true 絖???????
746     * @return false 絖?????????
747     *
748     */
749     static bool gidExists( groupid_t gid )
750     {
751     string sql;
752 youi 1.32 SQLRETURN sqlcode;
753     SQLHANDLE hstmt = NULL;
754 youi 1.19
755 youi 1.32 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) != SQL_SUCCESS ) {
756 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in gidExists" );
757     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
758     setLastErrorString( s.c_str( ) );
759 youi 1.32 return false;
760     }
761    
762 aga 1.36 sql = "SELECT * FROM " + dbprefix + "_xnpaccount_groups ";
763 youi 1.19 sql += "WHERE gid=" + string( unsignedIntToString( gid ) );
764 youi 1.32 if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) != SQL_SUCCESS ){
765     setLastErrorString( "SQLExecDirect in gidExists" );
766     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
767 youi 1.19 return false;
768     }
769 youi 1.32
770     if( ( sqlcode = SQLFetch( hstmt ) ) != SQL_SUCCESS ){
771     setLastErrorString( "SQLFetch in gidExists" );
772     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
773 youi 1.19 return false;
774     }
775 youi 1.32
776     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
777 youi 1.19 return true;
778     }
779    
780    
781     /**
782     *
783 youi 1.20 * Platform???若?倶???宴??id??絖??????????????с????
784 youi 1.19 * DB???≪???祉?劫け????????false??????鐚?/span>
785     *
786     * @param uid ???с??????????UID
787     * @return true 絖???????
788     * @return false 絖?????????
789     *
790     */
791     static bool uidExists( userid_t uid )
792     {
793 youi 1.32 bool ret = false;
794 youi 1.19 string sql;
795 youi 1.32 SQLRETURN sqlcode;
796 youi 1.19
797 aga 1.36 sql = "SELECT * FROM " + dbprefix + "_xnpaccount_users ";
798 youi 1.19 sql += "WHERE uid=" + string( unsignedIntToString( uid ) );
799 youi 1.32 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
800     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
801     if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){
802     ret = true;
803     }else{
804     string s( "SQLFetch in uidExists ");
805 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
806 youi 1.32 s += string( ", sql=" ) + string( sql );
807     setLastErrorString( s.c_str( ) );
808     ret = false;
809     }
810     }else{
811     string s( "SQLExecDirect in uidExists ");
812 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
813 youi 1.32 s += string( ", sql=" ) + string( sql );
814     setLastErrorString( s.c_str( ) );
815     ret = false;
816     }
817     }else{
818     string s( "SQLAllocHandle in uidExists ");
819 youi 1.35 s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
820 youi 1.32 setLastErrorString( s.c_str( ) );
821     ret = false;
822 youi 1.19 }
823 youi 1.32 return ret;
824 youi 1.19 }
825    
826    
827     /**
828     *
829 youi 1.13 * criteria ?? SQL?????????
830     *
831     *
832     *
833     */
834     string criteria2str( criteria* cri )
835     {
836     string sql;
837    
838     const orderby* odrby = cri -> headOrderBy( );
839     if( odrby != 0 ){
840     sql += " ORDER BY " + string( odrby -> getColumn( ) );
841     sql += ( odrby -> getOrder( ) == orderby::DESC ) ? " DESC" : " ";
842     while( ( odrby = cri -> nextOrderBy( ) ) != 0 ){
843     sql += ", " + string( odrby -> getColumn( ) );
844     sql += ( odrby -> getOrder( ) == orderby::DESC ) ? " DESC" : " ";
845     }
846 youi 1.14 }
847    
848     if( cri -> getLimitStart( ) != 0 || cri -> getLimitRows( ) != 0 ){
849     sql += " LIMIT " + string( intToString( cri -> getLimitStart( ) ) )
850     + ", " + string( intToString( cri -> getLimitRows( ) ) );
851 youi 1.13 }
852     return sql;
853     }
854 youi 1.1
855 youi 1.32
856 youi 1.1 /**
857     *
858     * ???若?帥???若?鴻????????
859     *
860 youi 1.32 * @param dsn DSN
861 youi 1.1 * @param user ???若?帥???若?鴻???≪???祉?鴻???????若?九??
862     * @param password 筝?荐????若?吟?????鴻???若??
863 youi 1.32 * @param dbname ??????/span>
864 youi 1.1 * @param prefix XOOPS???若?帥???若?鴻???若??????REFIX
865 aga 1.60 * @param dbtype DBTYPE_MYSQL or DBTYPE_SQLITE
866 youi 1.31 * @return RES_OK
867     * @return RES_DB_INITIALIZE_ERROR
868     * @return RES_DB_CONNECT_ERROR
869 youi 1.1 * @refer result_t
870     */
871 aga 1.60 result_t initializeDB( const char* dsn, const char* user, const char* password, const char* dbname, const char* prefix, dbtype_t type )
872 youi 1.1 {
873 youi 1.32 SQLRETURN sqlcode;
874    
875 youi 1.33 #ifdef USE_SYSLOG
876     openlog( "commonal", LOG_ODELAY, LOG_USER );
877     #endif
878 youi 1.1 // ?≪??・膓?筝???????筝???????/span>
879 youi 1.32 if ( hdbc != NULL )
880     SQLDisconnect( hdbc );
881 youi 1.1
882 youi 1.7 dbprefix = prefix;
883 aga 1.60 dbtype = type;
884 youi 1.7
885 youi 1.32 // ????????・膓?
886     // if( SQLAllocEnv( &henv ) != SQL_SUCCESS ) {
887 youi 1.56 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv ) ) != SQL_SUCCESS ) {
888 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_ENV,...) in initializeDB" );
889     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
890     setLastErrorString( s.c_str( ) );
891 youi 1.33 #ifdef USE_SYSLOG
892     syslog( LOG_DEBUG, "initializeDB %s", getLastErrorString( ) );
893     closelog( );
894     #endif
895 youi 1.32 return RES_DB_INITIALIZE_ERROR;
896     }
897     //ODBC Ver.3 ????????????????????с??荐??
898     SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
899 aga 1.27
900 youi 1.32 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_DBC, henv, &hdbc ) ) != SQL_SUCCESS ) {
901 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_DBC,...) in initializeDB" );
902     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
903     setLastErrorString( s.c_str( ) );
904 youi 1.33 #ifdef USE_SYSLOG
905     syslog( LOG_DEBUG, "initializeDB %s", getLastErrorString( ) );
906     closelog( );
907     #endif
908 youi 1.1 return RES_DB_INITIALIZE_ERROR;
909     }
910 youi 1.32 //???違?ゃ?潟??腱?篁ヤ?荀????????帥?ゃ???≪????????荐??
911     SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)5, 0);
912 youi 1.33
913 youi 1.32 if ( ( sqlcode = SQLConnect( hdbc, (SQLCHAR*)dsn, strlen( dsn ), (SQLCHAR*)user, strlen( user ), (SQLCHAR*)password, strlen( password ) ) ) != SQL_SUCCESS ){
914 youi 1.33 string s( "SQLConnect in initializeDB " );
915     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
916     setLastErrorString( s.c_str( ) );
917     #ifdef USE_SYSLOG
918     syslog( LOG_DEBUG, "initializeDB %s", getLastErrorString( ) );
919     closelog( );
920     #endif
921 youi 1.1 return RES_DB_CONNECT_ERROR;
922 aga 1.27 }
923 youi 1.33 #ifdef USE_SYSLOG
924     syslog( LOG_DEBUG, "initializeDB succeed" );
925     closelog( );
926     #endif
927 aga 1.27 return RES_OK;
928     }
929    
930     /**
931     *
932     * DB?ョ????????違???????????障??????
933     *
934     * @param ????
935     * @return RES_OK
936     */
937     result_t uninitializeDB()
938     {
939 youi 1.32 if ( hdbc != NULL ){
940     SQLDisconnect( hdbc );
941     hdbc = NULL;
942 youi 1.1 }
943 youi 1.2 return RES_OK;
944 youi 1.1 }
945    
946     /**
947     *
948     * Platform???若?倶?粋??倶????緇?
949     *
950 youi 1.31 * @param sid ?祉???激?с??D
951     * @param uid ?倶??????緇??????????若?吟??ID
952     * @return true ?粋?羝???/span>
953     * @return false ???粋?
954 youi 1.1 *
955     */
956 youi 1.2 bool isActivated( sessionid_t sid, userid_t uid )
957 youi 1.1 {
958 youi 1.32 if( hdbc == NULL ) return false;
959 youi 1.17 if( !isValidSessionID( sid ) ) return false;
960    
961 youi 1.32 bool ret = false;
962 youi 1.17 string sql;
963 youi 1.32 SQLRETURN sqlcode;
964     SQLHANDLE hstmt = NULL;
965 youi 1.17
966 aga 1.36 sql = "SELECT * FROM " + dbprefix + "_xnpaccount_users ";
967 youi 1.17 sql += "WHERE activate=1 and uid=" + string( unsignedIntToString( uid ) );
968 youi 1.32 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
969     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
970     if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){
971     ret = true;
972     }else{
973     string s( "SQLFetch in isActivated " );
974 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
975 youi 1.32 s += ", sql=" + sql;
976     setLastErrorString( s.c_str() );
977     ret = false;
978     }
979     }else{
980     string s( "SQLExecDirect in isActivated " );
981 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
982 youi 1.32 s += ", sql=" + sql;
983     setLastErrorString( s.c_str() );
984     ret = false;
985     }
986     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
987     }else{
988 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in isActivated" );
989     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
990     setLastErrorString( s.c_str( ) );
991 youi 1.32 ret = false;
992 youi 1.17 }
993 youi 1.32 return ret;
994 youi 1.1 }
995    
996     /**
997     *
998     * Platform???若?倶?粋??倶??紊???/span>
999     *
1000 youi 1.31 * @param sid ?祉???激?с??D
1001     * @param uid 紊??眼?????????若?吟??ID
1002     * @param activate ?粋?(true) / ???粋?(false)????絎?
1003     * @return RES_OK
1004     * @return RES_DB_QUERY_ERROR
1005     * @return RES_NO_SUCH_USER
1006 youi 1.1 */
1007 youi 1.2 result_t activate( sessionid_t sid, userid_t uid, bool activate )
1008 youi 1.1 {
1009 youi 1.32 if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
1010 youi 1.17 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
1011    
1012     string sql;
1013 youi 1.32 SQLRETURN sqlcode;
1014     result_t ret = RES_ERROR;
1015 youi 1.17
1016 aga 1.36 sql = "UPDATE " + dbprefix + "_xnpaccount_users ";
1017 youi 1.17 sql += "SET activate=" + string( activate ? "1" : "0" );
1018     sql += " WHERE uid=" + string( unsignedIntToString( uid ) );
1019 youi 1.32 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1020     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
1021 youi 1.64 SQLLEN count = 0;
1022 youi 1.32 if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){
1023     ret = RES_OK;
1024     }else{
1025     string s( "SQLRowCount in activate ");
1026 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1027 youi 1.32 s += string( ", sql=" ) + string( sql );
1028     setLastErrorString( s.c_str( ) );
1029     ret = RES_NO_SUCH_USER;
1030     }
1031     }else{
1032     string s( "SQLExecDirect in activate " );
1033 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1034 youi 1.32 s += ", sql=";
1035     s += string( sql );
1036     setLastErrorString( s.c_str( ) );
1037     ret = RES_DB_QUERY_ERROR;
1038     }
1039     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
1040     }else{
1041 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in activate" );
1042     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1043     setLastErrorString( s.c_str( ) );
1044 youi 1.32 ret = RES_ERROR;
1045 youi 1.17 }
1046 youi 1.32 return ret;
1047 youi 1.1 }
1048    
1049     /**
1050     *
1051 youi 1.31 * ?≪?????潟???違????緇?????鐚?/span>
1052 youi 1.1 *
1053 youi 1.31 * @param sid ?祉???激?с??D
1054     * @return ?≪?????潟????/span>
1055 youi 1.1 *
1056     */
1057 youi 1.2 int getAccountCount( sessionid_t sid )
1058 youi 1.1 {
1059 youi 1.32 if( hdbc == NULL ) return 0;
1060 youi 1.16 if( !isValidSessionID( sid ) ) return 0;
1061    
1062     int ret = 0;
1063     string sql;
1064 youi 1.32 SQLRETURN sqlcode;
1065     SQLHANDLE hstmt = NULL;
1066 youi 1.16
1067     //?≪?????潟???違??羆?????
1068 aga 1.36 sql = "SELECT COUNT(*) FROM " + dbprefix + "_xnpaccount_users ";
1069 youi 1.32 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1070     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
1071     SQLUINTEGER count = 0;
1072 youi 1.56 SQLLEN len = 0;
1073 youi 1.32 SQLBindCol( hstmt, 1, SQL_C_ULONG, &count, 0, &len );
1074     if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){
1075     ret = count;
1076     }else {
1077     string s( "SQLFetch in getAccountCount sql=" );
1078     s += string( sql );
1079     setLastErrorString( s.c_str( ) );
1080     ret = 0;
1081     }
1082     }else{
1083     setLastErrorString( "SQLExecDirect in getAccountCount" );
1084     ret = 0;
1085     }
1086     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
1087 youi 1.16 }else{
1088 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getAccountCount" );
1089     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1090     setLastErrorString( s.c_str( ) );
1091 youi 1.32 ret = 0;
1092 youi 1.16 }
1093     return ret;
1094 youi 1.1 }
1095    
1096     /**
1097     *
1098     * ?≪?????潟??????/span>
1099 youi 1.35 * ?違???若???????????ゃ?????若?倶???宴?????ゃ??茵??????障??鐚?/span>
1100 youi 1.1 *
1101     * @param
1102 youi 1.20 * @return RES_OK
1103 youi 1.35 * @return RES_ERROR
1104 youi 1.31 * @return RES_DB_NOT_INITIALIZED
1105 youi 1.20 * @return RES_NO_SUCH_SESSION
1106     * @return RES_DB_QUERY_ERROR
1107 youi 1.1 *
1108     */
1109 youi 1.2 result_t deleteAccount( sessionid_t sid, userid_t uid )
1110 youi 1.1 {
1111 youi 1.32 if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
1112 youi 1.10 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
1113 youi 1.32
1114     result_t ret1 = RES_ERROR, ret2 = RES_ERROR;
1115 youi 1.35 criteria_t c;
1116 youi 1.32 string sql;
1117 youi 1.35 groupid_t* gids;
1118     int gidsLen;
1119 youi 1.32 SQLRETURN sqlcode;
1120     SQLHANDLE hstmt = NULL;
1121 youi 1.10
1122 youi 1.35 /*
1123     1. delete user from default platform group
1124     2. delete user profile from xoops_users
1125 aga 1.36 3. delete platform user from xnpaccount_users
1126 youi 1.35 */
1127    
1128     //1. delete user from platform groups
1129     c.clearAll();
1130     if( getGroupsByUid( sid, uid, &c, &gids, &gidsLen ) == RES_OK ){
1131     for( int i = 0; i < gidsLen; i++ )
1132     deleteMemberNoLimit( sid, gids[ i ], uid );
1133     freeGID( gids );
1134     }
1135    
1136     //2. delete user profile from xoops_users
1137 youi 1.10 sql = "DELETE FROM " + dbprefix + "_users ";
1138     sql += "WHERE uid = " + string( unsignedIntToString( uid ) );
1139 youi 1.32 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1140     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
1141 youi 1.64 SQLLEN count = 0;
1142 youi 1.32 if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){
1143     ret1 = RES_OK;
1144     }else{
1145     string s( "SQLRowCount in deleteAccount" );
1146 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1147 youi 1.32 s += string( ", sql=" ) + string( sql );
1148     setLastErrorString( s.c_str( ) );
1149     ret1 = RES_NO_SUCH_USER;
1150     }
1151     }else{
1152     string s( "SQLExecDirect in deleteAccount" );
1153 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1154 youi 1.32 s += ", sql=";
1155     s += string( sql );
1156     setLastErrorString( s.c_str( ) );
1157     ret1 = RES_DB_QUERY_ERROR;
1158     }
1159     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
1160     }else{
1161 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in deleteAccount" );
1162     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1163     setLastErrorString( s.c_str( ) );
1164 youi 1.32 ret1 = RES_ERROR;
1165 youi 1.10 }
1166    
1167 aga 1.36 //3. delete platform user from xnpaccount_users
1168     sql = "DELETE FROM " + dbprefix + "_xnpaccount_users ";
1169 youi 1.10 sql += "WHERE uid = " + string( unsignedIntToString( uid ) );
1170 youi 1.32 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1171     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
1172 youi 1.64 SQLLEN count = 0;
1173 youi 1.32 if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){
1174     ret2 = RES_OK;
1175     }else{
1176     string s( "SQLRowCount in deleteAccount" );
1177 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1178 youi 1.32 s += string( ", sql=" ) + string( sql );
1179     setLastErrorString( s.c_str( ) );
1180     ret2 = RES_NO_SUCH_USER;
1181     }
1182     }else{
1183     string s( "SQLExecDirect in deleteAccount" );
1184 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1185 youi 1.32 s += ", sql=";
1186     s += string( sql );
1187     setLastErrorString( s.c_str( ) );
1188     ret2 = RES_DB_QUERY_ERROR;
1189     }
1190     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
1191     }else{
1192 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in deleteAccount" );
1193     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1194     setLastErrorString( s.c_str( ) );
1195 youi 1.32 ret2 = RES_ERROR;
1196 youi 1.10 }
1197    
1198 youi 1.32 //筝??鴻?с???????若?????????若??菴???
1199     return ret1 != RES_OK ? ret1 : ret2;
1200 youi 1.1 }
1201    
1202     /**
1203     *
1204     * ?≪?????潟?????怨??
1205     *
1206 youi 1.13 * @param sid ?祉???激?с??D
1207     * @param uid ??緇??????????若?吟??ID
1208     * @param acc ??緇??????≪?????潟??????account_t)?????ゃ?潟?帥???吾??莨若??綣???/span>
1209 youi 1.20 * @return RES_OK
1210 youi 1.31 * @return RES_DB_NOT_INITIALIZED
1211 youi 1.20 * @return RES_NO_SUCH_USER
1212     * @return RES_NO_SUCH_SESSION
1213     * @return RES_DB_QUERY_ERROR
1214 youi 1.1 *
1215     */
1216 youi 1.12 result_t getAccount( sessionid_t sid, userid_t uid, const account_t** acc )
1217 youi 1.1 {
1218 youi 1.13 int len;
1219     static criteria c;
1220     result_t res = getAccounts( sid, &uid, 1, &c, acc, &len );
1221     if( len == 0 ) return RES_NO_SUCH_USER;
1222     return res;
1223     }
1224    
1225     /**
1226     *
1227     * ?≪?????潟?????怨??
1228     *
1229     * @param sid ?祉???激?с??D
1230     * @param uids ??緇??????????若?吟??ID??????
1231     * @param uidsLen uids???????膣???/span>
1232     * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
1233     * @param accounts 罎?膣∝??????????????ゃ?潟?帥???吾??莨若??綣???/span>
1234     * @param accountsLen 罎?膣∝???????????*accounts???膣???
1235 youi 1.31 * @return RES_OK
1236     * @return RES_DB_NOT_INITIALIZED
1237     * @return RES_NO_SUCH_SESSION
1238 youi 1.20 * @return RES_DB_QUERY_ERROR
1239 youi 1.13 *
1240     */
1241     result_t getAccounts( sessionid_t sid, const userid_t* uids, int uidsLen, criteria_t* cri, const account_t** accounts, int* accountsLen )
1242     {
1243 youi 1.32 if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
1244 youi 1.12 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
1245 youi 1.28 if( uidsLen <= 0 ){
1246     *accounts = new account_t[ 0 ];
1247     *accountsLen = 0;
1248     #ifdef USE_SYSLOG
1249 youi 1.33 openlog( "commonal", LOG_ODELAY, LOG_USER );
1250     syslog( LOG_DEBUG, "getAccounts succeed len=0" );
1251     closelog( );
1252 youi 1.28 #endif
1253     return RES_OK;
1254     }
1255 youi 1.12
1256 youi 1.33 #ifdef USE_SYSLOG
1257     openlog( "commonal", LOG_ODELAY, LOG_USER );
1258     syslog( LOG_DEBUG, "begin of getAccounts" );
1259     #endif
1260 youi 1.32 result_t ret = RES_ERROR;
1261     SQLRETURN sqlcode;
1262     SQLHANDLE hstmt = NULL;
1263 youi 1.12 string sql;
1264 youi 1.13 account_t* dst = new account_t[ uidsLen ];
1265 youi 1.12
1266 aga 1.61 sql += "SELECT u1.uid, u1.name, u1.uname, u1.email, u1.url, u1.user_avatar, u1.user_regdate, u1.user_icq, u1.user_from, u1.user_sig, u1.user_viewemail, u1.actkey, u1.user_aim, u1.user_yim, u1.user_msnm, u1.pass, u1.posts, u1.attachsig, u1.rank, u1.level, u1.theme, u1.timezone_offset, u1.last_login, u1.umode, u1.uorder, u1.notify_method, u1.notify_mode, u1.user_occ, u1.bio, u1.user_intrest, u1.user_mailok, u2.activate, u2.address, u2.division, u2.tel, u2.company_name, u2.country, u2.zipcode, u2.fax, u2.notice_mail, u2.notice_mail_since, u2.private_index_id ";
1267 aga 1.36 sql += "FROM " + dbprefix + "_users AS u1, " + dbprefix + "_xnpaccount_users AS u2 ";
1268 youi 1.28 sql += "WHERE u1.uid = u2.uid ";
1269     if( uidsLen > 0 ){
1270 youi 1.33 #ifdef USE_SYSLOG
1271     syslog( LOG_DEBUG, "set uid[%d] value=%d to ...", 0, uids[0] );
1272     #endif
1273 youi 1.28 sql += "AND ( u1.uid=" + string( unsignedIntToString( uids[ 0 ] ) );
1274     for( int i = 1; i < uidsLen; i++ ){
1275 youi 1.33 #ifdef USE_SYSLOG
1276     syslog( LOG_DEBUG, "set uid[%d] value=%d to ...", i, uids[i] );
1277     #endif
1278 youi 1.28 sql += " OR u1.uid=" + string( unsignedIntToString( uids[ i ] ) );
1279     }
1280     sql += " ) ";
1281 youi 1.12 }
1282 youi 1.13 sql += criteria2str( cri );
1283 youi 1.33 #ifdef USE_SYSLOG
1284     syslog( LOG_DEBUG, "sql=%s", sql.c_str() );
1285     #endif
1286 youi 1.32
1287     if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1288     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
1289 youi 1.56 SQLLEN len = 0;
1290 youi 1.32 userid_t uid = 0;
1291     SQLBindCol( hstmt, 1, SQL_C_ULONG, &uid, 0, &len );
1292     *accountsLen=0;
1293     for( int i = 0; ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS && i < uidsLen ; i++ ){
1294     dst[ i ].setUID( uid );
1295     dst[ i ].setName( getResultCol( hstmt, 2 ).c_str() );
1296     dst[ i ].setUname( getResultCol( hstmt, 3 ).c_str() );
1297     dst[ i ].setEmail( getResultCol( hstmt, 4 ).c_str() );
1298     dst[ i ].setURL( getResultCol( hstmt, 5 ).c_str() );
1299     dst[ i ].setUserAvatar( getResultCol( hstmt, 6 ).c_str() );
1300     dst[ i ].setUserRegdate( atoi( getResultCol( hstmt, 7 ).c_str() ) );
1301     dst[ i ].setUserIcq( getResultCol( hstmt, 8 ).c_str() );
1302     dst[ i ].setUserFrom( getResultCol( hstmt, 9 ).c_str() );
1303     dst[ i ].setUserSig( getResultCol( hstmt, 10 ).c_str() );
1304     dst[ i ].setUserViewemail( atoi( getResultCol( hstmt, 11 ).c_str() ));
1305     dst[ i ].setActkey( getResultCol( hstmt, 12 ).c_str() );
1306     dst[ i ].setUserAim( getResultCol( hstmt, 13 ).c_str() );
1307     dst[ i ].setUserYim( getResultCol( hstmt, 14 ).c_str() );
1308     dst[ i ].setUserMsnm( getResultCol( hstmt, 15 ).c_str() );
1309     dst[ i ].setPass( getResultCol( hstmt, 16 ).c_str() );
1310     dst[ i ].setPosts( atoi( getResultCol( hstmt, 17 ).c_str() ));
1311     dst[ i ].setAttachsig( atoi( getResultCol( hstmt, 18 ).c_str() ));
1312     dst[ i ].setRank( atoi( getResultCol( hstmt, 19 ).c_str() ));
1313     dst[ i ].setLevel( atoi( getResultCol( hstmt, 20 ).c_str() ));
1314     dst[ i ].setTheme( getResultCol( hstmt, 21 ).c_str() );
1315     dst[ i ].setTimezoneOffset( atof( getResultCol( hstmt, 22 ).c_str() ) );
1316     dst[ i ].setLastLogin( atoi( getResultCol( hstmt, 23 ).c_str() ));
1317     dst[ i ].setUmode( getResultCol( hstmt, 24 ).c_str() );
1318     dst[ i ].setUorder( atoi( getResultCol( hstmt, 25 ).c_str() ));
1319     dst[ i ].setNotifyMethod( atoi( getResultCol( hstmt, 26 ).c_str() ));
1320     dst[ i ].setNotifyMode( atoi( getResultCol( hstmt, 27 ).c_str() ));
1321     dst[ i ].setUserOcc( getResultCol( hstmt, 28 ).c_str() );
1322     dst[ i ].setBio( getResultCol( hstmt, 29 ).c_str() );
1323     dst[ i ].setUserIntrest( getResultCol( hstmt, 30 ).c_str() );
1324     dst[ i ].setUserMailok( atoi( getResultCol( hstmt, 31 ).c_str() ));
1325     dst[ i ].setActivate( atoi( getResultCol( hstmt, 32 ).c_str() ));
1326     dst[ i ].setAddress( getResultCol( hstmt, 33 ).c_str() );
1327     dst[ i ].setDivision( getResultCol( hstmt, 34 ).c_str() );
1328     dst[ i ].setTel( getResultCol( hstmt, 35 ).c_str() );
1329     dst[ i ].setCompanyName( getResultCol( hstmt, 36 ).c_str() );
1330     dst[ i ].setCountry( getResultCol( hstmt, 37 ).c_str() );
1331     dst[ i ].setZipcode( getResultCol( hstmt, 38 ).c_str() );
1332     dst[ i ].setFax( getResultCol( hstmt, 39 ).c_str() );
1333 aga 1.61 dst[ i ].setNoticeMail( atoi( getResultCol( hstmt, 40 ).c_str() ));
1334     dst[ i ].setNoticeMailSince( atoi( getResultCol( hstmt, 41 ).c_str() ));
1335     dst[ i ].setPrivateIndexID( atoi( getResultCol( hstmt, 42 ).c_str() ));
1336 youi 1.33 #ifdef USE_SYSLOG
1337     syslog( LOG_DEBUG, "set to account_t %d", i );
1338     #endif
1339 youi 1.32 ( *accountsLen )++;
1340     }
1341     *accounts = dst;
1342 youi 1.33 #ifdef USE_SYSLOG
1343     syslog( LOG_DEBUG, "getAccounts succeed" );
1344     #endif
1345 youi 1.32 ret = RES_OK;
1346     }else{
1347 youi 1.33 string s( "SQLExecDirect in getAccounts" );
1348     s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1349     s += string( ", sql=" ) + string( sql );
1350     setLastErrorString( s.c_str( ) );
1351     #ifdef USE_SYSLOG
1352     syslog( LOG_DEBUG, "getAccounts %s", getLastErrorString( ) );
1353     #endif
1354 youi 1.32 ret = RES_DB_QUERY_ERROR;
1355     }
1356     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
1357     }else{
1358 youi 1.33 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getAccounts" );
1359     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1360     setLastErrorString( s.c_str( ) );
1361     #ifdef USE_SYSLOG
1362     syslog( LOG_DEBUG, "getAccounts %s", getLastErrorString( ) );
1363     #endif
1364 youi 1.32 ret = RES_DB_QUERY_ERROR;
1365 youi 1.12 }
1366 youi 1.33 #ifdef USE_SYSLOG
1367     closelog( );
1368     #endif
1369 youi 1.32 return ret;
1370 youi 1.1 }
1371    
1372     /**
1373     *
1374 youi 1.25 * ?≪?????潟???脂??
1375 youi 1.35 *
1376 youi 1.25 * ???若?倶???宴?????若?帥???若?鴻???脂?蚊???障??鐚?/span>
1377 youi 1.35 * ?脂?蚊???????若?倶???宴???綽????????若??D??uid???主????障??鐚?/span>
1378 youi 1.1 *
1379 youi 1.7 * @param sid ?祉???激?с??/span>
1380 youi 1.10 * @param account ?脂?蚊?????≪?????潟??????/span>
1381 youi 1.25 * @param uid ?脂?蚊?????≪?????潟?????宴???綽????????若??D
1382 youi 1.20 * @return RES_OK
1383     * @return RES_NO_SUCH_SESSION
1384     * @return RES_DB_QUERY_ERROR
1385 youi 1.31 * @return RES_DB_NOT_INITIALIZED
1386 youi 1.1 *
1387     */
1388 youi 1.25 result_t insertAccount( sessionid_t sid, const account_t* account, userid_t* uid )
1389 youi 1.1 {
1390 youi 1.32 if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
1391 youi 1.10 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
1392    
1393 youi 1.7 string sql;
1394     string tmp;
1395 youi 1.32 SQLRETURN sqlcode;
1396     result_t ret = RES_ERROR;
1397 youi 1.7
1398 youi 1.35 /*
1399     1. insert user profile into xoops_users
1400 aga 1.36 2. insert platform user profile into xnpaccount_users
1401 youi 1.35 3. add user to default platform group
1402 aga 1.37 4. create private index
1403     5. update account set private_index_id=...
1404 youi 1.35 */
1405    
1406     //1.xoops?????若?吟???若???????吾??莨若??
1407 youi 1.39 SQLCHAR uname[ACCOUNT_UNAME_LEN+1], name[ACCOUNT_NAME_LEN+1], email[ACCOUNT_EMAIL_LEN+1], url[ACCOUNT_URL_LEN+1], user_avatar[ACCOUNT_USER_AVATAR_LEN+1], user_icq[ACCOUNT_USER_ICQ_LEN+1], user_from[ACCOUNT_USER_FROM_LEN+1], user_sig[ACCOUNT_USER_SIG_LEN+1], actkey[ACCOUNT_ACTKEY_LEN+1], user_aim[ACCOUNT_USER_AIM_LEN+1], user_yim[ACCOUNT_USER_YIM_LEN+1], user_msnm[ACCOUNT_USER_MSNM_LEN+1], pass[ACCOUNT_PASS_LEN+1], theme[ACCOUNT_THEME_LEN+1], umode[ACCOUNT_UMODE_LEN+1], user_occ[ACCOUNT_USER_OCC_LEN+1], bio[ACCOUNT_BIO_LEN+1], user_intrest[ACCOUNT_USER_INTREST_LEN+1];
1408 youi 1.32 SQLINTEGER user_regdate, user_viewemail, posts, attachsig, rank, level, last_login, uorder, notify_method, notify_mode, user_mailok;
1409     SQLDOUBLE timezone_offset;
1410    
1411 youi 1.56 SQLLEN cbUname = SQL_NTS, cbName = SQL_NTS, cbEmail = SQL_NTS, cbUrl = SQL_NTS, cbUser_avatar = SQL_NTS, cbUser_icq = SQL_NTS, cbUser_from = SQL_NTS, cbUser_sig = SQL_NTS, cbActkey = SQL_NTS, cbUser_aim = SQL_NTS, cbUser_yim = SQL_NTS, cbUser_msnm = SQL_NTS, cbPass = SQL_NTS, cbTheme = SQL_NTS, cbUmode = SQL_NTS, cbUser_occ = SQL_NTS, cbBio = SQL_NTS, cbUser_intrest = SQL_NTS;
1412     SQLLEN cbUser_regdate = 0, cbUser_viewemail = 0, cbPosts = 0, cbAttachsig = 0, cbRank = 0, cbLevel = 0, cbLast_login = 0, cbUorder = 0, cbNotify_method = 0, cbNotify_mode = 0, cbUser_mailok = 0, cbTimezone_offset = 0;
1413 youi 1.32
1414     if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1415     string sql;
1416 aga 1.48 sql = "INSERT INTO " + dbprefix + "_users (uname, name, email, url, user_avatar, user_regdate, user_icq, user_from, user_sig, user_viewemail, actkey, user_aim, user_yim, user_msnm, pass, posts, attachsig, rank, level, theme, timezone_offset, last_login, umode, uorder, notify_method, notify_mode, user_occ, bio, user_intrest, user_mailok) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
1417 youi 1.32 sqlcode = SQLPrepare(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS);
1418     if( sqlcode == SQL_SUCCESS || sqlcode == SQL_SUCCESS_WITH_INFO ){
1419     SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_UNAME_LEN, 0, uname, 0, &cbUname );
1420     SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_NAME_LEN, 0, name, 0, &cbName );
1421     SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_EMAIL_LEN, 0, email, 0, &cbEmail );
1422     SQLBindParameter(hstmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_URL_LEN, 0, url, 0, &cbUrl );
1423     SQLBindParameter(hstmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_AVATAR_LEN, 0, user_avatar, 0, &cbUser_avatar );
1424     SQLBindParameter(hstmt, 6, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &user_regdate, 0, &cbUser_regdate );
1425     SQLBindParameter(hstmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_ICQ_LEN, 0, user_icq, 0, &cbUser_icq );
1426     SQLBindParameter(hstmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_FROM_LEN, 0, user_from, 0, &cbUser_from );
1427     SQLBindParameter(hstmt, 9, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_SIG_LEN, 0, user_sig, 0, &cbUser_sig );
1428     SQLBindParameter(hstmt, 10, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &user_viewemail, 0, &cbUser_viewemail );
1429     SQLBindParameter(hstmt, 11, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_ACTKEY_LEN, 0, actkey, 0, &cbActkey );
1430     SQLBindParameter(hstmt, 12, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_AIM_LEN, 0, user_aim, 0, &cbUser_aim );
1431     SQLBindParameter(hstmt, 13, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_YIM_LEN, 0, user_yim, 0, &cbUser_yim );
1432     SQLBindParameter(hstmt, 14, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_MSNM_LEN, 0, user_msnm, 0, &cbUser_msnm );
1433     SQLBindParameter(hstmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_PASS_LEN, 0, pass, 0, &cbPass );
1434     SQLBindParameter(hstmt, 16, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &posts, 0, &cbPosts );
1435     SQLBindParameter(hstmt, 17, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &attachsig, 0, &cbAttachsig );
1436     SQLBindParameter(hstmt, 18, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &rank, 0, &cbRank );
1437     SQLBindParameter(hstmt, 19, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &level, 0, &cbLevel );
1438     SQLBindParameter(hstmt, 20, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_THEME_LEN, 0, theme, 0, &cbTheme );
1439     SQLBindParameter(hstmt, 21, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &timezone_offset, 0, &cbTimezone_offset );
1440     SQLBindParameter(hstmt, 22, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &last_login, 0, &cbLast_login );
1441     SQLBindParameter(hstmt, 23, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_UMODE_LEN, 0, umode, 0, &cbUmode );
1442     SQLBindParameter(hstmt, 24, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &uorder, 0, &cbUorder );
1443     SQLBindParameter(hstmt, 25, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &notify_method, 0, &cbNotify_method );
1444     SQLBindParameter(hstmt, 26, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &notify_mode, 0, &cbNotify_mode );
1445     SQLBindParameter(hstmt, 27, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_OCC_LEN, 0, user_occ, 0, &cbUser_occ );
1446     SQLBindParameter(hstmt, 28, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_BIO_LEN, 0, bio, 0, &cbBio );
1447     SQLBindParameter(hstmt, 29, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_INTREST_LEN, 0, user_intrest, 0, &cbUser_intrest );
1448     SQLBindParameter(hstmt, 30, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &user_mailok, 0, &cbUser_mailok );
1449    
1450     strncpy2( (char*)uname, account -> getUname( ), ACCOUNT_UNAME_LEN );
1451     strncpy2( (char*)name, account -> getName( ), ACCOUNT_NAME_LEN );
1452     strncpy2( (char*)email, account -> getEmail( ), ACCOUNT_EMAIL_LEN );
1453     strncpy2( (char*)url, account -> getURL( ), ACCOUNT_URL_LEN );
1454     strncpy2( (char*)user_avatar, account -> getUserAvatar( ), ACCOUNT_USER_AVATAR_LEN );
1455     user_regdate = time( NULL );
1456     strncpy2( (char*)user_icq, account -> getUserIcq( ), ACCOUNT_USER_ICQ_LEN );
1457     strncpy2( (char*)user_from, account -> getUserFrom( ), ACCOUNT_USER_FROM_LEN );
1458     strncpy2( (char*)user_sig, account -> getUserSig( ), ACCOUNT_USER_SIG_LEN );
1459     user_viewemail = account -> getUserViewemail( );
1460     strncpy2( (char*)actkey, account -> getActkey( ), ACCOUNT_ACTKEY_LEN );
1461     strncpy2( (char*)user_aim, account -> getUserAim( ), ACCOUNT_USER_AIM_LEN );
1462     strncpy2( (char*)user_yim, account -> getUserYim( ), ACCOUNT_USER_YIM_LEN );
1463     strncpy2( (char*)user_msnm, account -> getUserMsnm( ), ACCOUNT_USER_MSNM_LEN );
1464     strncpy2( (char*)pass, account -> getPass( ), ACCOUNT_PASS_LEN );
1465     posts = account -> getPosts( );
1466     attachsig = account -> getAttachsig( );
1467     rank = account -> getRank( );
1468     level = account -> getLevel( );
1469     strncpy2( (char*)theme, account -> getTheme( ), ACCOUNT_THEME_LEN );
1470     timezone_offset = account -> getTimezoneOffset( );
1471     last_login = 0;
1472     strncpy2( (char*)umode, account -> getUmode( ), ACCOUNT_UMODE_LEN );
1473     uorder = account -> getUorder( );
1474     notify_method = account -> getNotifyMethod( );
1475     notify_mode = account -> getNotifyMode( );
1476     strncpy2( (char*)user_occ, account -> getUserOcc( ), ACCOUNT_USER_OCC_LEN );
1477     strncpy2( (char*)bio, account -> getBio( ), ACCOUNT_BIO_LEN );
1478     strncpy2( (char*)user_intrest, account -> getUserIntrest( ), ACCOUNT_USER_INTREST_LEN );
1479     user_mailok = account -> getUserMailok( );
1480    
1481     if( ( sqlcode = SQLExecute( hstmt ) ) == SQL_SUCCESS ){
1482 youi 1.64 SQLLEN count = 0;
1483 youi 1.32 if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){
1484     //???若??D????緇?????
1485 youi 1.44 sql = "SELECT LAST_INSERT_ID()";
1486     ret = queryGetUnsignedInt( "insertAccount", sql, (unsigned int*)uid );
1487 youi 1.32 }else{
1488     string s( "SQLRowCount in insertAccount sql=" );
1489     s += string( sql );
1490     setLastErrorString( s.c_str( ) );
1491     ret = RES_DB_QUERY_ERROR;
1492     }
1493     }else{
1494     string s( "SQLExecute in insertAccount " );
1495 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1496 youi 1.32 setLastErrorString( s.c_str( ) );
1497     ret = RES_DB_QUERY_ERROR;
1498     }
1499     }else{
1500     string s( "SQLPrepare in insertAccount " );
1501 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1502 youi 1.32 setLastErrorString( s.c_str( ) );
1503     ret = RES_ERROR;
1504     }
1505     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
1506     }else{
1507 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in insertAccount" );
1508     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1509     setLastErrorString( s.c_str( ) );
1510 youi 1.32 ret = RES_ERROR;
1511 youi 1.7 }
1512    
1513 youi 1.35 if( ret == RES_OK ){
1514 aga 1.36 //2.xnpaccount?????若?吟???若??????????????宴???吾??莨若??
1515 youi 1.35 SQLUINTEGER activate;
1516 aga 1.36 SQLCHAR address[XNP_ACCOUNT_ADDRESS_LEN+1];
1517     SQLCHAR division[XNP_ACCOUNT_DIVISION_LEN+1];
1518     SQLCHAR tel[XNP_ACCOUNT_TEL_LEN+1];
1519     SQLCHAR company_name[XNP_ACCOUNT_COMPANY_NAME_LEN+1];
1520     SQLCHAR country[XNP_ACCOUNT_COUNTRY_LEN+1];
1521     SQLCHAR zipcode[XNP_ACCOUNT_ZIPCODE_LEN+1];
1522     SQLCHAR fax[XNP_ACCOUNT_FAX_LEN+1];
1523 aga 1.61 SQLLEN cbAddress = SQL_NTS, cbDivision = SQL_NTS, cbTel = SQL_NTS, cbCompany_name = SQL_NTS, cbCountry = SQL_NTS, cbZipcode = SQL_NTS, cbFax = SQL_NTS;
1524 youi 1.56 SQLLEN cbUid = 0, cbActivate = 0, cbNotice_mail = 0, cbNotice_mail_since = 0;
1525 youi 1.35 SQLUINTEGER notice_mail;
1526     SQLUINTEGER notice_mail_since;
1527     if( ret == RES_OK && ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1528     string sql;
1529 aga 1.61 sql = "INSERT INTO " + dbprefix + "_xnpaccount_users (uid, activate, address, division, tel, company_name, country, zipcode, fax, notice_mail, notice_mail_since) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
1530 youi 1.35 sqlcode = SQLPrepare(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS);
1531     if( sqlcode == SQL_SUCCESS || sqlcode == SQL_SUCCESS_WITH_INFO ){
1532     SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SSHORT, SQL_INTEGER, 0, 0, uid, 0, &cbUid);
1533     SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_SSHORT, SQL_INTEGER, 0, 0, &activate, 0, &cbActivate);
1534 aga 1.36 SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_ADDRESS_LEN, 0, address, 0, &cbAddress);
1535     SQLBindParameter(hstmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_DIVISION_LEN, 0, division, 0, &cbDivision);
1536     SQLBindParameter(hstmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_TEL_LEN, 0, tel, 0, &cbTel);
1537     SQLBindParameter(hstmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_COMPANY_NAME_LEN, 0, company_name, 0, &cbCompany_name);
1538     SQLBindParameter(hstmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_COUNTRY_LEN, 0, country, 0, &cbCountry);
1539     SQLBindParameter(hstmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_ZIPCODE_LEN, 0, zipcode, 0, &cbZipcode);
1540     SQLBindParameter(hstmt, 9, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_FAX_LEN, 0, fax, 0, &cbFax);
1541 aga 1.61 SQLBindParameter(hstmt, 10, SQL_PARAM_INPUT, SQL_C_SSHORT, SQL_INTEGER, 0, 0, &notice_mail, 0, &cbNotice_mail);
1542     SQLBindParameter(hstmt, 11, SQL_PARAM_INPUT, SQL_C_SSHORT, SQL_INTEGER, 0, 0, &notice_mail_since, 0, &cbNotice_mail_since);
1543 youi 1.32
1544 youi 1.35 activate = account -> getActivate() ? 1 : 0;
1545 aga 1.36 strncpy2( (char*)address, account -> getAddress(), XNP_ACCOUNT_ADDRESS_LEN );
1546     strncpy2( (char*)division, account -> getDivision(), XNP_ACCOUNT_DIVISION_LEN );
1547     strncpy2( (char*)tel, account -> getTel(), XNP_ACCOUNT_TEL_LEN );
1548     strncpy2( (char*)company_name, account -> getCompanyName(), XNP_ACCOUNT_COMPANY_NAME_LEN );
1549     strncpy2( (char*)country, account -> getCountry(), XNP_ACCOUNT_COUNTRY_LEN );
1550     strncpy2( (char*)zipcode, account -> getZipcode(), XNP_ACCOUNT_ZIPCODE_LEN );
1551     strncpy2( (char*)fax, account -> getFax(), XNP_ACCOUNT_FAX_LEN );
1552 youi 1.35 notice_mail = account -> getNoticeMail( );
1553     notice_mail_since = account -> getNoticeMailSince( );
1554 youi 1.32
1555 youi 1.35 if( ( sqlcode = SQLExecute( hstmt ) ) == SQL_SUCCESS ){
1556 youi 1.64 SQLLEN count = 0;
1557 youi 1.35 if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){
1558     ret = RES_OK;
1559     if( ret == RES_OK ){
1560     //3.add new user to default group(not a group admin)
1561 youi 1.39 ret = insertMember( sid, group_t::GID_DEFAULT, *uid, false );
1562 youi 1.35 }else{
1563     //xoops_users??nsert???????潟?若???????ゃ????
1564     sql = "DELETE FROM " + dbprefix + "_users where uid=";
1565     sql += unsignedIntToString( *uid );
1566     SQLHANDLE hstmt2 = NULL;
1567     if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt2 ) ) == SQL_SUCCESS ) {
1568     SQLExecDirect( hstmt2, (SQLCHAR*)sql.c_str(), sql.length() );
1569     SQLFreeHandle( SQL_HANDLE_STMT, hstmt2 );
1570     }
1571     setLastErrorString( "insertMember in insertAccount" );
1572     ret = RES_DB_QUERY_ERROR;
1573     }
1574     }else{
1575     string s( "SQLRowCount in insertAccount sql=" );
1576     s += string( sql );
1577     setLastErrorString( s.c_str( ) );
1578     ret = RES_DB_QUERY_ERROR;
1579     }
1580 youi 1.32 }else{
1581 youi 1.35 string s( "SQLExecute in insertAccount " );
1582     s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1583 youi 1.32 setLastErrorString( s.c_str( ) );
1584     ret = RES_DB_QUERY_ERROR;
1585     }
1586     }else{
1587 youi 1.35 //xoops_users??nsert???????潟?若???????ゃ????
1588     sql = "DELETE FROM " + dbprefix + "_users where uid=";
1589     sql += unsignedIntToString( *uid );
1590     SQLHANDLE hstmt2 = NULL;
1591     if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt2 ) ) == SQL_SUCCESS ) {
1592     SQLExecDirect( hstmt2, (SQLCHAR*)sql.c_str(), sql.length() );
1593     SQLFreeHandle( SQL_HANDLE_STMT, hstmt2 );
1594     }
1595     string s( "SQLExecDirect in insertAccount sql=" );
1596     s += string( sql );
1597 youi 1.32 setLastErrorString( s.c_str( ) );
1598     ret = RES_DB_QUERY_ERROR;
1599     }
1600 youi 1.35 SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
1601 youi 1.32 }else{
1602 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in insertAccount" );
1603     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1604     setLastErrorString( s.c_str( ) );
1605 youi 1.35 ret = RES_ERROR;
1606 youi 1.32 }
1607 youi 1.7 }
1608 aga 1.37
1609     if ( ret == RES_OK ){
1610     //4.private index??篏???
1611    
1612     // private index????ort_number????
1613     string sql = "select min(sort_number) from " +
1614     dbprefix + "_xnpaccount_index where parent_index_id=" + unsignedIntToString(item::IID_ROOT) +
1615     " and open_level=" + unsignedIntToString(index::OL_PRIVATE);
1616     unsigned int sortNumber;
1617     ret = queryGetUnsignedInt( "insertAccount", sql, &sortNumber );
1618     sortNumber--;
1619     if ( ret == RES_OK ){
1620     // private index篏???
1621     index_t index;
1622     index.setItemTypeID(item::ITID_INDEX);
1623     index.setContributorUID(*uid);
1624     index.setParentIndexID(item::IID_ROOT);
1625     index.setOwnerUID(*uid);
1626     index.setOpenLevel(index::OL_PRIVATE);
1627     index.setSortNumber(sortNumber);
1628     index.setTitle(account->getUname());
1629     indexid_t privateXID;
1630     ret = insertIndexInternal( sid, &index, &privateXID );
1631     if ( ret == RES_OK ){
1632     // xnpaccuont_users??rivate_index_id???吾??????
1633     sql = "UPDATE " + dbprefix + "_xnpaccount_users SET private_index_id="
1634     + unsignedIntToString(privateXID) + " WHERE uid=" + unsignedIntToString(*uid);
1635     ret = querySimple( "insertAccount", sql );
1636     }
1637     }
1638     }
1639    
1640 youi 1.32 return ret;
1641 youi 1.1 }
1642    
1643     /**
1644     *
1645 youi 1.20 * ?≪?????潟?????宴??紊??眼????.
1646     *
1647 youi 1.1 *
1648 youi 1.20 * @param sid ?祉???激?с??D
1649     * @param account 紊??眼???????≪?????潟??????/span>
1650     * @return RES_OK
1651 youi 1.31 * @return RES_DB_NOT_INITIALIZED
1652 youi 1.20 * @return RES_NO_SUCH_SESSION
1653     * @return RES_DB_QUERY_ERROR
1654     * @return RES_NO_SUCH_USER
1655 youi 1.31 * @return RES_ERROR
1656 youi 1.1 *
1657     */
1658 youi 1.2 result_t updateAccount( sessionid_t sid, const account_t* account )
1659 youi 1.1 {
1660 youi 1.32 if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
1661 youi 1.20 if( account == NULL ) return RES_ERROR;
1662 youi 1.10 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
1663 youi 1.20 if( !uidExists( account -> getUID( ) ) ) return RES_NO_SUCH_USER;
1664 youi 1.39
1665 youi 1.32 SQLRETURN sqlcode;
1666     result_t ret = RES_ERROR;
1667 youi 1.39 SQLHANDLE hstmt = NULL;
1668 youi 1.10
1669     //xoops?????若?吟???若???????吾??莨若??
1670 youi 1.39 SQLCHAR uname[ACCOUNT_UNAME_LEN+1], name[ACCOUNT_NAME_LEN+1], email[ACCOUNT_EMAIL_LEN+1], url[ACCOUNT_URL_LEN+1], user_avatar[ACCOUNT_USER_AVATAR_LEN+1], user_icq[ACCOUNT_USER_ICQ_LEN+1], user_from[ACCOUNT_USER_FROM_LEN+1], user_sig[ACCOUNT_USER_SIG_LEN+1], actkey[ACCOUNT_ACTKEY_LEN+1], user_aim[ACCOUNT_USER_AIM_LEN+1], user_yim[ACCOUNT_USER_YIM_LEN+1], user_msnm[ACCOUNT_USER_MSNM_LEN+1], pass[ACCOUNT_PASS_LEN+1], theme[ACCOUNT_THEME_LEN+1], umode[ACCOUNT_UMODE_LEN+1], user_occ[ACCOUNT_USER_OCC_LEN+1], bio[ACCOUNT_BIO_LEN+1], user_intrest[ACCOUNT_USER_INTREST_LEN+1];
1671 youi 1.32 SQLINTEGER uid, user_regdate, user_viewemail, posts, attachsig, rank, level, last_login, uorder, notify_method, notify_mode, user_mailok;
1672     SQLDOUBLE timezone_offset;
1673    
1674 youi 1.56 SQLLEN cbUname = SQL_NTS, cbName = SQL_NTS, cbEmail = SQL_NTS, cbUrl = SQL_NTS, cbUser_avatar = SQL_NTS, cbUser_icq = SQL_NTS, cbUser_from = SQL_NTS, cbUser_sig = SQL_NTS, cbActkey = SQL_NTS, cbUser_aim = SQL_NTS, cbUser_yim = SQL_NTS, cbUser_msnm = SQL_NTS, cbPass = SQL_NTS, cbTheme = SQL_NTS, cbUmode = SQL_NTS, cbUser_occ = SQL_NTS, cbBio = SQL_NTS, cbUser_intrest = SQL_NTS;
1675     SQLLEN cbUid = 0, cbUser_regdate = 0, cbUser_viewemail = 0, cbPosts = 0, cbAttachsig = 0, cbRank = 0, cbLevel = 0, cbLast_login = 0, cbUorder = 0, cbNotify_method = 0, cbNotify_mode = 0, cbUser_mailok = 0, cbTimezone_offset = 0;
1676 youi 1.32
1677     SQLUINTEGER activate;
1678 aga 1.36 SQLCHAR address[XNP_ACCOUNT_ADDRESS_LEN+1];
1679     SQLCHAR division[XNP_ACCOUNT_DIVISION_LEN+1];
1680     SQLCHAR tel[XNP_ACCOUNT_TEL_LEN+1];
1681     SQLCHAR company_name[XNP_ACCOUNT_COMPANY_NAME_LEN+1];
1682     SQLCHAR country[XNP_ACCOUNT_COUNTRY_LEN+1];
1683     SQLCHAR zipcode[XNP_ACCOUNT_ZIPCODE_LEN+1];
1684     SQLCHAR fax[XNP_ACCOUNT_FAX_LEN+1];
1685 aga 1.61 SQLLEN cbActivate = 0, cbAddress = SQL_NTS, cbDivision = SQL_NTS, cbTel = SQL_NTS, cbCompany_name = SQL_NTS, cbCountry = SQL_NTS, cbZipcode = SQL_NTS, cbFax = SQL_NTS;
1686 youi 1.39 SQLUINTEGER notice_mail, notice_mail_since;
1687 youi 1.56 SQLLEN cbNotice_mail = 0, cbNotice_mail_since = 0;
1688 youi 1.32
1689     if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1690     string sql;
1691    
1692     sql = "UPDATE " + dbprefix + "_users SET ";
1693 youi 1.39 sql += "uname=?";
1694     sql += ", name=?";
1695     sql += ", email=?";
1696     sql += ", url=?";
1697     sql += ", user_avatar=?";
1698     sql += ", user_regdate=?";
1699     sql += ", user_icq=?";
1700     sql += ", user_from=?";
1701     sql += ", user_sig=?";
1702     sql += ", user_viewemail=?";
1703     sql += ", actkey=?";
1704     sql += ", user_aim=?";
1705     sql += ", user_yim=?";
1706     sql += ", user_msnm=?";
1707     sql += ", pass=?";
1708     sql += ", posts=?";
1709     sql += ", attachsig=?";
1710     sql += ", rank=?";
1711     sql += ", level=?";
1712     sql += ", theme=?";
1713     sql += ", timezone_offset=?";
1714     sql += ", last_login=?";
1715     sql += ", umode=?";
1716     sql += ", uorder=?";
1717     sql += ", notify_method=?";
1718     sql += ", notify_mode=?";
1719     sql += ", user_occ=?";
1720     sql += ", bio=?";
1721     sql += ", user_intrest=?";
1722     sql += ", user_mailok=? ";
1723 youi 1.32 sql += " WHERE uid = ?";
1724 youi 1.39
1725 youi 1.32 sqlcode = SQLPrepare(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS);
1726     if( sqlcode == SQL_SUCCESS || sqlcode == SQL_SUCCESS_WITH_INFO ){
1727     SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_UNAME_LEN, 0, uname, 0, &cbUname );
1728     SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_NAME_LEN, 0, name, 0, &cbName );
1729     SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_EMAIL_LEN, 0, email, 0, &cbEmail );
1730     SQLBindParameter(hstmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_URL_LEN, 0, url, 0, &cbUrl );
1731     SQLBindParameter(hstmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_AVATAR_LEN, 0, user_avatar, 0, &cbUser_avatar );
1732     SQLBindParameter(hstmt, 6, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &user_regdate, 0, &cbUser_regdate );
1733     SQLBindParameter(hstmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_ICQ_LEN, 0, user_icq, 0, &cbUser_icq );
1734     SQLBindParameter(hstmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_FROM_LEN, 0, user_from, 0, &cbUser_from );
1735     SQLBindParameter(hstmt, 9, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_SIG_LEN, 0, user_sig, 0, &cbUser_sig );
1736     SQLBindParameter(hstmt, 10, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &user_viewemail, 0, &cbUser_viewemail );
1737     SQLBindParameter(hstmt, 11, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_ACTKEY_LEN, 0, actkey, 0, &cbActkey );
1738     SQLBindParameter(hstmt, 12, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_AIM_LEN, 0, user_aim, 0, &cbUser_aim );
1739     SQLBindParameter(hstmt, 13, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_YIM_LEN, 0, user_yim, 0, &cbUser_yim );
1740     SQLBindParameter(hstmt, 14, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_MSNM_LEN, 0, user_msnm, 0, &cbUser_msnm );
1741     SQLBindParameter(hstmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_PASS_LEN, 0, pass, 0, &cbPass );
1742     SQLBindParameter(hstmt, 16, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &posts, 0, &cbPosts );
1743     SQLBindParameter(hstmt, 17, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &attachsig, 0, &cbAttachsig );
1744     SQLBindParameter(hstmt, 18, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &rank, 0, &cbRank );
1745     SQLBindParameter(hstmt, 19, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &level, 0, &cbLevel );
1746     SQLBindParameter(hstmt, 20, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_THEME_LEN, 0, theme, 0, &cbTheme );
1747     SQLBindParameter(hstmt, 21, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &timezone_offset, 0, &cbTimezone_offset );
1748     SQLBindParameter(hstmt, 22, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &last_login, 0, &cbLast_login );
1749     SQLBindParameter(hstmt, 23, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_UMODE_LEN, 0, umode, 0, &cbUmode );
1750     SQLBindParameter(hstmt, 24, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &uorder, 0, &cbUorder );
1751     SQLBindParameter(hstmt, 25, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &notify_method, 0, &cbNotify_method );
1752     SQLBindParameter(hstmt, 26, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &notify_mode, 0, &cbNotify_mode );
1753     SQLBindParameter(hstmt, 27, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_OCC_LEN, 0, user_occ, 0, &cbUser_occ );
1754     SQLBindParameter(hstmt, 28, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_BIO_LEN, 0, bio, 0, &cbBio );
1755     SQLBindParameter(hstmt, 29, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, ACCOUNT_USER_INTREST_LEN, 0, user_intrest, 0, &cbUser_intrest );
1756     SQLBindParameter(hstmt, 30, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &user_mailok, 0, &cbUser_mailok );
1757     SQLBindParameter(hstmt, 31, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &uid, 0, &cbUid );
1758 youi 1.39
1759 youi 1.32 strncpy2( (char*)uname, account -> getUname( ), ACCOUNT_UNAME_LEN );
1760     strncpy2( (char*)name, account -> getName( ), ACCOUNT_NAME_LEN );
1761     strncpy2( (char*)email, account -> getEmail( ), ACCOUNT_EMAIL_LEN );
1762     strncpy2( (char*)url, account -> getURL( ), ACCOUNT_URL_LEN );
1763     strncpy2( (char*)user_avatar, account -> getUserAvatar( ), ACCOUNT_USER_AVATAR_LEN );
1764     user_regdate = time( NULL );
1765     strncpy2( (char*)user_icq, account -> getUserIcq( ), ACCOUNT_USER_ICQ_LEN );
1766     strncpy2( (char*)user_from, account -> getUserFrom( ), ACCOUNT_USER_FROM_LEN );
1767     strncpy2( (char*)user_sig, account -> getUserSig( ), ACCOUNT_USER_SIG_LEN );
1768     user_viewemail = account -> getUserViewemail( );
1769     strncpy2( (char*)actkey, account -> getActkey( ), ACCOUNT_ACTKEY_LEN );
1770     strncpy2( (char*)user_aim, account -> getUserAim( ), ACCOUNT_USER_AIM_LEN );
1771     strncpy2( (char*)user_yim, account -> getUserYim( ), ACCOUNT_USER_YIM_LEN );
1772     strncpy2( (char*)user_msnm, account -> getUserMsnm( ), ACCOUNT_USER_MSNM_LEN );
1773     strncpy2( (char*)pass, account -> getPass( ), ACCOUNT_PASS_LEN );
1774     posts = account -> getPosts( );
1775     attachsig = account -> getAttachsig( );
1776     rank = account -> getRank( );
1777     level = account -> getLevel( );
1778     strncpy2( (char*)theme, account -> getTheme( ), ACCOUNT_THEME_LEN );
1779     timezone_offset = account -> getTimezoneOffset( );
1780     last_login = 0;
1781     strncpy2( (char*)umode, account -> getUmode( ), ACCOUNT_UMODE_LEN );
1782     uorder = account -> getUorder( );
1783     notify_method = account -> getNotifyMethod( );
1784     notify_mode = account -> getNotifyMode( );
1785     strncpy2( (char*)user_occ, account -> getUserOcc( ), ACCOUNT_USER_OCC_LEN );
1786     strncpy2( (char*)bio, account -> getBio( ), ACCOUNT_BIO_LEN );
1787     strncpy2( (char*)user_intrest, account -> getUserIntrest( ), ACCOUNT_USER_INTREST_LEN );
1788     user_mailok = account -> getUserMailok( );
1789     uid = account -> getUID( );
1790    
1791     if( ( sqlcode = SQLExecute( hstmt ) ) == SQL_SUCCESS ){
1792 youi 1.64 SQLLEN count = 0;
1793 youi 1.32 if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){
1794     ret = RES_OK;
1795     }else{
1796     string s( "SQLRowCount in updateAccount sql=" );
1797     s += string( sql );
1798     setLastErrorString( s.c_str( ) );
1799     ret = RES_DB_QUERY_ERROR;
1800     }
1801     }else{
1802 youi 1.39 string s( "SQLExecute in updateAccount 1 " );
1803 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1804 youi 1.32 setLastErrorString( s.c_str( ) );
1805     ret = RES_DB_QUERY_ERROR;
1806     }
1807     }else{
1808     setLastErrorString( "SQLPrepare in updateAccount sql=" );
1809     ret = RES_ERROR;
1810     }
1811     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
1812 youi 1.39 hstmt = NULL;
1813 youi 1.32 }else{
1814 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in updateAccount" );
1815     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1816     setLastErrorString( s.c_str( ) );
1817 youi 1.32 ret = RES_ERROR;
1818 youi 1.10 }
1819    
1820 youi 1.39 if( ret != RES_OK ){
1821     return ret;
1822     }
1823    
1824 aga 1.36 //xnpaccount?????若?吟???若??????????????宴??筝??吾??????
1825 youi 1.39 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1826 youi 1.32 string sql;
1827    
1828 aga 1.36 sql = "UPDATE " + dbprefix + "_xnpaccount_users SET ";
1829 youi 1.32 sql += "activate=?, ";
1830     sql += "address=?, ";
1831     sql += "division=?, ";
1832     sql += "tel=?, ";
1833     sql += "company_name=?, ";
1834     sql += "country=?, ";
1835     sql += "zipcode=?, ";
1836     sql += "fax=?, ";
1837     sql += "notice_mail=?, ";
1838     sql += "notice_mail_since=? ";
1839     sql += "WHERE uid=?";
1840    
1841     sqlcode = SQLPrepare(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS);
1842     if( sqlcode == SQL_SUCCESS || sqlcode == SQL_SUCCESS_WITH_INFO ){
1843 youi 1.39 SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SSHORT, SQL_INTEGER, 0, 0, &activate, 0, &cbActivate);
1844 aga 1.36 SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_ADDRESS_LEN, 0, address, 0, &cbAddress);
1845     SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_DIVISION_LEN, 0, division, 0, &cbDivision);
1846     SQLBindParameter(hstmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_TEL_LEN, 0, tel, 0, &cbTel);
1847     SQLBindParameter(hstmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_COMPANY_NAME_LEN, 0, company_name, 0, &cbCompany_name);
1848     SQLBindParameter(hstmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_COUNTRY_LEN, 0, country, 0, &cbCountry);
1849     SQLBindParameter(hstmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_ZIPCODE_LEN, 0, zipcode, 0, &cbZipcode);
1850     SQLBindParameter(hstmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ACCOUNT_FAX_LEN, 0, fax, 0, &cbFax);
1851 aga 1.61 SQLBindParameter(hstmt, 9, SQL_PARAM_INPUT, SQL_C_SSHORT, SQL_INTEGER, 0, 0, &notice_mail, 0, &cbNotice_mail);
1852     SQLBindParameter(hstmt, 10, SQL_PARAM_INPUT, SQL_C_SSHORT, SQL_INTEGER, 0, 0, &notice_mail_since, 0, &cbNotice_mail_since);
1853     SQLBindParameter(hstmt, 11, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &uid, 0, &cbUid );
1854 youi 1.32
1855     activate = account -> getActivate() ? 1 : 0;
1856 aga 1.36 strncpy2( (char*)address, account -> getAddress( ) , XNP_ACCOUNT_ADDRESS_LEN );
1857     strncpy2( (char*)division, account -> getDivision(), XNP_ACCOUNT_DIVISION_LEN );
1858     strncpy2( (char*)tel, account -> getTel(), XNP_ACCOUNT_TEL_LEN );
1859     strncpy2( (char*)company_name, account -> getCompanyName(), XNP_ACCOUNT_COMPANY_NAME_LEN );
1860     strncpy2( (char*)country, account -> getCountry(), XNP_ACCOUNT_COUNTRY_LEN );
1861     strncpy2( (char*)zipcode, account -> getZipcode(), XNP_ACCOUNT_ZIPCODE_LEN );
1862     strncpy2( (char*)fax, account -> getFax(), XNP_ACCOUNT_FAX_LEN );
1863 youi 1.32 notice_mail = account -> getNoticeMail( );
1864     notice_mail_since = account -> getNoticeMailSince( );
1865     uid = account -> getUID( );
1866    
1867     if( ( sqlcode = SQLExecute( hstmt ) ) == SQL_SUCCESS ){
1868 youi 1.64 SQLLEN count = 0;
1869 youi 1.32 if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){
1870     ret = RES_OK;
1871     }else{
1872     string s( "SQLRowCount in updateAccount sql=" );
1873     s += string( sql );
1874     setLastErrorString( s.c_str( ) );
1875     ret = RES_DB_QUERY_ERROR;
1876     }
1877     }else{
1878 youi 1.39 string s( "SQLExecute in updateAccount 2 " );
1879 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1880 youi 1.32 setLastErrorString( s.c_str( ) );
1881     ret = RES_DB_QUERY_ERROR;
1882     }
1883     }else{
1884     setLastErrorString( "SQLPrepare in updateAccount sql=" );
1885     ret = RES_ERROR;
1886     }
1887     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
1888     }else{
1889 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in updateAccount" );
1890     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1891     setLastErrorString( s.c_str( ) );
1892 youi 1.32 ret = RES_ERROR;
1893 youi 1.10 }
1894 youi 1.32 return ret;
1895 youi 1.1 }
1896    
1897     /**
1898     *
1899 youi 1.17 * criteria_t?ф??絎???????膀??蚊?????若??D??菴???.
1900     * ???若??D????????腆坂????????????吾??莨若?随????????≪?????鴻??*uids???吾??莨若??.
1901     * ???????泣?ゃ?冴??*uidsLen???吾??莨若??
1902 youi 1.1 *
1903 youi 1.17 * @param sid ?祉???激?с??D
1904     * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
1905 youi 1.31 * @param uids ???若?吟??ID?????????阪????
1906     * @param uidsLen uids???????膣??違???阪????
1907     * @return RES_OK
1908     * @return RES_DB_NOT_INITIALIZED
1909     * @return RES_NO_SUCH_SESSION
1910     * @return RES_DB_QUERY_ERROR
1911 youi 1.1 *
1912     */
1913 youi 1.13 result_t dumpUids( sessionid_t sid, criteria_t* cri, userid_t** uids, int* uidsLen )
1914 youi 1.1 {
1915 youi 1.32 if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
1916 youi 1.17 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
1917    
1918 youi 1.33 #ifdef USE_SYSLOG
1919     openlog( "commonal", LOG_ODELAY, LOG_USER );
1920     #endif
1921    
1922 youi 1.32 result_t ret = RES_ERROR;
1923     userid_t* dst = 0;
1924 youi 1.17 string sql;
1925 youi 1.32 SQLRETURN sqlcode;
1926 youi 1.64 SQLLEN count = 0;
1927 youi 1.32
1928    
1929 aga 1.36 sql = "SELECT uid FROM " + dbprefix + "_xnpaccount_users ";
1930 youi 1.17 sql += criteria2str( cri );
1931 youi 1.32 if( countResultRows( sql.c_str(), &count ) == RES_OK ){
1932     *uidsLen = count;
1933     dst = new userid_t[ *uidsLen ];
1934     *uids = dst;
1935     }else{
1936     return RES_ERROR;
1937     }
1938     if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1939     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
1940 youi 1.44 userid_t uid = 0;
1941 youi 1.56 SQLLEN len = 0;
1942 youi 1.32 SQLBindCol( hstmt, 1, SQL_C_ULONG, &uid, 0, &len );
1943    
1944     for( int i = 0; ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS && i < *uidsLen ; i++ ){
1945     dst[ i ] = uid;
1946     }
1947    
1948 youi 1.33 #ifdef USE_SYSLOG
1949     syslog( LOG_DEBUG, "dumpUids succeed" );
1950     #endif
1951 youi 1.32 ret = RES_OK;
1952     }else{
1953     string s( "SQLExecDirect in dumpUids " );
1954 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1955 youi 1.32 s += "sql=";
1956     s += string( sql );
1957     setLastErrorString( s.c_str( ) );
1958 youi 1.33 #ifdef USE_SYSLOG
1959     syslog( LOG_DEBUG, "dumpUids %s", getLastErrorString( ) );
1960     #endif
1961 youi 1.32 ret = RES_DB_QUERY_ERROR;
1962     }
1963     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
1964     }else{
1965 youi 1.33 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in dumpUids" );
1966     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1967     setLastErrorString( s.c_str( ) );
1968     #ifdef USE_SYSLOG
1969     syslog( LOG_DEBUG, "dumpUids %s", getLastErrorString( ) );
1970     #endif
1971 youi 1.44 ret = RES_ERROR;
1972 youi 1.17 }
1973 youi 1.32 return ret;
1974 youi 1.1 }
1975    
1976     /**
1977     *
1978 youi 1.19 * ?違???若???違??菴???.
1979     * 筝?罩c???祉???激?с??D????0??菴???.
1980 youi 1.1 *
1981 youi 1.19 * @param sid ?祉???激?с??D
1982     * @return ?違???若????/span>
1983 youi 1.1 *
1984     */
1985 youi 1.2 int getGroupCount( sessionid_t sid )
1986 youi 1.1 {
1987 youi 1.32 if( hdbc == NULL ) return 0;
1988 youi 1.19 if( !isValidSessionID( sid ) ) return 0;
1989    
1990 youi 1.32 SQLRETURN sqlcode;
1991     SQLHANDLE hstmt = NULL;
1992 youi 1.19 string sql;
1993 youi 1.32 int ret = 0;
1994 youi 1.19
1995     //?違???若???違??羆?????
1996 aga 1.36 sql = "SELECT COUNT(*) FROM " + dbprefix + "_xnpaccount_groups";
1997 youi 1.32 if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1998     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
1999     SQLUINTEGER count = 0;
2000 youi 1.56 SQLLEN len = 0;
2001 youi 1.32 SQLBindCol( hstmt, 1, SQL_C_ULONG, &count, 0, &len );
2002     if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){
2003     ret = count;
2004     }else {
2005     string s( "SQLFetch in getGroupCount sql=" );
2006     s += string( sql );
2007     setLastErrorString( s.c_str( ) );
2008     ret = 0;
2009     }
2010     }else{
2011     setLastErrorString( "SQLExecDirect in getGroupCount" );
2012     ret = 0;
2013     }
2014     SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
2015     }else{
2016 youi 1.55 string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getGroupCount" );
2017     s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
2018     setLastErrorString( s.c_str( ) );
2019 youi 1.32 ret = 0;
2020 youi 1.19 }
2021 youi 1.32 return ret;
2022 youi 1.1 }
2023    
2024     /**
2025     *
2026 youi 1.31 * ??絮??違???若??筝?荀у??.
2027     * ???若?吟????絮??????????違???若????D????緇?????
2028 youi 1.1 *
2029 youi 1.31 * @param sid ?祉???激?с??D
2030     * @param uid ???若?吟??ID
2031     * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
2032     * @param gids ?違???若??ID?????????阪????
2033     * @param gidsLen gids???????膣??違???阪????
2034     * @return RES_DB_NOT_INITIALIZED
2035     * @return RES_NO_SUCH_SESSION
2036     * @return RES_NO_SUCH_USER
2037     * @return RES_DB_QUERY_ERROR
2038     * @return RES_OK
2039 youi 1.1 *
2040     */
2041 youi 1.13 result_t getGroupsByUid( sessionid_t sid, userid_t uid, criteria_t* cri, groupid_t** gids, int* gidsLen )
2042 youi 1.1 {
2043 youi 1.32 if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
2044 youi 1.19 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
2045     if( !uidExists( uid ) ) return RES_NO_SUCH_USER; //uid??????????с????/span>
2046    
2047 youi 1.32 result_t ret = RES_ERROR;
2048 youi 1.19 string sql;
2049 youi 1.32 SQLRETURN sqlcode;
2050     SQLHANDLE hstmt = NULL;
2051 youi 1.64 SQLLEN count = 0;
2052 youi 1.19 groupid_t* dst = 0;
2053    
2054 aga 1.36 sql = "SELECT gid FROM " + dbprefix + "_xnpaccount_groups_users_link";
2055 youi 1.19 sql += " WHERE uid=" + string( unsignedIntToString( uid ) );
2056     sql += criteria2str( cri );
2057 youi 1.32 if( countResultRows( sql.c_str(), &count ) == RES_OK ){
2058     *gidsLen = count;
2059     dst = new groupid_t[ *gidsLen ];
2060     *gids = dst;
2061     }else{
2062     return RES_ERROR;
2063 youi 1.19 }
2064    
2065 youi 1.32 //??絮??????違???若??????紊у???違??羆?????
2066     if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
2067     if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
2068     if( count > 0 ){
2069     SQLHANDLE hstmt2 = NULL;
2070     if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt2 ) ) == SQL_SUCCESS ) {
2071 aga 1.36 sql = "SELECT gid, uid, is_admin FROM " + dbprefix + "_xnpaccount_groups_users_link";
2072 youi 1.32 sql += " WHERE uid=" + string( unsignedIntToString( uid ) );
2073     sql += criteria2str( cri );
2074     if( ( sqlcode = SQLExecDirect( hstmt2, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
2075 youi 1.56 SQLLEN len = 0;
2076 youi 1.32 groupid_t gid = 0;
2077     SQLBindCol( hstmt, 1, SQL_C_ULONG, &gid, 0, &len );
2078     for( int i = 0; ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS && i < *gidsLen ; i++ ){
2079     dst[ i ] = gid;
2080     }
2081     ret = RES_OK;
2082     }else{
2083     string s( "SQLExecDirect in getGroupsByUid " );
2084 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2085 youi 1.32 s += string( ", sql=" ) + string( sql );
2086 youi 1.55 setLastErrorString( s.c_str( ) );
2087 youi 1.32 ret = RES_DB_QUERY_ERROR;
2088     }
2089     }else{
2090     string s( "SQLAllocHandle in getGroupsByUid " );
2091 youi 1.35 s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
2092 youi 1.55 setLastErrorString( s.c_str( ) );
2093 youi 1.44 ret = RES_ERROR;
2094 youi 1.32 }
2095     }else{
2096     ret = RES_OK;
2097     }
2098     }else{
2099     string s( "SQLExecDirect in getGroupsByUid " );
2100 youi 1.33 s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2101 youi 1.32 s += string( ", sql=" ) + string( sql );
2102 youi 1.55 setLastErrorString( s.c_str( ) );
2103 youi 1.32 ret = RES_DB_QUERY_ERROR;
2104     }
2105     }else{
2106     string s( "SQLAllocHandle in getGroupsByUid " );
2107 youi 1.55 s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
2108 youi 1.32 setLastErrorString( s.c_str( ) );
2109 youi 1.44 ret = RES_ERROR;
2110 youi 1.19 }
2111 youi 1.32 return ret;
2112 youi 1.1 }
2113    
2114     /**
2115     *
2116 youi 1.31 * ?違???若??膊∞??罔????????.
2117     * ???若?吟?????若???????罔???????????(?違???若??膊∞?????с??????)????????????.
2118     * ???若?吟???違???若????絖????????????????医幻???翫??鐚?false??菴???.
2119 youi 1.1 *
2120 youi 1.31 * @param sid ?祉???激?с??D
2121     * @param gid ?違???若????ID
2122     * @param uid ???若?吟??ID
2123     * @return true 膊∞??罔???????
2124     * @return false 膊∞??罔???????鐚??障???????/span>
2125 youi 1.1 *
2126     */
2127 youi 1.2 bool isGroupAdmin( sessionid_t sid, groupid_t gid, userid_t uid )
2128 youi 1.1 {
2129 youi 1.32 if( hdbc == NULL ) return false;
2130 youi 1.19 if( !isValidSessionID( sid ) ) return false;
2131     if( !uidExists( uid ) ) return false;
2132     if( !gidExists( gid ) ) return false;
2133    
2134 youi 1.32 bool ret = false;
2135 youi 1.19 string sql;
2136 youi 1.64 SQLLEN count = 0;
2137 youi 1.19
2138 aga 1.36 sql = "SELECT * FROM " + dbprefix + "_xnpaccount_groups_users_link ";
2139 youi 1.19 sql += "WHERE gid=" + string( unsignedIntToString( gid ) );
2140     sql += " AND uid=" + string( unsignedIntToString( uid ) );
2141     sql += " AND is_admin=1";
2142 youi 1.32 if( countResultRows( sql.c_str(), &count ) == RES_OK ){
2143     if( count > 0 ){
2144     ret = true;
2145     }else{
2146     ret = false;
2147     }
2148     }else{
2149     ret = false;
2150 youi 1.19 }
2151 youi 1.32 return ret;
2152 youi 1.1 }
2153    
2154     /**
2155     *
2156 youi 1.31 * ?違???若??ID筝?荀?
2157     * ?脂?蚊???????????違???若????D筝?荀с????緇?????.
2158 youi 1.1 *
2159 youi 1.31 * @param sid ?祉???激?с??D
2160     * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
2161     * @param gids ?違???若??ID?????????阪????
2162     * @param gidsLen gids???????膣??違???阪????
2163     * @return RES_DB_NOT_INITIALIZED
2164     * @return RES_NO_SUCH_SESSION
2165     * @return RES_DB_QUERY_ERROR
2166     * @return RES_OK
2167 youi 1.1 *
2168     */
2169 youi 1.13 result_t dumpGids( sessionid_t sid, criteria_t* cri, groupid_t** gids, int* gidsLen )
2170 youi 1.1 {
2171 youi 1.32 if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
2172 youi 1.16 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
2173    
2174 youi 1.32 result_t ret = RES_ERROR;
2175     groupid_t* dst = 0;
2176 youi 1.16 string sql;
2177 youi 1.32 SQLRETURN sqlcode;
2178 youi 1.64 SQLLEN count = 0;
2179 youi 1.32
2180 aga 1.36 sql = "SELECT gid FROM " + dbprefix + "_xnpaccount_groups ";
2181 youi 1.19 sql += criteria2str( cri );
2182 youi 1.32 if( countResultRows( sql.c_str(), &count ) == RES_OK ){
2183     *gidsLen = count;
2184 youi 1.16 dst = new groupid_t[ *gidsLen ];
2185 youi 1.32 *gids = dst;
2186 youi 1.16 }else{
2187     return RES_ERROR;
2188     }
2189    
2190 youi 1.32