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.85 - (hide annotations) (download) (as text)
Mon Mar 14 09:30:50 2005 UTC (19 years, 1 month ago) by aga4096
Branch: MAIN
Changes since 1.84: +11 -5 lines
File MIME type: text/x-c++src
・getItemCountByIndexで、作成者・グループ管理者は未承認アイテムをカウントするよう修正.

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