/* FILE tResource 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 tresourcefunc.h while RAD is still to be used. */ #include "mysqlrad.h" //Table Variables //Table Variables //uResource: Primary Key static unsigned uResource=0; //uZone: Belongs to this tZone static unsigned uZone=0; //cName: Host name relative, full or emtpy=zone static char cName[101]={""}; //uTTL: Optional TTL for this record only static unsigned uTTL=0; //uRRType: Pulldown of resource record type table static unsigned uRRType=0; static char cuRRTypePullDown[256]={""}; //cParam1: Parameter 1 field static char cParam1[256]={""}; //cParam2: Parameter 2 field static char cParam2[256]={""}; //cParam3: Parameter 3 field static char cParam3[256]={""}; //cParam4: Parameter 4 field static char cParam4[256]={""}; //cComment: Optional comment static char *cComment={""}; //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_tResource "tResource.uResource,tResource.uZone,tResource.cName,tResource.uTTL,tResource.uRRType,tResource.cParam1,tResource.cParam2,tResource.cParam3,tResource.cParam4,tResource.cComment,tResource.uOwner,tResource.uCreatedBy,tResource.uCreatedDate,tResource.uModBy,tResource.uModDate" //Local only void Insert_tResource(void); void Update_tResource(char *cRowid); void ProcesstResourceListVars(pentry entries[], int x); //In tResourcefunc.h file included below void ExtProcesstResourceVars(pentry entries[], int x); void ExttResourceCommands(pentry entries[], int x); void ExttResourceButtons(void); void ExttResourceNavBar(void); void ExttResourceGetHook(entry gentries[], int x); void ExttResourceSelect(void); void ExttResourceSelectRow(void); void ExttResourceListSelect(void); void ExttResourceListFilter(void); void ExttResourceAuxTable(void); #include "tresourcefunc.h" //Table Variables Assignment Function void ProcesstResourceVars(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(""); ExttResourceButtons(); printf(""); // OpenFieldSet("tResource Record Data",100); if(guMode==2000 || guMode==2002) tResourceInput(1); else tResourceInput(0); // CloseFieldSet(); //Bottom table printf(""); ExttResourceAuxTable(); Footer_ism3(); }//end of tResource(); void tResourceInput(unsigned uMode) { //uResource OpenRow(LANG_FL_tResource_uResource,"black"); printf("=20 && uMode) { printf(">\n"); } else { printf("disabled>\n"); printf("\n",uResource); } //uZone OpenRow(LANG_FL_tResource_uZone,IsZero(uZone)); if(guPermLevel>=20 && uMode) { printf("%s\n",ForeignKey("tZone","cZone",uZone),uZone); } else { printf("%s\n",ForeignKey("tZone","cZone",uZone),uZone); } //cName OpenRow(LANG_FL_tResource_cName,"black"); printf("=0 && uMode) { printf(">\n"); } else { printf("disabled>\n"); printf("\n",EncodeDoubleQuotes(cName)); } //uTTL OpenRow(LANG_FL_tResource_uTTL,"black"); printf("=0 && uMode) { printf(">\n"); } else { printf("disabled>\n"); printf("\n",uTTL); } //uRRType OpenRow(LANG_FL_tResource_uRRType,IsZero(uRRType)); if(guPermLevel>=0 && uMode) tTablePullDown("tRRType;cuRRTypePullDown","cLabel","cLabel",uRRType,1); else tTablePullDown("tRRType;cuRRTypePullDown","cLabel","cLabel",uRRType,0); //cParam1 OpenRow(LANG_FL_tResource_cParam1,EmptyString(cParam1)); printf("=0 && uMode) { printf(">\n"); } else { printf("disabled>\n"); printf("\n",EncodeDoubleQuotes(cParam1)); } //cParam2 OpenRow(LANG_FL_tResource_cParam2,"black"); printf("=0 && uMode) { printf(">\n"); } else { printf("disabled>\n"); printf("\n",EncodeDoubleQuotes(cParam2)); } //cParam3 OpenRow(LANG_FL_tResource_cParam3,"black"); printf("=0 && uMode) { printf(">\n"); } else { printf("disabled>\n"); printf("\n",EncodeDoubleQuotes(cParam3)); } //cParam4 OpenRow(LANG_FL_tResource_cParam4,"black"); printf("=0 && uMode) { printf(">\n"); } else { printf("disabled>\n"); printf("\n",EncodeDoubleQuotes(cParam4)); } //cComment OpenRow(LANG_FL_tResource_cComment,"black"); printf("\n",cComment); } else { printf("disabled>%s\n",cComment); printf("\n",EncodeDoubleQuotes(cComment)); } //uOwner OpenRow(LANG_FL_tResource_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_tResource_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_tResource_uCreatedDate,"black"); if(uCreatedDate) printf("%s\n\n",ctime(&uCreatedDate)); else printf("---\n\n"); printf("\n",uCreatedDate); //uModBy OpenRow(LANG_FL_tResource_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_tResource_uModDate,"black"); if(uModDate) printf("%s\n\n",ctime(&uModDate)); else printf("---\n\n"); printf("\n",uModDate); printf("\n"); }//void tResourceInput(unsigned uMode) void NewtResource(unsigned uMode) { register int i=0; MYSQL_RES *res; sprintf(gcQuery,"SELECT uResource FROM tResource\ WHERE uResource=%u" ,uResource); mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); res=mysql_store_result(&gMysql); i=mysql_num_rows(res); if(i) //tResource("Record already exists"); tResource(LANG_NBR_RECEXISTS); //insert query Insert_tResource(); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); //sprintf(gcQuery,"New record %u added"); uResource=mysql_insert_id(&gMysql); #ifdef ISM3FIELDS uCreatedDate=luGetCreatedDate("tResource",uResource); iDNSLog(uResource,"tResource","New"); #endif if(!uMode) { sprintf(gcQuery,LANG_NBR_NEWRECADDED,uResource); tResource(gcQuery); } }//NewtResource(unsigned uMode) void DeletetResource(void) { #ifdef ISM3FIELDS sprintf(gcQuery,"DELETE FROM tResource WHERE uResource=%u AND ( uOwner=%u OR %u>9 )" ,uResource,guLoginClient,guPermLevel); #else sprintf(gcQuery,"DELETE FROM tResource WHERE uResource=%u" ,uResource); #endif mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); //tResource("Record Deleted"); if(mysql_affected_rows(&gMysql)>0) { #ifdef ISM3FIELDS iDNSLog(uResource,"tResource","Del"); #endif tResource(LANG_NBR_RECDELETED); } else { #ifdef ISM3FIELDS iDNSLog(uResource,"tResource","DelError"); #endif tResource(LANG_NBR_RECNOTDELETED); } }//void DeletetResource(void) void Insert_tResource(void) { //insert query sprintf(gcQuery,"INSERT INTO tResource SET uResource=%u,uZone=%u,cName='%s',uTTL=%u,uRRType=%u,cParam1='%s',cParam2='%s',cParam3='%s',cParam4='%s',cComment='%s',uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())", uResource ,uZone ,TextAreaSave(cName) ,uTTL ,uRRType ,TextAreaSave(cParam1) ,TextAreaSave(cParam2) ,TextAreaSave(cParam3) ,TextAreaSave(cParam4) ,TextAreaSave(cComment) ,uOwner ,uCreatedBy ); mysql_query(&gMysql,gcQuery); }//void Insert_tResource(void) void Update_tResource(char *cRowid) { //update query sprintf(gcQuery,"UPDATE tResource SET uResource=%u,uZone=%u,cName='%s',uTTL=%u,uRRType=%u,cParam1='%s',cParam2='%s',cParam3='%s',cParam4='%s',cComment='%s',uModBy=%u,uModDate=UNIX_TIMESTAMP(NOW()) WHERE _rowid=%s", uResource ,uZone ,TextAreaSave(cName) ,uTTL ,uRRType ,TextAreaSave(cParam1) ,TextAreaSave(cParam2) ,TextAreaSave(cParam3) ,TextAreaSave(cParam4) ,TextAreaSave(cComment) ,uModBy ,cRowid); mysql_query(&gMysql,gcQuery); }//void Update_tResource(void) void ModtResource(void) { register int i=0; MYSQL_RES *res; MYSQL_ROW field; #ifdef ISM3FIELDS unsigned uPreModDate=0; sprintf(gcQuery,"SELECT uResource,uModDate FROM tResource WHERE uResource=%u" ,uResource); #else sprintf(gcQuery,"SELECT uResource FROM tResource WHERE uResource=%u" ,uResource); #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) tResource("Record does not exist"); if(i<1) tResource(LANG_NBR_RECNOTEXIST); //if(i>1) tResource("Multiple rows!"); if(i>1) tResource(LANG_NBR_MULTRECS); field=mysql_fetch_row(res); #ifdef ISM3FIELDS sscanf(field[1],"%u",&uPreModDate); if(uPreModDate!=uModDate) tResource(LANG_NBR_EXTMOD); #endif Update_tResource(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("tResource",uResource); iDNSLog(uResource,"tResource","Mod"); #endif tResource(gcQuery); }//ModtResource(void) void tResourceList(void) { MYSQL_RES *res; MYSQL_ROW field; ExttResourceListSelect(); mysql_query(&gMysql,gcQuery); if(mysql_error(&gMysql)[0]) htmlPlainTextError(mysql_error(&gMysql)); res=mysql_store_result(&gMysql); guI=mysql_num_rows(res); PageMachine("tResourceList",1,"");//1 is auto header list guMode. Opens table! //Filter select drop down ExttResourceListFilter(); 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("
uResourceuZonecNameuTTLuRRTypecParam1cParam2cParam3cParam4cCommentuOwneruCreatedByuCreatedDateuModByuModDate
End of data
"); Footer_ism3(); } if(guN % 2) printf(""); else printf(""); long luTime12=strtoul(field[12],NULL,10); char cBuf12[32]; if(luTime12) ctime_r(&luTime12,cBuf12); else sprintf(cBuf12,"---"); long luTime14=strtoul(field[14],NULL,10); char cBuf14[32]; if(luTime14) ctime_r(&luTime14,cBuf14); else sprintf(cBuf14,"---"); printf(" %s%s%s%s%s%s%s%s%s%s%s%s%s%s" ,field[0] ,field[0] ,ForeignKey("tZone","cZone",strtoul(field[1],NULL,10)) ,field[2] ,field[3] ,ForeignKey("tRRType","cLabel",strtoul(field[4],NULL,10)) ,field[5] ,field[6] ,field[7] ,field[8] ,field[9] ,ForeignKey(TCLIENT,"cLabel",strtoul(field[10],NULL,10)) ,ForeignKey(TCLIENT,"cLabel",strtoul(field[11],NULL,10)) ,cBuf12 ,ForeignKey(TCLIENT,"cLabel",strtoul(field[13],NULL,10)) ,cBuf14 ); } printf("\n"); Footer_ism3(); }//tResourceList() void CreatetResource(void) { sprintf(gcQuery,"CREATE TABLE IF NOT EXISTS tResource ( uResource INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, cName VARCHAR(100) 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, uTTL INT UNSIGNED NOT NULL DEFAULT 0, uRRType INT UNSIGNED NOT NULL DEFAULT 0, cParam1 VARCHAR(255) NOT NULL DEFAULT '', cParam2 VARCHAR(255) NOT NULL DEFAULT '', cComment TEXT NOT NULL DEFAULT '', uZone INT UNSIGNED NOT NULL DEFAULT 0,index (uZone), cParam3 VARCHAR(255) NOT NULL DEFAULT '', cParam4 VARCHAR(255) NOT NULL DEFAULT '' )"); mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); }//CreatetResource()