root/trunk/tgroup.c

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