root/trunk/tclient.c

Revision 444, 15.1 KB (checked in by Gary, 3 years ago)

unxsVZ changed to new tClient/tAuthorize with MD5 passwords and other features. Fixed typo in unxsBind/mysqlrad.h.

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