root/trunk/tnode.c

Revision 1810, 15.0 KB (checked in by Gary, 8 months ago)

unxsVZ extending common clone container function.

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