root/trunk/tnameserverfunc.h

Revision 1564, 11.7 KB (checked in by Gary, 20 months ago)

unxsVZ finished adding the datacenter enable/disable buttons.

  • 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
8        (C) 2001-2010 Unixservice, LLC.
9 
10*/
11
12void tNameserverNavList(void);
13
14//file scoped var
15static unsigned uDatacenter=0;
16static char cuDatacenterPullDown[256]={""};
17
18
19void ExtProcesstNameserverVars(pentry entries[], int x)
20{
21        register int i;
22        for(i=0;i<x;i++)
23        {
24                if(!strcmp(entries[i].name,"uDatacenter"))
25                        sscanf(entries[i].val,"%u",&uDatacenter);
26                else if(!strcmp(entries[i].name,"cuDatacenterPullDown"))
27                {
28                        sprintf(cuDatacenterPullDown,"%.255s",entries[i].val);
29                        uDatacenter=ReadPullDown("tDatacenter","cLabel",cuDatacenterPullDown);
30                }
31        }
32}//void ExtProcesstNameserverVars(pentry entries[], int x)
33
34
35void ExttNameserverCommands(pentry entries[], int x)
36{
37
38        if(!strcmp(gcFunction,"tNameserverTools"))
39        {
40                MYSQL_RES *res;
41
42                if(!strcmp(gcCommand,LANG_NB_NEW))
43                {
44                        if(guPermLevel>=10)
45                        {
46                                ProcesstNameserverVars(entries,x);
47                                guMode=2000;
48                                tNameserver(LANG_NB_CONFIRMNEW);
49                        }
50                }
51                else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW))
52                {
53                        if(guPermLevel>=10)
54                        {
55                                ProcesstNameserverVars(entries,x);
56
57                                guMode=2000;
58                                //Check entries here
59                                if(strlen(cLabel)<3)
60                                        tNameserver("<blink>Error</blink>: cLabel too short!");
61                                sprintf(gcQuery,"SELECT uNameserver FROM tNameserver WHERE cLabel='%s'",
62                                                cLabel);
63                                mysql_query(&gMysql,gcQuery);
64                                if(mysql_errno(&gMysql))
65                                                htmlPlainTextError(mysql_error(&gMysql));
66                                res=mysql_store_result(&gMysql);
67                                if(mysql_num_rows(res))
68                                {
69                                        mysql_free_result(res);
70                                        tNameserver("<blink>Error</blink>: Nameserver cLabel in use!");
71                                }
72                                guMode=0;
73
74                                uNameserver=0;
75                                uCreatedBy=guLoginClient;
76                                uOwner=guCompany;
77                                uModBy=0;//Never modified
78                                uModDate=0;//Never modified
79                                NewtNameserver(1);
80                                if(!uNameserver)
81                                        tNameserver("<blink>Error</blink>: New tNameserver entry was not created!");
82
83                                sprintf(gcQuery,"INSERT INTO tProperty SET uKey=%u,uType="PROP_NAMESERVER
84                                                ",cName='cDatacenter',cValue='All Datacenters',uOwner=%u,uCreatedBy=%u"
85                                                ",uCreatedDate=UNIX_TIMESTAMP(NOW())"
86                                                        ,uNameserver,guCompany,guLoginClient);
87                                mysql_query(&gMysql,gcQuery);
88                                if(mysql_errno(&gMysql))
89                                                htmlPlainTextError(mysql_error(&gMysql));
90                                tNameserver("New nameserver created");
91                        }
92                }
93                else if(!strcmp(gcCommand,LANG_NB_DELETE))
94                {
95                        ProcesstNameserverVars(entries,x);
96                        if(uAllowDel(uOwner,uCreatedBy))
97                        {
98                                guMode=0;
99                                sprintf(gcQuery,"SELECT uNameserver FROM tContainer WHERE uNameserver=%u",
100                                                                        uNameserver);
101                                mysql_query(&gMysql,gcQuery);
102                                if(mysql_errno(&gMysql))
103                                                htmlPlainTextError(mysql_error(&gMysql));
104                                res=mysql_store_result(&gMysql);
105                                if(mysql_num_rows(res))
106                                {
107                                        mysql_free_result(res);
108                                        tNameserver("<blink>Error</blink>: Can't delete a nameserver used by a container!");
109                                }
110                                guMode=2001;
111                                tNameserver(LANG_NB_CONFIRMDEL);
112                        }
113                }
114                else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL))
115                {
116                        ProcesstNameserverVars(entries,x);
117                        if(uAllowDel(uOwner,uCreatedBy))
118                        {
119                                guMode=5;
120                                sprintf(gcQuery,"SELECT uNameserver FROM tContainer WHERE uNameserver=%u",
121                                                                        uNameserver);
122                                mysql_query(&gMysql,gcQuery);
123                                if(mysql_errno(&gMysql))
124                                                htmlPlainTextError(mysql_error(&gMysql));
125                                res=mysql_store_result(&gMysql);
126                                if(mysql_num_rows(res))
127                                {
128                                        mysql_free_result(res);
129                                        tNameserver("<blink>Error</blink>: Can't delete a nameserver used by a container!");
130                                }
131                                DeletetNameserver();
132                        }
133                }
134                else if(!strcmp(gcCommand,LANG_NB_MODIFY))
135                {
136                        ProcesstNameserverVars(entries,x);
137                        if(uAllowMod(uOwner,uCreatedBy))
138                        {
139                                guMode=2002;
140                                tNameserver(LANG_NB_CONFIRMMOD);
141                        }
142                }
143                else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD))
144                {
145                        ProcesstNameserverVars(entries,x);
146                        if(uAllowMod(uOwner,uCreatedBy))
147                        {
148                                guMode=2002;
149                                //Check entries here
150                                if(strlen(cLabel)<3)
151                                        tNameserver("<blink>Error</blink>: cLabel too short!");
152                                guMode=0;
153
154                                uModBy=guLoginClient;
155                                ModtNameserver();
156                        }
157                }
158                else if(!strcmp(gcCommand,"Enable"))
159                {
160                        ProcesstNameserverVars(entries,x);
161                        if(uAllowMod(uOwner,uCreatedBy))
162                        {
163                                guMode=6;
164                                if(!uDatacenter)
165                                        sprintf(gcQuery,"INSERT tProperty SET cName='cDatacenter',cValue='All Datacenters',"
166                                                "uType=%u,uKey=%u,uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())",
167                                                uPROP_NAMESERVER,uNameserver,uOwner,guLoginClient);
168                                else
169                                        sprintf(gcQuery,"INSERT tProperty SET cName='cDatacenter',cValue='%s',"
170                                                "uType=%u,uKey=%u,uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())",
171                                                ForeignKey("tDatacenter","cLabel",uDatacenter),
172                                                uPROP_NAMESERVER,uNameserver,uOwner,guLoginClient);
173                                mysql_query(&gMysql,gcQuery);
174                                if(mysql_errno(&gMysql))
175                                                htmlPlainTextError(mysql_error(&gMysql));
176                        }
177                        else
178                        {
179                                tNameserver("<blink>Error</blink>: Enable not allowed!");
180                        }
181                }
182                else if(!strcmp(gcCommand,"Disable"))
183                {
184                        ProcesstNameserverVars(entries,x);
185                        if(uAllowMod(uOwner,uCreatedBy))
186                        {
187                                guMode=6;
188                                if(!uDatacenter)
189                                        sprintf(gcQuery,"DELETE FROM tProperty WHERE cName='cDatacenter' AND cValue='All Datacenters'"
190                                                " AND uType=%u AND uKey=%u AND (uOwner=%u OR uCreatedBy=%u)",
191                                                uPROP_NAMESERVER,uNameserver,uOwner,guLoginClient);
192                                else
193                                        sprintf(gcQuery,"DELETE FROM tProperty WHERE cName='cDatacenter' AND cValue='%s'"
194                                                " AND uType=%u AND uKey=%u AND (uOwner=%u OR uCreatedBy=%u)",
195                                                ForeignKey("tDatacenter","cLabel",uDatacenter),
196                                                uPROP_NAMESERVER,uNameserver,uOwner,guLoginClient);
197                                mysql_query(&gMysql,gcQuery);
198                                if(mysql_errno(&gMysql))
199                                                htmlPlainTextError(mysql_error(&gMysql));
200                        }
201                        else
202                        {
203                                tNameserver("<blink>Error</blink>: Disable not allowed!");
204                        }
205                }
206        }
207
208}//void ExttNameserverCommands(pentry entries[], int x)
209
210
211void ExttNameserverButtons(void)
212{
213        OpenFieldSet("tNameserver Aux Panel",100);
214        switch(guMode)
215        {
216                case 2000:
217                        printf("<p><u>Enter/mod data</u><br>");
218                        printf(LANG_NBB_CONFIRMNEW);
219                break;
220
221                case 2001:
222                        printf("<p><u>Think twice</u><br>");
223                        printf(LANG_NBB_CONFIRMDEL);
224                break;
225
226                case 2002:
227                        printf("<p><u>Review changes</u><br>");
228                        printf(LANG_NBB_CONFIRMMOD);
229                break;
230
231                default:
232                        printf("<u>Table Tips</u><br>");
233                        printf("<p><u>Record Context Info</u><br>");
234                        tNameserverNavList();
235        }
236        CloseFieldSet();
237
238}//void ExttNameserverButtons(void)
239
240
241void ExttNameserverAuxTable(void)
242{
243        if(!uNameserver || guMode==2000 )//uMODE_NEW
244                return;
245
246        MYSQL_RES *res;
247        MYSQL_ROW field;
248
249        sprintf(gcQuery,"tNameserver %s Property Panel",cLabel);
250        OpenFieldSet(gcQuery,100);
251        sprintf(gcQuery,"SELECT uProperty,cName,cValue FROM tProperty WHERE uKey=%u AND uType="PROP_NAMESERVER
252                        " ORDER BY cName",uNameserver);
253
254        mysql_query(&gMysql,gcQuery);
255        if(mysql_errno(&gMysql))
256                htmlPlainTextError(mysql_error(&gMysql));
257
258        res=mysql_store_result(&gMysql);
259        printf("<table cols=2>");
260        if(mysql_num_rows(res))
261        {
262                while((field=mysql_fetch_row(res)))
263                {
264                        printf("<tr>\n");
265                        printf("<td width=200 valign=top><a class=darkLink href=unxsVZ.cgi?"
266                                        "gcFunction=tProperty&uProperty=%s&cReturn=tNameserver_%u>"
267                                        "%s</a></td><td>%s</td>\n",
268                                                field[0],uNameserver,field[1],field[2]);
269                        printf("</tr>\n");
270                }
271        }
272
273        //Simple interface to add to tConfiguration table
274        if(uAllowMod(uOwner,uCreatedBy))
275        {
276                printf("<tr>");
277                printf("<td width=200 valign=top><input type=submit class=largeButton"
278                " title='Enable for one or more datacenters; for new container creation'"
279                " name=gcCommand value='Enable'><p>");
280                printf("<input type=submit class=largeButton"
281                " title='Disable for one or more datacenters; for new container creation'"
282                " name=gcCommand value='Disable'</td>");
283                printf("<td valign=top> Select a datacenter or none (---) for all ");
284                tTablePullDown("tDatacenter;cuDatacenterPullDown","cLabel","cLabel",uDatacenter,1);
285                printf("</td>");
286                printf("</tr>\n");
287        }
288       
289        printf("</table>");
290
291        CloseFieldSet();
292
293}//void ExttNameserverAuxTable(void)
294
295
296void ExttNameserverGetHook(entry gentries[], int x)
297{
298        register int i;
299
300        for(i=0;i<x;i++)
301        {
302                if(!strcmp(gentries[i].name,"uNameserver"))
303                {
304                        sscanf(gentries[i].val,"%u",&uNameserver);
305                        guMode=6;
306                }
307        }
308        tNameserver("");
309
310}//void ExttNameserverGetHook(entry gentries[], int x)
311
312
313void ExttNameserverSelect(void)
314{
315        ExtSelect("tNameserver",VAR_LIST_tNameserver);
316
317}//void ExttNameserverSelect(void)
318
319
320void ExttNameserverSelectRow(void)
321{
322        ExtSelectRow("tNameserver",VAR_LIST_tNameserver,uNameserver);
323
324}//void ExttNameserverSelectRow(void)
325
326
327void ExttNameserverListSelect(void)
328{
329        char cCat[512];
330
331        ExtListSelect("tNameserver",VAR_LIST_tNameserver);
332       
333        //Changes here must be reflected below in ExttNameserverListFilter()
334        if(!strcmp(gcFilter,"uNameserver"))
335        {
336                sscanf(gcCommand,"%u",&uNameserver);
337                if(guLoginClient==1 && guPermLevel>11)
338                        strcat(gcQuery," WHERE ");
339                else
340                        strcat(gcQuery," AND ");
341                sprintf(cCat,"tNameserver.uNameserver=%u ORDER BY uNameserver",uNameserver);
342                strcat(gcQuery,cCat);
343        }
344        else if(1)
345        {
346                //None NO FILTER
347                strcpy(gcFilter,"None");
348                strcat(gcQuery," ORDER BY uNameserver");
349        }
350
351}//void ExttNameserverListSelect(void)
352
353
354void ExttNameserverListFilter(void)
355{
356        //Filter
357        printf("&nbsp;&nbsp;&nbsp;Filter on ");
358        printf("<select name=gcFilter>");
359        if(strcmp(gcFilter,"uNameserver"))
360                printf("<option>uNameserver</option>");
361        else
362                printf("<option selected>uNameserver</option>");
363        if(strcmp(gcFilter,"None"))
364                printf("<option>None</option>");
365        else
366                printf("<option selected>None</option>");
367        printf("</select>");
368
369}//void ExttNameserverListFilter(void)
370
371
372void ExttNameserverNavBar(void)
373{
374        if(uOwner) GetClientOwner(uOwner,&guReseller);
375
376        printf(LANG_NBB_SKIPFIRST);
377        printf(LANG_NBB_SKIPBACK);
378        printf(LANG_NBB_SEARCH);
379
380        if(guPermLevel>=10 && !guListMode)
381                printf(LANG_NBB_NEW);
382
383        if(uAllowMod(uOwner,uCreatedBy))
384                printf(LANG_NBB_MODIFY);
385
386        if(uAllowDel(uOwner,uCreatedBy))
387                printf(LANG_NBB_DELETE);
388
389        if(uOwner)
390                printf(LANG_NBB_LIST);
391
392        printf(LANG_NBB_SKIPNEXT);
393        printf(LANG_NBB_SKIPLAST);
394        printf("&nbsp;&nbsp;&nbsp;\n");
395
396}//void ExttNameserverNavBar(void)
397
398
399void tNameserverNavList(void)
400{
401        MYSQL_RES *res;
402        MYSQL_ROW field;
403
404        ExtSelect("tNameserver","tNameserver.uNameserver,tNameserver.cLabel");
405        mysql_query(&gMysql,gcQuery);
406        if(mysql_errno(&gMysql))
407        {
408                printf("<p><u>tNameserverNavList</u><br>\n");
409                printf("%s",mysql_error(&gMysql));
410                return;
411        }
412
413        res=mysql_store_result(&gMysql);
414        if(mysql_num_rows(res))
415        {       
416                printf("<p><u>tNameserverNavList</u><br>\n");
417
418                while((field=mysql_fetch_row(res)))
419                        printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tNameserver&"
420                                "uNameserver=%s>%s</a><br>\n",field[0],field[1]);
421        }
422        mysql_free_result(res);
423
424}//void tNameserverNavList(void)
425
426
Note: See TracBrowser for help on using the browser.