| 1 | /* |
|---|
| 2 | FILE |
|---|
| 3 | $Id$ |
|---|
| 4 | (Built initially by unixservice.com mysqlRAD2) |
|---|
| 5 | PURPOSE |
|---|
| 6 | Non schema-dependent table and application table related functions. |
|---|
| 7 | AUTHOR |
|---|
| 8 | (C) 2001-2010 Unixservice, LLC. |
|---|
| 9 | |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | void tSearchdomainNavList(void); |
|---|
| 13 | |
|---|
| 14 | //file scoped var |
|---|
| 15 | static unsigned uDatacenter=0; |
|---|
| 16 | static char cuDatacenterPullDown[256]={""}; |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | void ExtProcesstSearchdomainVars(pentry entries[], int x) |
|---|
| 20 | { |
|---|
| 21 | register int i; |
|---|
| 22 | for(i=0;i<x;i++) |
|---|
| 23 | { |
|---|
| 24 | if(!strcmp(entries[i].name,"uDatacenter")) |
|---|
| 25 | sscanf(entries[i].val,"%u",&uDatacenter); |
|---|
| 26 | else if(!strcmp(entries[i].name,"cuDatacenterPullDown")) |
|---|
| 27 | { |
|---|
| 28 | sprintf(cuDatacenterPullDown,"%.255s",entries[i].val); |
|---|
| 29 | uDatacenter=ReadPullDown("tDatacenter","cLabel",cuDatacenterPullDown); |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | }//void ExtProcesstSearchdomainVars(pentry entries[], int x) |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | void ExttSearchdomainCommands(pentry entries[], int x) |
|---|
| 36 | { |
|---|
| 37 | |
|---|
| 38 | if(!strcmp(gcFunction,"tSearchdomainTools")) |
|---|
| 39 | { |
|---|
| 40 | MYSQL_RES *res; |
|---|
| 41 | |
|---|
| 42 | if(!strcmp(gcCommand,LANG_NB_NEW)) |
|---|
| 43 | { |
|---|
| 44 | if(guPermLevel>=10) |
|---|
| 45 | { |
|---|
| 46 | ProcesstSearchdomainVars(entries,x); |
|---|
| 47 | guMode=2000; |
|---|
| 48 | tSearchdomain(LANG_NB_CONFIRMNEW); |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW)) |
|---|
| 52 | { |
|---|
| 53 | if(guPermLevel>=10) |
|---|
| 54 | { |
|---|
| 55 | ProcesstSearchdomainVars(entries,x); |
|---|
| 56 | |
|---|
| 57 | guMode=2000; |
|---|
| 58 | //Check entries here |
|---|
| 59 | if(strlen(cLabel)<3) |
|---|
| 60 | tSearchdomain("<blink>Error</blink>: cLabel too short!"); |
|---|
| 61 | sprintf(gcQuery,"SELECT uSearchdomain FROM tSearchdomain WHERE cLabel='%s'", |
|---|
| 62 | cLabel); |
|---|
| 63 | mysql_query(&gMysql,gcQuery); |
|---|
| 64 | if(mysql_errno(&gMysql)) |
|---|
| 65 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 66 | res=mysql_store_result(&gMysql); |
|---|
| 67 | if(mysql_num_rows(res)) |
|---|
| 68 | { |
|---|
| 69 | mysql_free_result(res); |
|---|
| 70 | tSearchdomain("<blink>Error</blink>: Searchdomain cLabel in use!"); |
|---|
| 71 | } |
|---|
| 72 | guMode=0; |
|---|
| 73 | |
|---|
| 74 | uSearchdomain=0; |
|---|
| 75 | uCreatedBy=guLoginClient; |
|---|
| 76 | uOwner=guCompany; |
|---|
| 77 | uModBy=0;//Never modified |
|---|
| 78 | uModDate=0;//Never modified |
|---|
| 79 | NewtSearchdomain(1); |
|---|
| 80 | if(!uSearchdomain) |
|---|
| 81 | tSearchdomain("<blink>Error</blink>: New tSearchdomain entry was not created!"); |
|---|
| 82 | |
|---|
| 83 | sprintf(gcQuery,"INSERT INTO tProperty SET uKey=%u,uType="PROP_SEARCHDOMAIN |
|---|
| 84 | ",cName='cDatacenter',cValue='All Datacenters',uOwner=%u,uCreatedBy=%u" |
|---|
| 85 | ",uCreatedDate=UNIX_TIMESTAMP(NOW())" |
|---|
| 86 | ,uSearchdomain,guCompany,guLoginClient); |
|---|
| 87 | mysql_query(&gMysql,gcQuery); |
|---|
| 88 | if(mysql_errno(&gMysql)) |
|---|
| 89 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 90 | tSearchdomain("New searchdomain created"); |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | else if(!strcmp(gcCommand,LANG_NB_DELETE)) |
|---|
| 94 | { |
|---|
| 95 | ProcesstSearchdomainVars(entries,x); |
|---|
| 96 | if(uAllowDel(uOwner,uCreatedBy)) |
|---|
| 97 | { |
|---|
| 98 | guMode=0; |
|---|
| 99 | sprintf(gcQuery,"SELECT uSearchdomain FROM tContainer WHERE uSearchdomain=%u", |
|---|
| 100 | uSearchdomain); |
|---|
| 101 | mysql_query(&gMysql,gcQuery); |
|---|
| 102 | if(mysql_errno(&gMysql)) |
|---|
| 103 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 104 | res=mysql_store_result(&gMysql); |
|---|
| 105 | if(mysql_num_rows(res)) |
|---|
| 106 | { |
|---|
| 107 | mysql_free_result(res); |
|---|
| 108 | tSearchdomain("<blink>Error</blink>: Can't delete a searchdomain" |
|---|
| 109 | " used by a container!"); |
|---|
| 110 | } |
|---|
| 111 | guMode=2001; |
|---|
| 112 | tSearchdomain(LANG_NB_CONFIRMDEL); |
|---|
| 113 | } |
|---|
| 114 | } |
|---|
| 115 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL)) |
|---|
| 116 | { |
|---|
| 117 | ProcesstSearchdomainVars(entries,x); |
|---|
| 118 | if(uAllowDel(uOwner,uCreatedBy)) |
|---|
| 119 | { |
|---|
| 120 | guMode=5; |
|---|
| 121 | sprintf(gcQuery,"SELECT uSearchdomain FROM tContainer WHERE uSearchdomain=%u", |
|---|
| 122 | uSearchdomain); |
|---|
| 123 | mysql_query(&gMysql,gcQuery); |
|---|
| 124 | if(mysql_errno(&gMysql)) |
|---|
| 125 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 126 | res=mysql_store_result(&gMysql); |
|---|
| 127 | if(mysql_num_rows(res)) |
|---|
| 128 | { |
|---|
| 129 | mysql_free_result(res); |
|---|
| 130 | tSearchdomain("<blink>Error</blink>: Can't delete a searchdomain" |
|---|
| 131 | " used by a container!"); |
|---|
| 132 | } |
|---|
| 133 | guMode=0; |
|---|
| 134 | DeletetSearchdomain(); |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | else if(!strcmp(gcCommand,LANG_NB_MODIFY)) |
|---|
| 138 | { |
|---|
| 139 | ProcesstSearchdomainVars(entries,x); |
|---|
| 140 | { |
|---|
| 141 | guMode=2002; |
|---|
| 142 | tSearchdomain(LANG_NB_CONFIRMMOD); |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD)) |
|---|
| 146 | { |
|---|
| 147 | ProcesstSearchdomainVars(entries,x); |
|---|
| 148 | { |
|---|
| 149 | guMode=2002; |
|---|
| 150 | //Check entries here |
|---|
| 151 | if(strlen(cLabel)<3) |
|---|
| 152 | tSearchdomain("<blink>Error</blink>: cLabel too short!"); |
|---|
| 153 | guMode=0; |
|---|
| 154 | |
|---|
| 155 | uModBy=guLoginClient; |
|---|
| 156 | ModtSearchdomain(); |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | else if(!strcmp(gcCommand,"Enable")) |
|---|
| 160 | { |
|---|
| 161 | ProcesstSearchdomainVars(entries,x); |
|---|
| 162 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 163 | { |
|---|
| 164 | guMode=6; |
|---|
| 165 | if(!uDatacenter) |
|---|
| 166 | sprintf(gcQuery,"INSERT tProperty SET cName='cDatacenter',cValue='All Datacenters'," |
|---|
| 167 | "uType=%u,uKey=%u,uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())", |
|---|
| 168 | uPROP_SEARCHDOMAIN,uSearchdomain,uOwner,guLoginClient); |
|---|
| 169 | else |
|---|
| 170 | sprintf(gcQuery,"INSERT tProperty SET cName='cDatacenter',cValue='%s'," |
|---|
| 171 | "uType=%u,uKey=%u,uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())", |
|---|
| 172 | ForeignKey("tDatacenter","cLabel",uDatacenter), |
|---|
| 173 | uPROP_SEARCHDOMAIN,uSearchdomain,uOwner,guLoginClient); |
|---|
| 174 | mysql_query(&gMysql,gcQuery); |
|---|
| 175 | if(mysql_errno(&gMysql)) |
|---|
| 176 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 177 | } |
|---|
| 178 | else |
|---|
| 179 | { |
|---|
| 180 | tSearchdomain("<blink>Error</blink>: Enable not allowed!"); |
|---|
| 181 | } |
|---|
| 182 | } |
|---|
| 183 | else if(!strcmp(gcCommand,"Disable")) |
|---|
| 184 | { |
|---|
| 185 | ProcesstSearchdomainVars(entries,x); |
|---|
| 186 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 187 | { |
|---|
| 188 | guMode=6; |
|---|
| 189 | if(!uDatacenter) |
|---|
| 190 | sprintf(gcQuery,"DELETE FROM tProperty WHERE cName='cDatacenter' AND cValue='All Datacenters'" |
|---|
| 191 | " AND uType=%u AND uKey=%u AND (uOwner=%u OR uCreatedBy=%u)", |
|---|
| 192 | uPROP_SEARCHDOMAIN,uSearchdomain,uOwner,guLoginClient); |
|---|
| 193 | else |
|---|
| 194 | sprintf(gcQuery,"DELETE FROM tProperty WHERE cName='cDatacenter' AND cValue='%s'" |
|---|
| 195 | " AND uType=%u AND uKey=%u AND (uOwner=%u OR uCreatedBy=%u)", |
|---|
| 196 | ForeignKey("tDatacenter","cLabel",uDatacenter), |
|---|
| 197 | uPROP_SEARCHDOMAIN,uSearchdomain,uOwner,guLoginClient); |
|---|
| 198 | mysql_query(&gMysql,gcQuery); |
|---|
| 199 | if(mysql_errno(&gMysql)) |
|---|
| 200 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 201 | } |
|---|
| 202 | else |
|---|
| 203 | { |
|---|
| 204 | tSearchdomain("<blink>Error</blink>: Disable not allowed!"); |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | }//void ExttSearchdomainCommands(pentry entries[], int x) |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | void ExttSearchdomainButtons(void) |
|---|
| 213 | { |
|---|
| 214 | OpenFieldSet("tSearchdomain Aux Panel",100); |
|---|
| 215 | switch(guMode) |
|---|
| 216 | { |
|---|
| 217 | case 2000: |
|---|
| 218 | printf("<p><u>Enter/mod data</u><br>"); |
|---|
| 219 | printf(LANG_NBB_CONFIRMNEW); |
|---|
| 220 | break; |
|---|
| 221 | |
|---|
| 222 | case 2001: |
|---|
| 223 | printf("<p><u>Think twice</u><br>"); |
|---|
| 224 | printf(LANG_NBB_CONFIRMDEL); |
|---|
| 225 | break; |
|---|
| 226 | |
|---|
| 227 | case 2002: |
|---|
| 228 | printf("<p><u>Review changes</u><br>"); |
|---|
| 229 | printf(LANG_NBB_CONFIRMMOD); |
|---|
| 230 | break; |
|---|
| 231 | |
|---|
| 232 | default: |
|---|
| 233 | printf("<u>Table Tips</u><br>"); |
|---|
| 234 | printf("<p><u>Record Context Info</u><br>"); |
|---|
| 235 | tSearchdomainNavList(); |
|---|
| 236 | } |
|---|
| 237 | CloseFieldSet(); |
|---|
| 238 | |
|---|
| 239 | }//void ExttSearchdomainButtons(void) |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | void ExttSearchdomainAuxTable(void) |
|---|
| 243 | { |
|---|
| 244 | if(!uSearchdomain || guMode==2000 )//uMODE_NEW |
|---|
| 245 | return; |
|---|
| 246 | |
|---|
| 247 | MYSQL_RES *res; |
|---|
| 248 | MYSQL_ROW field; |
|---|
| 249 | |
|---|
| 250 | sprintf(gcQuery,"tSearchdomain %s Property Panel",cLabel); |
|---|
| 251 | OpenFieldSet(gcQuery,100); |
|---|
| 252 | sprintf(gcQuery,"SELECT uProperty,cName,cValue FROM tProperty WHERE uKey=%u AND uType="PROP_SEARCHDOMAIN |
|---|
| 253 | " ORDER BY cName",uSearchdomain); |
|---|
| 254 | |
|---|
| 255 | mysql_query(&gMysql,gcQuery); |
|---|
| 256 | if(mysql_errno(&gMysql)) |
|---|
| 257 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 258 | |
|---|
| 259 | res=mysql_store_result(&gMysql); |
|---|
| 260 | printf("<table cols=2>"); |
|---|
| 261 | if(mysql_num_rows(res)) |
|---|
| 262 | { |
|---|
| 263 | while((field=mysql_fetch_row(res))) |
|---|
| 264 | { |
|---|
| 265 | printf("<tr>\n"); |
|---|
| 266 | printf("<td width=200 valign=top><a class=darkLink href=unxsVZ.cgi?" |
|---|
| 267 | "gcFunction=tProperty&uProperty=%s&cReturn=tSearchdomain_%u>" |
|---|
| 268 | "%s</a></td><td>%s</td>\n", |
|---|
| 269 | field[0],uSearchdomain,field[1],field[2]); |
|---|
| 270 | printf("</tr>\n"); |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | //Simple interface to add to tConfiguration table |
|---|
| 275 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 276 | { |
|---|
| 277 | printf("<tr>"); |
|---|
| 278 | printf("<td width=200 valign=top><input type=submit class=largeButton" |
|---|
| 279 | " title='Enable for one or more datacenters; for new container creation'" |
|---|
| 280 | " name=gcCommand value='Enable'><p>"); |
|---|
| 281 | printf("<input type=submit class=largeButton" |
|---|
| 282 | " title='Disable for one or more datacenters; for new container creation'" |
|---|
| 283 | " name=gcCommand value='Disable'</td>"); |
|---|
| 284 | printf("<td valign=top> Select a datacenter or none (---) for all "); |
|---|
| 285 | tTablePullDown("tDatacenter;cuDatacenterPullDown","cLabel","cLabel",uDatacenter,1); |
|---|
| 286 | printf("</td>"); |
|---|
| 287 | printf("</tr>\n"); |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | printf("</table>"); |
|---|
| 291 | |
|---|
| 292 | CloseFieldSet(); |
|---|
| 293 | |
|---|
| 294 | }//void ExttSearchdomainAuxTable(void) |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | void ExttSearchdomainGetHook(entry gentries[], int x) |
|---|
| 298 | { |
|---|
| 299 | register int i; |
|---|
| 300 | |
|---|
| 301 | for(i=0;i<x;i++) |
|---|
| 302 | { |
|---|
| 303 | if(!strcmp(gentries[i].name,"uSearchdomain")) |
|---|
| 304 | { |
|---|
| 305 | sscanf(gentries[i].val,"%u",&uSearchdomain); |
|---|
| 306 | guMode=6; |
|---|
| 307 | } |
|---|
| 308 | } |
|---|
| 309 | tSearchdomain(""); |
|---|
| 310 | |
|---|
| 311 | }//void ExttSearchdomainGetHook(entry gentries[], int x) |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | void ExttSearchdomainSelect(void) |
|---|
| 315 | { |
|---|
| 316 | ExtSelect("tSearchdomain",VAR_LIST_tSearchdomain); |
|---|
| 317 | |
|---|
| 318 | }//void ExttSearchdomainSelect(void) |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | void ExttSearchdomainSelectRow(void) |
|---|
| 322 | { |
|---|
| 323 | ExtSelectRow("tSearchdomain",VAR_LIST_tSearchdomain,uSearchdomain); |
|---|
| 324 | |
|---|
| 325 | }//void ExttSearchdomainSelectRow(void) |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | void ExttSearchdomainListSelect(void) |
|---|
| 329 | { |
|---|
| 330 | char cCat[512]; |
|---|
| 331 | |
|---|
| 332 | ExtListSelect("tSearchdomain",VAR_LIST_tSearchdomain); |
|---|
| 333 | |
|---|
| 334 | //Changes here must be reflected below in ExttSearchdomainListFilter() |
|---|
| 335 | if(!strcmp(gcFilter,"uSearchdomain")) |
|---|
| 336 | { |
|---|
| 337 | sscanf(gcCommand,"%u",&uSearchdomain); |
|---|
| 338 | if(guLoginClient==1 && guPermLevel>11) |
|---|
| 339 | strcat(gcQuery," WHERE "); |
|---|
| 340 | else |
|---|
| 341 | strcat(gcQuery," AND "); |
|---|
| 342 | sprintf(cCat,"tSearchdomain.uSearchdomain=%u ORDER BY uSearchdomain", |
|---|
| 343 | uSearchdomain); |
|---|
| 344 | strcat(gcQuery,cCat); |
|---|
| 345 | } |
|---|
| 346 | else if(1) |
|---|
| 347 | { |
|---|
| 348 | //None NO FILTER |
|---|
| 349 | strcpy(gcFilter,"None"); |
|---|
| 350 | strcat(gcQuery," ORDER BY uSearchdomain"); |
|---|
| 351 | } |
|---|
| 352 | |
|---|
| 353 | }//void ExttSearchdomainListSelect(void) |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | void ExttSearchdomainListFilter(void) |
|---|
| 357 | { |
|---|
| 358 | //Filter |
|---|
| 359 | printf(" Filter on "); |
|---|
| 360 | printf("<select name=gcFilter>"); |
|---|
| 361 | if(strcmp(gcFilter,"uSearchdomain")) |
|---|
| 362 | printf("<option>uSearchdomain</option>"); |
|---|
| 363 | else |
|---|
| 364 | printf("<option selected>uSearchdomain</option>"); |
|---|
| 365 | if(strcmp(gcFilter,"None")) |
|---|
| 366 | printf("<option>None</option>"); |
|---|
| 367 | else |
|---|
| 368 | printf("<option selected>None</option>"); |
|---|
| 369 | printf("</select>"); |
|---|
| 370 | |
|---|
| 371 | }//void ExttSearchdomainListFilter(void) |
|---|
| 372 | |
|---|
| 373 | |
|---|
| 374 | void ExttSearchdomainNavBar(void) |
|---|
| 375 | { |
|---|
| 376 | if(uOwner) GetClientOwner(uOwner,&guReseller); |
|---|
| 377 | |
|---|
| 378 | printf(LANG_NBB_SKIPFIRST); |
|---|
| 379 | printf(LANG_NBB_SKIPBACK); |
|---|
| 380 | printf(LANG_NBB_SEARCH); |
|---|
| 381 | |
|---|
| 382 | if(guPermLevel>=10 && !guListMode) |
|---|
| 383 | printf(LANG_NBB_NEW); |
|---|
| 384 | |
|---|
| 385 | printf(LANG_NBB_MODIFY); |
|---|
| 386 | |
|---|
| 387 | printf(LANG_NBB_DELETE); |
|---|
| 388 | |
|---|
| 389 | if(uOwner) |
|---|
| 390 | printf(LANG_NBB_LIST); |
|---|
| 391 | |
|---|
| 392 | printf(LANG_NBB_SKIPNEXT); |
|---|
| 393 | printf(LANG_NBB_SKIPLAST); |
|---|
| 394 | printf(" \n"); |
|---|
| 395 | |
|---|
| 396 | }//void ExttSearchdomainNavBar(void) |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | void tSearchdomainNavList(void) |
|---|
| 400 | { |
|---|
| 401 | MYSQL_RES *res; |
|---|
| 402 | MYSQL_ROW field; |
|---|
| 403 | |
|---|
| 404 | ExtSelect("tSearchdomain","tSearchdomain.uSearchdomain,tSearchdomain.cLabel"); |
|---|
| 405 | |
|---|
| 406 | mysql_query(&gMysql,gcQuery); |
|---|
| 407 | if(mysql_errno(&gMysql)) |
|---|
| 408 | { |
|---|
| 409 | printf("<p><u>tSearchdomainNavList</u><br>\n"); |
|---|
| 410 | printf("%s",mysql_error(&gMysql)); |
|---|
| 411 | return; |
|---|
| 412 | } |
|---|
| 413 | |
|---|
| 414 | res=mysql_store_result(&gMysql); |
|---|
| 415 | if(mysql_num_rows(res)) |
|---|
| 416 | { |
|---|
| 417 | printf("<p><u>tSearchdomainNavList</u><br>\n"); |
|---|
| 418 | |
|---|
| 419 | while((field=mysql_fetch_row(res))) |
|---|
| 420 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tSearchdomain&" |
|---|
| 421 | "uSearchdomain=%s>%s</a><br>\n",field[0],field[1]); |
|---|
| 422 | } |
|---|
| 423 | mysql_free_result(res); |
|---|
| 424 | |
|---|
| 425 | }//void tSearchdomainNavList(void) |
|---|
| 426 | |
|---|
| 427 | |
|---|