/* FILE tTemplate source code of iDNS.cgi Built by mysqlRAD2.cgi (C) Gary Wallis and Hugo Urquiza 2001-2009 $Id$ PURPOSE Schema dependent RAD generated file. Program app functionality in ttemplatefunc.h while RAD is still to be used. */ #include "mysqlrad.h" //Table Variables //Table Variables //uTemplate: Primary Key static unsigned uTemplate=0; //cLabel: Short label static char cLabel[33]={""}; //uTemplateSet: Short label static unsigned uTemplateSet=0; static char cuTemplateSetPullDown[256]={""}; //uTemplateType: Short label static unsigned uTemplateType=0; static char cuTemplateTypePullDown[256]={""}; //cComment: About the template static char *cComment={""}; //cTemplate: Template itself static char *cTemplate={""}; //uOwner: Record owner static unsigned uOwner=0; //uCreatedBy: uClient for last insert static unsigned uCreatedBy=0; #define ISM3FIELDS //uCreatedDate: Unix seconds date last insert static long uCreatedDate=0; //uModBy: uClient for last update static unsigned uModBy=0; //uModDate: Unix seconds date last update static long uModDate=0; #define VAR_LIST_tTemplate "tTemplate.uTemplate,tTemplate.cLabel,tTemplate.uTemplateSet,tTemplate.uTemplateType,tTemplate.cComment,tTemplate.cTemplate,tTemplate.uOwner,tTemplate.uCreatedBy,tTemplate.uCreatedDate,tTemplate.uModBy,tTemplate.uModDate" //Local only void Insert_tTemplate(void); void Update_tTemplate(char *cRowid); void ProcesstTemplateListVars(pentry entries[], int x); //In tTemplatefunc.h file included below void ExtProcesstTemplateVars(pentry entries[], int x); void ExttTemplateCommands(pentry entries[], int x); void ExttTemplateButtons(void); void ExttTemplateNavBar(void); void ExttTemplateGetHook(entry gentries[], int x); void ExttTemplateSelect(void); void ExttTemplateSelectRow(void); void ExttTemplateListSelect(void); void ExttTemplateListFilter(void); void ExttTemplateAuxTable(void); #include "ttemplatefunc.h" //Table Variables Assignment Function void ProcesstTemplateVars(pentry entries[], int x) { register int i; for(i=0;i\n"); printf(""); printf(""); printf("",gluRowid); if(guI) { if(guMode==6) //printf(" Found"); printf(LANG_NBR_FOUND); else if(guMode==5) //printf(" Modified"); printf(LANG_NBR_MODIFIED); else if(guMode==4) //printf(" New"); printf(LANG_NBR_NEW); printf(LANG_NBRF_SHOWING,gluRowid,guI); } else { if(!cResult[0]) //printf(" No records found"); printf(LANG_NBR_NORECS); } if(cResult[0]) printf("%s",cResult); printf(""); printf(""); ExttTemplateButtons(); printf(""); // OpenFieldSet("tTemplate Record Data",100); if(guMode==2000 || guMode==2002) tTemplateInput(1); else tTemplateInput(0); // CloseFieldSet(); //Bottom table printf(""); ExttTemplateAuxTable(); Footer_ism3(); }//end of tTemplate(); void tTemplateInput(unsigned uMode) { //uTemplate OpenRow(LANG_FL_tTemplate_uTemplate,"black"); printf("=20 && uMode) { printf(">\n"); } else { printf("disabled>\n"); printf("\n",uTemplate); } //cLabel OpenRow(LANG_FL_tTemplate_cLabel,"black"); printf("=7 && uMode) { printf(">\n"); } else { printf("disabled>\n"); printf("\n",EncodeDoubleQuotes(cLabel)); } //uTemplateSet OpenRow(LANG_FL_tTemplate_uTemplateSet,"black"); if(guPermLevel>=7 && uMode) tTablePullDown("tTemplateSet;cuTemplateSetPullDown","cLabel","cLabel",uTemplateSet,1); else tTablePullDown("tTemplateSet;cuTemplateSetPullDown","cLabel","cLabel",uTemplateSet,0); //uTemplateType OpenRow(LANG_FL_tTemplate_uTemplateType,"black"); if(guPermLevel>=7 && uMode) tTablePullDown("tTemplateType;cuTemplateTypePullDown","cLabel","cLabel",uTemplateType,1); else tTablePullDown("tTemplateType;cuTemplateTypePullDown","cLabel","cLabel",uTemplateType,0); //cComment OpenRow(LANG_FL_tTemplate_cComment,"black"); printf("\n",cComment); } else { printf("disabled>%s\n",cComment); printf("\n",EncodeDoubleQuotes(cComment)); } //cTemplate OpenRow(LANG_FL_tTemplate_cTemplate,"black"); printf("\n",cTemplate); } else { printf("disabled>%s\n",cTemplate); printf("\n",EncodeDoubleQuotes(cTemplate)); } //uOwner OpenRow(LANG_FL_tTemplate_uOwner,"black"); if(guPermLevel>=20 && uMode) { printf("%s\n",ForeignKey(TCLIENT,"cLabel",uOwner),uOwner); } else { printf("%s\n",ForeignKey(TCLIENT,"cLabel",uOwner),uOwner); } //uCreatedBy OpenRow(LANG_FL_tTemplate_uCreatedBy,"black"); if(guPermLevel>=20 && uMode) { printf("%s\n",ForeignKey(TCLIENT,"cLabel",uCreatedBy),uCreatedBy); } else { printf("%s\n",ForeignKey(TCLIENT,"cLabel",uCreatedBy),uCreatedBy); } //uCreatedDate OpenRow(LANG_FL_tTemplate_uCreatedDate,"black"); if(uCreatedDate) printf("%s\n\n",ctime(&uCreatedDate)); else printf("---\n\n"); printf("\n",uCreatedDate); //uModBy OpenRow(LANG_FL_tTemplate_uModBy,"black"); if(guPermLevel>=20 && uMode) { printf("%s\n",ForeignKey(TCLIENT,"cLabel",uModBy),uModBy); } else { printf("%s\n",ForeignKey(TCLIENT,"cLabel",uModBy),uModBy); } //uModDate OpenRow(LANG_FL_tTemplate_uModDate,"black"); if(uModDate) printf("%s\n\n",ctime(&uModDate)); else printf("---\n\n"); printf("\n",uModDate); printf("\n"); }//void tTemplateInput(unsigned uMode) void NewtTemplate(unsigned uMode) { register int i=0; MYSQL_RES *res; sprintf(gcQuery,"SELECT uTemplate FROM tTemplate\ WHERE uTemplate=%u" ,uTemplate); mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); res=mysql_store_result(&gMysql); i=mysql_num_rows(res); if(i) //tTemplate("Record already exists"); tTemplate(LANG_NBR_RECEXISTS); //insert query Insert_tTemplate(); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); //sprintf(gcQuery,"New record %u added"); uTemplate=mysql_insert_id(&gMysql); #ifdef ISM3FIELDS uCreatedDate=luGetCreatedDate("tTemplate",uTemplate); iDNSLog(uTemplate,"tTemplate","New"); #endif if(!uMode) { sprintf(gcQuery,LANG_NBR_NEWRECADDED,uTemplate); tTemplate(gcQuery); } }//NewtTemplate(unsigned uMode) void DeletetTemplate(void) { #ifdef ISM3FIELDS sprintf(gcQuery,"DELETE FROM tTemplate WHERE uTemplate=%u AND ( uOwner=%u OR %u>9 )" ,uTemplate,guLoginClient,guPermLevel); #else sprintf(gcQuery,"DELETE FROM tTemplate WHERE uTemplate=%u" ,uTemplate); #endif mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); //tTemplate("Record Deleted"); if(mysql_affected_rows(&gMysql)>0) { #ifdef ISM3FIELDS iDNSLog(uTemplate,"tTemplate","Del"); #endif tTemplate(LANG_NBR_RECDELETED); } else { #ifdef ISM3FIELDS iDNSLog(uTemplate,"tTemplate","DelError"); #endif tTemplate(LANG_NBR_RECNOTDELETED); } }//void DeletetTemplate(void) void Insert_tTemplate(void) { //insert query sprintf(gcQuery,"INSERT INTO tTemplate SET uTemplate=%u,cLabel='%s',uTemplateSet=%u,uTemplateType=%u,cComment='%s',cTemplate='%s',uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())", uTemplate ,TextAreaSave(cLabel) ,uTemplateSet ,uTemplateType ,TextAreaSave(cComment) ,TextAreaSave(cTemplate) ,uOwner ,uCreatedBy ); mysql_query(&gMysql,gcQuery); }//void Insert_tTemplate(void) void Update_tTemplate(char *cRowid) { //update query sprintf(gcQuery,"UPDATE tTemplate SET uTemplate=%u,cLabel='%s',uTemplateSet=%u,uTemplateType=%u,cComment='%s',cTemplate='%s',uModBy=%u,uModDate=UNIX_TIMESTAMP(NOW()) WHERE _rowid=%s", uTemplate ,TextAreaSave(cLabel) ,uTemplateSet ,uTemplateType ,TextAreaSave(cComment) ,TextAreaSave(cTemplate) ,uModBy ,cRowid); mysql_query(&gMysql,gcQuery); }//void Update_tTemplate(void) void ModtTemplate(void) { register int i=0; MYSQL_RES *res; MYSQL_ROW field; #ifdef ISM3FIELDS unsigned uPreModDate=0; sprintf(gcQuery,"SELECT uTemplate,uModDate FROM tTemplate WHERE uTemplate=%u" ,uTemplate); #else sprintf(gcQuery,"SELECT uTemplate FROM tTemplate WHERE uTemplate=%u" ,uTemplate); #endif mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); res=mysql_store_result(&gMysql); i=mysql_num_rows(res); //if(i<1) tTemplate("Record does not exist"); if(i<1) tTemplate(LANG_NBR_RECNOTEXIST); //if(i>1) tTemplate("Multiple rows!"); if(i>1) tTemplate(LANG_NBR_MULTRECS); field=mysql_fetch_row(res); #ifdef ISM3FIELDS sscanf(field[1],"%u",&uPreModDate); if(uPreModDate!=uModDate) tTemplate(LANG_NBR_EXTMOD); #endif Update_tTemplate(field[0]); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); //sprintf(query,"record %s modified",field[0]); sprintf(gcQuery,LANG_NBRF_REC_MODIFIED,field[0]); #ifdef ISM3FIELDS uModDate=luGetModDate("tTemplate",uTemplate); iDNSLog(uTemplate,"tTemplate","Mod"); #endif tTemplate(gcQuery); }//ModtTemplate(void) void tTemplateList(void) { MYSQL_RES *res; MYSQL_ROW field; ExttTemplateListSelect(); mysql_query(&gMysql,gcQuery); if(mysql_error(&gMysql)[0]) htmlPlainTextError(mysql_error(&gMysql)); res=mysql_store_result(&gMysql); guI=mysql_num_rows(res); PageMachine("tTemplateList",1,"");//1 is auto header list guMode. Opens table! //Filter select drop down ExttTemplateListFilter(); printf("",gcCommand); printf("\n"); printf("\n"); printf(""); mysql_data_seek(res,guStart-1); for(guN=0;guN<(guEnd-guStart+1);guN++) { field=mysql_fetch_row(res); if(!field) { printf("
uTemplatecLabeluTemplateSetuTemplateTypecCommentcTemplateuOwneruCreatedByuCreatedDateuModByuModDate
End of data
"); Footer_ism3(); } if(guN % 2) printf(""); else printf(""); long luTime8=strtoul(field[8],NULL,10); char cBuf8[32]; if(luTime8) ctime_r(&luTime8,cBuf8); else sprintf(cBuf8,"---"); long luTime10=strtoul(field[10],NULL,10); char cBuf10[32]; if(luTime10) ctime_r(&luTime10,cBuf10); else sprintf(cBuf10,"---"); printf(" %s%s%s%s%s%s%s%s%s" ,field[0] ,field[0] ,field[1] ,ForeignKey("tTemplateSet","cLabel",strtoul(field[2],NULL,10)) ,ForeignKey("tTemplateType","cLabel",strtoul(field[3],NULL,10)) ,field[4] ,field[5] ,ForeignKey(TCLIENT,"cLabel",strtoul(field[6],NULL,10)) ,ForeignKey(TCLIENT,"cLabel",strtoul(field[7],NULL,10)) ,cBuf8 ,ForeignKey(TCLIENT,"cLabel",strtoul(field[9],NULL,10)) ,cBuf10 ); } printf("\n"); Footer_ism3(); }//tTemplateList() void CreatetTemplate(void) { sprintf(gcQuery,"CREATE TABLE IF NOT EXISTS tTemplate ( uTemplate 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, cComment TEXT NOT NULL DEFAULT '', cTemplate TEXT NOT NULL DEFAULT '', uTemplateSet INT UNSIGNED NOT NULL DEFAULT 0, uTemplateType INT UNSIGNED NOT NULL DEFAULT 0 )"); mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); }//CreatetTemplate()