root/trunk/tgroupgluefunc.h

Revision 1355, 10.7 KB (checked in by Gary, 2 years ago)

unxsVZ minor work in pogress save for new for tClient.

  • Property svn:keywords set to id
Line 
1/*
2FILE
3        $Id$
4        (Built initially by unixservice.com mysqlRAD2)
5PURPOSE
6        Non schema-dependent table and application table related functions.
7AUTHOR/LEGAL
8        (C) 2001-2010 Gary Wallis for Unixservice, LLC.
9        GPLv2 license applies. See LICENSE file included.
10*/
11
12//ModuleFunctionProtos()
13void tTableMultiplePullDown(const char *cTableName,const char *cFieldName,const char *cOrderby);
14
15
16//uContainer: Glue into tContainer
17static char cuMulContainerPullDown[256]={""};
18
19void ExtProcesstGroupGlueVars(pentry entries[], int x)
20{
21        register int i;
22        for(i=0;i<x;i++)
23        {
24                if(!strcmp(entries[i].name,"cuMulContainerPullDown") && !strcmp(gcCommand,"Add Multiple Containers"))
25                {
26                        sprintf(cuMulContainerPullDown,"%.255s",entries[i].val);
27                        uContainer=ReadPullDown("tContainer","cLabel",cuMulContainerPullDown);
28                        uGroupGlue=0;
29                        uNode=0;
30                        if(uContainer && uGroup) NewtGroupGlue(1);
31                }
32                else if(!strcmp(entries[i].name,"cuMulContainerPullDown") && !strcmp(gcCommand,"Del Multiple Containers"))
33                {
34                        sprintf(cuMulContainerPullDown,"%.255s",entries[i].val);
35                        uContainer=ReadPullDown("tContainer","cLabel",cuMulContainerPullDown);
36                        if(uContainer && uGroup)
37                        {
38                                sprintf(gcQuery,"DELETE FROM tGroupGlue WHERE uContainer=%u AND uGroup=%u",
39                                                uContainer,uGroup);
40                                MYSQL_RUN;
41                        }
42               
43                }
44        }
45
46}//void ExtProcesstGroupGlueVars(pentry entries[], int x)
47
48
49void ExttGroupGlueCommands(pentry entries[], int x)
50{
51
52        if(!strcmp(gcFunction,"tGroupGlueTools"))
53        {
54                //ModuleFunctionProcess()
55
56                if(!strcmp(gcCommand,LANG_NB_NEW))
57                {
58                        if(guPermLevel>=12)
59                        {
60                                ProcesstGroupGlueVars(entries,x);
61                                guMode=2000;
62                                tGroupGlue(LANG_NB_CONFIRMNEW);
63                        }
64                }
65                else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW))
66                {
67                        if(guPermLevel>=12)
68                        {
69                                ProcesstGroupGlueVars(entries,x);
70
71                                guMode=2000;
72                                if(!uGroup || (uNode==0 && uContainer==0))
73                                        tGroupGlue("Must Supply a uGroup and a uNode or uContainer");
74                                guMode=0;
75
76                                uGroupGlue=0;
77                                NewtGroupGlue(0);
78                        }
79                }
80                else if(!strcmp(gcCommand,"Add Multiple Containers"))
81                {
82                        if(guPermLevel>=12)
83                        {
84                                ProcesstGroupGlueVars(entries,x);
85                                guMode=0;
86                                if(mysql_insert_id(&gMysql)>0)
87                                        tGroupGlue("Multiple containers added");
88                                else
89                                        tGroupGlue("No containers added");
90                        }
91                }
92                else if(!strcmp(gcCommand,LANG_NB_DELETE))
93                {
94                        if(guPermLevel>=12)
95                        {
96                                ProcesstGroupGlueVars(entries,x);
97                                guMode=2001;
98                                tGroupGlue(LANG_NB_CONFIRMDEL);
99                        }
100                }
101                else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL))
102                {
103                        if(guPermLevel>=12)
104                        {
105                                ProcesstGroupGlueVars(entries,x);
106                                guMode=5;
107                                DeletetGroupGlue();
108                        }
109                }
110                else if(!strcmp(gcCommand,"Del Multiple Containers"))
111                {
112                        if(guPermLevel>=12)
113                        {
114                                ProcesstGroupGlueVars(entries,x);
115                                guMode=0;
116                                if(mysql_affected_rows(&gMysql)>0)
117                                        tGroupGlue("Multiple containers deleted");
118                                else
119                                        tGroupGlue("No containers deleted");
120                        }
121                }
122                else if(!strcmp(gcCommand,LANG_NB_MODIFY))
123                {
124                        if(guPermLevel>=12)
125                        {
126                                ProcesstGroupGlueVars(entries,x);
127                                guMode=2002;
128                                tGroupGlue(LANG_NB_CONFIRMMOD);
129                        }
130                }
131                else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD))
132                {
133                        if(guPermLevel>=12)
134                        {
135                                ProcesstGroupGlueVars(entries,x);
136                                guMode=2002;
137                                //Check entries here
138                                guMode=0;
139
140                                ModtGroupGlue();
141                        }
142                }
143        }
144
145}//void ExttGroupGlueCommands(pentry entries[], int x)
146
147
148void ExttGroupGlueButtons(void)
149{
150        OpenFieldSet("tGroupGlue Aux Panel",100);
151        switch(guMode)
152        {
153                case 2000:
154                        printf("<p><u>Enter/mod data</u><br>");
155                        printf(LANG_NBB_CONFIRMNEW);
156                        printf("<p><u>Add multiple containers</u><br>");
157                        printf("Select with shift and ctrl multiple containers from list below"
158                                " to the uGroup selected in right panel. The uContainer and uNode are ignored."
159                                " Warning: You may add inadvertently the same containers multiple times no"
160                                " checking takes place.<p>");
161                        tTableMultiplePullDown("tContainer;cuMulContainerPullDown","cLabel","cLabel");
162                        printf("<p><input type=submit class=largeButton name=gcCommand value='Add Multiple Containers'>");
163                break;
164
165                case 2001:
166                        printf("<p><u>Think twice</u><br>");
167                        printf(LANG_NBB_CONFIRMDEL);
168                        printf("<p><u>Delete multiple containers</u><br>");
169                        printf("Select with shift and ctrl multiple containers from list below"
170                                " to the uGroup selected in right panel. The uContainer and uNode are ignored.<p>");
171                        tTableMultiplePullDown("tContainer;cuMulContainerPullDown","cLabel","cLabel");
172                        printf("<p><input type=submit class=largeButton name=gcCommand value='Del Multiple Containers'>");
173                break;
174
175                case 2002:
176                        printf("<p><u>Review changes</u><br>");
177                        printf(LANG_NBB_CONFIRMMOD);
178                break;
179
180                default:
181                        printf("<u>Table Tips</u><br>");
182                        printf("This is just a glue table, see [New], [Delete] and <a href=?gcFunction=tGroup>tGroup</a>"
183                                " for more info.<br>");
184        }
185        CloseFieldSet();
186
187}//void ExttGroupGlueButtons(void)
188
189
190void ExttGroupGlueAuxTable(void)
191{
192
193}//void ExttGroupGlueAuxTable(void)
194
195
196void ExttGroupGlueGetHook(entry gentries[], int x)
197{
198        register int i;
199
200        for(i=0;i<x;i++)
201        {
202                if(!strcmp(gentries[i].name,"uGroupGlue"))
203                {
204                        sscanf(gentries[i].val,"%u",&uGroupGlue);
205                        guMode=6;
206                }
207        }
208        tGroupGlue("");
209
210}//void ExttGroupGlueGetHook(entry gentries[], int x)
211
212
213void ExttGroupGlueSelect(void)
214{
215        sprintf(gcQuery,"SELECT %s FROM tGroupGlue ORDER BY\
216                                        uGroupGlue",
217                                        VAR_LIST_tGroupGlue);
218
219}//void ExttGroupGlueSelect(void)
220
221
222void ExttGroupGlueSelectRow(void)
223{
224        sprintf(gcQuery,"SELECT %s FROM tGroupGlue WHERE uGroupGlue=%u",
225                        VAR_LIST_tGroupGlue,uGroupGlue);
226
227}//void ExttGroupGlueSelectRow(void)
228
229
230void ExttGroupGlueListSelect(void)
231{
232        char cCat[512];
233
234        sprintf(gcQuery,"SELECT %s FROM tGroupGlue",VAR_LIST_tGroupGlue);
235
236        //Changes here must be reflected below in ExttGroupGlueListFilter()
237        if(!strcmp(gcFilter,"uGroupGlue"))
238        {
239                sscanf(gcCommand,"%u",&uGroupGlue);
240                sprintf(cCat," WHERE tGroupGlue.uGroupGlue=%u ORDER BY uGroupGlue",uGroupGlue);
241                strcat(gcQuery,cCat);
242        }
243        else if(!strcmp(gcFilter,"uGroup"))
244        {
245                sscanf(gcCommand,"%u",&uGroup);
246                sprintf(cCat," WHERE tGroupGlue.uGroup=%u ORDER BY uGroup",uGroup);
247                strcat(gcQuery,cCat);
248        }
249        else if(!strcmp(gcFilter,"uNode"))
250        {
251                sscanf(gcCommand,"%u",&uNode);
252                sprintf(cCat," WHERE tGroupGlue.uNode=%u ORDER BY uNode",uNode);
253                strcat(gcQuery,cCat);
254        }
255        else if(!strcmp(gcFilter,"uContainer"))
256        {
257                sscanf(gcCommand,"%u",&uContainer);
258                sprintf(cCat," WHERE tGroupGlue.uContainer=%u ORDER BY uContainer",uContainer);
259                strcat(gcQuery,cCat);
260        }
261        else if(1)
262        {
263                //None NO FILTER
264                strcpy(gcFilter,"None");
265                strcat(gcQuery," ORDER BY uGroupGlue");
266        }
267
268}//void ExttGroupGlueListSelect(void)
269
270
271void ExttGroupGlueListFilter(void)
272{
273        //Filter
274        printf("&nbsp;&nbsp;&nbsp;Filter on ");
275        printf("<select name=gcFilter>");
276        if(strcmp(gcFilter,"uGroupGlue"))
277                printf("<option>uGroupGlue</option>");
278        else
279                printf("<option selected>uGroupGlue</option>");
280        if(strcmp(gcFilter,"uGroup"))
281                printf("<option>uGroup</option>");
282        else
283                printf("<option selected>uGroup</option>");
284        if(strcmp(gcFilter,"uNode"))
285                printf("<option>uNode</option>");
286        else
287                printf("<option selected>uNode</option>");
288        if(strcmp(gcFilter,"uContainer"))
289                printf("<option>uContainer</option>");
290        else
291                printf("<option selected>uContainer</option>");
292        if(strcmp(gcFilter,"None"))
293                printf("<option>None</option>");
294        else
295                printf("<option selected>None</option>");
296        printf("</select>");
297
298}//void ExttGroupGlueListFilter(void)
299
300
301void ExttGroupGlueNavBar(void)
302{
303        printf(LANG_NBB_SKIPFIRST);
304        printf(LANG_NBB_SKIPBACK);
305        printf(LANG_NBB_SEARCH);
306
307        if(guPermLevel>=12 && !guListMode)
308                printf(LANG_NBB_NEW);
309
310        if(guPermLevel>=12 && !guListMode)
311                printf(LANG_NBB_MODIFY);
312
313        if(guPermLevel>=12 && !guListMode)
314                printf(LANG_NBB_DELETE);
315
316        if(guPermLevel>=12)
317                printf(LANG_NBB_LIST);
318
319        printf(LANG_NBB_SKIPNEXT);
320        printf(LANG_NBB_SKIPLAST);
321        printf("&nbsp;&nbsp;&nbsp;\n");
322
323}//void ExttGroupGlueNavBar(void)
324
325
326void tTableMultiplePullDown(const char *cTableName,const char *cFieldName,const char *cOrderby)
327{
328        register int i,n;
329        char cLabel[256];
330        MYSQL_RES *mysqlRes;         
331        MYSQL_ROW mysqlField;
332
333        char cSelectName[100]={""};
334        char cHidden[100]={""};
335        char cLocalTableName[256]={""};
336        char *cp;
337
338        if(!cTableName[0] || !cFieldName[0] || !cOrderby[0])
339        {
340                printf("Invalid input tTableMultiplePullDown()");
341                return;
342        }
343
344        //Extended functionality
345        strncpy(cLocalTableName,cTableName,255);
346        if((cp=strchr(cLocalTableName,';')))
347        {
348                strncpy(cSelectName,cp+1,99);
349                cSelectName[99]=0;
350                *cp=0;
351        }
352
353
354        sprintf(gcQuery,"SELECT _rowid,%s FROM %s ORDER BY %s",
355                                cFieldName,cLocalTableName,cOrderby);
356
357        MYSQL_RUN_STORE_TEXT_RET_VOID(mysqlRes);
358       
359        i=mysql_num_rows(mysqlRes);
360
361        if(cSelectName[0])
362                sprintf(cLabel,"%s",cSelectName);
363        else
364                sprintf(cLabel,"%s_%sPullDown",cLocalTableName,cFieldName);
365
366        if(i>0)
367        {
368                printf("<select multiple size=%u name=%s >\n",(i>16)?16:i,cLabel);
369
370                for(n=0;n<i;n++)
371                {
372                        int unsigned field0=0;
373
374                        mysqlField=mysql_fetch_row(mysqlRes);
375                        sscanf(mysqlField[0],"%u",&field0);
376                        printf("<option>%s</option>\n",mysqlField[1]);
377                }
378        }
379        else
380        {
381                printf("<select multiple size=1 name=%s><option title='No selection'>---</option></select>\n"
382                        ,cLabel);
383        }
384        printf("</select>\n");
385        if(cHidden[0])
386                printf("%s",cHidden);
387
388}//tTableMultiplePullDown()
389
Note: See TracBrowser for help on using the browser.