root/trunk/tgroupglue.c

Revision 1919, 10.6 KB (checked in by Dylan, 4 weeks ago)

unxsVZ adding search set for tIP.

  • Property svn:keywords set to id
Line 
1/*
2FILE
3        tGroupGlue 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 tgroupgluefunc.h while
9        RAD is still to be used.
10*/
11
12
13#include "mysqlrad.h"
14
15//Table Variables
16//Table Variables
17//uGroupGlue: Primary Key
18static unsigned uGroupGlue=0;
19//uGroup: Glue into tGroup
20static unsigned uGroup=0;
21static char cuGroupPullDown[256]={""};
22//uNode: Glue into tNode
23static unsigned uNode=0;
24static char cuNodePullDown[256]={""};
25//uContainer: Glue into tContainer
26static unsigned uContainer=0;
27static char cuContainerPullDown[256]={""};
28
29
30
31#define VAR_LIST_tGroupGlue "tGroupGlue.uGroupGlue,tGroupGlue.uGroup,tGroupGlue.uNode,tGroupGlue.uContainer"
32
33 //Local only
34void Insert_tGroupGlue(void);
35void Update_tGroupGlue(char *cRowid);
36void ProcesstGroupGlueListVars(pentry entries[], int x);
37
38 //In tGroupGluefunc.h file included below
39void ExtProcesstGroupGlueVars(pentry entries[], int x);
40void ExttGroupGlueCommands(pentry entries[], int x);
41void ExttGroupGlueButtons(void);
42void ExttGroupGlueNavBar(void);
43void ExttGroupGlueGetHook(entry gentries[], int x);
44void ExttGroupGlueSelect(void);
45void ExttGroupGlueSelectRow(void);
46void ExttGroupGlueListSelect(void);
47void ExttGroupGlueListFilter(void);
48void ExttGroupGlueAuxTable(void);
49
50#include "tgroupgluefunc.h"
51
52 //Table Variables Assignment Function
53void ProcesstGroupGlueVars(pentry entries[], int x)
54{
55        register int i;
56
57
58        for(i=0;i<x;i++)
59        {
60                if(!strcmp(entries[i].name,"uGroupGlue"))
61                        sscanf(entries[i].val,"%u",&uGroupGlue);
62                else if(!strcmp(entries[i].name,"uGroup"))
63                        sscanf(entries[i].val,"%u",&uGroup);
64                else if(!strcmp(entries[i].name,"cuGroupPullDown"))
65                {
66                        sprintf(cuGroupPullDown,"%.255s",entries[i].val);
67                        uGroup=ReadPullDown("tGroup","cLabel",cuGroupPullDown);
68                }
69                else if(!strcmp(entries[i].name,"uNode"))
70                        sscanf(entries[i].val,"%u",&uNode);
71                else if(!strcmp(entries[i].name,"cuNodePullDown"))
72                {
73                        sprintf(cuNodePullDown,"%.255s",entries[i].val);
74                        uNode=ReadPullDown("tNode","cLabel",cuNodePullDown);
75                }
76                else if(!strcmp(entries[i].name,"uContainer"))
77                        sscanf(entries[i].val,"%u",&uContainer);
78                else if(!strcmp(entries[i].name,"cuContainerPullDown"))
79                {
80                        sprintf(cuContainerPullDown,"%.255s",entries[i].val);
81                        uContainer=ReadPullDown("tContainer","cLabel",cuContainerPullDown);
82                }
83
84        }
85
86        //After so we can overwrite form data if needed.
87        ExtProcesstGroupGlueVars(entries,x);
88
89}//ProcesstGroupGlueVars()
90
91
92void ProcesstGroupGlueListVars(pentry entries[], int x)
93{
94        register int i;
95
96        for(i=0;i<x;i++)
97        {
98                if(!strncmp(entries[i].name,"ED",2))
99                {
100                        sscanf(entries[i].name+2,"%u",&uGroupGlue);
101                        guMode=2002;
102                        tGroupGlue("");
103                }
104        }
105}//void ProcesstGroupGlueListVars(pentry entries[], int x)
106
107
108int tGroupGlueCommands(pentry entries[], int x)
109{
110        ProcessControlVars(entries,x);
111
112        ExttGroupGlueCommands(entries,x);
113
114        if(!strcmp(gcFunction,"tGroupGlueTools"))
115        {
116                if(!strcmp(gcFind,LANG_NB_LIST))
117                {
118                        tGroupGlueList();
119                }
120
121                //Default
122                ProcesstGroupGlueVars(entries,x);
123                tGroupGlue("");
124        }
125        else if(!strcmp(gcFunction,"tGroupGlueList"))
126        {
127                ProcessControlVars(entries,x);
128                ProcesstGroupGlueListVars(entries,x);
129                tGroupGlueList();
130        }
131
132        return(0);
133
134}//tGroupGlueCommands()
135
136
137void tGroupGlue(const char *cResult)
138{
139        MYSQL_RES *res;
140        MYSQL_RES *res2;
141        MYSQL_ROW field;
142
143        //Internal skip reloading
144        if(!cResult[0])
145        {
146                if(guMode)
147                        ExttGroupGlueSelectRow();
148                else
149                        ExttGroupGlueSelect();
150
151                mysql_query(&gMysql,gcQuery);
152                if(mysql_errno(&gMysql))
153                {
154                        if(strstr(mysql_error(&gMysql)," doesn't exist"))
155                        {
156                                CreatetGroupGlue();
157                                unxsVZ("New tGroupGlue table created");
158                        }
159                        else
160                        {
161                                htmlPlainTextError(mysql_error(&gMysql));
162                        }
163                }
164
165                res=mysql_store_result(&gMysql);
166                if((guI=mysql_num_rows(res)))
167                {
168                        if(guMode==6)
169                        {
170                        sprintf(gcQuery,"SELECT _rowid FROM tGroupGlue WHERE uGroupGlue=%u"
171                                                ,uGroupGlue);
172                                MYSQL_RUN_STORE(res2);
173                                field=mysql_fetch_row(res2);
174                                sscanf(field[0],"%lu",&gluRowid);
175                                gluRowid++;
176                        }
177                        PageMachine("",0,"");
178                        if(!guMode) mysql_data_seek(res,gluRowid-1);
179                        field=mysql_fetch_row(res);
180                sscanf(field[0],"%u",&uGroupGlue);
181                sscanf(field[1],"%u",&uGroup);
182                sscanf(field[2],"%u",&uNode);
183                sscanf(field[3],"%u",&uContainer);
184
185                }
186
187        }//Internal Skip
188
189        Header_ism3(":: Glues uContainers or uNodes to uGroups",0);
190        printf("<table width=100%% cellspacing=0 cellpadding=0>\n");
191        printf("<tr><td colspan=2 align=right valign=center>");
192
193
194        printf("<input type=hidden name=gcFunction value=tGroupGlueTools>");
195        printf("<input type=hidden name=gluRowid value=%lu>",gluRowid);
196        if(guI)
197        {
198                if(guMode==6)
199                        //printf(" Found");
200                        printf(LANG_NBR_FOUND);
201                else if(guMode==5)
202                        //printf(" Modified");
203                        printf(LANG_NBR_MODIFIED);
204                else if(guMode==4)
205                        //printf(" New");
206                        printf(LANG_NBR_NEW);
207                printf(LANG_NBRF_SHOWING,gluRowid,guI);
208        }
209        else
210        {
211                if(!cResult[0])
212                //printf(" No records found");
213                printf(LANG_NBR_NORECS);
214        }
215        if(cResult[0]) printf("%s",cResult);
216        printf("</td></tr>");
217        printf("<tr><td valign=top width=25%%>");
218
219        ExttGroupGlueButtons();
220
221        printf("</td><td valign=top>");
222        //
223        OpenFieldSet("tGroupGlue Record Data",100);
224
225        if(guMode==2000 || guMode==2002)
226                tGroupGlueInput(1);
227        else
228                tGroupGlueInput(0);
229
230        //
231        CloseFieldSet();
232
233        //Bottom table
234        printf("<tr><td colspan=2>");
235        ExttGroupGlueAuxTable();
236
237        Footer_ism3();
238
239}//end of tGroupGlue();
240
241
242void tGroupGlueInput(unsigned uMode)
243{
244
245//uGroupGlue
246        OpenRow(LANG_FL_tGroupGlue_uGroupGlue,"black");
247        printf("<input title='%s' type=text name=uGroupGlue value=%u size=16 maxlength=10 "
248,LANG_FT_tGroupGlue_uGroupGlue,uGroupGlue);
249        if(guPermLevel>=20 && uMode)
250        {
251                printf("></td></tr>\n");
252        }
253        else
254        {
255                printf("disabled></td></tr>\n");
256                printf("<input type=hidden name=uGroupGlue value=%u >\n",uGroupGlue);
257        }
258//uGroup
259        OpenRow(LANG_FL_tGroupGlue_uGroup,"black");
260        if(guPermLevel>=10 && uMode)
261                tTablePullDownOwner("tGroup;cuGroupPullDown","cLabel","cLabel",uGroup,1);
262        else
263                tTablePullDownOwner("tGroup;cuGroupPullDown","cLabel","cLabel",uGroup,0);
264//uNode
265        OpenRow(LANG_FL_tGroupGlue_uNode,"black");
266        if(guPermLevel>=10 && uMode)
267                tTablePullDown("tNode;cuNodePullDown","cLabel","cLabel",uNode,1);
268        else
269                tTablePullDown("tNode;cuNodePullDown","cLabel","cLabel",uNode,0);
270//uContainer
271        OpenRow(LANG_FL_tGroupGlue_uContainer,"black");
272        if(guPermLevel>=10 && uMode)
273                tTablePullDownOwner("tContainer;cuContainerPullDown","cLabel","cLabel",uContainer,1);
274        else
275                tTablePullDownOwner("tContainer;cuContainerPullDown","cLabel","cLabel",uContainer,0);
276        printf("</tr>\n");
277
278
279
280}//void tGroupGlueInput(unsigned uMode)
281
282
283void NewtGroupGlue(unsigned uMode)
284{
285        register int i=0;
286        MYSQL_RES *res;
287
288        sprintf(gcQuery,"SELECT uGroupGlue FROM tGroupGlue WHERE uGroupGlue=%u",uGroupGlue);
289        MYSQL_RUN_STORE(res);
290        i=mysql_num_rows(res);
291
292        if(i)
293                //tGroupGlue("<blink>Record already exists");
294                tGroupGlue(LANG_NBR_RECEXISTS);
295
296        //insert query
297        Insert_tGroupGlue();
298        if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql));
299        //sprintf(gcQuery,"New record %u added");
300        uGroupGlue=mysql_insert_id(&gMysql);
301
302        if(!uMode)
303        {
304                sprintf(gcQuery,LANG_NBR_NEWRECADDED,uGroupGlue);
305                tGroupGlue(gcQuery);
306        }
307
308}//NewtGroupGlue(unsigned uMode)
309
310
311void DeletetGroupGlue(void)
312{
313        sprintf(gcQuery,"DELETE FROM tGroupGlue WHERE uGroupGlue=%u",uGroupGlue);
314        MYSQL_RUN;
315        //tGroupGlue("Record Deleted");
316        if(mysql_affected_rows(&gMysql)>0)
317                tGroupGlue(LANG_NBR_RECDELETED);
318        else
319                tGroupGlue(LANG_NBR_RECNOTDELETED);
320}//void DeletetGroupGlue(void)
321
322
323void Insert_tGroupGlue(void)
324{
325
326        //insert query
327        sprintf(gcQuery,"INSERT INTO tGroupGlue SET uGroupGlue=%u,uGroup=%u,uNode=%u,uContainer=%u",
328                        uGroupGlue
329                        ,uGroup
330                        ,uNode
331                        ,uContainer
332                        );
333
334        MYSQL_RUN;
335
336}//void Insert_tGroupGlue(void)
337
338
339void Update_tGroupGlue(char *cRowid)
340{
341
342        //update query
343        sprintf(gcQuery,"UPDATE tGroupGlue SET uGroupGlue=%u,uGroup=%u,uNode=%u,uContainer=%u WHERE _rowid=%s",
344                        uGroupGlue
345                        ,uGroup
346                        ,uNode
347                        ,uContainer
348                        ,cRowid);
349
350        MYSQL_RUN;
351
352}//void Update_tGroupGlue(void)
353
354
355void ModtGroupGlue(void)
356{
357        register int i=0;
358        MYSQL_RES *res;
359        MYSQL_ROW field;
360        sprintf(gcQuery,"SELECT uGroupGlue FROM tGroupGlue WHERE uGroupGlue=%u",uGroupGlue);
361
362        MYSQL_RUN_STORE(res);
363        i=mysql_num_rows(res);
364
365        //if(i<1) tGroupGlue("<blink>Record does not exist");
366        if(i<1) tGroupGlue(LANG_NBR_RECNOTEXIST);
367        //if(i>1) tGroupGlue("<blink>Multiple rows!");
368        if(i>1) tGroupGlue(LANG_NBR_MULTRECS);
369
370        field=mysql_fetch_row(res);
371        Update_tGroupGlue(field[0]);
372        if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql));
373        //sprintf(query,"record %s modified",field[0]);
374        sprintf(gcQuery,LANG_NBRF_REC_MODIFIED,field[0]);
375        tGroupGlue(gcQuery);
376
377}//ModtGroupGlue(void)
378
379
380void tGroupGlueList(void)
381{
382        MYSQL_RES *res;
383        MYSQL_ROW field;
384
385        ExttGroupGlueListSelect();
386
387        MYSQL_RUN_STORE(res);
388        guI=mysql_num_rows(res);
389
390        PageMachine("tGroupGlueList",1,"");//1 is auto header list guMode. Opens table!
391
392        //Filter select drop down
393        ExttGroupGlueListFilter();
394
395        printf("<input type=text size=16 name=gcCommand maxlength=98 value=\"%s\" >",gcCommand);
396
397        printf("</table>\n");
398
399        printf("<table bgcolor=#9BC1B3 border=0 width=100%%>\n");
400        printf("<tr bgcolor=black><td><font face=arial,helvetica color=white>uGroupGlue<td><font face=arial,helvetica color=white>uGroup<td><font face=arial,helvetica color=white>uNode<td><font face=arial,helvetica color=white>uContainer</tr>");
401
402
403
404        mysql_data_seek(res,guStart-1);
405
406        for(guN=0;guN<(guEnd-guStart+1);guN++)
407        {
408                field=mysql_fetch_row(res);
409                if(!field)
410                {
411                        printf("<tr><td><font face=arial,helvetica>End of data</table>");
412                        Footer_ism3();
413                }
414                        if(guN % 2)
415                                printf("<tr bgcolor=#BBE1D3>");
416                        else
417                                printf("<tr>");
418                printf("<td><input type=submit name=ED%s value=Edit> %s<td>%s<td>%s<td>%s</tr>"
419                        ,field[0]
420                        ,field[0]
421                        ,ForeignKey("tGroup","cLabel",strtoul(field[1],NULL,10))
422                        ,ForeignKey("tNode","cLabel",strtoul(field[2],NULL,10))
423                        ,ForeignKey("tContainer","cLabel",strtoul(field[3],NULL,10))
424                                );
425
426        }
427
428        printf("</table></form>\n");
429        Footer_ism3();
430
431}//tGroupGlueList()
432
433
434void CreatetGroupGlue(void)
435{
436        sprintf(gcQuery,"CREATE TABLE IF NOT EXISTS tGroupGlue "
437                        " ("
438                        " uGroup INT UNSIGNED NOT NULL DEFAULT 0,INDEX (uGroup),"
439                        " uNode INT UNSIGNED NOT NULL DEFAULT 0,INDEX (uNode),"
440                        " uContainer INT UNSIGNED NOT NULL DEFAULT 0,INDEX (uContainer),"
441                        " uIP INT UNSIGNED NOT NULL DEFAULT 0,INDEX (uIP),"
442                        " uGroupGlue INT UNSIGNED PRIMARY KEY AUTO_INCREMENT"
443                        " )");
444        mysql_query(&gMysql,gcQuery);
445        if(mysql_errno(&gMysql))
446                htmlPlainTextError(mysql_error(&gMysql));
447}//CreatetGroupGlue()
448
Note: See TracBrowser for help on using the browser.