root/trunk/tmonth.c

Revision 166, 12.6 KB (checked in by Dylan, 3 years ago)

unxsVZ and unxsBind propset for Id set. Added unxsVZ.tDatacenter backend test reports for in progress datacenter health and
UBC consistency checking.

  • Property svn:keywords set to id
Line 
1/*
2FILE
3        tMonth source code of unxsVZ.cgi
4        Built by mysqlRAD2.cgi (C) Gary Wallis 2001-2007
5        $Id$
6PURPOSE
7        Schema dependent RAD generated file.
8        Program app functionality in tmonthfunc.h while
9        RAD is still to be used.
10*/
11
12
13#include "mysqlrad.h"
14
15//Table Variables
16//Table Variables
17//uMonth: Primary Key
18static unsigned uMonth=0;
19//cLabel: Name of Archive Table Ex. tNov2009
20static char cLabel[33]={""};
21//uOwner: Record owner
22static unsigned uOwner=0;
23//uCreatedBy: uClient for last insert
24static unsigned uCreatedBy=0;
25#define ISM3FIELDS
26//uCreatedDate: Unix seconds date last insert
27static time_t uCreatedDate=0;
28//uModBy: uClient for last update
29static unsigned uModBy=0;
30//uModDate: Unix seconds date last update
31static time_t uModDate=0;
32
33
34
35#define VAR_LIST_tMonth "tMonth.uMonth,tMonth.cLabel,tMonth.uOwner,tMonth.uCreatedBy,tMonth.uCreatedDate,tMonth.uModBy,tMonth.uModDate"
36
37 //Local only
38void Insert_tMonth(void);
39void Update_tMonth(char *cRowid);
40void ProcesstMonthListVars(pentry entries[], int x);
41
42 //In tMonthfunc.h file included below
43void ExtProcesstMonthVars(pentry entries[], int x);
44void ExttMonthCommands(pentry entries[], int x);
45void ExttMonthButtons(void);
46void ExttMonthNavBar(void);
47void ExttMonthGetHook(entry gentries[], int x);
48void ExttMonthSelect(void);
49void ExttMonthSelectRow(void);
50void ExttMonthListSelect(void);
51void ExttMonthListFilter(void);
52void ExttMonthAuxTable(void);
53
54#include "tmonthfunc.h"
55
56 //Table Variables Assignment Function
57void ProcesstMonthVars(pentry entries[], int x)
58{
59        register int i;
60
61
62        for(i=0;i<x;i++)
63        {
64                if(!strcmp(entries[i].name,"uMonth"))
65                        sscanf(entries[i].val,"%u",&uMonth);
66                else if(!strcmp(entries[i].name,"cLabel"))
67                        sprintf(cLabel,"%.32s",entries[i].val);
68                else if(!strcmp(entries[i].name,"uOwner"))
69                        sscanf(entries[i].val,"%u",&uOwner);
70                else if(!strcmp(entries[i].name,"uCreatedBy"))
71                        sscanf(entries[i].val,"%u",&uCreatedBy);
72                else if(!strcmp(entries[i].name,"uCreatedDate"))
73                        sscanf(entries[i].val,"%lu",&uCreatedDate);
74                else if(!strcmp(entries[i].name,"uModBy"))
75                        sscanf(entries[i].val,"%u",&uModBy);
76                else if(!strcmp(entries[i].name,"uModDate"))
77                        sscanf(entries[i].val,"%lu",&uModDate);
78
79        }
80
81        //After so we can overwrite form data if needed.
82        ExtProcesstMonthVars(entries,x);
83
84}//ProcesstMonthVars()
85
86
87void ProcesstMonthListVars(pentry entries[], int x)
88{
89        register int i;
90
91        for(i=0;i<x;i++)
92        {
93                if(!strncmp(entries[i].name,"ED",2))
94                {
95                        sscanf(entries[i].name+2,"%u",&uMonth);
96                        guMode=2002;
97                        tMonth("");
98                }
99        }
100}//void ProcesstMonthListVars(pentry entries[], int x)
101
102
103int tMonthCommands(pentry entries[], int x)
104{
105        ProcessControlVars(entries,x);
106
107        ExttMonthCommands(entries,x);
108
109        if(!strcmp(gcFunction,"tMonthTools"))
110        {
111                if(!strcmp(gcFind,LANG_NB_LIST))
112                {
113                        tMonthList();
114                }
115
116                //Default
117                ProcesstMonthVars(entries,x);
118                tMonth("");
119        }
120        else if(!strcmp(gcFunction,"tMonthList"))
121        {
122                ProcessControlVars(entries,x);
123                ProcesstMonthListVars(entries,x);
124                tMonthList();
125        }
126
127        return(0);
128
129}//tMonthCommands()
130
131
132void tMonth(const char *cResult)
133{
134        MYSQL_RES *res;
135        MYSQL_RES *res2;
136        MYSQL_ROW field;
137
138        //Internal skip reloading
139        if(!cResult[0])
140        {
141                if(guMode)
142                        ExttMonthSelectRow();
143                else
144                        ExttMonthSelect();
145
146                mysql_query(&gMysql,gcQuery);
147                if(mysql_errno(&gMysql))
148                {
149                        if(strstr(mysql_error(&gMysql)," doesn't exist"))
150                        {
151                                CreatetMonth();
152                                unxsVZ("New tMonth table created");
153                        }
154                        else
155                        {
156                                htmlPlainTextError(mysql_error(&gMysql));
157                        }
158                }
159
160                res=mysql_store_result(&gMysql);
161                if((guI=mysql_num_rows(res)))
162                {
163                        if(guMode==6)
164                        {
165                        sprintf(gcQuery,"SELECT _rowid FROM tMonth WHERE uMonth=%u"
166                                                ,uMonth);
167                                MYSQL_RUN_STORE(res2);
168                                field=mysql_fetch_row(res2);
169                                sscanf(field[0],"%lu",&gluRowid);
170                                gluRowid++;
171                        }
172                        PageMachine("",0,"");
173                        if(!guMode) mysql_data_seek(res,gluRowid-1);
174                        field=mysql_fetch_row(res);
175                sscanf(field[0],"%u",&uMonth);
176                sprintf(cLabel,"%.32s",field[1]);
177                sscanf(field[2],"%u",&uOwner);
178                sscanf(field[3],"%u",&uCreatedBy);
179                sscanf(field[4],"%lu",&uCreatedDate);
180                sscanf(field[5],"%u",&uModBy);
181                sscanf(field[6],"%lu",&uModDate);
182
183                }
184
185        }//Internal Skip
186
187        Header_ism3(":: tMonth",0);
188        printf("<table width=100%% cellspacing=0 cellpadding=0>\n");
189        printf("<tr><td colspan=2 align=right valign=center>");
190
191
192        printf("<input type=hidden name=gcFunction value=tMonthTools>");
193        printf("<input type=hidden name=gluRowid value=%lu>",gluRowid);
194        if(guI)
195        {
196                if(guMode==6)
197                        //printf(" Found");
198                        printf(LANG_NBR_FOUND);
199                else if(guMode==5)
200                        //printf(" Modified");
201                        printf(LANG_NBR_MODIFIED);
202                else if(guMode==4)
203                        //printf(" New");
204                        printf(LANG_NBR_NEW);
205                printf(LANG_NBRF_SHOWING,gluRowid,guI);
206        }
207        else
208        {
209                if(!cResult[0])
210                //printf(" No records found");
211                printf(LANG_NBR_NORECS);
212        }
213        if(cResult[0]) printf("%s",cResult);
214        printf("</td></tr>");
215        printf("<tr><td valign=top width=25%%>");
216
217        ExttMonthButtons();
218
219        printf("</td><td valign=top>");
220        //
221        OpenFieldSet("tMonth Record Data",100);
222
223        if(guMode==2000 || guMode==2002)
224                tMonthInput(1);
225        else
226                tMonthInput(0);
227
228        //
229        CloseFieldSet();
230
231        //Bottom table
232        printf("<tr><td colspan=2>");
233        ExttMonthAuxTable();
234
235        Footer_ism3();
236
237}//end of tMonth();
238
239
240void tMonthInput(unsigned uMode)
241{
242
243//uMonth
244        OpenRow(LANG_FL_tMonth_uMonth,"black");
245        printf("<input title='%s' type=text name=uMonth value=%u size=16 maxlength=10 "
246,LANG_FT_tMonth_uMonth,uMonth);
247        if(guPermLevel>=20 && uMode)
248        {
249                printf("></td></tr>\n");
250        }
251        else
252        {
253                printf("disabled></td></tr>\n");
254                printf("<input type=hidden name=uMonth value=%u >\n",uMonth);
255        }
256//cLabel
257        OpenRow(LANG_FL_tMonth_cLabel,"black");
258        printf("<input title='%s' type=text name=cLabel value=\"%s\" size=40 maxlength=32 "
259,LANG_FT_tMonth_cLabel,EncodeDoubleQuotes(cLabel));
260        if(guPermLevel>=0 && uMode)
261        {
262                printf("></td></tr>\n");
263        }
264        else
265        {
266                printf("disabled></td></tr>\n");
267                printf("<input type=hidden name=cLabel value=\"%s\">\n",EncodeDoubleQuotes(cLabel));
268        }
269//uOwner
270        OpenRow(LANG_FL_tMonth_uOwner,"black");
271        if(guPermLevel>=20 && uMode)
272        {
273        printf("%s<input type=hidden name=uOwner value=%u >\n",ForeignKey("tClient","cLabel",uOwner),uOwner);
274        }
275        else
276        {
277        printf("%s<input type=hidden name=uOwner value=%u >\n",ForeignKey("tClient","cLabel",uOwner),uOwner);
278        }
279//uCreatedBy
280        OpenRow(LANG_FL_tMonth_uCreatedBy,"black");
281        if(guPermLevel>=20 && uMode)
282        {
283        printf("%s<input type=hidden name=uCreatedBy value=%u >\n",ForeignKey("tClient","cLabel",uCreatedBy),uCreatedBy);
284        }
285        else
286        {
287        printf("%s<input type=hidden name=uCreatedBy value=%u >\n",ForeignKey("tClient","cLabel",uCreatedBy),uCreatedBy);
288        }
289//uCreatedDate
290        OpenRow(LANG_FL_tMonth_uCreatedDate,"black");
291        if(uCreatedDate)
292                printf("%s\n\n",ctime(&uCreatedDate));
293        else
294                printf("---\n\n");
295        printf("<input type=hidden name=uCreatedDate value=%lu >\n",uCreatedDate);
296//uModBy
297        OpenRow(LANG_FL_tMonth_uModBy,"black");
298        if(guPermLevel>=20 && uMode)
299        {
300        printf("%s<input type=hidden name=uModBy value=%u >\n",ForeignKey("tClient","cLabel",uModBy),uModBy);
301        }
302        else
303        {
304        printf("%s<input type=hidden name=uModBy value=%u >\n",ForeignKey("tClient","cLabel",uModBy),uModBy);
305        }
306//uModDate
307        OpenRow(LANG_FL_tMonth_uModDate,"black");
308        if(uModDate)
309                printf("%s\n\n",ctime(&uModDate));
310        else
311                printf("---\n\n");
312        printf("<input type=hidden name=uModDate value=%lu >\n",uModDate);
313        printf("</tr>\n");
314
315
316
317}//void tMonthInput(unsigned uMode)
318
319
320void NewtMonth(unsigned uMode)
321{
322        register int i=0;
323        MYSQL_RES *res;
324
325        sprintf(gcQuery,"SELECT uMonth FROM tMonth\
326                                WHERE uMonth=%u"
327                                                        ,uMonth);
328        MYSQL_RUN_STORE(res);
329        i=mysql_num_rows(res);
330
331        if(i)
332                //tMonth("<blink>Record already exists");
333                tMonth(LANG_NBR_RECEXISTS);
334
335        //insert query
336        Insert_tMonth();
337        if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql));
338        //sprintf(gcQuery,"New record %u added");
339        uMonth=mysql_insert_id(&gMysql);
340#ifdef ISM3FIELDS
341        uCreatedDate=luGetCreatedDate("tMonth",uMonth);
342        unxsVZLog(uMonth,"tMonth","New");
343#endif
344
345        if(!uMode)
346        {
347        sprintf(gcQuery,LANG_NBR_NEWRECADDED,uMonth);
348        tMonth(gcQuery);
349        }
350
351}//NewtMonth(unsigned uMode)
352
353
354void DeletetMonth(void)
355{
356#ifdef ISM3FIELDS
357        sprintf(gcQuery,"DELETE FROM tMonth WHERE uMonth=%u AND ( uOwner=%u OR %u>9 )"
358                                        ,uMonth,guLoginClient,guPermLevel);
359#else
360        sprintf(gcQuery,"DELETE FROM tMonth WHERE uMonth=%u"
361                                        ,uMonth);
362#endif
363        MYSQL_RUN;
364        //tMonth("Record Deleted");
365        if(mysql_affected_rows(&gMysql)>0)
366        {
367#ifdef ISM3FIELDS
368                unxsVZLog(uMonth,"tMonth","Del");
369#endif
370                tMonth(LANG_NBR_RECDELETED);
371        }
372        else
373        {
374#ifdef ISM3FIELDS
375                unxsVZLog(uMonth,"tMonth","DelError");
376#endif
377                tMonth(LANG_NBR_RECNOTDELETED);
378        }
379
380}//void DeletetMonth(void)
381
382
383void Insert_tMonth(void)
384{
385
386        //insert query
387        sprintf(gcQuery,"INSERT INTO tMonth SET uMonth=%u,cLabel='%s',uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())",
388                        uMonth
389                        ,TextAreaSave(cLabel)
390                        ,uOwner
391                        ,uCreatedBy
392                        );
393
394        MYSQL_RUN;
395
396}//void Insert_tMonth(void)
397
398
399void Update_tMonth(char *cRowid)
400{
401
402        //update query
403        sprintf(gcQuery,"UPDATE tMonth SET uMonth=%u,cLabel='%s',uModBy=%u,uModDate=UNIX_TIMESTAMP(NOW()) WHERE _rowid=%s",
404                        uMonth
405                        ,TextAreaSave(cLabel)
406                        ,uModBy
407                        ,cRowid);
408
409        MYSQL_RUN;
410
411}//void Update_tMonth(void)
412
413
414void ModtMonth(void)
415{
416        register int i=0;
417        MYSQL_RES *res;
418        MYSQL_ROW field;
419#ifdef ISM3FIELDS
420        unsigned uPreModDate=0;
421
422        //Mod select gcQuery
423        if(guPermLevel<10)
424        sprintf(gcQuery,"SELECT tMonth.uMonth,\
425                                tMonth.uModDate\
426                                FROM tMonth,tClient\
427                                WHERE tMonth.uMonth=%u\
428                                AND tMonth.uOwner=tClient.uClient\
429                                AND (tClient.uOwner=%u OR tClient.uClient=%u)"
430                        ,uMonth,guLoginClient,guLoginClient);
431        else
432        sprintf(gcQuery,"SELECT uMonth,uModDate FROM tMonth\
433                                WHERE uMonth=%u"
434                                                ,uMonth);
435#else
436        sprintf(gcQuery,"SELECT uMonth FROM tMonth\
437                                WHERE uMonth=%u"
438                                                ,uMonth);
439#endif
440
441        MYSQL_RUN_STORE(res);
442        i=mysql_num_rows(res);
443
444        //if(i<1) tMonth("<blink>Record does not exist");
445        if(i<1) tMonth(LANG_NBR_RECNOTEXIST);
446        //if(i>1) tMonth("<blink>Multiple rows!");
447        if(i>1) tMonth(LANG_NBR_MULTRECS);
448
449        field=mysql_fetch_row(res);
450#ifdef ISM3FIELDS
451        sscanf(field[1],"%u",&uPreModDate);
452        if(uPreModDate!=uModDate) tMonth(LANG_NBR_EXTMOD);
453#endif
454
455        Update_tMonth(field[0]);
456        if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql));
457        //sprintf(query,"record %s modified",field[0]);
458        sprintf(gcQuery,LANG_NBRF_REC_MODIFIED,field[0]);
459#ifdef ISM3FIELDS
460        uModDate=luGetModDate("tMonth",uMonth);
461        unxsVZLog(uMonth,"tMonth","Mod");
462#endif
463        tMonth(gcQuery);
464
465}//ModtMonth(void)
466
467
468void tMonthList(void)
469{
470        MYSQL_RES *res;
471        MYSQL_ROW field;
472
473        ExttMonthListSelect();
474
475        MYSQL_RUN_STORE(res);
476        guI=mysql_num_rows(res);
477
478        PageMachine("tMonthList",1,"");//1 is auto header list guMode. Opens table!
479
480        //Filter select drop down
481        ExttMonthListFilter();
482
483        printf("<input type=text size=16 name=gcCommand maxlength=98 value=\"%s\" >",gcCommand);
484
485        printf("</table>\n");
486
487        printf("<table bgcolor=#9BC1B3 border=0 width=100%%>\n");
488        printf("<tr bgcolor=black><td><font face=arial,helvetica color=white>uMonth<td><font face=arial,helvetica color=white>cLabel<td><font face=arial,helvetica color=white>uOwner<td><font face=arial,helvetica color=white>uCreatedBy<td><font face=arial,helvetica color=white>uCreatedDate<td><font face=arial,helvetica color=white>uModBy<td><font face=arial,helvetica color=white>uModDate</tr>");
489
490
491
492        mysql_data_seek(res,guStart-1);
493
494        for(guN=0;guN<(guEnd-guStart+1);guN++)
495        {
496                field=mysql_fetch_row(res);
497                if(!field)
498                {
499                        printf("<tr><td><font face=arial,helvetica>End of data</table>");
500                        Footer_ism3();
501                }
502                        if(guN % 2)
503                                printf("<tr bgcolor=#BBE1D3>");
504                        else
505                                printf("<tr>");
506                time_t luTime4=strtoul(field[4],NULL,10);
507                char cBuf4[32];
508                if(luTime4)
509                        ctime_r(&luTime4,cBuf4);
510                else
511                        sprintf(cBuf4,"---");
512                time_t luTime6=strtoul(field[6],NULL,10);
513                char cBuf6[32];
514                if(luTime6)
515                        ctime_r(&luTime6,cBuf6);
516                else
517                        sprintf(cBuf6,"---");
518                printf("<td><input type=submit name=ED%s value=Edit> %s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s</tr>"
519                        ,field[0]
520                        ,field[0]
521                        ,field[1]
522                        ,ForeignKey("tClient","cLabel",strtoul(field[2],NULL,10))
523                        ,ForeignKey("tClient","cLabel",strtoul(field[3],NULL,10))
524                        ,cBuf4
525                        ,ForeignKey("tClient","cLabel",strtoul(field[5],NULL,10))
526                        ,cBuf6
527                                );
528
529        }
530
531        printf("</table></form>\n");
532        Footer_ism3();
533
534}//tMonthList()
535
536
537void CreatetMonth(void)
538{
539        sprintf(gcQuery,"CREATE TABLE IF NOT EXISTS tMonth ( uMonth INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, cLabel VARCHAR(32) NOT NULL DEFAULT '', UNIQUE (cLabel), uOwner INT UNSIGNED NOT NULL DEFAULT 0,index (uOwner), uCreatedBy INT UNSIGNED NOT NULL DEFAULT 0, uCreatedDate INT UNSIGNED NOT NULL DEFAULT 0, uModBy INT UNSIGNED NOT NULL DEFAULT 0, uModDate INT UNSIGNED NOT NULL DEFAULT 0 )");
540        MYSQL_RUN;
541
542}//CreatetMonth()
543
Note: See TracBrowser for help on using the browser.