root/trunk/tproperty.c

Revision 1583, 14.8 KB (checked in by Gary, 19 months ago)

unxsVZ fixed major install bug missing ) in create table SQL.

  • Property svn:keywords set to id
Line 
1/*
2FILE
3        tProperty 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 tpropertyfunc.h while
9        RAD is still to be used.
10AUTHOR/LEGAL
11        (C) 2001-2010 Gary Wallis for Unixservice, LLC.
12        GPLv2 license applies. See LICENSE file.       
13*/
14
15
16#include "mysqlrad.h"
17
18//Table Variables
19//Table Variables
20//uProperty: Primary Key
21static unsigned uProperty=0;
22//cName: Property Name
23static char cName[33]={""};
24//cValue: Value of property
25static char *cValue={""};
26//uType: Type of property
27static unsigned uType=0;
28static char cuTypePullDown[256]={""};
29//uKey: Abstract FK
30static unsigned uKey=0;
31//uOwner: Record owner
32static unsigned uOwner=0;
33//uCreatedBy: uClient for last insert
34static unsigned uCreatedBy=0;
35//uCreatedDate: Unix seconds date last insert
36static time_t uCreatedDate=0;
37//uModBy: uClient for last update
38static unsigned uModBy=0;
39//uModDate: Unix seconds date last update
40static time_t uModDate=0;
41
42
43
44#define VAR_LIST_tProperty "tProperty.uProperty,tProperty.cName,tProperty.cValue,tProperty.uType,tProperty.uKey,tProperty.uOwner,tProperty.uCreatedBy,tProperty.uCreatedDate,tProperty.uModBy,tProperty.uModDate"
45
46 //Local only
47void Insert_tProperty(void);
48void Update_tProperty(char *cRowid);
49void ProcesstPropertyListVars(pentry entries[], int x);
50
51 //In tPropertyfunc.h file included below
52void ExtProcesstPropertyVars(pentry entries[], int x);
53void ExttPropertyCommands(pentry entries[], int x);
54void ExttPropertyButtons(void);
55void ExttPropertyNavBar(void);
56void ExttPropertyGetHook(entry gentries[], int x);
57void ExttPropertySelect(void);
58void ExttPropertySelectRow(void);
59void ExttPropertyListSelect(void);
60void ExttPropertyListFilter(void);
61void ExttPropertyAuxTable(void);
62
63#include "tpropertyfunc.h"
64
65 //Table Variables Assignment Function
66void ProcesstPropertyVars(pentry entries[], int x)
67{
68        register int i;
69
70
71        for(i=0;i<x;i++)
72        {
73                if(!strcmp(entries[i].name,"uProperty"))
74                        sscanf(entries[i].val,"%u",&uProperty);
75                else if(!strcmp(entries[i].name,"cName"))
76                        sprintf(cName,"%.32s",entries[i].val);
77                else if(!strcmp(entries[i].name,"cValue"))
78                        cValue=entries[i].val;
79                else if(!strcmp(entries[i].name,"uType"))
80                        sscanf(entries[i].val,"%u",&uType);
81                else if(!strcmp(entries[i].name,"cuTypePullDown"))
82                {
83                        sprintf(cuTypePullDown,"%.255s",entries[i].val);
84                        uType=ReadPullDown("tType","cLabel",cuTypePullDown);
85                }
86                else if(!strcmp(entries[i].name,"uKey"))
87                        sscanf(entries[i].val,"%u",&uKey);
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        ExtProcesstPropertyVars(entries,x);
103
104}//ProcesstPropertyVars()
105
106
107void ProcesstPropertyListVars(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",&uProperty);
116                        guMode=2002;
117                        tProperty("");
118                }
119        }
120}//void ProcesstPropertyListVars(pentry entries[], int x)
121
122
123int tPropertyCommands(pentry entries[], int x)
124{
125        ProcessControlVars(entries,x);
126
127        ExttPropertyCommands(entries,x);
128
129        if(!strcmp(gcFunction,"tPropertyTools"))
130        {
131                if(!strcmp(gcFind,LANG_NB_LIST))
132                {
133                        tPropertyList();
134                }
135
136                //Default
137                ProcesstPropertyVars(entries,x);
138                tProperty("");
139        }
140        else if(!strcmp(gcFunction,"tPropertyList"))
141        {
142                ProcessControlVars(entries,x);
143                ProcesstPropertyListVars(entries,x);
144                tPropertyList();
145        }
146
147        return(0);
148
149}//tPropertyCommands()
150
151
152void tProperty(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                        ExttPropertySelectRow();
163                else
164                        ExttPropertySelect();
165
166                mysql_query(&gMysql,gcQuery);
167                if(mysql_errno(&gMysql))
168                {
169                        if(strstr(mysql_error(&gMysql)," doesn't exist"))
170                        {
171                                CreatetProperty();
172                                unxsVZ("New tProperty 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 tProperty WHERE uProperty=%u"
186                                                ,uProperty);
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",&uProperty);
196                        sprintf(cName,"%.32s",field[1]);
197                        cValue=field[2];
198                        sscanf(field[3],"%u",&uType);
199                        sscanf(field[4],"%u",&uKey);
200                        sscanf(field[5],"%u",&uOwner);
201                        sscanf(field[6],"%u",&uCreatedBy);
202                        sscanf(field[7],"%lu",&uCreatedDate);
203                        sscanf(field[8],"%u",&uModBy);
204                        sscanf(field[9],"%lu",&uModDate);
205
206                }
207
208        }//Internal Skip
209
210        Header_ism3(":: Shared property table",0);
211        printf("<table width=100%% cellspacing=0 cellpadding=0>\n");
212        printf("<tr><td colspan=2 align=right valign=center>");
213
214
215        printf("<input type=hidden name=gcFunction value=tPropertyTools>");
216        printf("<input type=hidden name=gluRowid value=%lu>",gluRowid);
217        if(guI)
218        {
219                if(guMode==6)
220                        //printf(" Found");
221                        printf(LANG_NBR_FOUND);
222                else if(guMode==5)
223                        //printf(" Modified");
224                        printf(LANG_NBR_MODIFIED);
225                else if(guMode==4)
226                        //printf(" New");
227                        printf(LANG_NBR_NEW);
228                printf(LANG_NBRF_SHOWING,gluRowid,guI);
229        }
230        else
231        {
232                if(!cResult[0])
233                //printf(" No records found");
234                printf(LANG_NBR_NORECS);
235        }
236        if(cResult[0]) printf("%s",cResult);
237        printf("</td></tr>");
238        printf("<tr><td valign=top width=25%%>");
239
240        ExttPropertyButtons();
241
242        printf("</td><td valign=top>");
243        //
244        OpenFieldSet("tProperty Record Data",100);
245
246        if(guMode==2000 || guMode==2002)
247                tPropertyInput(1);
248        else
249                tPropertyInput(0);
250
251        //
252        CloseFieldSet();
253
254        //Bottom table
255        printf("<tr><td colspan=2>");
256        ExttPropertyAuxTable();
257
258        Footer_ism3();
259
260}//end of tProperty();
261
262
263void tPropertyInput(unsigned uMode)
264{
265
266//uProperty
267        OpenRow(LANG_FL_tProperty_uProperty,"black");
268        printf("<input title='%s' type=text name=uProperty value=%u size=16 maxlength=10 ",
269                        LANG_FT_tProperty_uProperty,uProperty);
270        if(guPermLevel>=20 && uMode)
271        {
272                printf("></td></tr>\n");
273        }
274        else
275        {
276                printf("disabled></td></tr>\n");
277                printf("<input type=hidden name=uProperty value=%u >\n",uProperty);
278        }
279//cName
280        OpenRow(LANG_FL_tProperty_cName,"black");
281        printf("<input title='%s' type=text name=cName value=\"%s\" size=40 maxlength=32 ",
282                        LANG_FT_tProperty_cName,EncodeDoubleQuotes(cName));
283        if(guPermLevel>=0 && uMode)
284        {
285                printf("></td></tr>\n");
286        }
287        else
288        {
289                printf("disabled></td></tr>\n");
290                printf("<input type=hidden name=cName value=\"%s\">\n",EncodeDoubleQuotes(cName));
291        }
292//cValue
293        OpenRow(LANG_FL_tProperty_cValue,"black");
294        printf("<textarea title='%s' cols=80 wrap=hard rows=16 name=cValue ",LANG_FT_tProperty_cValue);
295        if(guPermLevel>=0 && uMode)
296        {
297                printf(">%s</textarea></td></tr>\n",cValue);
298        }
299        else
300        {
301                printf("disabled>%s</textarea></td></tr>\n",cValue);
302                printf("<input type=hidden name=cValue value=\"%s\" >\n",EncodeDoubleQuotes(cValue));
303        }
304//uType
305        OpenRow(LANG_FL_tProperty_uType,"black");
306        if(guPermLevel>=12 && uMode)
307                tTablePullDown("tType;cuTypePullDown","cLabel","cLabel",uType,1);
308        else
309                tTablePullDown("tType;cuTypePullDown","cLabel","cLabel",uType,0);
310//uKey
311        OpenRow(LANG_FL_tProperty_uKey,"black");
312        printf("<input title='%s' type=text name=uKey value=%u size=16 maxlength=10 ",LANG_FT_tProperty_uKey,uKey);
313        if(guPermLevel>=12 && uMode)
314        {
315                printf("></td></tr>\n");
316        }
317        else
318        {
319                printf("disabled></td></tr>\n");
320                printf("<input type=hidden name=uKey value=%u >\n",uKey);
321        }
322//uOwner
323        OpenRow(LANG_FL_tProperty_uOwner,"black");
324        if(guPermLevel>=20 && uMode)
325                printf("%s<input type=hidden name=uOwner value=%u >\n",ForeignKey(TCLIENT,"cLabel",uOwner),uOwner);
326        else
327                printf("%s<input type=hidden name=uOwner value=%u >\n",ForeignKey(TCLIENT,"cLabel",uOwner),uOwner);
328//uCreatedBy
329        OpenRow(LANG_FL_tProperty_uCreatedBy,"black");
330        if(guPermLevel>=20 && uMode)
331                printf("%s<input type=hidden name=uCreatedBy value=%u >\n",
332                        ForeignKey(TCLIENT,"cLabel",uCreatedBy),uCreatedBy);
333        else
334                printf("%s<input type=hidden name=uCreatedBy value=%u >\n",
335                        ForeignKey(TCLIENT,"cLabel",uCreatedBy),uCreatedBy);
336//uCreatedDate
337        OpenRow(LANG_FL_tProperty_uCreatedDate,"black");
338        if(uCreatedDate)
339                printf("%s\n\n",ctime(&uCreatedDate));
340        else
341                printf("---\n\n");
342        printf("<input type=hidden name=uCreatedDate value=%lu >\n",uCreatedDate);
343//uModBy
344        OpenRow(LANG_FL_tProperty_uModBy,"black");
345        if(guPermLevel>=20 && uMode)
346                printf("%s<input type=hidden name=uModBy value=%u >\n",ForeignKey(TCLIENT,"cLabel",uModBy),uModBy);
347        else
348                printf("%s<input type=hidden name=uModBy value=%u >\n",ForeignKey(TCLIENT,"cLabel",uModBy),uModBy);
349//uModDate
350        OpenRow(LANG_FL_tProperty_uModDate,"black");
351        if(uModDate)
352                printf("%s\n\n",ctime(&uModDate));
353        else
354                printf("---\n\n");
355        printf("<input type=hidden name=uModDate value=%lu >\n",uModDate);
356        printf("</tr>\n");
357
358
359
360}//void tPropertyInput(unsigned uMode)
361
362
363void NewtProperty(unsigned uMode)
364{
365        register int i=0;
366        MYSQL_RES *res;
367
368        sprintf(gcQuery,"SELECT uProperty FROM tProperty WHERE uProperty=%u",uProperty);
369        MYSQL_RUN_STORE(res);
370        i=mysql_num_rows(res);
371
372        if(i)
373                //tProperty("<blink>Record already exists");
374                tProperty(LANG_NBR_RECEXISTS);
375
376        //insert query
377        Insert_tProperty();
378        if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql));
379        //sprintf(gcQuery,"New record %u added");
380        uProperty=mysql_insert_id(&gMysql);
381        uCreatedDate=luGetCreatedDate("tProperty",uProperty);
382        unxsVZLog(uProperty,"tProperty","New");
383
384        if(!uMode)
385        {
386        sprintf(gcQuery,LANG_NBR_NEWRECADDED,uProperty);
387        tProperty(gcQuery);
388        }
389
390}//NewtProperty(unsigned uMode)
391
392
393void DeletetProperty(void)
394{
395        sprintf(gcQuery,"DELETE FROM tProperty WHERE uProperty=%u AND ( uOwner=%u OR %u>9 )"
396                                        ,uProperty,guLoginClient,guPermLevel);
397        MYSQL_RUN;
398        //tProperty("Record Deleted");
399        if(mysql_affected_rows(&gMysql)>0)
400        {
401                unxsVZLog(uProperty,"tProperty","Del");
402                tProperty(LANG_NBR_RECDELETED);
403        }
404        else
405        {
406                unxsVZLog(uProperty,"tProperty","DelError");
407                tProperty(LANG_NBR_RECNOTDELETED);
408        }
409
410}//void DeletetProperty(void)
411
412
413void Insert_tProperty(void)
414{
415
416        //insert query
417        sprintf(gcQuery,"INSERT INTO tProperty SET uProperty=%u,cName='%s',cValue='%s',uType=%u,uKey=%u,uOwner=%u,"
418                        "uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())",
419                        uProperty
420                        ,TextAreaSave(cName)
421                        ,TextAreaSave(cValue)
422                        ,uType
423                        ,uKey
424                        ,uOwner
425                        ,uCreatedBy
426                        );
427
428        MYSQL_RUN;
429
430}//void Insert_tProperty(void)
431
432
433void Update_tProperty(char *cRowid)
434{
435
436        //update query
437        sprintf(gcQuery,"UPDATE tProperty SET uProperty=%u,cName='%s',cValue='%s',uType=%u,uKey=%u,uModBy=%u,"
438                        "uModDate=UNIX_TIMESTAMP(NOW()) WHERE _rowid=%s",
439                        uProperty
440                        ,TextAreaSave(cName)
441                        ,TextAreaSave(cValue)
442                        ,uType
443                        ,uKey
444                        ,uModBy
445                        ,cRowid);
446
447        MYSQL_RUN;
448
449}//void Update_tProperty(void)
450
451
452void ModtProperty(void)
453{
454        register int i=0;
455        MYSQL_RES *res;
456        MYSQL_ROW field;
457        unsigned uPreModDate=0;
458
459        sprintf(gcQuery,"SELECT uProperty,uModDate FROM tProperty WHERE uProperty=%u",uProperty);
460        MYSQL_RUN_STORE(res);
461        i=mysql_num_rows(res);
462
463        //if(i<1) tProperty("<blink>Record does not exist");
464        if(i<1) tProperty(LANG_NBR_RECNOTEXIST);
465        //if(i>1) tProperty("<blink>Multiple rows!");
466        if(i>1) tProperty(LANG_NBR_MULTRECS);
467
468        field=mysql_fetch_row(res);
469        sscanf(field[1],"%u",&uPreModDate);
470        if(uPreModDate!=uModDate) tProperty(LANG_NBR_EXTMOD);
471
472        Update_tProperty(field[0]);
473        if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql));
474        //sprintf(query,"record %s modified",field[0]);
475        sprintf(gcQuery,LANG_NBRF_REC_MODIFIED,field[0]);
476        uModDate=luGetModDate("tProperty",uProperty);
477        unxsVZLog(uProperty,"tProperty","Mod");
478        tProperty(gcQuery);
479
480}//ModtProperty(void)
481
482
483void tPropertyList(void)
484{
485        MYSQL_RES *res;
486        MYSQL_ROW field;
487
488        ExttPropertyListSelect();
489
490        MYSQL_RUN_STORE(res);
491        guI=mysql_num_rows(res);
492
493        PageMachine("tPropertyList",1,"");//1 is auto header list guMode. Opens table!
494
495        //Filter select drop down
496        ExttPropertyListFilter();
497
498        printf("<input type=text size=16 name=gcCommand maxlength=98 value=\"%s\" >",gcCommand);
499
500        printf("</table>\n");
501
502        printf("<table bgcolor=#9BC1B3 border=0 width=100%%>\n");
503        printf("<tr bgcolor=black>"
504                "<td><font face=arial,helvetica color=white>uProperty"
505                "<td><font face=arial,helvetica color=white>cName"
506                "<td><font face=arial,helvetica color=white>cValue"
507                "<td><font face=arial,helvetica color=white>uType"
508                "<td><font face=arial,helvetica color=white>uKey"
509                "<td><font face=arial,helvetica color=white>uOwner"
510                "<td><font face=arial,helvetica color=white>uCreatedBy"
511                "<td><font face=arial,helvetica color=white>uCreatedDate"
512                "<td><font face=arial,helvetica color=white>uModBy"
513                "<td><font face=arial,helvetica color=white>uModDate</tr>");
514
515        mysql_data_seek(res,guStart-1);
516
517        for(guN=0;guN<(guEnd-guStart+1);guN++)
518        {
519                field=mysql_fetch_row(res);
520                if(!field)
521                {
522                        printf("<tr><td><font face=arial,helvetica>End of data</table>");
523                        Footer_ism3();
524                }
525                        if(guN % 2)
526                                printf("<tr bgcolor=#BBE1D3>");
527                        else
528                                printf("<tr>");
529                time_t luTime7=strtoul(field[7],NULL,10);
530                char cBuf7[32];
531                if(luTime7)
532                        ctime_r(&luTime7,cBuf7);
533                else
534                        sprintf(cBuf7,"---");
535                time_t luTime9=strtoul(field[9],NULL,10);
536                char cBuf9[32];
537                if(luTime9)
538                        ctime_r(&luTime9,cBuf9);
539                else
540                        sprintf(cBuf9,"---");
541                printf("<td><input type=submit name=ED%s value=Edit> %s<td>%s<td><textarea disabled>%s</textarea>"
542                        "<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s</tr>"
543                        ,field[0]
544                        ,field[0]
545                        ,field[1]
546                        ,field[2]
547                        ,ForeignKey("tType","cLabel",strtoul(field[3],NULL,10))
548                        ,field[4]
549                        ,ForeignKey(TCLIENT,"cLabel",strtoul(field[5],NULL,10))
550                        ,ForeignKey(TCLIENT,"cLabel",strtoul(field[6],NULL,10))
551                        ,cBuf7
552                        ,ForeignKey(TCLIENT,"cLabel",strtoul(field[8],NULL,10))
553                        ,cBuf9
554                                );
555
556        }
557
558        printf("</table></form>\n");
559        Footer_ism3();
560
561}//tPropertyList()
562
563
564void CreatetProperty(void)
565{
566        sprintf(gcQuery,"CREATE TABLE IF NOT EXISTS tProperty ( "
567                        "uProperty INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,"
568                        "cName VARCHAR(32) NOT NULL DEFAULT '', INDEX (cName),"
569                        "uOwner INT UNSIGNED NOT NULL DEFAULT 0, INDEX (uOwner),"
570                        "uCreatedBy INT UNSIGNED NOT NULL DEFAULT 0,"
571                        "uCreatedDate INT UNSIGNED NOT NULL DEFAULT 0,"
572                        "uModBy INT UNSIGNED NOT NULL DEFAULT 0,"
573                        "uModDate INT UNSIGNED NOT NULL DEFAULT 0,"
574                        "cValue TEXT NOT NULL DEFAULT '',"
575                        "uKey INT UNSIGNED NOT NULL DEFAULT 0, INDEX (uKey),"
576                        "uType INT UNSIGNED NOT NULL DEFAULT 0, INDEX (uType) )");
577        mysql_query(&gMysql,gcQuery);
578        if(mysql_errno(&gMysql))
579                htmlPlainTextError(mysql_error(&gMysql));
580}//CreatetProperty()
581
Note: See TracBrowser for help on using the browser.